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

Unified Diff: content/browser/service_worker/service_worker_context.h

Issue 62203007: Implement memory-persistent registration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove some stray #includes Created 7 years, 1 month 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.h
diff --git a/content/browser/service_worker/service_worker_context.h b/content/browser/service_worker/service_worker_context.h
index f69599ca4c12a7f7cfddab0cc14c5d4c494afede..3f963cb5c9930fcc114591f09e5ea69a5f07063b 100644
--- a/content/browser/service_worker/service_worker_context.h
+++ b/content/browser/service_worker/service_worker_context.h
@@ -5,9 +5,16 @@
#ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_H_
#define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_H_
+#include <map>
+#include <string>
+
+#include "base/bind.h"
#include "base/files/file_path.h"
+#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
+#include "content/browser/service_worker/service_worker_registration.h"
#include "content/common/content_export.h"
+#include "url/gurl.h"
namespace base {
class FilePath;
@@ -19,14 +26,19 @@ class QuotaManagerProxy;
namespace content {
+class ServiceWorkerRegistration;
+
// This class manages metadata associated with all service workers,
// including:
// - persistent storage of pattern -> service worker scripts
// - initialization and initial installation of service workers
// - dispatching of non-fetch events to service workers
class CONTENT_EXPORT ServiceWorkerContext
- : public base::RefCountedThreadSafe<ServiceWorkerContext> {
+ : NON_EXPORTED_BASE(
+ public base::RefCountedThreadSafe<ServiceWorkerContext>) {
public:
+ typedef base::Callback<void(int64)> ResponseCallback;
+
// This is owned by the StoragePartition, which will supply it with
// the local path on disk.
ServiceWorkerContext(const base::FilePath& path,
@@ -34,13 +46,53 @@ class CONTENT_EXPORT ServiceWorkerContext
bool IsEnabled();
+ // The callback will be called on the IO thread.
+ void RegisterServiceWorker(const GURL& pattern,
+ const GURL& script_url,
+ const ResponseCallback& callback);
+
+ // The callback will be called on the IO thread.
+ void UnregisterServiceWorker(const GURL& pattern,
+ const base::Closure& callback);
+
+ // TODO(alecflett): These exist primarily for testing. As this class
+ // evolves to have persistent storage, they will need to become
+ // asynchronous.
+ scoped_refptr<ServiceWorkerRegistration> RegistrationForDocument(
+ const GURL& document_url);
+ scoped_refptr<ServiceWorkerRegistration> RegistrationForPattern(
+ const GURL& pattern);
+
private:
friend class base::RefCountedThreadSafe<ServiceWorkerContext>;
~ServiceWorkerContext();
+ // TODO(alecflett): These are temporary internal methods mainly for
+ // exposure to tests. These should eventually call through to some
+ // sort of ServiceWorkerStorage interface which will be
+ // asynchronous.
+ scoped_refptr<ServiceWorkerRegistration> Register(const GURL& pattern,
+ const GURL& script_url);
+ void Unregister(const GURL& pattern);
+ static bool PatternMatches(const GURL& pattern, const GURL& script_url);
+
+ FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextTest,
+ DifferentMatchDifferentRegistration);
+ FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextTest,
+ SameDocumentSameRegistration);
+ FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextTest, SameMatchSameRegistration);
+ FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextTest, RegisterMatch);
+
scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_;
base::FilePath path_;
+ // Mapping of url pattern -> script instance
+ // eventually the registration should be stored in leveldb, not in memory.
+ typedef std::map<GURL, scoped_refptr<ServiceWorkerRegistration> >
+ PatternToRegistrationMap;
+
+ PatternToRegistrationMap registration_by_pattern_;
+
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContext);
};

Powered by Google App Engine
This is Rietveld 408576698