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

Side by Side Diff: content/renderer/service_worker/service_worker_cache_storage_dispatcher.h

Issue 1039763002: Cache Storage: Move files to content/*/cache_storage, rename classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: GN fix Created 5 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_DISPATCHER_ H_
6 #define CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_DISPATCHER_ H_
7
8 #include <vector>
9
10 #include "base/id_map.h"
11 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/strings/string16.h"
14 #include "base/time/time.h"
15 #include "content/child/worker_task_runner.h"
16 #include "content/public/renderer/render_process_observer.h"
17 #include "third_party/WebKit/public/platform/WebServiceWorkerCache.h"
18 #include "third_party/WebKit/public/platform/WebServiceWorkerCacheError.h"
19 #include "third_party/WebKit/public/platform/WebServiceWorkerCacheStorage.h"
20
21 namespace content {
22
23 class ServiceWorkerScriptContext;
24 class ThreadSafeSender;
25 struct ServiceWorkerFetchRequest;
26 struct ServiceWorkerResponse;
27
28 // Handle the Cache Storage messaging for this context thread. The
29 // main thread and each worker thread have their own instances.
30 class ServiceWorkerCacheStorageDispatcher : public WorkerTaskRunner::Observer {
31 public:
32 explicit ServiceWorkerCacheStorageDispatcher(
33 ThreadSafeSender* thread_safe_sender);
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);
45
46 // ServiceWorkerScriptContext calls our OnMessageReceived directly.
47 bool OnMessageReceived(const IPC::Message& message);
48
49 // Message handlers for CacheStorage messages from the browser process.
50 void OnCacheStorageHasSuccess(int thread_id, int request_id);
51 void OnCacheStorageOpenSuccess(int thread_id, int request_id, int cache_id);
52 void OnCacheStorageDeleteSuccess(int thread_id, int request_id);
53 void OnCacheStorageKeysSuccess(int thread_id,
54 int request_id,
55 const std::vector<base::string16>& keys);
56 void OnCacheStorageMatchSuccess(int thread_id,
57 int request_id,
58 const ServiceWorkerResponse& response);
59
60 void OnCacheStorageHasError(int thread_id,
61 int request_id,
62 blink::WebServiceWorkerCacheError reason);
63 void OnCacheStorageOpenError(int thread_id,
64 int request_id,
65 blink::WebServiceWorkerCacheError reason);
66 void OnCacheStorageDeleteError(int thread_id,
67 int request_id,
68 blink::WebServiceWorkerCacheError reason);
69 void OnCacheStorageKeysError(int thread_id,
70 int request_id,
71 blink::WebServiceWorkerCacheError reason);
72 void OnCacheStorageMatchError(int thread_id,
73 int request_id,
74 blink::WebServiceWorkerCacheError reason);
75
76 // Message handlers for Cache messages from the browser process.
77 void OnCacheMatchSuccess(int thread_id,
78 int request_id,
79 const ServiceWorkerResponse& response);
80 void OnCacheMatchAllSuccess(
81 int thread_id,
82 int request_id,
83 const std::vector<ServiceWorkerResponse>& response);
84 void OnCacheKeysSuccess(
85 int thread_id,
86 int request_id,
87 const std::vector<ServiceWorkerFetchRequest>& response);
88 void OnCacheBatchSuccess(int thread_id,
89 int request_id,
90 const std::vector<ServiceWorkerResponse>& response);
91
92 void OnCacheMatchError(int thread_id,
93 int request_id,
94 blink::WebServiceWorkerCacheError reason);
95 void OnCacheMatchAllError(int thread_id,
96 int request_id,
97 blink::WebServiceWorkerCacheError reason);
98 void OnCacheKeysError(int thread_id,
99 int request_id,
100 blink::WebServiceWorkerCacheError reason);
101 void OnCacheBatchError(int thread_id,
102 int request_id,
103 blink::WebServiceWorkerCacheError reason);
104
105 // TODO(jsbell): These are only called by WebServiceWorkerCacheStorageImpl
106 // and should be renamed to match Chromium conventions. crbug.com/439389
107 void dispatchHas(
108 blink::WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks,
109 const GURL& origin,
110 const blink::WebString& cacheName);
111 void dispatchOpen(
112 blink::WebServiceWorkerCacheStorage::CacheStorageWithCacheCallbacks*
113 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,
127 const blink::WebServiceWorkerRequest& request,
128 const blink::WebServiceWorkerCache::QueryParams& query_params);
129
130 // These methods are used by WebCache to forward events to the browser
131 // process.
132 void dispatchMatchForCache(
133 int cache_id,
134 blink::WebServiceWorkerCache::CacheMatchCallbacks* callbacks,
135 const blink::WebServiceWorkerRequest& request,
136 const blink::WebServiceWorkerCache::QueryParams& query_params);
137 void dispatchMatchAllForCache(
138 int cache_id,
139 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks,
140 const blink::WebServiceWorkerRequest& request,
141 const blink::WebServiceWorkerCache::QueryParams& query_params);
142 void dispatchKeysForCache(
143 int cache_id,
144 blink::WebServiceWorkerCache::CacheWithRequestsCallbacks* callbacks,
145 const blink::WebServiceWorkerRequest* request,
146 const blink::WebServiceWorkerCache::QueryParams& query_params);
147 void dispatchBatchForCache(
148 int cache_id,
149 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks,
150 const blink::WebVector<blink::WebServiceWorkerCache::BatchOperation>&
151 batch_operations);
152
153 void OnWebCacheDestruction(int cache_id);
154
155 private:
156 class WebCache;
157
158 typedef IDMap<blink::WebServiceWorkerCacheStorage::CacheStorageCallbacks,
159 IDMapOwnPointer> CallbacksMap;
160 typedef IDMap<
161 blink::WebServiceWorkerCacheStorage::CacheStorageWithCacheCallbacks,
162 IDMapOwnPointer> WithCacheCallbacksMap;
163 typedef IDMap<blink::WebServiceWorkerCacheStorage::CacheStorageKeysCallbacks,
164 IDMapOwnPointer> KeysCallbacksMap;
165 typedef IDMap<blink::WebServiceWorkerCacheStorage::CacheStorageMatchCallbacks,
166 IDMapOwnPointer> StorageMatchCallbacksMap;
167
168 typedef base::hash_map<int32, base::TimeTicks> TimeMap;
169
170 typedef IDMap<blink::WebServiceWorkerCache::CacheMatchCallbacks,
171 IDMapOwnPointer> MatchCallbacksMap;
172 typedef IDMap<blink::WebServiceWorkerCache::CacheWithResponsesCallbacks,
173 IDMapOwnPointer> WithResponsesCallbacksMap;
174 typedef IDMap<blink::WebServiceWorkerCache::CacheWithRequestsCallbacks,
175 IDMapOwnPointer> WithRequestsCallbacksMap;
176
177 static int32 CurrentWorkerId() {
178 return WorkerTaskRunner::Instance()->CurrentWorkerId();
179 }
180
181 void PopulateWebResponseFromResponse(
182 const ServiceWorkerResponse& response,
183 blink::WebServiceWorkerResponse* web_response);
184
185 blink::WebVector<blink::WebServiceWorkerResponse> WebResponsesFromResponses(
186 const std::vector<ServiceWorkerResponse>& responses);
187
188 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
189
190 CallbacksMap has_callbacks_;
191 WithCacheCallbacksMap open_callbacks_;
192 CallbacksMap delete_callbacks_;
193 KeysCallbacksMap keys_callbacks_;
194 StorageMatchCallbacksMap match_callbacks_;
195
196 TimeMap has_times_;
197 TimeMap open_times_;
198 TimeMap delete_times_;
199 TimeMap keys_times_;
200 TimeMap match_times_;
201
202 // The individual caches created under this CacheStorage object.
203 IDMap<WebCache, IDMapExternalPointer> web_caches_;
204
205 // These ID maps are held in the CacheStorage object rather than the Cache
206 // object to ensure that the IDs are unique.
207 MatchCallbacksMap cache_match_callbacks_;
208 WithResponsesCallbacksMap cache_match_all_callbacks_;
209 WithRequestsCallbacksMap cache_keys_callbacks_;
210 WithResponsesCallbacksMap cache_batch_callbacks_;
211
212 TimeMap cache_match_times_;
213 TimeMap cache_match_all_times_;
214 TimeMap cache_keys_times_;
215 TimeMap cache_batch_times_;
216
217 base::WeakPtrFactory<ServiceWorkerCacheStorageDispatcher> weak_factory_;
218
219 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheStorageDispatcher);
220 };
221
222 } // namespace content
223
224 #endif // CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_DISPATCH ER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698