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

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

Issue 992353003: Decouple Cache Storage messaging from Service Worker/Embedded Worker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 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
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 #include "content/renderer/service_worker/service_worker_cache_storage_dispatche r.h" 5 #include "content/renderer/service_worker/service_worker_cache_storage_dispatche r.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/lazy_instance.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
13 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
14 #include "content/common/service_worker/service_worker_messages.h" 15 #include "base/threading/thread_local.h"
16 #include "content/child/thread_safe_sender.h"
17 #include "content/common/service_worker/cache_storage_messages.h"
15 #include "content/public/common/referrer.h" 18 #include "content/public/common/referrer.h"
16 #include "content/public/renderer/render_thread.h" 19 #include "content/public/renderer/render_thread.h"
17 #include "content/renderer/service_worker/service_worker_script_context.h"
18 #include "content/renderer/service_worker/service_worker_type_util.h" 20 #include "content/renderer/service_worker/service_worker_type_util.h"
19 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h"
20 #include "third_party/WebKit/public/platform/WebServiceWorkerCache.h" 21 #include "third_party/WebKit/public/platform/WebServiceWorkerCache.h"
21 #include "third_party/WebKit/public/platform/WebServiceWorkerRequest.h" 22 #include "third_party/WebKit/public/platform/WebServiceWorkerRequest.h"
22 #include "third_party/WebKit/public/platform/WebServiceWorkerResponse.h" 23 #include "third_party/WebKit/public/platform/WebServiceWorkerResponse.h"
23 24
24 using base::TimeTicks; 25 using base::TimeTicks;
25 26
26 namespace content { 27 namespace content {
27 28
29 using blink::WebServiceWorkerCacheStorage;
28 using blink::WebServiceWorkerCacheError; 30 using blink::WebServiceWorkerCacheError;
29 using blink::WebServiceWorkerRequest; 31 using blink::WebServiceWorkerRequest;
30 32
33 static base::LazyInstance<
34 base::ThreadLocalPointer<ServiceWorkerCacheStorageDispatcher>>::Leaky
35 g_cache_storage_dispatcher_tls = LAZY_INSTANCE_INITIALIZER;
36
31 namespace { 37 namespace {
32 38
39 ServiceWorkerCacheStorageDispatcher* const kHasBeenDeleted =
40 reinterpret_cast<ServiceWorkerCacheStorageDispatcher*>(0x1);
41
33 ServiceWorkerFetchRequest FetchRequestFromWebRequest( 42 ServiceWorkerFetchRequest FetchRequestFromWebRequest(
34 const blink::WebServiceWorkerRequest& web_request) { 43 const blink::WebServiceWorkerRequest& web_request) {
35 ServiceWorkerHeaderMap headers; 44 ServiceWorkerHeaderMap headers;
36 GetServiceWorkerHeaderMapFromWebRequest(web_request, &headers); 45 GetServiceWorkerHeaderMapFromWebRequest(web_request, &headers);
37 46
38 return ServiceWorkerFetchRequest( 47 return ServiceWorkerFetchRequest(
39 web_request.url(), base::UTF16ToASCII(web_request.method()), headers, 48 web_request.url(), base::UTF16ToASCII(web_request.method()), headers,
40 Referrer(web_request.referrerUrl(), web_request.referrerPolicy()), 49 Referrer(web_request.referrerUrl(), web_request.referrerPolicy()),
41 web_request.isReload()); 50 web_request.isReload());
42 } 51 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 return; 188 return;
180 dispatcher_->dispatchBatchForCache(cache_id_, callbacks, batch_operations); 189 dispatcher_->dispatchBatchForCache(cache_id_, callbacks, batch_operations);
181 } 190 }
182 191
183 private: 192 private:
184 const base::WeakPtr<ServiceWorkerCacheStorageDispatcher> dispatcher_; 193 const base::WeakPtr<ServiceWorkerCacheStorageDispatcher> dispatcher_;
185 const int cache_id_; 194 const int cache_id_;
186 }; 195 };
187 196
188 ServiceWorkerCacheStorageDispatcher::ServiceWorkerCacheStorageDispatcher( 197 ServiceWorkerCacheStorageDispatcher::ServiceWorkerCacheStorageDispatcher(
189 ServiceWorkerScriptContext* script_context) 198 ThreadSafeSender* thread_safe_sender)
190 : script_context_(script_context), 199 : thread_safe_sender_(thread_safe_sender), weak_factory_(this) {
191 weak_factory_(this) {} 200 g_cache_storage_dispatcher_tls.Pointer()->Set(this);
201 }
192 202
193 ServiceWorkerCacheStorageDispatcher::~ServiceWorkerCacheStorageDispatcher() { 203 ServiceWorkerCacheStorageDispatcher::~ServiceWorkerCacheStorageDispatcher() {
194 ClearCallbacksMapWithErrors(&has_callbacks_); 204 ClearCallbacksMapWithErrors(&has_callbacks_);
195 ClearCallbacksMapWithErrors(&open_callbacks_); 205 ClearCallbacksMapWithErrors(&open_callbacks_);
196 ClearCallbacksMapWithErrors(&delete_callbacks_); 206 ClearCallbacksMapWithErrors(&delete_callbacks_);
197 ClearCallbacksMapWithErrors(&keys_callbacks_); 207 ClearCallbacksMapWithErrors(&keys_callbacks_);
198 ClearCallbacksMapWithErrors(&match_callbacks_); 208 ClearCallbacksMapWithErrors(&match_callbacks_);
199 209
200 ClearCallbacksMapWithErrors(&cache_match_callbacks_); 210 ClearCallbacksMapWithErrors(&cache_match_callbacks_);
201 ClearCallbacksMapWithErrors(&cache_match_all_callbacks_); 211 ClearCallbacksMapWithErrors(&cache_match_all_callbacks_);
202 ClearCallbacksMapWithErrors(&cache_keys_callbacks_); 212 ClearCallbacksMapWithErrors(&cache_keys_callbacks_);
203 ClearCallbacksMapWithErrors(&cache_batch_callbacks_); 213 ClearCallbacksMapWithErrors(&cache_batch_callbacks_);
214
215 g_cache_storage_dispatcher_tls.Pointer()->Set(kHasBeenDeleted);
216 }
217
218 ServiceWorkerCacheStorageDispatcher*
219 ServiceWorkerCacheStorageDispatcher::ThreadSpecificInstance(
220 ThreadSafeSender* thread_safe_sender) {
221 if (g_cache_storage_dispatcher_tls.Pointer()->Get() == kHasBeenDeleted) {
222 NOTREACHED() << "Re-instantiating TLS ServiceWorkerCacheStorageDispatcher.";
223 g_cache_storage_dispatcher_tls.Pointer()->Set(NULL);
224 }
225 if (g_cache_storage_dispatcher_tls.Pointer()->Get())
226 return g_cache_storage_dispatcher_tls.Pointer()->Get();
227
228 ServiceWorkerCacheStorageDispatcher* dispatcher =
229 new ServiceWorkerCacheStorageDispatcher(thread_safe_sender);
230 if (WorkerTaskRunner::Instance()->CurrentWorkerId())
231 WorkerTaskRunner::Instance()->AddStopObserver(dispatcher);
232 return dispatcher;
233 }
234
235 void ServiceWorkerCacheStorageDispatcher::OnWorkerRunLoopStopped() {
236 delete this;
237 }
238
239 bool ServiceWorkerCacheStorageDispatcher::Send(IPC::Message* msg) {
240 return thread_safe_sender_->Send(msg);
204 } 241 }
205 242
206 bool ServiceWorkerCacheStorageDispatcher::OnMessageReceived( 243 bool ServiceWorkerCacheStorageDispatcher::OnMessageReceived(
207 const IPC::Message& message) { 244 const IPC::Message& message) {
208 bool handled = true; 245 bool handled = true;
209 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerCacheStorageDispatcher, message) 246 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerCacheStorageDispatcher, message)
210 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageHasSuccess, 247 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageHasSuccess,
211 OnCacheStorageHasSuccess) 248 OnCacheStorageHasSuccess)
212 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageOpenSuccess, 249 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageOpenSuccess,
213 OnCacheStorageOpenSuccess) 250 OnCacheStorageOpenSuccess)
(...skipping 29 matching lines...) Expand all
243 OnCacheKeysError) 280 OnCacheKeysError)
244 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheBatchError, 281 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheBatchError,
245 OnCacheBatchError) 282 OnCacheBatchError)
246 IPC_MESSAGE_UNHANDLED(handled = false) 283 IPC_MESSAGE_UNHANDLED(handled = false)
247 IPC_END_MESSAGE_MAP() 284 IPC_END_MESSAGE_MAP()
248 285
249 return handled; 286 return handled;
250 } 287 }
251 288
252 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageHasSuccess( 289 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageHasSuccess(
290 int thread_id,
253 int request_id) { 291 int request_id) {
292 DCHECK_EQ(thread_id, CurrentWorkerId());
254 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.CacheStorage.Has", 293 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.CacheStorage.Has",
255 TimeTicks::Now() - has_times_[request_id]); 294 TimeTicks::Now() - has_times_[request_id]);
256 CacheStorageCallbacks* callbacks = has_callbacks_.Lookup(request_id); 295 WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks =
296 has_callbacks_.Lookup(request_id);
257 callbacks->onSuccess(); 297 callbacks->onSuccess();
258 has_callbacks_.Remove(request_id); 298 has_callbacks_.Remove(request_id);
259 has_times_.erase(request_id); 299 has_times_.erase(request_id);
260 } 300 }
261 301
262 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageOpenSuccess( 302 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageOpenSuccess(
303 int thread_id,
263 int request_id, 304 int request_id,
264 int cache_id) { 305 int cache_id) {
306 DCHECK_EQ(thread_id, CurrentWorkerId());
265 WebCache* web_cache = new WebCache(weak_factory_.GetWeakPtr(), cache_id); 307 WebCache* web_cache = new WebCache(weak_factory_.GetWeakPtr(), cache_id);
266 web_caches_.AddWithID(web_cache, cache_id); 308 web_caches_.AddWithID(web_cache, cache_id);
267 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.CacheStorage.Open", 309 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.CacheStorage.Open",
268 TimeTicks::Now() - open_times_[request_id]); 310 TimeTicks::Now() - open_times_[request_id]);
269 CacheStorageWithCacheCallbacks* callbacks = 311 WebServiceWorkerCacheStorage::CacheStorageWithCacheCallbacks* callbacks =
270 open_callbacks_.Lookup(request_id); 312 open_callbacks_.Lookup(request_id);
271 callbacks->onSuccess(web_cache); 313 callbacks->onSuccess(web_cache);
272 open_callbacks_.Remove(request_id); 314 open_callbacks_.Remove(request_id);
273 open_times_.erase(request_id); 315 open_times_.erase(request_id);
274 } 316 }
275 317
276 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageDeleteSuccess( 318 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageDeleteSuccess(
319 int thread_id,
277 int request_id) { 320 int request_id) {
321 DCHECK_EQ(thread_id, CurrentWorkerId());
278 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.CacheStorage.Delete", 322 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.CacheStorage.Delete",
279 TimeTicks::Now() - delete_times_[request_id]); 323 TimeTicks::Now() - delete_times_[request_id]);
280 CacheStorageCallbacks* callbacks = delete_callbacks_.Lookup(request_id); 324 WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks =
325 delete_callbacks_.Lookup(request_id);
281 callbacks->onSuccess(); 326 callbacks->onSuccess();
282 delete_callbacks_.Remove(request_id); 327 delete_callbacks_.Remove(request_id);
283 delete_times_.erase(request_id); 328 delete_times_.erase(request_id);
284 } 329 }
285 330
286 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageKeysSuccess( 331 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageKeysSuccess(
332 int thread_id,
287 int request_id, 333 int request_id,
288 const std::vector<base::string16>& keys) { 334 const std::vector<base::string16>& keys) {
335 DCHECK_EQ(thread_id, CurrentWorkerId());
289 blink::WebVector<blink::WebString> webKeys(keys.size()); 336 blink::WebVector<blink::WebString> webKeys(keys.size());
290 for (size_t i = 0; i < keys.size(); ++i) 337 for (size_t i = 0; i < keys.size(); ++i)
291 webKeys[i] = keys[i]; 338 webKeys[i] = keys[i];
292 339
293 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.CacheStorage.Keys", 340 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.CacheStorage.Keys",
294 TimeTicks::Now() - keys_times_[request_id]); 341 TimeTicks::Now() - keys_times_[request_id]);
295 CacheStorageKeysCallbacks* callbacks = keys_callbacks_.Lookup(request_id); 342 WebServiceWorkerCacheStorage::CacheStorageKeysCallbacks* callbacks =
343 keys_callbacks_.Lookup(request_id);
296 callbacks->onSuccess(&webKeys); 344 callbacks->onSuccess(&webKeys);
297 keys_callbacks_.Remove(request_id); 345 keys_callbacks_.Remove(request_id);
298 keys_times_.erase(request_id); 346 keys_times_.erase(request_id);
299 } 347 }
300 348
301 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageMatchSuccess( 349 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageMatchSuccess(
350 int thread_id,
302 int request_id, 351 int request_id,
303 const ServiceWorkerResponse& response) { 352 const ServiceWorkerResponse& response) {
353 DCHECK_EQ(thread_id, CurrentWorkerId());
304 blink::WebServiceWorkerResponse web_response; 354 blink::WebServiceWorkerResponse web_response;
305 PopulateWebResponseFromResponse(response, &web_response); 355 PopulateWebResponseFromResponse(response, &web_response);
306 356
307 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.CacheStorage.Match", 357 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.CacheStorage.Match",
308 TimeTicks::Now() - match_times_[request_id]); 358 TimeTicks::Now() - match_times_[request_id]);
309 CacheStorageMatchCallbacks* callbacks = match_callbacks_.Lookup(request_id); 359 WebServiceWorkerCacheStorage::CacheStorageMatchCallbacks* callbacks =
360 match_callbacks_.Lookup(request_id);
310 callbacks->onSuccess(&web_response); 361 callbacks->onSuccess(&web_response);
311 match_callbacks_.Remove(request_id); 362 match_callbacks_.Remove(request_id);
312 match_times_.erase(request_id); 363 match_times_.erase(request_id);
313 } 364 }
314 365
315 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageHasError( 366 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageHasError(
316 int request_id, 367 int thread_id,
317 blink::WebServiceWorkerCacheError reason) { 368 int request_id,
318 CacheStorageCallbacks* callbacks = has_callbacks_.Lookup(request_id); 369 blink::WebServiceWorkerCacheError reason) {
370 DCHECK_EQ(thread_id, CurrentWorkerId());
371 WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks =
372 has_callbacks_.Lookup(request_id);
319 callbacks->onError(&reason); 373 callbacks->onError(&reason);
320 has_callbacks_.Remove(request_id); 374 has_callbacks_.Remove(request_id);
321 has_times_.erase(request_id); 375 has_times_.erase(request_id);
322 } 376 }
323 377
324 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageOpenError( 378 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageOpenError(
379 int thread_id,
325 int request_id, 380 int request_id,
326 blink::WebServiceWorkerCacheError reason) { 381 blink::WebServiceWorkerCacheError reason) {
327 CacheStorageWithCacheCallbacks* callbacks = 382 DCHECK_EQ(thread_id, CurrentWorkerId());
383 WebServiceWorkerCacheStorage::CacheStorageWithCacheCallbacks* callbacks =
328 open_callbacks_.Lookup(request_id); 384 open_callbacks_.Lookup(request_id);
329 callbacks->onError(&reason); 385 callbacks->onError(&reason);
330 open_callbacks_.Remove(request_id); 386 open_callbacks_.Remove(request_id);
331 open_times_.erase(request_id); 387 open_times_.erase(request_id);
332 } 388 }
333 389
334 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageDeleteError( 390 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageDeleteError(
335 int request_id, 391 int thread_id,
336 blink::WebServiceWorkerCacheError reason) { 392 int request_id,
337 CacheStorageCallbacks* callbacks = delete_callbacks_.Lookup(request_id); 393 blink::WebServiceWorkerCacheError reason) {
394 DCHECK_EQ(thread_id, CurrentWorkerId());
395 WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks =
396 delete_callbacks_.Lookup(request_id);
338 callbacks->onError(&reason); 397 callbacks->onError(&reason);
339 delete_callbacks_.Remove(request_id); 398 delete_callbacks_.Remove(request_id);
340 delete_times_.erase(request_id); 399 delete_times_.erase(request_id);
341 } 400 }
342 401
343 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageKeysError( 402 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageKeysError(
344 int request_id, 403 int thread_id,
345 blink::WebServiceWorkerCacheError reason) { 404 int request_id,
346 CacheStorageKeysCallbacks* callbacks = keys_callbacks_.Lookup(request_id); 405 blink::WebServiceWorkerCacheError reason) {
406 DCHECK_EQ(thread_id, CurrentWorkerId());
407 WebServiceWorkerCacheStorage::CacheStorageKeysCallbacks* callbacks =
408 keys_callbacks_.Lookup(request_id);
347 callbacks->onError(&reason); 409 callbacks->onError(&reason);
348 keys_callbacks_.Remove(request_id); 410 keys_callbacks_.Remove(request_id);
349 keys_times_.erase(request_id); 411 keys_times_.erase(request_id);
350 } 412 }
351 413
352 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageMatchError( 414 void ServiceWorkerCacheStorageDispatcher::OnCacheStorageMatchError(
415 int thread_id,
353 int request_id, 416 int request_id,
354 blink::WebServiceWorkerCacheError reason) { 417 blink::WebServiceWorkerCacheError reason) {
355 CacheStorageMatchCallbacks* callbacks = match_callbacks_.Lookup(request_id); 418 DCHECK_EQ(thread_id, CurrentWorkerId());
419 WebServiceWorkerCacheStorage::CacheStorageMatchCallbacks* callbacks =
420 match_callbacks_.Lookup(request_id);
356 callbacks->onError(&reason); 421 callbacks->onError(&reason);
357 match_callbacks_.Remove(request_id); 422 match_callbacks_.Remove(request_id);
358 match_times_.erase(request_id); 423 match_times_.erase(request_id);
359 } 424 }
360 425
361 void ServiceWorkerCacheStorageDispatcher::OnCacheMatchSuccess( 426 void ServiceWorkerCacheStorageDispatcher::OnCacheMatchSuccess(
427 int thread_id,
362 int request_id, 428 int request_id,
363 const ServiceWorkerResponse& response) { 429 const ServiceWorkerResponse& response) {
430 DCHECK_EQ(thread_id, CurrentWorkerId());
364 blink::WebServiceWorkerResponse web_response; 431 blink::WebServiceWorkerResponse web_response;
365 PopulateWebResponseFromResponse(response, &web_response); 432 PopulateWebResponseFromResponse(response, &web_response);
366 433
367 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.Cache.Match", 434 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.Cache.Match",
368 TimeTicks::Now() - cache_match_times_[request_id]); 435 TimeTicks::Now() - cache_match_times_[request_id]);
369 blink::WebServiceWorkerCache::CacheMatchCallbacks* callbacks = 436 blink::WebServiceWorkerCache::CacheMatchCallbacks* callbacks =
370 cache_match_callbacks_.Lookup(request_id); 437 cache_match_callbacks_.Lookup(request_id);
371 callbacks->onSuccess(&web_response); 438 callbacks->onSuccess(&web_response);
372 cache_match_callbacks_.Remove(request_id); 439 cache_match_callbacks_.Remove(request_id);
373 cache_match_times_.erase(request_id); 440 cache_match_times_.erase(request_id);
374 } 441 }
375 442
376 void ServiceWorkerCacheStorageDispatcher::OnCacheMatchAllSuccess( 443 void ServiceWorkerCacheStorageDispatcher::OnCacheMatchAllSuccess(
444 int thread_id,
377 int request_id, 445 int request_id,
378 const std::vector<ServiceWorkerResponse>& responses) { 446 const std::vector<ServiceWorkerResponse>& responses) {
447 DCHECK_EQ(thread_id, CurrentWorkerId());
379 blink::WebVector<blink::WebServiceWorkerResponse> 448 blink::WebVector<blink::WebServiceWorkerResponse>
380 web_responses = WebResponsesFromResponses(responses); 449 web_responses = WebResponsesFromResponses(responses);
381 450
382 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.Cache.MatchAll", 451 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.Cache.MatchAll",
383 TimeTicks::Now() - cache_match_all_times_[request_id]); 452 TimeTicks::Now() - cache_match_all_times_[request_id]);
384 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks = 453 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks =
385 cache_match_all_callbacks_.Lookup(request_id); 454 cache_match_all_callbacks_.Lookup(request_id);
386 callbacks->onSuccess(&web_responses); 455 callbacks->onSuccess(&web_responses);
387 cache_match_all_callbacks_.Remove(request_id); 456 cache_match_all_callbacks_.Remove(request_id);
388 cache_match_all_times_.erase(request_id); 457 cache_match_all_times_.erase(request_id);
389 } 458 }
390 459
391 void ServiceWorkerCacheStorageDispatcher::OnCacheKeysSuccess( 460 void ServiceWorkerCacheStorageDispatcher::OnCacheKeysSuccess(
461 int thread_id,
392 int request_id, 462 int request_id,
393 const std::vector<ServiceWorkerFetchRequest>& requests) { 463 const std::vector<ServiceWorkerFetchRequest>& requests) {
464 DCHECK_EQ(thread_id, CurrentWorkerId());
394 blink::WebVector<blink::WebServiceWorkerRequest> 465 blink::WebVector<blink::WebServiceWorkerRequest>
395 web_requests = WebRequestsFromRequests(requests); 466 web_requests = WebRequestsFromRequests(requests);
396 467
397 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.Cache.Keys", 468 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.Cache.Keys",
398 TimeTicks::Now() - cache_keys_times_[request_id]); 469 TimeTicks::Now() - cache_keys_times_[request_id]);
399 blink::WebServiceWorkerCache::CacheWithRequestsCallbacks* callbacks = 470 blink::WebServiceWorkerCache::CacheWithRequestsCallbacks* callbacks =
400 cache_keys_callbacks_.Lookup(request_id); 471 cache_keys_callbacks_.Lookup(request_id);
401 callbacks->onSuccess(&web_requests); 472 callbacks->onSuccess(&web_requests);
402 cache_keys_callbacks_.Remove(request_id); 473 cache_keys_callbacks_.Remove(request_id);
403 cache_keys_times_.erase(request_id); 474 cache_keys_times_.erase(request_id);
404 } 475 }
405 476
406 void ServiceWorkerCacheStorageDispatcher::OnCacheBatchSuccess( 477 void ServiceWorkerCacheStorageDispatcher::OnCacheBatchSuccess(
478 int thread_id,
407 int request_id, 479 int request_id,
408 const std::vector<ServiceWorkerResponse>& responses) { 480 const std::vector<ServiceWorkerResponse>& responses) {
481 DCHECK_EQ(thread_id, CurrentWorkerId());
409 blink::WebVector<blink::WebServiceWorkerResponse> 482 blink::WebVector<blink::WebServiceWorkerResponse>
410 web_responses = WebResponsesFromResponses(responses); 483 web_responses = WebResponsesFromResponses(responses);
411 484
412 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.Cache.Batch", 485 UMA_HISTOGRAM_TIMES("ServiceWorkerCache.Cache.Batch",
413 TimeTicks::Now() - cache_batch_times_[request_id]); 486 TimeTicks::Now() - cache_batch_times_[request_id]);
414 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks = 487 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks =
415 cache_batch_callbacks_.Lookup(request_id); 488 cache_batch_callbacks_.Lookup(request_id);
416 callbacks->onSuccess(&web_responses); 489 callbacks->onSuccess(&web_responses);
417 cache_batch_callbacks_.Remove(request_id); 490 cache_batch_callbacks_.Remove(request_id);
418 cache_batch_times_.erase(request_id); 491 cache_batch_times_.erase(request_id);
419 } 492 }
420 493
421 void ServiceWorkerCacheStorageDispatcher::OnCacheMatchError( 494 void ServiceWorkerCacheStorageDispatcher::OnCacheMatchError(
495 int thread_id,
422 int request_id, 496 int request_id,
423 blink::WebServiceWorkerCacheError reason) { 497 blink::WebServiceWorkerCacheError reason) {
498 DCHECK_EQ(thread_id, CurrentWorkerId());
424 blink::WebServiceWorkerCache::CacheMatchCallbacks* callbacks = 499 blink::WebServiceWorkerCache::CacheMatchCallbacks* callbacks =
425 cache_match_callbacks_.Lookup(request_id); 500 cache_match_callbacks_.Lookup(request_id);
426 callbacks->onError(&reason); 501 callbacks->onError(&reason);
427 cache_match_callbacks_.Remove(request_id); 502 cache_match_callbacks_.Remove(request_id);
428 cache_match_times_.erase(request_id); 503 cache_match_times_.erase(request_id);
429 } 504 }
430 505
431 void ServiceWorkerCacheStorageDispatcher::OnCacheMatchAllError( 506 void ServiceWorkerCacheStorageDispatcher::OnCacheMatchAllError(
507 int thread_id,
432 int request_id, 508 int request_id,
433 blink::WebServiceWorkerCacheError reason) { 509 blink::WebServiceWorkerCacheError reason) {
510 DCHECK_EQ(thread_id, CurrentWorkerId());
434 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks = 511 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks =
435 cache_match_all_callbacks_.Lookup(request_id); 512 cache_match_all_callbacks_.Lookup(request_id);
436 callbacks->onError(&reason); 513 callbacks->onError(&reason);
437 cache_match_all_callbacks_.Remove(request_id); 514 cache_match_all_callbacks_.Remove(request_id);
438 cache_match_all_times_.erase(request_id); 515 cache_match_all_times_.erase(request_id);
439 } 516 }
440 517
441 void ServiceWorkerCacheStorageDispatcher::OnCacheKeysError( 518 void ServiceWorkerCacheStorageDispatcher::OnCacheKeysError(
519 int thread_id,
442 int request_id, 520 int request_id,
443 blink::WebServiceWorkerCacheError reason) { 521 blink::WebServiceWorkerCacheError reason) {
522 DCHECK_EQ(thread_id, CurrentWorkerId());
444 blink::WebServiceWorkerCache::CacheWithRequestsCallbacks* callbacks = 523 blink::WebServiceWorkerCache::CacheWithRequestsCallbacks* callbacks =
445 cache_keys_callbacks_.Lookup(request_id); 524 cache_keys_callbacks_.Lookup(request_id);
446 callbacks->onError(&reason); 525 callbacks->onError(&reason);
447 cache_keys_callbacks_.Remove(request_id); 526 cache_keys_callbacks_.Remove(request_id);
448 cache_keys_times_.erase(request_id); 527 cache_keys_times_.erase(request_id);
449 } 528 }
450 529
451 void ServiceWorkerCacheStorageDispatcher::OnCacheBatchError( 530 void ServiceWorkerCacheStorageDispatcher::OnCacheBatchError(
531 int thread_id,
452 int request_id, 532 int request_id,
453 blink::WebServiceWorkerCacheError reason) { 533 blink::WebServiceWorkerCacheError reason) {
534 DCHECK_EQ(thread_id, CurrentWorkerId());
454 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks = 535 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks =
455 cache_batch_callbacks_.Lookup(request_id); 536 cache_batch_callbacks_.Lookup(request_id);
456 callbacks->onError(&reason); 537 callbacks->onError(&reason);
457 cache_batch_callbacks_.Remove(request_id); 538 cache_batch_callbacks_.Remove(request_id);
458 cache_batch_times_.erase(request_id); 539 cache_batch_times_.erase(request_id);
459 } 540 }
460 541
461 void ServiceWorkerCacheStorageDispatcher::dispatchHas( 542 void ServiceWorkerCacheStorageDispatcher::dispatchHas(
462 CacheStorageCallbacks* callbacks, 543 WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks,
544 const GURL& origin,
463 const blink::WebString& cacheName) { 545 const blink::WebString& cacheName) {
464 int request_id = has_callbacks_.Add(callbacks); 546 int request_id = has_callbacks_.Add(callbacks);
465 has_times_[request_id] = base::TimeTicks::Now(); 547 has_times_[request_id] = base::TimeTicks::Now();
466 script_context_->Send(new ServiceWorkerHostMsg_CacheStorageHas( 548 Send(new ServiceWorkerHostMsg_CacheStorageHas(CurrentWorkerId(), request_id,
467 script_context_->GetRoutingID(), request_id, cacheName)); 549 origin, cacheName));
468 } 550 }
469 551
470 void ServiceWorkerCacheStorageDispatcher::dispatchOpen( 552 void ServiceWorkerCacheStorageDispatcher::dispatchOpen(
471 CacheStorageWithCacheCallbacks* callbacks, 553 WebServiceWorkerCacheStorage::CacheStorageWithCacheCallbacks* callbacks,
554 const GURL& origin,
472 const blink::WebString& cacheName) { 555 const blink::WebString& cacheName) {
473 int request_id = open_callbacks_.Add(callbacks); 556 int request_id = open_callbacks_.Add(callbacks);
474 open_times_[request_id] = base::TimeTicks::Now(); 557 open_times_[request_id] = base::TimeTicks::Now();
475 script_context_->Send(new ServiceWorkerHostMsg_CacheStorageOpen( 558 Send(new ServiceWorkerHostMsg_CacheStorageOpen(CurrentWorkerId(), request_id,
476 script_context_->GetRoutingID(), request_id, cacheName)); 559 origin, cacheName));
477 } 560 }
478 561
479 void ServiceWorkerCacheStorageDispatcher::dispatchDelete( 562 void ServiceWorkerCacheStorageDispatcher::dispatchDelete(
480 CacheStorageCallbacks* callbacks, 563 WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks,
564 const GURL& origin,
481 const blink::WebString& cacheName) { 565 const blink::WebString& cacheName) {
482 int request_id = delete_callbacks_.Add(callbacks); 566 int request_id = delete_callbacks_.Add(callbacks);
483 delete_times_[request_id] = base::TimeTicks::Now(); 567 delete_times_[request_id] = base::TimeTicks::Now();
484 script_context_->Send(new ServiceWorkerHostMsg_CacheStorageDelete( 568 Send(new ServiceWorkerHostMsg_CacheStorageDelete(
485 script_context_->GetRoutingID(), request_id, cacheName)); 569 CurrentWorkerId(), request_id, origin, cacheName));
486 } 570 }
487 571
488 void ServiceWorkerCacheStorageDispatcher::dispatchKeys( 572 void ServiceWorkerCacheStorageDispatcher::dispatchKeys(
489 CacheStorageKeysCallbacks* callbacks) { 573 WebServiceWorkerCacheStorage::CacheStorageKeysCallbacks* callbacks,
574 const GURL& origin) {
490 int request_id = keys_callbacks_.Add(callbacks); 575 int request_id = keys_callbacks_.Add(callbacks);
491 keys_times_[request_id] = base::TimeTicks::Now(); 576 keys_times_[request_id] = base::TimeTicks::Now();
492 script_context_->Send(new ServiceWorkerHostMsg_CacheStorageKeys( 577 Send(new ServiceWorkerHostMsg_CacheStorageKeys(CurrentWorkerId(), request_id,
493 script_context_->GetRoutingID(), request_id)); 578 origin));
494 } 579 }
495 580
496 void ServiceWorkerCacheStorageDispatcher::dispatchMatch( 581 void ServiceWorkerCacheStorageDispatcher::dispatchMatch(
497 CacheStorageMatchCallbacks* callbacks, 582 WebServiceWorkerCacheStorage::CacheStorageMatchCallbacks* callbacks,
583 const GURL& origin,
498 const blink::WebServiceWorkerRequest& request, 584 const blink::WebServiceWorkerRequest& request,
499 const blink::WebServiceWorkerCache::QueryParams& query_params) { 585 const blink::WebServiceWorkerCache::QueryParams& query_params) {
500 int request_id = match_callbacks_.Add(callbacks); 586 int request_id = match_callbacks_.Add(callbacks);
501 match_times_[request_id] = base::TimeTicks::Now(); 587 match_times_[request_id] = base::TimeTicks::Now();
502 script_context_->Send(new ServiceWorkerHostMsg_CacheStorageMatch( 588 Send(new ServiceWorkerHostMsg_CacheStorageMatch(
503 script_context_->GetRoutingID(), request_id, 589 CurrentWorkerId(), request_id, origin,
504 FetchRequestFromWebRequest(request), 590 FetchRequestFromWebRequest(request),
505 QueryParamsFromWebQueryParams(query_params))); 591 QueryParamsFromWebQueryParams(query_params)));
506 } 592 }
507 593
508 void ServiceWorkerCacheStorageDispatcher::dispatchMatchForCache( 594 void ServiceWorkerCacheStorageDispatcher::dispatchMatchForCache(
509 int cache_id, 595 int cache_id,
510 blink::WebServiceWorkerCache::CacheMatchCallbacks* callbacks, 596 blink::WebServiceWorkerCache::CacheMatchCallbacks* callbacks,
511 const blink::WebServiceWorkerRequest& request, 597 const blink::WebServiceWorkerRequest& request,
512 const blink::WebServiceWorkerCache::QueryParams& query_params) { 598 const blink::WebServiceWorkerCache::QueryParams& query_params) {
513 int request_id = cache_match_callbacks_.Add(callbacks); 599 int request_id = cache_match_callbacks_.Add(callbacks);
514 cache_match_times_[request_id] = base::TimeTicks::Now(); 600 cache_match_times_[request_id] = base::TimeTicks::Now();
515 601
516 script_context_->Send(new ServiceWorkerHostMsg_CacheMatch( 602 Send(new ServiceWorkerHostMsg_CacheMatch(
517 script_context_->GetRoutingID(), request_id, cache_id, 603 CurrentWorkerId(), request_id, cache_id,
518 FetchRequestFromWebRequest(request), 604 FetchRequestFromWebRequest(request),
519 QueryParamsFromWebQueryParams(query_params))); 605 QueryParamsFromWebQueryParams(query_params)));
520 } 606 }
521 607
522 void ServiceWorkerCacheStorageDispatcher::dispatchMatchAllForCache( 608 void ServiceWorkerCacheStorageDispatcher::dispatchMatchAllForCache(
523 int cache_id, 609 int cache_id,
524 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks, 610 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks,
525 const blink::WebServiceWorkerRequest& request, 611 const blink::WebServiceWorkerRequest& request,
526 const blink::WebServiceWorkerCache::QueryParams& query_params) { 612 const blink::WebServiceWorkerCache::QueryParams& query_params) {
527 int request_id = cache_match_all_callbacks_.Add(callbacks); 613 int request_id = cache_match_all_callbacks_.Add(callbacks);
528 cache_match_all_times_[request_id] = base::TimeTicks::Now(); 614 cache_match_all_times_[request_id] = base::TimeTicks::Now();
529 615
530 script_context_->Send(new ServiceWorkerHostMsg_CacheMatchAll( 616 Send(new ServiceWorkerHostMsg_CacheMatchAll(
531 script_context_->GetRoutingID(), request_id, cache_id, 617 CurrentWorkerId(), request_id, cache_id,
532 FetchRequestFromWebRequest(request), 618 FetchRequestFromWebRequest(request),
533 QueryParamsFromWebQueryParams(query_params))); 619 QueryParamsFromWebQueryParams(query_params)));
534 } 620 }
535 621
536 void ServiceWorkerCacheStorageDispatcher::dispatchKeysForCache( 622 void ServiceWorkerCacheStorageDispatcher::dispatchKeysForCache(
537 int cache_id, 623 int cache_id,
538 blink::WebServiceWorkerCache::CacheWithRequestsCallbacks* callbacks, 624 blink::WebServiceWorkerCache::CacheWithRequestsCallbacks* callbacks,
539 const blink::WebServiceWorkerRequest* request, 625 const blink::WebServiceWorkerRequest* request,
540 const blink::WebServiceWorkerCache::QueryParams& query_params) { 626 const blink::WebServiceWorkerCache::QueryParams& query_params) {
541 int request_id = cache_keys_callbacks_.Add(callbacks); 627 int request_id = cache_keys_callbacks_.Add(callbacks);
542 cache_keys_times_[request_id] = base::TimeTicks::Now(); 628 cache_keys_times_[request_id] = base::TimeTicks::Now();
543 629
544 script_context_->Send(new ServiceWorkerHostMsg_CacheKeys( 630 Send(new ServiceWorkerHostMsg_CacheKeys(
545 script_context_->GetRoutingID(), request_id, cache_id, 631 CurrentWorkerId(), request_id, cache_id,
546 request ? FetchRequestFromWebRequest(*request) 632 request ? FetchRequestFromWebRequest(*request)
547 : ServiceWorkerFetchRequest(), 633 : ServiceWorkerFetchRequest(),
548 QueryParamsFromWebQueryParams(query_params))); 634 QueryParamsFromWebQueryParams(query_params)));
549 } 635 }
550 636
551 void ServiceWorkerCacheStorageDispatcher::dispatchBatchForCache( 637 void ServiceWorkerCacheStorageDispatcher::dispatchBatchForCache(
552 int cache_id, 638 int cache_id,
553 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks, 639 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks,
554 const blink::WebVector< 640 const blink::WebVector<
555 blink::WebServiceWorkerCache::BatchOperation>& web_operations) { 641 blink::WebServiceWorkerCache::BatchOperation>& web_operations) {
556 int request_id = cache_batch_callbacks_.Add(callbacks); 642 int request_id = cache_batch_callbacks_.Add(callbacks);
557 cache_batch_times_[request_id] = base::TimeTicks::Now(); 643 cache_batch_times_[request_id] = base::TimeTicks::Now();
558 644
559 std::vector<ServiceWorkerBatchOperation> operations; 645 std::vector<ServiceWorkerBatchOperation> operations;
560 operations.reserve(web_operations.size()); 646 operations.reserve(web_operations.size());
561 for (size_t i = 0; i < web_operations.size(); ++i) { 647 for (size_t i = 0; i < web_operations.size(); ++i) {
562 operations.push_back( 648 operations.push_back(
563 BatchOperationFromWebBatchOperation(web_operations[i])); 649 BatchOperationFromWebBatchOperation(web_operations[i]));
564 } 650 }
565 651
566 script_context_->Send(new ServiceWorkerHostMsg_CacheBatch( 652 Send(new ServiceWorkerHostMsg_CacheBatch(CurrentWorkerId(), request_id,
567 script_context_->GetRoutingID(), request_id, cache_id, operations)); 653 cache_id, operations));
568 } 654 }
569 655
570 void ServiceWorkerCacheStorageDispatcher::OnWebCacheDestruction(int cache_id) { 656 void ServiceWorkerCacheStorageDispatcher::OnWebCacheDestruction(int cache_id) {
571 web_caches_.Remove(cache_id); 657 web_caches_.Remove(cache_id);
572 script_context_->Send(new ServiceWorkerHostMsg_CacheClosed( 658 Send(new ServiceWorkerHostMsg_CacheClosed(cache_id));
573 script_context_->GetRoutingID(), cache_id));
574 } 659 }
575 660
576 void ServiceWorkerCacheStorageDispatcher::PopulateWebResponseFromResponse( 661 void ServiceWorkerCacheStorageDispatcher::PopulateWebResponseFromResponse(
577 const ServiceWorkerResponse& response, 662 const ServiceWorkerResponse& response,
578 blink::WebServiceWorkerResponse* web_response) { 663 blink::WebServiceWorkerResponse* web_response) {
579 web_response->setURL(response.url); 664 web_response->setURL(response.url);
580 web_response->setStatus(response.status_code); 665 web_response->setStatus(response.status_code);
581 web_response->setStatusText(base::ASCIIToUTF16(response.status_text)); 666 web_response->setStatusText(base::ASCIIToUTF16(response.status_text));
582 web_response->setResponseType(response.response_type); 667 web_response->setResponseType(response.response_type);
583 668
584 for (const auto& i : response.headers) { 669 for (const auto& i : response.headers) {
585 web_response->setHeader(base::ASCIIToUTF16(i.first), 670 web_response->setHeader(base::ASCIIToUTF16(i.first),
586 base::ASCIIToUTF16(i.second)); 671 base::ASCIIToUTF16(i.second));
587 } 672 }
588 673
589 if (!response.blob_uuid.empty()) { 674 if (!response.blob_uuid.empty()) {
590 web_response->setBlob(blink::WebString::fromUTF8(response.blob_uuid), 675 web_response->setBlob(blink::WebString::fromUTF8(response.blob_uuid),
591 response.blob_size); 676 response.blob_size);
592 // Let the host know that it can release its reference to the blob. 677 // Let the host know that it can release its reference to the blob.
593 script_context_->Send(new ServiceWorkerHostMsg_BlobDataHandled( 678 Send(new ServiceWorkerHostMsg_BlobDataHandled(response.blob_uuid));
594 script_context_->GetRoutingID(), response.blob_uuid));
595 } 679 }
596 } 680 }
597 681
598 blink::WebVector<blink::WebServiceWorkerResponse> 682 blink::WebVector<blink::WebServiceWorkerResponse>
599 ServiceWorkerCacheStorageDispatcher::WebResponsesFromResponses( 683 ServiceWorkerCacheStorageDispatcher::WebResponsesFromResponses(
600 const std::vector<ServiceWorkerResponse>& responses) { 684 const std::vector<ServiceWorkerResponse>& responses) {
601 blink::WebVector<blink::WebServiceWorkerResponse> web_responses( 685 blink::WebVector<blink::WebServiceWorkerResponse> web_responses(
602 responses.size()); 686 responses.size());
603 for (size_t i = 0; i < responses.size(); ++i) 687 for (size_t i = 0; i < responses.size(); ++i)
604 PopulateWebResponseFromResponse(responses[i], &(web_responses[i])); 688 PopulateWebResponseFromResponse(responses[i], &(web_responses[i]));
605 return web_responses; 689 return web_responses;
606 } 690 }
607 691
608 } // namespace content 692 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698