diff --git a/dom/base/nsDOMCID.h b/dom/base/nsDOMCID.h index 94eca9e0947b..c1e60a1847df 100644 --- a/dom/base/nsDOMCID.h +++ b/dom/base/nsDOMCID.h @@ -20,6 +20,9 @@ 0x45f27d10, 0x987b, 0x11d2, \ {0xbd, 0x40, 0x00, 0x10, 0x5a, 0xa4, 0x5e, 0x89} } +#define SERVICEWORKERPERIODICUPDATER_CONTRACTID \ + "@mozilla.org/service-worker-periodic-updater;1" + //The dom cannot provide the crypto or pkcs11 classes that //were used in older days, so if someone wants to provide //the service they must implement an object and give it diff --git a/dom/workers/ServiceWorkerPeriodicUpdater.cpp b/dom/workers/ServiceWorkerPeriodicUpdater.cpp new file mode 100644 index 000000000000..a08b807d9db1 --- /dev/null +++ b/dom/workers/ServiceWorkerPeriodicUpdater.cpp @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "ServiceWorkerPeriodicUpdater.h" +#include "mozilla/ClearOnShutdown.h" + +#define OBSERVER_TOPIC_IDLE_DAILY "idle-daily" + +namespace mozilla { +namespace dom { +namespace workers { + +NS_IMPL_ISUPPORTS(ServiceWorkerPeriodicUpdater, nsIObserver) + +StaticRefPtr +ServiceWorkerPeriodicUpdater::sInstance; + +already_AddRefed +ServiceWorkerPeriodicUpdater::GetSingleton() +{ + MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default); + + if (!sInstance) { + sInstance = new ServiceWorkerPeriodicUpdater(); + ClearOnShutdown(&sInstance); + } + nsRefPtr copy(sInstance.get()); + return copy.forget(); +} + +ServiceWorkerPeriodicUpdater::ServiceWorkerPeriodicUpdater() +{ +} + +ServiceWorkerPeriodicUpdater::~ServiceWorkerPeriodicUpdater() +{ +} + +NS_IMETHODIMP +ServiceWorkerPeriodicUpdater::Observe(nsISupports* aSubject, + const char* aTopic, + const char16_t* aData) +{ + if (strcmp(aTopic, OBSERVER_TOPIC_IDLE_DAILY) == 0) { + // TODO: Update the service workers NOW!!!!! + } + + return NS_OK; +} + +} // namespace workers +} // namespace dom +} // namespace mozilla diff --git a/dom/workers/ServiceWorkerPeriodicUpdater.h b/dom/workers/ServiceWorkerPeriodicUpdater.h new file mode 100644 index 000000000000..ce46d96ddd0a --- /dev/null +++ b/dom/workers/ServiceWorkerPeriodicUpdater.h @@ -0,0 +1,37 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_ServiceWorkerPeriodicUpdater_h +#define mozilla_ServiceWorkerPeriodicUpdater_h + +#include "nsCOMPtr.h" +#include "nsIObserver.h" +#include "mozilla/StaticPtr.h" + +namespace mozilla { +namespace dom { +namespace workers { + +class ServiceWorkerPeriodicUpdater final : public nsIObserver +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIOBSERVER + + static already_AddRefed GetSingleton(); + +private: + ServiceWorkerPeriodicUpdater(); + ~ServiceWorkerPeriodicUpdater(); + + static StaticRefPtr sInstance; +}; + +} // namespace workers +} // namespace dom +} // namespace mozilla + +#endif diff --git a/dom/workers/moz.build b/dom/workers/moz.build index a984308c9604..62e4fae699a6 100644 --- a/dom/workers/moz.build +++ b/dom/workers/moz.build @@ -18,6 +18,7 @@ EXPORTS.mozilla.dom += [ EXPORTS.mozilla.dom.workers += [ 'ServiceWorkerManager.h', + 'ServiceWorkerPeriodicUpdater.h', 'WorkerDebuggerManager.h', 'Workers.h', ] @@ -68,6 +69,7 @@ UNIFIED_SOURCES += [ 'ServiceWorkerContainer.cpp', 'ServiceWorkerEvents.cpp', 'ServiceWorkerManager.cpp', + 'ServiceWorkerPeriodicUpdater.cpp', 'ServiceWorkerRegistrar.cpp', 'ServiceWorkerRegistration.cpp', 'ServiceWorkerScriptCache.cpp', diff --git a/layout/build/nsLayoutCID.h b/layout/build/nsLayoutCID.h index 5e7d639b86cc..e48fc281d2d8 100644 --- a/layout/build/nsLayoutCID.h +++ b/layout/build/nsLayoutCID.h @@ -82,4 +82,8 @@ #define SERVICEWORKERMANAGER_CID \ { 0xc74bde32, 0xbcc7, 0x4840, { 0x84, 0x30, 0xc7, 0x33, 0x35, 0x1b, 0x21, 0x2a } } +// {91f43ef6-8159-457a-ba68-249c3ff7a06a} +#define SERVICEWORKERPERIODICUPDATER_CID \ +{ 0x91f43ef6, 0x8159, 0x457a, { 0xba, 0x68, 0x24, 0x9c, 0x3f, 0xf7, 0xa0, 0x6a } } + #endif /* nsLayoutCID_h__ */ diff --git a/layout/build/nsLayoutModule.cpp b/layout/build/nsLayoutModule.cpp index c6846a395c94..2e122fd82d99 100644 --- a/layout/build/nsLayoutModule.cpp +++ b/layout/build/nsLayoutModule.cpp @@ -90,6 +90,7 @@ #include "mozilla/dom/network/UDPSocketChild.h" #include "mozilla/dom/quota/QuotaManager.h" #include "mozilla/dom/workers/ServiceWorkerManager.h" +#include "mozilla/dom/workers/ServiceWorkerPeriodicUpdater.h" #include "mozilla/dom/workers/WorkerDebuggerManager.h" #include "mozilla/OSFileConstants.h" #include "mozilla/Services.h" @@ -263,6 +264,7 @@ using mozilla::dom::alarm::AlarmHalService; using mozilla::dom::power::PowerManagerService; using mozilla::dom::quota::QuotaManager; using mozilla::dom::workers::ServiceWorkerManager; +using mozilla::dom::workers::ServiceWorkerPeriodicUpdater; using mozilla::dom::workers::WorkerDebuggerManager; using mozilla::dom::TCPSocketChild; using mozilla::dom::TCPSocketParent; @@ -308,6 +310,8 @@ NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(QuotaManager, QuotaManager::FactoryCreate) NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(ServiceWorkerManager, ServiceWorkerManager::FactoryCreate) +NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(ServiceWorkerPeriodicUpdater, + ServiceWorkerPeriodicUpdater::GetSingleton) NS_GENERIC_FACTORY_CONSTRUCTOR(WorkerDebuggerManager) #ifdef MOZ_WIDGET_GONK @@ -748,6 +752,7 @@ NS_DEFINE_NAMED_CID(NS_TEXTEDITOR_CID); NS_DEFINE_NAMED_CID(DOMREQUEST_SERVICE_CID); NS_DEFINE_NAMED_CID(QUOTA_MANAGER_CID); NS_DEFINE_NAMED_CID(SERVICEWORKERMANAGER_CID); +NS_DEFINE_NAMED_CID(SERVICEWORKERPERIODICUPDATER_CID); NS_DEFINE_NAMED_CID(WORKERDEBUGGERMANAGER_CID); #ifdef MOZ_WIDGET_GONK NS_DEFINE_NAMED_CID(SYSTEMWORKERMANAGER_CID); @@ -1051,6 +1056,7 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = { { &kDOMREQUEST_SERVICE_CID, false, nullptr, DOMRequestServiceConstructor }, { &kQUOTA_MANAGER_CID, false, nullptr, QuotaManagerConstructor }, { &kSERVICEWORKERMANAGER_CID, false, nullptr, ServiceWorkerManagerConstructor }, + { &kSERVICEWORKERPERIODICUPDATER_CID, false, nullptr, ServiceWorkerPeriodicUpdaterConstructor }, { &kWORKERDEBUGGERMANAGER_CID, true, nullptr, WorkerDebuggerManagerConstructor }, #ifdef MOZ_WIDGET_GONK { &kSYSTEMWORKERMANAGER_CID, true, nullptr, SystemWorkerManagerConstructor }, @@ -1214,6 +1220,7 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = { { DOMREQUEST_SERVICE_CONTRACTID, &kDOMREQUEST_SERVICE_CID }, { QUOTA_MANAGER_CONTRACTID, &kQUOTA_MANAGER_CID }, { SERVICEWORKERMANAGER_CONTRACTID, &kSERVICEWORKERMANAGER_CID }, + { SERVICEWORKERPERIODICUPDATER_CONTRACTID, &kSERVICEWORKERPERIODICUPDATER_CID, Module::MAIN_PROCESS_ONLY }, { WORKERDEBUGGERMANAGER_CONTRACTID, &kWORKERDEBUGGERMANAGER_CID }, #ifdef MOZ_WIDGET_GONK { SYSTEMWORKERMANAGER_CONTRACTID, &kSYSTEMWORKERMANAGER_CID }, @@ -1321,6 +1328,7 @@ static const mozilla::Module::CategoryEntry kLayoutCategories[] = { { "profile-after-change", "Bluetooth Service", BLUETOOTHSERVICE_CONTRACTID }, #endif { "profile-after-change", "PresentationDeviceManager", PRESENTATION_DEVICE_MANAGER_CONTRACTID }, + { "idle-daily", "ServiceWorker Periodic Updater", SERVICEWORKERPERIODICUPDATER_CONTRACTID }, { nullptr } };