Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(472)

Unified Diff: content/browser/service_worker/service_worker_context_core.cc

Issue 62203007: Implement memory-persistent registration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix variable that we don't need anymore Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_context_core.cc
diff --git a/content/browser/service_worker/service_worker_context_core.cc b/content/browser/service_worker/service_worker_context_core.cc
index 22ae50070557838d6d3f29d6b7a80abf9bb36805..19b6c7feb51d15bb4eeabbfc81aaa5ab0ab6cfa0 100644
--- a/content/browser/service_worker/service_worker_context_core.cc
+++ b/content/browser/service_worker/service_worker_context_core.cc
@@ -6,29 +6,23 @@
#include "base/command_line.h"
#include "base/files/file_path.h"
+#include "base/strings/string_util.h"
#include "content/browser/service_worker/service_worker_provider_host.h"
+#include "content/browser/service_worker/service_worker_register_job.h"
+#include "content/browser/service_worker/service_worker_registration.h"
+#include "content/browser/service_worker/service_worker_storage.h"
+#include "content/public/browser/browser_thread.h"
#include "content/public/common/content_switches.h"
-#include "webkit/browser/quota/quota_manager.h"
+#include "url/gurl.h"
namespace content {
-namespace {
-
-const base::FilePath::CharType kServiceWorkerDirectory[] =
- FILE_PATH_LITERAL("ServiceWorker");
-
-} // namespace
-
ServiceWorkerContextCore::ServiceWorkerContextCore(
- const base::FilePath& user_data_directory,
+ const base::FilePath& path,
quota::QuotaManagerProxy* quota_manager_proxy)
- : quota_manager_proxy_(quota_manager_proxy) {
- if (!user_data_directory.empty())
- path_ = user_data_directory.Append(kServiceWorkerDirectory);
-}
+ : storage_(new ServiceWorkerStorage(path, quota_manager_proxy)) {}
-ServiceWorkerContextCore::~ServiceWorkerContextCore() {
-}
+ServiceWorkerContextCore::~ServiceWorkerContextCore() {}
ServiceWorkerProviderHost* ServiceWorkerContextCore::GetProviderHost(
int process_id, int provider_id) {
@@ -67,4 +61,51 @@ bool ServiceWorkerContextCore::IsEnabled() {
switches::kEnableServiceWorker);
}
+void ServiceWorkerContextCore::RegisterServiceWorker(
+ const GURL& pattern,
+ const GURL& script_url,
+ const RegistrationCallback& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+
+ storage_->Register(pattern,
+ script_url,
+ base::Bind(&ServiceWorkerContextCore::RegistrationComplete,
+ AsWeakPtr(),
+ callback));
+}
+
+void ServiceWorkerContextCore::UnregisterServiceWorker(
+ const GURL& pattern,
+ const UnregistrationCallback& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+
+ storage_->Unregister(
+ pattern,
+ base::Bind(&ServiceWorkerContextCore::UnregistrationComplete,
+ AsWeakPtr(),
+ callback));
+}
+
+void ServiceWorkerContextCore::RegistrationComplete(
+ const ServiceWorkerContextCore::RegistrationCallback& callback,
+ ServiceWorkerRegistrationStatus status,
+ const scoped_refptr<ServiceWorkerRegistration>& registration) {
+ if (status != REGISTRATION_OK) {
+ DCHECK(!registration);
+ callback.Run(status, -1L);
+ }
+
+ callback.Run(status, registration->id());
+}
+
+void ServiceWorkerContextCore::UnregistrationComplete(
+ const UnregistrationCallback& callback,
+ ServiceWorkerRegistrationStatus status) {
+ // Unregistering a non-existent registration is a no-op.
+ if (status == REGISTRATION_OK || status == REGISTRATION_NOT_FOUND)
+ callback.Run(REGISTRATION_OK);
+ else
+ callback.Run(status);
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698