OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/browser/cache_storage/cache_storage_dispatcher_host.h" | 5 #include "content/browser/cache_storage/cache_storage_dispatcher_host.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> |
8 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
15 #include "content/browser/bad_message.h" | 16 #include "content/browser/bad_message.h" |
16 #include "content/browser/cache_storage/cache_storage_cache.h" | 17 #include "content/browser/cache_storage/cache_storage_cache.h" |
17 #include "content/browser/cache_storage/cache_storage_context_impl.h" | 18 #include "content/browser/cache_storage/cache_storage_context_impl.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); | 184 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); |
184 return; | 185 return; |
185 } | 186 } |
186 scoped_ptr<ServiceWorkerFetchRequest> scoped_request( | 187 scoped_ptr<ServiceWorkerFetchRequest> scoped_request( |
187 new ServiceWorkerFetchRequest(request.url, request.method, | 188 new ServiceWorkerFetchRequest(request.url, request.method, |
188 request.headers, request.referrer, | 189 request.headers, request.referrer, |
189 request.is_reload)); | 190 request.is_reload)); |
190 | 191 |
191 if (match_params.cache_name.empty()) { | 192 if (match_params.cache_name.empty()) { |
192 context_->cache_manager()->MatchAllCaches( | 193 context_->cache_manager()->MatchAllCaches( |
193 origin, scoped_request.Pass(), | 194 origin, std::move(scoped_request), |
194 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageMatchCallback, | 195 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageMatchCallback, |
195 this, thread_id, request_id)); | 196 this, thread_id, request_id)); |
196 return; | 197 return; |
197 } | 198 } |
198 context_->cache_manager()->MatchCache( | 199 context_->cache_manager()->MatchCache( |
199 origin, base::UTF16ToUTF8(match_params.cache_name), scoped_request.Pass(), | 200 origin, base::UTF16ToUTF8(match_params.cache_name), |
| 201 std::move(scoped_request), |
200 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageMatchCallback, this, | 202 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageMatchCallback, this, |
201 thread_id, request_id)); | 203 thread_id, request_id)); |
202 } | 204 } |
203 | 205 |
204 void CacheStorageDispatcherHost::OnCacheMatch( | 206 void CacheStorageDispatcherHost::OnCacheMatch( |
205 int thread_id, | 207 int thread_id, |
206 int request_id, | 208 int request_id, |
207 int cache_id, | 209 int cache_id, |
208 const ServiceWorkerFetchRequest& request, | 210 const ServiceWorkerFetchRequest& request, |
209 const CacheStorageCacheQueryParams& match_params) { | 211 const CacheStorageCacheQueryParams& match_params) { |
210 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id); | 212 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id); |
211 if (it == id_to_cache_map_.end()) { | 213 if (it == id_to_cache_map_.end()) { |
212 Send(new CacheStorageMsg_CacheMatchError( | 214 Send(new CacheStorageMsg_CacheMatchError( |
213 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); | 215 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); |
214 return; | 216 return; |
215 } | 217 } |
216 | 218 |
217 scoped_refptr<CacheStorageCache> cache = it->second; | 219 scoped_refptr<CacheStorageCache> cache = it->second; |
218 scoped_ptr<ServiceWorkerFetchRequest> scoped_request( | 220 scoped_ptr<ServiceWorkerFetchRequest> scoped_request( |
219 new ServiceWorkerFetchRequest(request.url, request.method, | 221 new ServiceWorkerFetchRequest(request.url, request.method, |
220 request.headers, request.referrer, | 222 request.headers, request.referrer, |
221 request.is_reload)); | 223 request.is_reload)); |
222 cache->Match(scoped_request.Pass(), | 224 cache->Match(std::move(scoped_request), |
223 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchCallback, | 225 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchCallback, |
224 this, thread_id, request_id, cache)); | 226 this, thread_id, request_id, cache)); |
225 } | 227 } |
226 | 228 |
227 void CacheStorageDispatcherHost::OnCacheMatchAll( | 229 void CacheStorageDispatcherHost::OnCacheMatchAll( |
228 int thread_id, | 230 int thread_id, |
229 int request_id, | 231 int request_id, |
230 int cache_id, | 232 int cache_id, |
231 const ServiceWorkerFetchRequest& request, | 233 const ServiceWorkerFetchRequest& request, |
232 const CacheStorageCacheQueryParams& match_params) { | 234 const CacheStorageCacheQueryParams& match_params) { |
(...skipping 10 matching lines...) Expand all Loading... |
243 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchAllCallback, this, | 245 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchAllCallback, this, |
244 thread_id, request_id, cache)); | 246 thread_id, request_id, cache)); |
245 return; | 247 return; |
246 } | 248 } |
247 | 249 |
248 scoped_ptr<ServiceWorkerFetchRequest> scoped_request( | 250 scoped_ptr<ServiceWorkerFetchRequest> scoped_request( |
249 new ServiceWorkerFetchRequest(request.url, request.method, | 251 new ServiceWorkerFetchRequest(request.url, request.method, |
250 request.headers, request.referrer, | 252 request.headers, request.referrer, |
251 request.is_reload)); | 253 request.is_reload)); |
252 cache->Match( | 254 cache->Match( |
253 scoped_request.Pass(), | 255 std::move(scoped_request), |
254 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchAllCallbackAdapter, | 256 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchAllCallbackAdapter, |
255 this, thread_id, request_id, cache)); | 257 this, thread_id, request_id, cache)); |
256 } | 258 } |
257 | 259 |
258 void CacheStorageDispatcherHost::OnCacheKeys( | 260 void CacheStorageDispatcherHost::OnCacheKeys( |
259 int thread_id, | 261 int thread_id, |
260 int request_id, | 262 int request_id, |
261 int cache_id, | 263 int cache_id, |
262 const ServiceWorkerFetchRequest& request, | 264 const ServiceWorkerFetchRequest& request, |
263 const CacheStorageCacheQueryParams& match_params) { | 265 const CacheStorageCacheQueryParams& match_params) { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 scoped_ptr<CacheStorageCache::Responses> responses( | 414 scoped_ptr<CacheStorageCache::Responses> responses( |
413 new CacheStorageCache::Responses); | 415 new CacheStorageCache::Responses); |
414 scoped_ptr<CacheStorageCache::BlobDataHandles> blob_data_handles( | 416 scoped_ptr<CacheStorageCache::BlobDataHandles> blob_data_handles( |
415 new CacheStorageCache::BlobDataHandles); | 417 new CacheStorageCache::BlobDataHandles); |
416 if (error == CACHE_STORAGE_OK) { | 418 if (error == CACHE_STORAGE_OK) { |
417 DCHECK(response); | 419 DCHECK(response); |
418 responses->push_back(*response); | 420 responses->push_back(*response); |
419 if (blob_data_handle) | 421 if (blob_data_handle) |
420 blob_data_handles->push_back(*blob_data_handle); | 422 blob_data_handles->push_back(*blob_data_handle); |
421 } | 423 } |
422 OnCacheMatchAllCallback(thread_id, request_id, cache, error, responses.Pass(), | 424 OnCacheMatchAllCallback(thread_id, request_id, cache, error, |
423 blob_data_handles.Pass()); | 425 std::move(responses), std::move(blob_data_handles)); |
424 } | 426 } |
425 | 427 |
426 void CacheStorageDispatcherHost::OnCacheMatchAllCallback( | 428 void CacheStorageDispatcherHost::OnCacheMatchAllCallback( |
427 int thread_id, | 429 int thread_id, |
428 int request_id, | 430 int request_id, |
429 const scoped_refptr<CacheStorageCache>& cache, | 431 const scoped_refptr<CacheStorageCache>& cache, |
430 CacheStorageError error, | 432 CacheStorageError error, |
431 scoped_ptr<CacheStorageCache::Responses> responses, | 433 scoped_ptr<CacheStorageCache::Responses> responses, |
432 scoped_ptr<CacheStorageCache::BlobDataHandles> blob_data_handles) { | 434 scoped_ptr<CacheStorageCache::BlobDataHandles> blob_data_handles) { |
433 if (error != CACHE_STORAGE_OK && error != CACHE_STORAGE_ERROR_NOT_FOUND) { | 435 if (error != CACHE_STORAGE_OK && error != CACHE_STORAGE_ERROR_NOT_FOUND) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid); | 507 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid); |
506 if (it == blob_handle_store_.end()) | 508 if (it == blob_handle_store_.end()) |
507 return; | 509 return; |
508 DCHECK(!it->second.empty()); | 510 DCHECK(!it->second.empty()); |
509 it->second.pop_front(); | 511 it->second.pop_front(); |
510 if (it->second.empty()) | 512 if (it->second.empty()) |
511 blob_handle_store_.erase(it); | 513 blob_handle_store_.erase(it); |
512 } | 514 } |
513 | 515 |
514 } // namespace content | 516 } // namespace content |
OLD | NEW |