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_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_DISPATCHER_
H_ | 5 #ifndef CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_DISPATCHER_
H_ |
6 #define CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_DISPATCHER_
H_ | 6 #define CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_DISPATCHER_
H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/id_map.h" | 10 #include "base/id_map.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "content/child/worker_task_runner.h" |
15 #include "content/public/renderer/render_process_observer.h" | 16 #include "content/public/renderer/render_process_observer.h" |
16 #include "third_party/WebKit/public/platform/WebServiceWorkerCache.h" | 17 #include "third_party/WebKit/public/platform/WebServiceWorkerCache.h" |
17 #include "third_party/WebKit/public/platform/WebServiceWorkerCacheError.h" | 18 #include "third_party/WebKit/public/platform/WebServiceWorkerCacheError.h" |
18 #include "third_party/WebKit/public/platform/WebServiceWorkerCacheStorage.h" | 19 #include "third_party/WebKit/public/platform/WebServiceWorkerCacheStorage.h" |
19 | 20 |
20 namespace content { | 21 namespace content { |
21 | 22 |
| 23 class ServiceWorkerScriptContext; |
| 24 class ThreadSafeSender; |
22 struct ServiceWorkerFetchRequest; | 25 struct ServiceWorkerFetchRequest; |
23 class ServiceWorkerScriptContext; | |
24 struct ServiceWorkerResponse; | 26 struct ServiceWorkerResponse; |
25 | 27 |
26 // There is one ServiceWorkerCacheStorageDispatcher per | 28 // Handle the Cache Storage messaging for this context thread. The |
27 // ServiceWorkerScriptContext. It handles CacheStorage operations with messages | 29 // main thread and each worker thread have their own instances. |
28 // to/from the browser, creating Cache objects (for which it also handles | 30 class ServiceWorkerCacheStorageDispatcher : public WorkerTaskRunner::Observer { |
29 // messages) as it goes. | |
30 | |
31 class ServiceWorkerCacheStorageDispatcher | |
32 : public blink::WebServiceWorkerCacheStorage { | |
33 public: | 31 public: |
34 explicit ServiceWorkerCacheStorageDispatcher( | 32 explicit ServiceWorkerCacheStorageDispatcher( |
35 ServiceWorkerScriptContext* script_context); | 33 ThreadSafeSender* thread_safe_sender); |
36 virtual ~ServiceWorkerCacheStorageDispatcher(); | 34 ~ServiceWorkerCacheStorageDispatcher() override; |
| 35 |
| 36 // |thread_safe_sender| needs to be passed in because if the call leads to |
| 37 // construction it will be needed. |
| 38 static ServiceWorkerCacheStorageDispatcher* ThreadSpecificInstance( |
| 39 ThreadSafeSender* thread_safe_sender); |
| 40 |
| 41 // WorkerTaskRunner::Observer implementation. |
| 42 void OnWorkerRunLoopStopped() override; |
| 43 |
| 44 bool Send(IPC::Message* msg); |
37 | 45 |
38 // ServiceWorkerScriptContext calls our OnMessageReceived directly. | 46 // ServiceWorkerScriptContext calls our OnMessageReceived directly. |
39 bool OnMessageReceived(const IPC::Message& message); | 47 bool OnMessageReceived(const IPC::Message& message); |
40 | 48 |
41 // Message handlers for CacheStorage messages from the browser process. | 49 // Message handlers for CacheStorage messages from the browser process. |
42 void OnCacheStorageHasSuccess(int request_id); | 50 void OnCacheStorageHasSuccess(int thread_id, int request_id); |
43 void OnCacheStorageOpenSuccess(int request_id, int cache_id); | 51 void OnCacheStorageOpenSuccess(int thread_id, int request_id, int cache_id); |
44 void OnCacheStorageDeleteSuccess(int request_id); | 52 void OnCacheStorageDeleteSuccess(int thread_id, int request_id); |
45 void OnCacheStorageKeysSuccess(int request_id, | 53 void OnCacheStorageKeysSuccess(int thread_id, |
| 54 int request_id, |
46 const std::vector<base::string16>& keys); | 55 const std::vector<base::string16>& keys); |
47 void OnCacheStorageMatchSuccess(int request_id, | 56 void OnCacheStorageMatchSuccess(int thread_id, |
| 57 int request_id, |
48 const ServiceWorkerResponse& response); | 58 const ServiceWorkerResponse& response); |
49 | 59 |
50 void OnCacheStorageHasError(int request_id, | 60 void OnCacheStorageHasError(int thread_id, |
| 61 int request_id, |
51 blink::WebServiceWorkerCacheError reason); | 62 blink::WebServiceWorkerCacheError reason); |
52 void OnCacheStorageOpenError(int request_id, | 63 void OnCacheStorageOpenError(int thread_id, |
| 64 int request_id, |
53 blink::WebServiceWorkerCacheError reason); | 65 blink::WebServiceWorkerCacheError reason); |
54 void OnCacheStorageDeleteError(int request_id, | 66 void OnCacheStorageDeleteError(int thread_id, |
| 67 int request_id, |
55 blink::WebServiceWorkerCacheError reason); | 68 blink::WebServiceWorkerCacheError reason); |
56 void OnCacheStorageKeysError(int request_id, | 69 void OnCacheStorageKeysError(int thread_id, |
| 70 int request_id, |
57 blink::WebServiceWorkerCacheError reason); | 71 blink::WebServiceWorkerCacheError reason); |
58 void OnCacheStorageMatchError(int request_id, | 72 void OnCacheStorageMatchError(int thread_id, |
| 73 int request_id, |
59 blink::WebServiceWorkerCacheError reason); | 74 blink::WebServiceWorkerCacheError reason); |
60 | 75 |
61 // Message handlers for Cache messages from the browser process. | 76 // Message handlers for Cache messages from the browser process. |
62 void OnCacheMatchSuccess(int request_id, | 77 void OnCacheMatchSuccess(int thread_id, |
| 78 int request_id, |
63 const ServiceWorkerResponse& response); | 79 const ServiceWorkerResponse& response); |
64 void OnCacheMatchAllSuccess( | 80 void OnCacheMatchAllSuccess( |
| 81 int thread_id, |
65 int request_id, | 82 int request_id, |
66 const std::vector<ServiceWorkerResponse>& response); | 83 const std::vector<ServiceWorkerResponse>& response); |
67 void OnCacheKeysSuccess( | 84 void OnCacheKeysSuccess( |
| 85 int thread_id, |
68 int request_id, | 86 int request_id, |
69 const std::vector<ServiceWorkerFetchRequest>& response); | 87 const std::vector<ServiceWorkerFetchRequest>& response); |
70 void OnCacheBatchSuccess(int request_id, | 88 void OnCacheBatchSuccess(int thread_id, |
| 89 int request_id, |
71 const std::vector<ServiceWorkerResponse>& response); | 90 const std::vector<ServiceWorkerResponse>& response); |
72 | 91 |
73 void OnCacheMatchError(int request_id, | 92 void OnCacheMatchError(int thread_id, |
| 93 int request_id, |
74 blink::WebServiceWorkerCacheError reason); | 94 blink::WebServiceWorkerCacheError reason); |
75 void OnCacheMatchAllError(int request_id, | 95 void OnCacheMatchAllError(int thread_id, |
| 96 int request_id, |
76 blink::WebServiceWorkerCacheError reason); | 97 blink::WebServiceWorkerCacheError reason); |
77 void OnCacheKeysError(int request_id, | 98 void OnCacheKeysError(int thread_id, |
| 99 int request_id, |
78 blink::WebServiceWorkerCacheError reason); | 100 blink::WebServiceWorkerCacheError reason); |
79 void OnCacheBatchError(int request_id, | 101 void OnCacheBatchError(int thread_id, |
| 102 int request_id, |
80 blink::WebServiceWorkerCacheError reason); | 103 blink::WebServiceWorkerCacheError reason); |
81 | 104 |
82 // From WebServiceWorkerCacheStorage: | 105 // TODO(jsbell): These are only called by WebServiceWorkerCacheStorageImpl |
83 virtual void dispatchHas(CacheStorageCallbacks* callbacks, | 106 // and should be renamed to match Chromium conventions. crbug.com/439389 |
84 const blink::WebString& cacheName); | 107 void dispatchHas( |
85 virtual void dispatchOpen(CacheStorageWithCacheCallbacks* callbacks, | 108 blink::WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks, |
86 const blink::WebString& cacheName); | 109 const GURL& origin, |
87 virtual void dispatchDelete(CacheStorageCallbacks* callbacks, | 110 const blink::WebString& cacheName); |
88 const blink::WebString& cacheName); | 111 void dispatchOpen( |
89 virtual void dispatchKeys(CacheStorageKeysCallbacks* callbacks); | 112 blink::WebServiceWorkerCacheStorage::CacheStorageWithCacheCallbacks* |
90 virtual void dispatchMatch( | 113 callbacks, |
91 CacheStorageMatchCallbacks* callbacks, | 114 const GURL& origin, |
| 115 const blink::WebString& cacheName); |
| 116 void dispatchDelete( |
| 117 blink::WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks, |
| 118 const GURL& origin, |
| 119 const blink::WebString& cacheName); |
| 120 void dispatchKeys( |
| 121 blink::WebServiceWorkerCacheStorage::CacheStorageKeysCallbacks* callbacks, |
| 122 const GURL& origin); |
| 123 void dispatchMatch( |
| 124 blink::WebServiceWorkerCacheStorage::CacheStorageMatchCallbacks* |
| 125 callbacks, |
| 126 const GURL& origin, |
92 const blink::WebServiceWorkerRequest& request, | 127 const blink::WebServiceWorkerRequest& request, |
93 const blink::WebServiceWorkerCache::QueryParams& query_params); | 128 const blink::WebServiceWorkerCache::QueryParams& query_params); |
94 | 129 |
95 // These methods are used by WebCache to forward events to the browser | 130 // These methods are used by WebCache to forward events to the browser |
96 // process. | 131 // process. |
97 void dispatchMatchForCache( | 132 void dispatchMatchForCache( |
98 int cache_id, | 133 int cache_id, |
99 blink::WebServiceWorkerCache::CacheMatchCallbacks* callbacks, | 134 blink::WebServiceWorkerCache::CacheMatchCallbacks* callbacks, |
100 const blink::WebServiceWorkerRequest& request, | 135 const blink::WebServiceWorkerRequest& request, |
101 const blink::WebServiceWorkerCache::QueryParams& query_params); | 136 const blink::WebServiceWorkerCache::QueryParams& query_params); |
(...skipping 11 matching lines...) Expand all Loading... |
113 int cache_id, | 148 int cache_id, |
114 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks, | 149 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks, |
115 const blink::WebVector<blink::WebServiceWorkerCache::BatchOperation>& | 150 const blink::WebVector<blink::WebServiceWorkerCache::BatchOperation>& |
116 batch_operations); | 151 batch_operations); |
117 | 152 |
118 void OnWebCacheDestruction(int cache_id); | 153 void OnWebCacheDestruction(int cache_id); |
119 | 154 |
120 private: | 155 private: |
121 class WebCache; | 156 class WebCache; |
122 | 157 |
123 typedef IDMap<CacheStorageCallbacks, IDMapOwnPointer> CallbacksMap; | 158 typedef IDMap<blink::WebServiceWorkerCacheStorage::CacheStorageCallbacks, |
124 typedef IDMap<CacheStorageWithCacheCallbacks, IDMapOwnPointer> | 159 IDMapOwnPointer> CallbacksMap; |
125 WithCacheCallbacksMap; | 160 typedef IDMap< |
126 typedef IDMap<CacheStorageKeysCallbacks, IDMapOwnPointer> | 161 blink::WebServiceWorkerCacheStorage::CacheStorageWithCacheCallbacks, |
127 KeysCallbacksMap; | 162 IDMapOwnPointer> WithCacheCallbacksMap; |
128 typedef IDMap<CacheStorageMatchCallbacks, IDMapOwnPointer> | 163 typedef IDMap<blink::WebServiceWorkerCacheStorage::CacheStorageKeysCallbacks, |
129 StorageMatchCallbacksMap; | 164 IDMapOwnPointer> KeysCallbacksMap; |
| 165 typedef IDMap<blink::WebServiceWorkerCacheStorage::CacheStorageMatchCallbacks, |
| 166 IDMapOwnPointer> StorageMatchCallbacksMap; |
130 | 167 |
131 typedef base::hash_map<int32, base::TimeTicks> TimeMap; | 168 typedef base::hash_map<int32, base::TimeTicks> TimeMap; |
132 | 169 |
133 typedef IDMap<blink::WebServiceWorkerCache::CacheMatchCallbacks, | 170 typedef IDMap<blink::WebServiceWorkerCache::CacheMatchCallbacks, |
134 IDMapOwnPointer> MatchCallbacksMap; | 171 IDMapOwnPointer> MatchCallbacksMap; |
135 typedef IDMap<blink::WebServiceWorkerCache::CacheWithResponsesCallbacks, | 172 typedef IDMap<blink::WebServiceWorkerCache::CacheWithResponsesCallbacks, |
136 IDMapOwnPointer> WithResponsesCallbacksMap; | 173 IDMapOwnPointer> WithResponsesCallbacksMap; |
137 typedef IDMap<blink::WebServiceWorkerCache::CacheWithRequestsCallbacks, | 174 typedef IDMap<blink::WebServiceWorkerCache::CacheWithRequestsCallbacks, |
138 IDMapOwnPointer> WithRequestsCallbacksMap; | 175 IDMapOwnPointer> WithRequestsCallbacksMap; |
139 | 176 |
| 177 static int32 CurrentWorkerId() { |
| 178 return WorkerTaskRunner::Instance()->CurrentWorkerId(); |
| 179 } |
| 180 |
140 void PopulateWebResponseFromResponse( | 181 void PopulateWebResponseFromResponse( |
141 const ServiceWorkerResponse& response, | 182 const ServiceWorkerResponse& response, |
142 blink::WebServiceWorkerResponse* web_response); | 183 blink::WebServiceWorkerResponse* web_response); |
143 | 184 |
144 blink::WebVector<blink::WebServiceWorkerResponse> WebResponsesFromResponses( | 185 blink::WebVector<blink::WebServiceWorkerResponse> WebResponsesFromResponses( |
145 const std::vector<ServiceWorkerResponse>& responses); | 186 const std::vector<ServiceWorkerResponse>& responses); |
146 | 187 |
147 // Not owned. The script context containing this object. | 188 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
148 ServiceWorkerScriptContext* script_context_; | |
149 | 189 |
150 CallbacksMap has_callbacks_; | 190 CallbacksMap has_callbacks_; |
151 WithCacheCallbacksMap open_callbacks_; | 191 WithCacheCallbacksMap open_callbacks_; |
152 CallbacksMap delete_callbacks_; | 192 CallbacksMap delete_callbacks_; |
153 KeysCallbacksMap keys_callbacks_; | 193 KeysCallbacksMap keys_callbacks_; |
154 StorageMatchCallbacksMap match_callbacks_; | 194 StorageMatchCallbacksMap match_callbacks_; |
155 | 195 |
156 TimeMap has_times_; | 196 TimeMap has_times_; |
157 TimeMap open_times_; | 197 TimeMap open_times_; |
158 TimeMap delete_times_; | 198 TimeMap delete_times_; |
(...skipping 16 matching lines...) Expand all Loading... |
175 TimeMap cache_batch_times_; | 215 TimeMap cache_batch_times_; |
176 | 216 |
177 base::WeakPtrFactory<ServiceWorkerCacheStorageDispatcher> weak_factory_; | 217 base::WeakPtrFactory<ServiceWorkerCacheStorageDispatcher> weak_factory_; |
178 | 218 |
179 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheStorageDispatcher); | 219 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheStorageDispatcher); |
180 }; | 220 }; |
181 | 221 |
182 } // namespace content | 222 } // namespace content |
183 | 223 |
184 #endif // CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_DISPATCH
ER_H_ | 224 #endif // CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_DISPATCH
ER_H_ |
OLD | NEW |