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

Side by Side Diff: content/browser/cache_storage/cache_storage_cache.cc

Issue 1174943004: [CacheStorage] Use URLRequestContextGetter instead of URLRequestContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments from PS4 Created 5 years, 6 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/browser/cache_storage/cache_storage_cache.h" 5 #include "content/browser/cache_storage/cache_storage_cache.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/barrier_closure.h" 9 #include "base/barrier_closure.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/guid.h" 11 #include "base/guid.h"
12 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "content/browser/cache_storage/cache_storage.pb.h" 14 #include "content/browser/cache_storage/cache_storage.pb.h"
15 #include "content/browser/cache_storage/cache_storage_scheduler.h" 15 #include "content/browser/cache_storage/cache_storage_scheduler.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/common/referrer.h" 17 #include "content/public/common/referrer.h"
18 #include "net/base/completion_callback.h" 18 #include "net/base/completion_callback.h"
19 #include "net/base/io_buffer.h" 19 #include "net/base/io_buffer.h"
20 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
21 #include "net/disk_cache/disk_cache.h" 21 #include "net/disk_cache/disk_cache.h"
22 #include "net/url_request/url_request_context.h" 22 #include "net/url_request/url_request_context_getter.h"
23 #include "storage/browser/blob/blob_data_builder.h" 23 #include "storage/browser/blob/blob_data_builder.h"
24 #include "storage/browser/blob/blob_data_handle.h" 24 #include "storage/browser/blob/blob_data_handle.h"
25 #include "storage/browser/blob/blob_storage_context.h" 25 #include "storage/browser/blob/blob_storage_context.h"
26 #include "storage/browser/blob/blob_url_request_job_factory.h" 26 #include "storage/browser/blob/blob_url_request_job_factory.h"
27 #include "storage/browser/quota/quota_manager_proxy.h" 27 #include "storage/browser/quota/quota_manager_proxy.h"
28 #include "third_party/WebKit/public/platform/WebServiceWorkerResponseType.h" 28 #include "third_party/WebKit/public/platform/WebServiceWorkerResponseType.h"
29 29
30 namespace content { 30 namespace content {
31 31
32 namespace { 32 namespace {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 public: 171 public:
172 typedef base::Callback<void(disk_cache::ScopedEntryPtr, bool)> 172 typedef base::Callback<void(disk_cache::ScopedEntryPtr, bool)>
173 EntryAndBoolCallback; 173 EntryAndBoolCallback;
174 174
175 BlobReader() 175 BlobReader()
176 : cache_entry_offset_(0), 176 : cache_entry_offset_(0),
177 buffer_(new net::IOBufferWithSize(kBufferSize)), 177 buffer_(new net::IOBufferWithSize(kBufferSize)),
178 weak_ptr_factory_(this) {} 178 weak_ptr_factory_(this) {}
179 179
180 // |entry| is passed to the callback once complete. 180 // |entry| is passed to the callback once complete.
181 void StreamBlobToCache(disk_cache::ScopedEntryPtr entry, 181 void StreamBlobToCache(
182 net::URLRequestContext* request_context, 182 disk_cache::ScopedEntryPtr entry,
183 scoped_ptr<storage::BlobDataHandle> blob_data_handle, 183 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
184 const EntryAndBoolCallback& callback) { 184 scoped_ptr<storage::BlobDataHandle> blob_data_handle,
185 const EntryAndBoolCallback& callback) {
185 DCHECK(entry); 186 DCHECK(entry);
187 DCHECK(request_context_getter->GetURLRequestContext());
188
186 entry_ = entry.Pass(); 189 entry_ = entry.Pass();
187 callback_ = callback; 190 callback_ = callback;
191
188 blob_request_ = storage::BlobProtocolHandler::CreateBlobRequest( 192 blob_request_ = storage::BlobProtocolHandler::CreateBlobRequest(
189 blob_data_handle.Pass(), request_context, this); 193 blob_data_handle.Pass(), request_context_getter->GetURLRequestContext(),
194 this);
190 blob_request_->Start(); 195 blob_request_->Start();
191 } 196 }
192 197
193 // net::URLRequest::Delegate overrides for reading blobs. 198 // net::URLRequest::Delegate overrides for reading blobs.
194 void OnReceivedRedirect(net::URLRequest* request, 199 void OnReceivedRedirect(net::URLRequest* request,
195 const net::RedirectInfo& redirect_info, 200 const net::RedirectInfo& redirect_info,
196 bool* defer_redirect) override { 201 bool* defer_redirect) override {
197 NOTREACHED(); 202 NOTREACHED();
198 } 203 }
199 void OnAuthRequired(net::URLRequest* request, 204 void OnAuthRequired(net::URLRequest* request,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 }; 339 };
335 340
336 // The state needed to pass between CacheStorageCache::Put callbacks. 341 // The state needed to pass between CacheStorageCache::Put callbacks.
337 struct CacheStorageCache::PutContext { 342 struct CacheStorageCache::PutContext {
338 PutContext( 343 PutContext(
339 const GURL& origin, 344 const GURL& origin,
340 scoped_ptr<ServiceWorkerFetchRequest> request, 345 scoped_ptr<ServiceWorkerFetchRequest> request,
341 scoped_ptr<ServiceWorkerResponse> response, 346 scoped_ptr<ServiceWorkerResponse> response,
342 scoped_ptr<storage::BlobDataHandle> blob_data_handle, 347 scoped_ptr<storage::BlobDataHandle> blob_data_handle,
343 const CacheStorageCache::ErrorCallback& callback, 348 const CacheStorageCache::ErrorCallback& callback,
344 net::URLRequestContext* request_context, 349 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
345 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy) 350 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy)
346 : origin(origin), 351 : origin(origin),
347 request(request.Pass()), 352 request(request.Pass()),
348 response(response.Pass()), 353 response(response.Pass()),
349 blob_data_handle(blob_data_handle.Pass()), 354 blob_data_handle(blob_data_handle.Pass()),
350 callback(callback), 355 callback(callback),
351 request_context(request_context), 356 request_context_getter(request_context_getter),
352 quota_manager_proxy(quota_manager_proxy), 357 quota_manager_proxy(quota_manager_proxy),
353 cache_entry(NULL) {} 358 cache_entry(NULL) {}
354 ~PutContext() { 359 ~PutContext() {
355 if (cache_entry) 360 if (cache_entry)
356 cache_entry->Close(); 361 cache_entry->Close();
357 } 362 }
358 363
359 // Input parameters to the Put function. 364 // Input parameters to the Put function.
360 GURL origin; 365 GURL origin;
361 scoped_ptr<ServiceWorkerFetchRequest> request; 366 scoped_ptr<ServiceWorkerFetchRequest> request;
362 scoped_ptr<ServiceWorkerResponse> response; 367 scoped_ptr<ServiceWorkerResponse> response;
363 scoped_ptr<storage::BlobDataHandle> blob_data_handle; 368 scoped_ptr<storage::BlobDataHandle> blob_data_handle;
364 CacheStorageCache::ErrorCallback callback; 369 CacheStorageCache::ErrorCallback callback;
365 net::URLRequestContext* request_context; 370 scoped_refptr<net::URLRequestContextGetter> request_context_getter;
366 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy; 371 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy;
367 372
368 // This isn't a scoped_ptr because the disk_cache needs an Entry** as input to 373 // This isn't a scoped_ptr because the disk_cache needs an Entry** as input to
369 // CreateEntry. 374 // CreateEntry.
370 disk_cache::Entry* cache_entry; 375 disk_cache::Entry* cache_entry;
371 376
372 DISALLOW_COPY_AND_ASSIGN(PutContext); 377 DISALLOW_COPY_AND_ASSIGN(PutContext);
373 }; 378 };
374 379
375 // static 380 // static
376 scoped_refptr<CacheStorageCache> CacheStorageCache::CreateMemoryCache( 381 scoped_refptr<CacheStorageCache> CacheStorageCache::CreateMemoryCache(
377 const GURL& origin, 382 const GURL& origin,
378 net::URLRequestContext* request_context, 383 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
379 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, 384 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy,
380 base::WeakPtr<storage::BlobStorageContext> blob_context) { 385 base::WeakPtr<storage::BlobStorageContext> blob_context) {
381 return make_scoped_refptr( 386 return make_scoped_refptr(
382 new CacheStorageCache(origin, base::FilePath(), request_context, 387 new CacheStorageCache(origin, base::FilePath(), request_context_getter,
383 quota_manager_proxy, blob_context)); 388 quota_manager_proxy, blob_context));
384 } 389 }
385 390
386 // static 391 // static
387 scoped_refptr<CacheStorageCache> CacheStorageCache::CreatePersistentCache( 392 scoped_refptr<CacheStorageCache> CacheStorageCache::CreatePersistentCache(
388 const GURL& origin, 393 const GURL& origin,
389 const base::FilePath& path, 394 const base::FilePath& path,
390 net::URLRequestContext* request_context, 395 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
391 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, 396 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy,
392 base::WeakPtr<storage::BlobStorageContext> blob_context) { 397 base::WeakPtr<storage::BlobStorageContext> blob_context) {
393 return make_scoped_refptr(new CacheStorageCache( 398 return make_scoped_refptr(new CacheStorageCache(
394 origin, path, request_context, quota_manager_proxy, blob_context)); 399 origin, path, request_context_getter, quota_manager_proxy, blob_context));
395 } 400 }
396 401
397 CacheStorageCache::~CacheStorageCache() { 402 CacheStorageCache::~CacheStorageCache() {
398 } 403 }
399 404
400 base::WeakPtr<CacheStorageCache> CacheStorageCache::AsWeakPtr() { 405 base::WeakPtr<CacheStorageCache> CacheStorageCache::AsWeakPtr() {
401 return weak_ptr_factory_.GetWeakPtr(); 406 return weak_ptr_factory_.GetWeakPtr();
402 } 407 }
403 408
404 void CacheStorageCache::Match(scoped_ptr<ServiceWorkerFetchRequest> request, 409 void CacheStorageCache::Match(scoped_ptr<ServiceWorkerFetchRequest> request,
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 entry->GetDataSize(INDEX_RESPONSE_BODY); 552 entry->GetDataSize(INDEX_RESPONSE_BODY);
548 entry->Close(); 553 entry->Close();
549 } 554 }
550 555
551 return sum; 556 return sum;
552 } 557 }
553 558
554 CacheStorageCache::CacheStorageCache( 559 CacheStorageCache::CacheStorageCache(
555 const GURL& origin, 560 const GURL& origin,
556 const base::FilePath& path, 561 const base::FilePath& path,
557 net::URLRequestContext* request_context, 562 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
558 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, 563 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy,
559 base::WeakPtr<storage::BlobStorageContext> blob_context) 564 base::WeakPtr<storage::BlobStorageContext> blob_context)
560 : origin_(origin), 565 : origin_(origin),
561 path_(path), 566 path_(path),
562 request_context_(request_context), 567 request_context_getter_(request_context_getter),
563 quota_manager_proxy_(quota_manager_proxy), 568 quota_manager_proxy_(quota_manager_proxy),
564 blob_storage_context_(blob_context), 569 blob_storage_context_(blob_context),
565 backend_state_(BACKEND_UNINITIALIZED), 570 backend_state_(BACKEND_UNINITIALIZED),
566 scheduler_(new CacheStorageScheduler()), 571 scheduler_(new CacheStorageScheduler()),
567 initializing_(false), 572 initializing_(false),
568 memory_only_(path.empty()), 573 memory_only_(path.empty()),
569 weak_ptr_factory_(this) { 574 weak_ptr_factory_(this) {
570 } 575 }
571 576
572 void CacheStorageCache::MatchImpl(scoped_ptr<ServiceWorkerFetchRequest> request, 577 void CacheStorageCache::MatchImpl(scoped_ptr<ServiceWorkerFetchRequest> request,
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 return; 792 return;
788 } 793 }
789 } 794 }
790 795
791 ErrorCallback pending_callback = 796 ErrorCallback pending_callback =
792 base::Bind(&CacheStorageCache::PendingErrorCallback, 797 base::Bind(&CacheStorageCache::PendingErrorCallback,
793 weak_ptr_factory_.GetWeakPtr(), callback); 798 weak_ptr_factory_.GetWeakPtr(), callback);
794 799
795 scoped_ptr<PutContext> put_context(new PutContext( 800 scoped_ptr<PutContext> put_context(new PutContext(
796 origin_, request.Pass(), response.Pass(), blob_data_handle.Pass(), 801 origin_, request.Pass(), response.Pass(), blob_data_handle.Pass(),
797 pending_callback, request_context_, quota_manager_proxy_)); 802 pending_callback, request_context_getter_, quota_manager_proxy_));
798 803
799 scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::PutImpl, 804 scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::PutImpl,
800 weak_ptr_factory_.GetWeakPtr(), 805 weak_ptr_factory_.GetWeakPtr(),
801 base::Passed(put_context.Pass()))); 806 base::Passed(put_context.Pass())));
802 } 807 }
803 808
804 void CacheStorageCache::PutImpl(scoped_ptr<PutContext> put_context) { 809 void CacheStorageCache::PutImpl(scoped_ptr<PutContext> put_context) {
805 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); 810 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_);
806 if (backend_state_ != BACKEND_OPEN) { 811 if (backend_state_ != BACKEND_OPEN) {
807 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE); 812 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 } 930 }
926 931
927 DCHECK(put_context->blob_data_handle); 932 DCHECK(put_context->blob_data_handle);
928 933
929 disk_cache::ScopedEntryPtr entry(put_context->cache_entry); 934 disk_cache::ScopedEntryPtr entry(put_context->cache_entry);
930 put_context->cache_entry = NULL; 935 put_context->cache_entry = NULL;
931 scoped_ptr<BlobReader> reader(new BlobReader()); 936 scoped_ptr<BlobReader> reader(new BlobReader());
932 BlobReader* reader_ptr = reader.get(); 937 BlobReader* reader_ptr = reader.get();
933 938
934 // Grab some pointers before passing put_context in Bind. 939 // Grab some pointers before passing put_context in Bind.
935 net::URLRequestContext* request_context = put_context->request_context; 940 scoped_refptr<net::URLRequestContextGetter> request_context_getter =
941 put_context->request_context_getter;
936 scoped_ptr<storage::BlobDataHandle> blob_data_handle = 942 scoped_ptr<storage::BlobDataHandle> blob_data_handle =
937 put_context->blob_data_handle.Pass(); 943 put_context->blob_data_handle.Pass();
938 944
939 reader_ptr->StreamBlobToCache( 945 reader_ptr->StreamBlobToCache(
940 entry.Pass(), request_context, blob_data_handle.Pass(), 946 entry.Pass(), request_context_getter, blob_data_handle.Pass(),
941 base::Bind(&CacheStorageCache::PutDidWriteBlobToCache, 947 base::Bind(&CacheStorageCache::PutDidWriteBlobToCache,
942 weak_ptr_factory_.GetWeakPtr(), 948 weak_ptr_factory_.GetWeakPtr(),
943 base::Passed(put_context.Pass()), 949 base::Passed(put_context.Pass()),
944 base::Passed(reader.Pass()))); 950 base::Passed(reader.Pass())));
945 } 951 }
946 952
947 void CacheStorageCache::PutDidWriteBlobToCache( 953 void CacheStorageCache::PutDidWriteBlobToCache(
948 scoped_ptr<PutContext> put_context, 954 scoped_ptr<PutContext> put_context,
949 scoped_ptr<BlobReader> blob_reader, 955 scoped_ptr<BlobReader> blob_reader,
950 disk_cache::ScopedEntryPtr entry, 956 disk_cache::ScopedEntryPtr entry,
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 CacheStorageError error, 1271 CacheStorageError error,
1266 scoped_ptr<Requests> requests) { 1272 scoped_ptr<Requests> requests) {
1267 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr(); 1273 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr();
1268 1274
1269 callback.Run(error, requests.Pass()); 1275 callback.Run(error, requests.Pass());
1270 if (cache) 1276 if (cache)
1271 scheduler_->CompleteOperationAndRunNext(); 1277 scheduler_->CompleteOperationAndRunNext();
1272 } 1278 }
1273 1279
1274 } // namespace content 1280 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/cache_storage/cache_storage_cache.h ('k') | content/browser/cache_storage/cache_storage_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698