Bug 1112469 - Part 2: Update the service workers in the parent and all child processes every day; r=nsm

This commit is contained in:
Ehsan Akhgari 2015-04-13 13:36:06 -04:00
parent f8f4fef68c
commit 0dc6170284
7 changed files with 66 additions and 2 deletions

View File

@ -33,7 +33,7 @@ interface nsIServiceWorkerInfo : nsISupports
readonly attribute DOMString waitingCacheName;
};
[scriptable, builtinclass, uuid(3cd3acce-8c80-4fcc-9265-067ebe8cab92)]
[scriptable, builtinclass, uuid(c05b3b45-7f39-458c-8097-afafc7d69b01)]
interface nsIServiceWorkerManager : nsISupports
{
/**
@ -124,6 +124,8 @@ interface nsIServiceWorkerManager : nsISupports
void sendPushEvent(in ACString scope, in DOMString data);
void sendPushSubscriptionChangedEvent(in ACString scope);
void updateAllRegistrations();
};
%{ C++

View File

@ -78,6 +78,7 @@
#include "nsIMutable.h"
#include "nsIObserverService.h"
#include "nsIScriptSecurityManager.h"
#include "nsIServiceWorkerManager.h"
#include "nsScreenManagerProxy.h"
#include "nsMemoryInfoDumper.h"
#include "nsServiceManagerUtils.h"
@ -1239,6 +1240,16 @@ ContentChild::RecvBidiKeyboardNotify(const bool& aIsLangRTL)
return true;
}
bool
ContentChild::RecvUpdateServiceWorkerRegistrations()
{
nsCOMPtr<nsIServiceWorkerManager> swm = mozilla::services::GetServiceWorkerManager();
if (swm) {
swm->UpdateAllRegistrations();
}
return true;
}
static CancelableTask* sFirstIdleTask;
static void FirstIdle(void)

View File

@ -301,6 +301,8 @@ public:
virtual bool RecvBidiKeyboardNotify(const bool& isLangRTL) override;
virtual bool RecvUpdateServiceWorkerRegistrations() override;
virtual bool RecvNotifyVisited(const URIParams& aURI) override;
// auto remove when alertfinished is received.
nsresult AddRemoteAlertObserver(const nsString& aData, nsIObserver* aObserver);

View File

@ -465,6 +465,8 @@ child:
*/
async BidiKeyboardNotify(bool isLangRTL);
async UpdateServiceWorkerRegistrations();
async DataStoreNotify(uint32_t aAppId, nsString aName,
nsString aManifestURL);

View File

@ -34,6 +34,7 @@
#include "mozilla/ipc/BackgroundChild.h"
#include "mozilla/ipc/PBackgroundChild.h"
#include "mozilla/ipc/PBackgroundSharedTypes.h"
#include "mozilla/unused.h"
#include "nsContentUtils.h"
#include "nsGlobalWindow.h"
@ -3110,6 +3111,28 @@ ServiceWorkerManager::GetAllRegistrations(nsIArray** aResult)
return NS_OK;
}
static PLDHashOperator
UpdateEachRegistration(const nsACString& aKey,
ServiceWorkerRegistrationInfo* aInfo,
void* aUserArg) {
auto This = static_cast<ServiceWorkerManager*>(aUserArg);
MOZ_ASSERT(!aInfo->mScope.IsEmpty());
nsresult res = This->Update(NS_ConvertUTF8toUTF16(aInfo->mScope));
unused << NS_WARN_IF(NS_FAILED(res));
return PL_DHASH_NEXT;
}
NS_IMETHODIMP
ServiceWorkerManager::UpdateAllRegistrations()
{
AssertIsOnMainThread();
mServiceWorkerRegistrationInfos.EnumerateRead(UpdateEachRegistration, this);
return NS_OK;
}
void
ServiceWorkerInfo::AppendWorker(ServiceWorker* aWorker)
{

View File

@ -6,6 +6,10 @@
#include "ServiceWorkerPeriodicUpdater.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/unused.h"
#include "mozilla/Services.h"
#include "mozilla/dom/ContentParent.h"
#include "nsIServiceWorkerManager.h"
#define OBSERVER_TOPIC_IDLE_DAILY "idle-daily"
@ -45,7 +49,19 @@ ServiceWorkerPeriodicUpdater::Observe(nsISupports* aSubject,
const char16_t* aData)
{
if (strcmp(aTopic, OBSERVER_TOPIC_IDLE_DAILY) == 0) {
// TODO: Update the service workers NOW!!!!!
// First, update all registrations in the parent process.
nsCOMPtr<nsIServiceWorkerManager> swm =
mozilla::services::GetServiceWorkerManager();
if (swm) {
swm->UpdateAllRegistrations();
}
// Now, tell all child processes to update their registrations as well.
nsTArray<ContentParent*> children;
ContentParent::GetAll(children);
for (uint32_t i = 0; i < children.Length(); i++) {
unused << children[i]->SendUpdateServiceWorkerRegistrations();
}
}
return NS_OK;

View File

@ -15,6 +15,14 @@ namespace mozilla {
namespace dom {
namespace workers {
/**
* This XPCOM component is main-process only, which means that it will never
* get instantiated in child processes. When we receive the idle-daily
* notification in this component, we iterate over all PContent children, and
* send each one a message that will trigger a call to
* nsIServiceWorkerManager::UpdateAllRegistrations() in all child processes.
*/
class ServiceWorkerPeriodicUpdater final : public nsIObserver
{
public: