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

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

Issue 875573002: Service Worker: Expose Get/Store/ClearUserData to content layer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@publicrouter
Patch Set: Callback on IO thread Created 5 years, 11 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ 5 #ifndef CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_
6 #define CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ 6 #define CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback_forward.h" 12 #include "base/callback_forward.h"
13 #include "content/public/browser/service_worker_usage_info.h" 13 #include "content/public/browser/service_worker_usage_info.h"
14 #include "net/base/completion_callback.h" 14 #include "net/base/completion_callback.h"
15 #include "url/gurl.h" 15 #include "url/gurl.h"
16 16
17 namespace net { 17 namespace net {
18 class URLRequest; 18 class URLRequest;
19 } 19 }
20 20
21 namespace content { 21 namespace content {
22 22
23 class BrowserContext;
nhiroki 2015/01/26 11:52:30 nit: not necessary?
johnme 2015/01/26 11:58:54 Done.
24
23 // Represents the per-StoragePartition ServiceWorker data. 25 // Represents the per-StoragePartition ServiceWorker data.
24 class ServiceWorkerContext { 26 class ServiceWorkerContext {
25 public: 27 public:
26 // https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/ index.html#url-scope: 28 // https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/ index.html#url-scope:
27 // roughly, must be of the form "<origin>/<path>/*". 29 // roughly, must be of the form "<origin>/<path>/*".
28 typedef GURL Scope; 30 typedef GURL Scope;
29 31
30 typedef base::Callback<void(bool success)> ResultCallback; 32 typedef base::Callback<void(bool success)> ResultCallback;
31 33
34 typedef base::Callback<void(const std::string& data,
35 bool success,
36 bool not_found)> GetUserDataCallback;
37
32 typedef base::Callback<void(const std::vector<ServiceWorkerUsageInfo>& 38 typedef base::Callback<void(const std::vector<ServiceWorkerUsageInfo>&
33 usage_info)> GetUsageInfoCallback; 39 usage_info)> GetUsageInfoCallback;
34 40
35 // Registers the header name which should not be passed to the ServiceWorker. 41 // Registers the header name which should not be passed to the ServiceWorker.
36 // Must be called from the IO thread. 42 // Must be called from the IO thread.
37 CONTENT_EXPORT static void AddExcludedHeadersForFetchEvent( 43 CONTENT_EXPORT static void AddExcludedHeadersForFetchEvent(
38 const std::set<std::string>& header_names); 44 const std::set<std::string>& header_names);
39 45
40 // Returns true if the header name should not be passed to the ServiceWorker. 46 // Returns true if the header name should not be passed to the ServiceWorker.
41 // Must be called from the IO thread. 47 // Must be called from the IO thread.
(...skipping 22 matching lines...) Expand all
64 // renderer, except that |pattern| is an absolute URL instead of relative to 70 // renderer, except that |pattern| is an absolute URL instead of relative to
65 // some current origin. |callback| is passed true when the JS promise is 71 // some current origin. |callback| is passed true when the JS promise is
66 // fulfilled or false when the JS promise is rejected. 72 // fulfilled or false when the JS promise is rejected.
67 // 73 //
68 // Unregistration can fail if: 74 // Unregistration can fail if:
69 // * No Service Worker was registered for |pattern|. 75 // * No Service Worker was registered for |pattern|.
70 // * Something unexpected goes wrong, like a renderer crash. 76 // * Something unexpected goes wrong, like a renderer crash.
71 virtual void UnregisterServiceWorker(const Scope& pattern, 77 virtual void UnregisterServiceWorker(const Scope& pattern,
72 const ResultCallback& callback) = 0; 78 const ResultCallback& callback) = 0;
73 79
80 // Provide a storage mechanism to read/write arbitrary data associated with
81 // a registration. Each registration has its own key namespace. Stored data
82 // is deleted when the associated registraton is deleted. Must all be called
83 // from the IO thread.
84 virtual void GetUserData(int64 registration_id,
85 const std::string& key,
86 const GetUserDataCallback& callback) = 0;
87 virtual void StoreUserData(int64 registration_id,
88 const GURL& origin,
89 const std::string& key,
90 const std::string& data,
91 const ResultCallback& callback) = 0;
92 virtual void ClearUserData(int64 registration_id,
93 const std::string& key,
94 const ResultCallback& callback) = 0;
95
74 // TODO(jyasskin): Provide a way to SendMessage to a Scope. 96 // TODO(jyasskin): Provide a way to SendMessage to a Scope.
75 97
76 // Determines if a request for 'url' can be satisfied while offline. 98 // Determines if a request for 'url' can be satisfied while offline.
77 // This method always completes asynchronously. 99 // This method always completes asynchronously.
78 virtual void CanHandleMainResourceOffline(const GURL& url, 100 virtual void CanHandleMainResourceOffline(const GURL& url,
79 const GURL& first_party, 101 const GURL& first_party,
80 const net::CompletionCallback& 102 const net::CompletionCallback&
81 callback) = 0; 103 callback) = 0;
82 104
83 // Methods used in response to browsing data and quota manager requests. 105 // Methods used in response to browsing data and quota manager requests.
84 virtual void GetAllOriginsInfo(const GetUsageInfoCallback& callback) = 0; 106 virtual void GetAllOriginsInfo(const GetUsageInfoCallback& callback) = 0;
85 virtual void DeleteForOrigin(const GURL& origin_url) = 0; 107 virtual void DeleteForOrigin(const GURL& origin_url) = 0;
86 108
87 protected: 109 protected:
88 ServiceWorkerContext() {} 110 ServiceWorkerContext() {}
89 virtual ~ServiceWorkerContext() {} 111 virtual ~ServiceWorkerContext() {}
90 }; 112 };
91 113
92 } // namespace content 114 } // namespace content
93 115
94 #endif // CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ 116 #endif // CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698