BackgroundDataBridgeParent.cpp (2444B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #include "mozilla/net/BackgroundDataBridgeParent.h" 6 #include "mozilla/net/SocketProcessChild.h" 7 8 namespace mozilla { 9 namespace net { 10 11 BackgroundDataBridgeParent::BackgroundDataBridgeParent(uint64_t aChannelID) 12 : mChannelID(aChannelID), mBackgroundThread(GetCurrentSerialEventTarget()) { 13 if (SocketProcessChild* child = SocketProcessChild::GetSingleton()) { 14 child->AddDataBridgeToMap(aChannelID, this); 15 } 16 } 17 18 void BackgroundDataBridgeParent::ActorDestroy(ActorDestroyReason aWhy) { 19 if (SocketProcessChild* child = SocketProcessChild::GetSingleton()) { 20 child->RemoveDataBridgeFromMap(mChannelID); 21 } 22 } 23 24 already_AddRefed<nsISerialEventTarget> 25 BackgroundDataBridgeParent::GetBackgroundThread() { 26 return do_AddRef(mBackgroundThread); 27 } 28 29 void BackgroundDataBridgeParent::Destroy() { 30 RefPtr<BackgroundDataBridgeParent> self = this; 31 MOZ_ALWAYS_SUCCEEDS(mBackgroundThread->Dispatch( 32 NS_NewRunnableFunction("BackgroundDataBridgeParent::Destroy", 33 [self]() { 34 if (self->CanSend()) { 35 self->Close(); 36 } 37 }), 38 NS_DISPATCH_NORMAL)); 39 } 40 41 void BackgroundDataBridgeParent::OnStopRequest( 42 nsresult aStatus, const ResourceTimingStructArgs& aTiming, 43 const TimeStamp& aLastActiveTabOptHit, 44 const nsHttpHeaderArray& aResponseTrailers, 45 const TimeStamp& aOnStopRequestStart) { 46 RefPtr<BackgroundDataBridgeParent> self = this; 47 MOZ_ALWAYS_SUCCEEDS(mBackgroundThread->Dispatch( 48 NS_NewRunnableFunction("BackgroundDataBridgeParent::OnStopRequest", 49 [self, aStatus, aTiming, aLastActiveTabOptHit, 50 aResponseTrailers, aOnStopRequestStart]() { 51 if (self->CanSend()) { 52 (void)self->SendOnStopRequest( 53 aStatus, aTiming, aLastActiveTabOptHit, 54 aResponseTrailers, aOnStopRequestStart); 55 self->Close(); 56 } 57 }), 58 NS_DISPATCH_NORMAL)); 59 } 60 61 } // namespace net 62 } // namespace mozilla