Bug 552829 - e10s - Online and offline events. r=dougt

This commit is contained in:
Frederic Plourde<frederic.plourde@polymtl.ca> 2010-05-11 08:44:12 -04:00
parent 15cf233a2e
commit 4a5814f643
6 changed files with 45 additions and 0 deletions

View File

@ -152,6 +152,17 @@ ContentProcessChild::RecvRegisterChrome(const nsTArray<ChromePackage>& packages,
return true;
}
bool
ContentProcessChild::RecvSetOffline(const PRBool& offline)
{
nsCOMPtr<nsIIOService> io (do_GetIOService());
NS_ASSERTION(io, "IO Service can not be null");
io->SetOffline(offline);
return true;
}
void
ContentProcessChild::Quit()
{

View File

@ -83,6 +83,8 @@ public:
const nsTArray<ResourceMapping>& resources,
const nsTArray<OverrideMapping>& overrides);
virtual bool RecvSetOffline(const PRBool& offline);
private:
NS_OVERRIDE
virtual void ActorDestroy(ActorDestroyReason why);

View File

@ -57,6 +57,8 @@ using mozilla::MonitorAutoEnter;
namespace mozilla {
namespace dom {
#define NS_E10S_IOSERVICE_SET_OFFLINE_TOPIC "e10s:network:set-offline"
ContentProcessParent* ContentProcessParent::gSingleton;
ContentProcessParent*
@ -75,6 +77,8 @@ ContentProcessParent::GetSingleton(PRBool aForceNew)
PR_FALSE))) {
gSingleton = parent;
}
obs->AddObserver(
parent, NS_E10S_IOSERVICE_SET_OFFLINE_TOPIC, PR_FALSE);
}
nsCOMPtr<nsIThreadInternal>
threadInt(do_QueryInterface(NS_GetCurrentThread()));
@ -180,6 +184,12 @@ ContentProcessParent::Observe(nsISupports* aSubject,
NewRunnableFunction(DeleteSubprocess, mSubprocess));
mSubprocess = nsnull;
}
if (!strcmp(aTopic, NS_E10S_IOSERVICE_SET_OFFLINE_TOPIC) && mSubprocess) {
NS_ConvertUTF16toUTF8 dataStr(aData);
const char *offline = dataStr.get();
SendSetOffline(!strcmp(offline, "true") ? true : false);
}
return NS_OK;
}

View File

@ -64,6 +64,8 @@ child:
RegisterChrome(ChromePackage[] packages, ResourceMapping[] resources,
OverrideMapping[] overrides);
async SetOffline(PRBool offline);
parent:
PNecko();
};

View File

@ -74,6 +74,7 @@
#include "nsTArray.h"
#include "nsIConsoleService.h"
#include "nsIUploadChannel2.h"
#include "nsXULAppAPI.h"
#if defined(XP_WIN) || defined(MOZ_ENABLE_LIBCONIC)
#include "nsNativeConnectionHelper.h"
@ -662,11 +663,25 @@ nsIOService::SetOffline(PRBool offline)
if (mSettingOffline) {
return NS_OK;
}
mSettingOffline = PR_TRUE;
nsCOMPtr<nsIObserverService> observerService =
do_GetService("@mozilla.org/observer-service;1");
NS_ASSERTION(observerService, "The observer service should not be null");
#ifdef MOZ_IPC
if (XRE_GetProcessType() == GeckoProcessType_Default) {
if (observerService) {
(void)observerService->NotifyObservers(nsnull,
NS_E10S_IOSERVICE_SET_OFFLINE_TOPIC, offline ?
NS_LITERAL_STRING("true").get() :
NS_LITERAL_STRING("false").get());
}
}
#endif
while (mSetOfflineValue != mOffline) {
offline = mSetOfflineValue;

View File

@ -60,6 +60,11 @@
#define NS_N(x) (sizeof(x)/sizeof(*x))
// We don't want to expose this observer topic.
// Intended internal use only for remoting offline/inline events.
// See Bug 552829
#define NS_E10S_IOSERVICE_SET_OFFLINE_TOPIC "e10s:network:set-offline"
static const char gScheme[][sizeof("resource")] =
{"chrome", "file", "http", "jar", "resource"};