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

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: Actually pass a getter 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,
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->GetURLRequestContext());
mmenke 2015/06/10 17:00:31 Do we have a strong guarantee that if we shut down
jkarlin 2015/06/10 18:26:03 This is only called via blink->...->RenderProcessH
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->GetURLRequestContext(), this);
190 blob_request_->Start(); 194 blob_request_->Start();
191 } 195 }
192 196
193 // net::URLRequest::Delegate overrides for reading blobs. 197 // net::URLRequest::Delegate overrides for reading blobs.
194 void OnReceivedRedirect(net::URLRequest* request, 198 void OnReceivedRedirect(net::URLRequest* request,
195 const net::RedirectInfo& redirect_info, 199 const net::RedirectInfo& redirect_info,
196 bool* defer_redirect) override { 200 bool* defer_redirect) override {
197 NOTREACHED(); 201 NOTREACHED();
198 } 202 }
199 void OnAuthRequired(net::URLRequest* request, 203 void OnAuthRequired(net::URLRequest* request,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 }; 338 };
335 339
336 // The state needed to pass between CacheStorageCache::Put callbacks. 340 // The state needed to pass between CacheStorageCache::Put callbacks.
337 struct CacheStorageCache::PutContext { 341 struct CacheStorageCache::PutContext {
338 PutContext( 342 PutContext(
339 const GURL& origin, 343 const GURL& origin,
340 scoped_ptr<ServiceWorkerFetchRequest> request, 344 scoped_ptr<ServiceWorkerFetchRequest> request,
341 scoped_ptr<ServiceWorkerResponse> response, 345 scoped_ptr<ServiceWorkerResponse> response,
342 scoped_ptr<storage::BlobDataHandle> blob_data_handle, 346 scoped_ptr<storage::BlobDataHandle> blob_data_handle,
343 const CacheStorageCache::ErrorCallback& callback, 347 const CacheStorageCache::ErrorCallback& callback,
344 net::URLRequestContext* request_context, 348 const scoped_refptr<net::URLRequestContextGetter>& request_context,
345 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy) 349 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy)
346 : origin(origin), 350 : origin(origin),
347 request(request.Pass()), 351 request(request.Pass()),
348 response(response.Pass()), 352 response(response.Pass()),
349 blob_data_handle(blob_data_handle.Pass()), 353 blob_data_handle(blob_data_handle.Pass()),
350 callback(callback), 354 callback(callback),
351 request_context(request_context), 355 request_context(request_context),
352 quota_manager_proxy(quota_manager_proxy), 356 quota_manager_proxy(quota_manager_proxy),
353 cache_entry(NULL) {} 357 cache_entry(NULL) {}
354 ~PutContext() { 358 ~PutContext() {
355 if (cache_entry) 359 if (cache_entry)
356 cache_entry->Close(); 360 cache_entry->Close();
357 } 361 }
358 362
359 // Input parameters to the Put function. 363 // Input parameters to the Put function.
360 GURL origin; 364 GURL origin;
361 scoped_ptr<ServiceWorkerFetchRequest> request; 365 scoped_ptr<ServiceWorkerFetchRequest> request;
362 scoped_ptr<ServiceWorkerResponse> response; 366 scoped_ptr<ServiceWorkerResponse> response;
363 scoped_ptr<storage::BlobDataHandle> blob_data_handle; 367 scoped_ptr<storage::BlobDataHandle> blob_data_handle;
364 CacheStorageCache::ErrorCallback callback; 368 CacheStorageCache::ErrorCallback callback;
365 net::URLRequestContext* request_context; 369 scoped_refptr<net::URLRequestContextGetter> request_context;
366 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy; 370 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy;
367 371
368 // This isn't a scoped_ptr because the disk_cache needs an Entry** as input to 372 // This isn't a scoped_ptr because the disk_cache needs an Entry** as input to
369 // CreateEntry. 373 // CreateEntry.
370 disk_cache::Entry* cache_entry; 374 disk_cache::Entry* cache_entry;
371 375
372 DISALLOW_COPY_AND_ASSIGN(PutContext); 376 DISALLOW_COPY_AND_ASSIGN(PutContext);
373 }; 377 };
374 378
375 // static 379 // static
376 scoped_refptr<CacheStorageCache> CacheStorageCache::CreateMemoryCache( 380 scoped_refptr<CacheStorageCache> CacheStorageCache::CreateMemoryCache(
377 const GURL& origin, 381 const GURL& origin,
378 net::URLRequestContext* request_context, 382 const scoped_refptr<net::URLRequestContextGetter>& request_context,
379 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, 383 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy,
380 base::WeakPtr<storage::BlobStorageContext> blob_context) { 384 base::WeakPtr<storage::BlobStorageContext> blob_context) {
381 return make_scoped_refptr( 385 return make_scoped_refptr(
382 new CacheStorageCache(origin, base::FilePath(), request_context, 386 new CacheStorageCache(origin, base::FilePath(), request_context,
383 quota_manager_proxy, blob_context)); 387 quota_manager_proxy, blob_context));
384 } 388 }
385 389
386 // static 390 // static
387 scoped_refptr<CacheStorageCache> CacheStorageCache::CreatePersistentCache( 391 scoped_refptr<CacheStorageCache> CacheStorageCache::CreatePersistentCache(
388 const GURL& origin, 392 const GURL& origin,
389 const base::FilePath& path, 393 const base::FilePath& path,
390 net::URLRequestContext* request_context, 394 const scoped_refptr<net::URLRequestContextGetter>& request_context,
391 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, 395 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy,
392 base::WeakPtr<storage::BlobStorageContext> blob_context) { 396 base::WeakPtr<storage::BlobStorageContext> blob_context) {
393 return make_scoped_refptr(new CacheStorageCache( 397 return make_scoped_refptr(new CacheStorageCache(
394 origin, path, request_context, quota_manager_proxy, blob_context)); 398 origin, path, request_context, quota_manager_proxy, blob_context));
395 } 399 }
396 400
397 CacheStorageCache::~CacheStorageCache() { 401 CacheStorageCache::~CacheStorageCache() {
398 } 402 }
399 403
400 base::WeakPtr<CacheStorageCache> CacheStorageCache::AsWeakPtr() { 404 base::WeakPtr<CacheStorageCache> CacheStorageCache::AsWeakPtr() {
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 entry->GetDataSize(INDEX_RESPONSE_BODY); 551 entry->GetDataSize(INDEX_RESPONSE_BODY);
548 entry->Close(); 552 entry->Close();
549 } 553 }
550 554
551 return sum; 555 return sum;
552 } 556 }
553 557
554 CacheStorageCache::CacheStorageCache( 558 CacheStorageCache::CacheStorageCache(
555 const GURL& origin, 559 const GURL& origin,
556 const base::FilePath& path, 560 const base::FilePath& path,
557 net::URLRequestContext* request_context, 561 const scoped_refptr<net::URLRequestContextGetter>& request_context,
558 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, 562 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy,
559 base::WeakPtr<storage::BlobStorageContext> blob_context) 563 base::WeakPtr<storage::BlobStorageContext> blob_context)
560 : origin_(origin), 564 : origin_(origin),
561 path_(path), 565 path_(path),
562 request_context_(request_context), 566 request_context_(request_context),
563 quota_manager_proxy_(quota_manager_proxy), 567 quota_manager_proxy_(quota_manager_proxy),
564 blob_storage_context_(blob_context), 568 blob_storage_context_(blob_context),
565 backend_state_(BACKEND_UNINITIALIZED), 569 backend_state_(BACKEND_UNINITIALIZED),
566 scheduler_(new CacheStorageScheduler()), 570 scheduler_(new CacheStorageScheduler()),
567 initializing_(false), 571 initializing_(false),
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 } 929 }
926 930
927 DCHECK(put_context->blob_data_handle); 931 DCHECK(put_context->blob_data_handle);
928 932
929 disk_cache::ScopedEntryPtr entry(put_context->cache_entry); 933 disk_cache::ScopedEntryPtr entry(put_context->cache_entry);
930 put_context->cache_entry = NULL; 934 put_context->cache_entry = NULL;
931 scoped_ptr<BlobReader> reader(new BlobReader()); 935 scoped_ptr<BlobReader> reader(new BlobReader());
932 BlobReader* reader_ptr = reader.get(); 936 BlobReader* reader_ptr = reader.get();
933 937
934 // Grab some pointers before passing put_context in Bind. 938 // Grab some pointers before passing put_context in Bind.
935 net::URLRequestContext* request_context = put_context->request_context; 939 scoped_refptr<net::URLRequestContextGetter> request_context =
940 put_context->request_context;
936 scoped_ptr<storage::BlobDataHandle> blob_data_handle = 941 scoped_ptr<storage::BlobDataHandle> blob_data_handle =
937 put_context->blob_data_handle.Pass(); 942 put_context->blob_data_handle.Pass();
938 943
939 reader_ptr->StreamBlobToCache( 944 reader_ptr->StreamBlobToCache(
940 entry.Pass(), request_context, blob_data_handle.Pass(), 945 entry.Pass(), request_context, blob_data_handle.Pass(),
941 base::Bind(&CacheStorageCache::PutDidWriteBlobToCache, 946 base::Bind(&CacheStorageCache::PutDidWriteBlobToCache,
942 weak_ptr_factory_.GetWeakPtr(), 947 weak_ptr_factory_.GetWeakPtr(),
943 base::Passed(put_context.Pass()), 948 base::Passed(put_context.Pass()),
944 base::Passed(reader.Pass()))); 949 base::Passed(reader.Pass())));
945 } 950 }
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 CacheStorageError error, 1270 CacheStorageError error,
1266 scoped_ptr<Requests> requests) { 1271 scoped_ptr<Requests> requests) {
1267 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr(); 1272 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr();
1268 1273
1269 callback.Run(error, requests.Pass()); 1274 callback.Run(error, requests.Pass());
1270 if (cache) 1275 if (cache)
1271 scheduler_->CompleteOperationAndRunNext(); 1276 scheduler_->CompleteOperationAndRunNext();
1272 } 1277 }
1273 1278
1274 } // namespace content 1279 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698