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 #include "content/renderer/cache_storage/cache_storage_dispatcher.h" | 5 #include "content/renderer/cache_storage/cache_storage_dispatcher.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 typename T::iterator iter(callbacks_map); | 129 typename T::iterator iter(callbacks_map); |
130 while (!iter.IsAtEnd()) { | 130 while (!iter.IsAtEnd()) { |
131 iter.GetCurrentValue()->onError( | 131 iter.GetCurrentValue()->onError( |
132 new blink::WebServiceWorkerCacheError( | 132 new blink::WebServiceWorkerCacheError( |
133 blink::WebServiceWorkerCacheErrorNotFound)); | 133 blink::WebServiceWorkerCacheErrorNotFound)); |
134 callbacks_map->Remove(iter.GetCurrentKey()); | 134 callbacks_map->Remove(iter.GetCurrentKey()); |
135 iter.Advance(); | 135 iter.Advance(); |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
| 139 template <typename T> |
| 140 void ClearCallbacksMapWithErrorsNonPtr(T* callbacks_map) { |
| 141 typename T::iterator iter(callbacks_map); |
| 142 while (!iter.IsAtEnd()) { |
| 143 iter.GetCurrentValue()->onError(blink::WebServiceWorkerCacheError( |
| 144 blink::WebServiceWorkerCacheErrorNotFound)); |
| 145 callbacks_map->Remove(iter.GetCurrentKey()); |
| 146 iter.Advance(); |
| 147 } |
| 148 } |
| 149 |
139 } // namespace | 150 } // namespace |
140 | 151 |
141 // The WebCache object is the Chromium side implementation of the Blink | 152 // The WebCache object is the Chromium side implementation of the Blink |
142 // WebServiceWorkerCache API. Most of its methods delegate directly to the | 153 // WebServiceWorkerCache API. Most of its methods delegate directly to the |
143 // ServiceWorkerStorage object, which is able to assign unique IDs as well | 154 // ServiceWorkerStorage object, which is able to assign unique IDs as well |
144 // as have a lifetime longer than the requests. | 155 // as have a lifetime longer than the requests. |
145 class CacheStorageDispatcher::WebCache : public blink::WebServiceWorkerCache { | 156 class CacheStorageDispatcher::WebCache : public blink::WebServiceWorkerCache { |
146 public: | 157 public: |
147 WebCache(base::WeakPtr<CacheStorageDispatcher> dispatcher, int cache_id) | 158 WebCache(base::WeakPtr<CacheStorageDispatcher> dispatcher, int cache_id) |
148 : dispatcher_(dispatcher), cache_id_(cache_id) {} | 159 : dispatcher_(dispatcher), cache_id_(cache_id) {} |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 CacheStorageDispatcher::~CacheStorageDispatcher() { | 210 CacheStorageDispatcher::~CacheStorageDispatcher() { |
200 ClearCallbacksMapWithErrors(&has_callbacks_); | 211 ClearCallbacksMapWithErrors(&has_callbacks_); |
201 ClearCallbacksMapWithErrors(&open_callbacks_); | 212 ClearCallbacksMapWithErrors(&open_callbacks_); |
202 ClearCallbacksMapWithErrors(&delete_callbacks_); | 213 ClearCallbacksMapWithErrors(&delete_callbacks_); |
203 ClearCallbacksMapWithErrors(&keys_callbacks_); | 214 ClearCallbacksMapWithErrors(&keys_callbacks_); |
204 ClearCallbacksMapWithErrors(&match_callbacks_); | 215 ClearCallbacksMapWithErrors(&match_callbacks_); |
205 | 216 |
206 ClearCallbacksMapWithErrors(&cache_match_callbacks_); | 217 ClearCallbacksMapWithErrors(&cache_match_callbacks_); |
207 ClearCallbacksMapWithErrors(&cache_match_all_callbacks_); | 218 ClearCallbacksMapWithErrors(&cache_match_all_callbacks_); |
208 ClearCallbacksMapWithErrors(&cache_keys_callbacks_); | 219 ClearCallbacksMapWithErrors(&cache_keys_callbacks_); |
209 ClearCallbacksMapWithErrors(&cache_batch_callbacks_); | 220 ClearCallbacksMapWithErrorsNonPtr(&cache_batch_callbacks_); |
210 | 221 |
211 g_cache_storage_dispatcher_tls.Pointer()->Set(kHasBeenDeleted); | 222 g_cache_storage_dispatcher_tls.Pointer()->Set(kHasBeenDeleted); |
212 } | 223 } |
213 | 224 |
214 CacheStorageDispatcher* CacheStorageDispatcher::ThreadSpecificInstance( | 225 CacheStorageDispatcher* CacheStorageDispatcher::ThreadSpecificInstance( |
215 ThreadSafeSender* thread_safe_sender) { | 226 ThreadSafeSender* thread_safe_sender) { |
216 if (g_cache_storage_dispatcher_tls.Pointer()->Get() == kHasBeenDeleted) { | 227 if (g_cache_storage_dispatcher_tls.Pointer()->Get() == kHasBeenDeleted) { |
217 NOTREACHED() << "Re-instantiating TLS CacheStorageDispatcher."; | 228 NOTREACHED() << "Re-instantiating TLS CacheStorageDispatcher."; |
218 g_cache_storage_dispatcher_tls.Pointer()->Set(NULL); | 229 g_cache_storage_dispatcher_tls.Pointer()->Set(NULL); |
219 } | 230 } |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 cache_keys_times_.erase(request_id); | 522 cache_keys_times_.erase(request_id); |
512 } | 523 } |
513 | 524 |
514 void CacheStorageDispatcher::OnCacheBatchError( | 525 void CacheStorageDispatcher::OnCacheBatchError( |
515 int thread_id, | 526 int thread_id, |
516 int request_id, | 527 int request_id, |
517 blink::WebServiceWorkerCacheError reason) { | 528 blink::WebServiceWorkerCacheError reason) { |
518 DCHECK_EQ(thread_id, CurrentWorkerId()); | 529 DCHECK_EQ(thread_id, CurrentWorkerId()); |
519 blink::WebServiceWorkerCache::CacheBatchCallbacks* callbacks = | 530 blink::WebServiceWorkerCache::CacheBatchCallbacks* callbacks = |
520 cache_batch_callbacks_.Lookup(request_id); | 531 cache_batch_callbacks_.Lookup(request_id); |
521 callbacks->onError(new blink::WebServiceWorkerCacheError(reason)); | 532 callbacks->onError(blink::WebServiceWorkerCacheError(reason)); |
522 cache_batch_callbacks_.Remove(request_id); | 533 cache_batch_callbacks_.Remove(request_id); |
523 cache_batch_times_.erase(request_id); | 534 cache_batch_times_.erase(request_id); |
524 } | 535 } |
525 | 536 |
526 void CacheStorageDispatcher::dispatchHas( | 537 void CacheStorageDispatcher::dispatchHas( |
527 WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks, | 538 WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks, |
528 const GURL& origin, | 539 const GURL& origin, |
529 const blink::WebString& cacheName) { | 540 const blink::WebString& cacheName) { |
530 int request_id = has_callbacks_.Add(callbacks); | 541 int request_id = has_callbacks_.Add(callbacks); |
531 has_times_[request_id] = base::TimeTicks::Now(); | 542 has_times_[request_id] = base::TimeTicks::Now(); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 CacheStorageDispatcher::WebResponsesFromResponses( | 678 CacheStorageDispatcher::WebResponsesFromResponses( |
668 const std::vector<ServiceWorkerResponse>& responses) { | 679 const std::vector<ServiceWorkerResponse>& responses) { |
669 blink::WebVector<blink::WebServiceWorkerResponse> web_responses( | 680 blink::WebVector<blink::WebServiceWorkerResponse> web_responses( |
670 responses.size()); | 681 responses.size()); |
671 for (size_t i = 0; i < responses.size(); ++i) | 682 for (size_t i = 0; i < responses.size(); ++i) |
672 PopulateWebResponseFromResponse(responses[i], &(web_responses[i])); | 683 PopulateWebResponseFromResponse(responses[i], &(web_responses[i])); |
673 return web_responses; | 684 return web_responses; |
674 } | 685 } |
675 | 686 |
676 } // namespace content | 687 } // namespace content |
OLD | NEW |