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

Side by Side Diff: content/public/browser/service_worker_context.h

Issue 208843004: Add the beginning of a public Service Worker API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Switch to a bool 'success' result. Created 6 years, 9 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/content_browser.gypi ('k') | content/public/browser/storage_partition.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_H_ 5 #ifndef CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_H_ 6 #define CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/callback_forward.h"
10 #include "url/gurl.h"
9 11
10 namespace content { 12 namespace content {
11 13
12 // Represents the per-BrowserContext ServiceWorker data. 14 // Represents the per-StoragePartition ServiceWorker data. Must be used from
15 // the UI thread.
13 class ServiceWorkerContext { 16 class ServiceWorkerContext {
14 public: 17 public:
15 // TODO(michaeln): This class is a place holder for content/public api 18 // https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/ index.html#url-scope:
16 // which will come later. Promote this class when we get there. 19 // roughly, must be of the form "<origin>/<path>/*".
20 typedef GURL Scope;
21
22 typedef base::Callback<void(bool success)> ResultCallback;
23
24 // Equivalent to calling navigator.serviceWorker.register(script_url, {scope:
25 // pattern}) from a renderer in |source_process_id|, except that |pattern| is
26 // an absolute URL instead of relative to some current origin. |callback| is
27 // passed true when the JS promise is fulfilled or false when the JS
28 // promise is rejected.
29 //
30 // The registration can fail if:
31 // * |script_url| is on a different origin from |pattern|
32 // * Fetching |script_url| fails.
33 // * |script_url| fails to parse or its top-level execution fails.
34 // TODO: The error message for this needs to be available to developers.
35 // * Something unexpected goes wrong, like a renderer crash or a full disk.
36 virtual void RegisterServiceWorker(const Scope& pattern,
37 const GURL& script_url,
38 int source_process_id,
39 const ResultCallback& callback) = 0;
40
41 // Equivalent to calling navigator.serviceWorker.unregister(pattern) from a
42 // renderer in |source_process_id|, except that |pattern| is an absolute URL
43 // instead of relative to some current origin. |callback| is passed true
44 // when the JS promise is fulfilled or false when the JS promise is rejected.
45 //
46 // Unregistration can fail if:
47 // * No Service Worker was registered for |pattern|.
48 // * Something unexpected goes wrong, like a renderer crash.
49 virtual void UnregisterServiceWorker(const Scope& pattern,
50 int source_process_id,
51 const ResultCallback& callback) = 0;
52
53 // TODO(jyasskin): Provide a way to SendMessage to a Scope.
17 54
18 protected: 55 protected:
19 ServiceWorkerContext() {} 56 ServiceWorkerContext() {}
20 virtual ~ServiceWorkerContext() {} 57 virtual ~ServiceWorkerContext() {}
21
22 private:
23 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContext);
24 }; 58 };
25 59
26 } // namespace content 60 } // namespace content
27 61
28 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_H_ 62 #endif // CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_
OLDNEW
« no previous file with comments | « content/content_browser.gypi ('k') | content/public/browser/storage_partition.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698