OLD | NEW |
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 |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 // Represents the per-StoragePartition ServiceWorker data. | 23 // Represents the per-StoragePartition ServiceWorker data. |
24 class ServiceWorkerContext { | 24 class ServiceWorkerContext { |
25 public: | 25 public: |
26 // https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/
index.html#url-scope: | 26 // https://rawgithub.com/slightlyoff/ServiceWorker/master/spec/service_worker/
index.html#url-scope: |
27 // roughly, must be of the form "<origin>/<path>/*". | 27 // roughly, must be of the form "<origin>/<path>/*". |
28 typedef GURL Scope; | 28 typedef GURL Scope; |
29 | 29 |
30 typedef base::Callback<void(bool success)> ResultCallback; | 30 typedef base::Callback<void(bool success)> ResultCallback; |
31 | 31 |
| 32 typedef base::Callback<void(const std::string& data, |
| 33 bool success, |
| 34 bool not_found)> GetUserDataCallback; |
| 35 |
32 typedef base::Callback<void(const std::vector<ServiceWorkerUsageInfo>& | 36 typedef base::Callback<void(const std::vector<ServiceWorkerUsageInfo>& |
33 usage_info)> GetUsageInfoCallback; | 37 usage_info)> GetUsageInfoCallback; |
34 | 38 |
35 // Registers the header name which should not be passed to the ServiceWorker. | 39 // Registers the header name which should not be passed to the ServiceWorker. |
36 // Must be called from the IO thread. | 40 // Must be called from the IO thread. |
37 CONTENT_EXPORT static void AddExcludedHeadersForFetchEvent( | 41 CONTENT_EXPORT static void AddExcludedHeadersForFetchEvent( |
38 const std::set<std::string>& header_names); | 42 const std::set<std::string>& header_names); |
39 | 43 |
40 // Returns true if the header name should not be passed to the ServiceWorker. | 44 // Returns true if the header name should not be passed to the ServiceWorker. |
41 // Must be called from the IO thread. | 45 // Must be called from the IO thread. |
(...skipping 22 matching lines...) Expand all Loading... |
64 // renderer, except that |pattern| is an absolute URL instead of relative to | 68 // 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 | 69 // some current origin. |callback| is passed true when the JS promise is |
66 // fulfilled or false when the JS promise is rejected. | 70 // fulfilled or false when the JS promise is rejected. |
67 // | 71 // |
68 // Unregistration can fail if: | 72 // Unregistration can fail if: |
69 // * No Service Worker was registered for |pattern|. | 73 // * No Service Worker was registered for |pattern|. |
70 // * Something unexpected goes wrong, like a renderer crash. | 74 // * Something unexpected goes wrong, like a renderer crash. |
71 virtual void UnregisterServiceWorker(const Scope& pattern, | 75 virtual void UnregisterServiceWorker(const Scope& pattern, |
72 const ResultCallback& callback) = 0; | 76 const ResultCallback& callback) = 0; |
73 | 77 |
| 78 // Provide a storage mechanism to read/write arbitrary data associated with |
| 79 // a registration. Each registration has its own key namespace. Stored data |
| 80 // is deleted when the associated registraton is deleted. Must all be called |
| 81 // from the IO thread. |
| 82 virtual void GetUserData(int64 registration_id, |
| 83 const std::string& key, |
| 84 const GetUserDataCallback& callback) = 0; |
| 85 virtual void StoreUserData(int64 registration_id, |
| 86 const GURL& origin, |
| 87 const std::string& key, |
| 88 const std::string& data, |
| 89 const ResultCallback& callback) = 0; |
| 90 virtual void ClearUserData(int64 registration_id, |
| 91 const std::string& key, |
| 92 const ResultCallback& callback) = 0; |
| 93 |
74 // TODO(jyasskin): Provide a way to SendMessage to a Scope. | 94 // TODO(jyasskin): Provide a way to SendMessage to a Scope. |
75 | 95 |
76 // Determines if a request for 'url' can be satisfied while offline. | 96 // Determines if a request for 'url' can be satisfied while offline. |
77 // This method always completes asynchronously. | 97 // This method always completes asynchronously. |
78 virtual void CanHandleMainResourceOffline(const GURL& url, | 98 virtual void CanHandleMainResourceOffline(const GURL& url, |
79 const GURL& first_party, | 99 const GURL& first_party, |
80 const net::CompletionCallback& | 100 const net::CompletionCallback& |
81 callback) = 0; | 101 callback) = 0; |
82 | 102 |
83 // Methods used in response to browsing data and quota manager requests. | 103 // Methods used in response to browsing data and quota manager requests. |
84 virtual void GetAllOriginsInfo(const GetUsageInfoCallback& callback) = 0; | 104 virtual void GetAllOriginsInfo(const GetUsageInfoCallback& callback) = 0; |
85 virtual void DeleteForOrigin(const GURL& origin_url) = 0; | 105 virtual void DeleteForOrigin(const GURL& origin_url) = 0; |
86 | 106 |
87 protected: | 107 protected: |
88 ServiceWorkerContext() {} | 108 ServiceWorkerContext() {} |
89 virtual ~ServiceWorkerContext() {} | 109 virtual ~ServiceWorkerContext() {} |
90 }; | 110 }; |
91 | 111 |
92 } // namespace content | 112 } // namespace content |
93 | 113 |
94 #endif // CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ | 114 #endif // CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ |
OLD | NEW |