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

Side by Side Diff: content/browser/blob_storage/blob_url_loader_factory.cc

Issue 2954853002: Use Independent URLLoader
Patch Set: . Created 3 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/blob_storage/blob_url_loader_factory.h" 5 #include "content/browser/blob_storage/blob_url_loader_factory.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 20 matching lines...) Expand all
31 namespace content { 31 namespace content {
32 32
33 namespace { 33 namespace {
34 constexpr size_t kDefaultAllocationSize = 512 * 1024; 34 constexpr size_t kDefaultAllocationSize = 512 * 1024;
35 35
36 // This class handles a request for a blob:// url. It self-destructs (see 36 // This class handles a request for a blob:// url. It self-destructs (see
37 // DeleteIfNeeded) when it has finished responding. 37 // DeleteIfNeeded) when it has finished responding.
38 // Note: some of this code is duplicated from storage::BlobURLRequestJob. 38 // Note: some of this code is duplicated from storage::BlobURLRequestJob.
39 class BlobURLLoader : public mojom::URLLoader { 39 class BlobURLLoader : public mojom::URLLoader {
40 public: 40 public:
41 BlobURLLoader(mojom::URLLoaderAssociatedRequest url_loader_request, 41 BlobURLLoader(mojom::URLLoaderRequest url_loader_request,
42 const ResourceRequest& request, 42 const ResourceRequest& request,
43 mojom::URLLoaderClientPtr client, 43 mojom::URLLoaderClientPtr client,
44 std::unique_ptr<storage::BlobDataHandle> blob_handle, 44 std::unique_ptr<storage::BlobDataHandle> blob_handle,
45 storage::FileSystemContext* file_system_context) 45 storage::FileSystemContext* file_system_context)
46 : binding_(this, std::move(url_loader_request)), 46 : binding_(this, std::move(url_loader_request)),
47 client_(std::move(client)), 47 client_(std::move(client)),
48 blob_handle_(std::move(blob_handle)), 48 blob_handle_(std::move(blob_handle)),
49 writable_handle_watcher_(FROM_HERE, 49 writable_handle_watcher_(FROM_HERE,
50 mojo::SimpleWatcher::ArmingPolicy::MANUAL), 50 mojo::SimpleWatcher::ArmingPolicy::MANUAL),
51 peer_closed_handle_watcher_(FROM_HERE, 51 peer_closed_handle_watcher_(FROM_HERE,
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 ReadMore(); 318 ReadMore();
319 } 319 }
320 320
321 void DeleteIfNeeded() { 321 void DeleteIfNeeded() {
322 bool has_data_pipe = 322 bool has_data_pipe =
323 pending_write_.get() || response_body_stream_.is_valid(); 323 pending_write_.get() || response_body_stream_.is_valid();
324 if (!has_data_pipe) 324 if (!has_data_pipe)
325 delete this; 325 delete this;
326 } 326 }
327 327
328 mojo::AssociatedBinding<mojom::URLLoader> binding_; 328 mojo::Binding<mojom::URLLoader> binding_;
329 mojom::URLLoaderClientPtr client_; 329 mojom::URLLoaderClientPtr client_;
330 330
331 bool byte_range_set_ = false; 331 bool byte_range_set_ = false;
332 net::HttpByteRange byte_range_; 332 net::HttpByteRange byte_range_;
333 333
334 bool sent_headers_ = false; 334 bool sent_headers_ = false;
335 335
336 std::unique_ptr<storage::BlobDataHandle> blob_handle_; 336 std::unique_ptr<storage::BlobDataHandle> blob_handle_;
337 std::unique_ptr<storage::BlobReader> blob_reader_; 337 std::unique_ptr<storage::BlobReader> blob_reader_;
338 338
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 } 378 }
379 379
380 void BlobURLLoaderFactory::BindOnIO(mojom::URLLoaderFactoryRequest request) { 380 void BlobURLLoaderFactory::BindOnIO(mojom::URLLoaderFactoryRequest request) {
381 DCHECK_CURRENTLY_ON(BrowserThread::IO); 381 DCHECK_CURRENTLY_ON(BrowserThread::IO);
382 382
383 loader_factory_bindings_.AddBinding(this, std::move(request)); 383 loader_factory_bindings_.AddBinding(this, std::move(request));
384 } 384 }
385 385
386 // static 386 // static
387 void BlobURLLoaderFactory::CreateLoaderAndStart( 387 void BlobURLLoaderFactory::CreateLoaderAndStart(
388 mojom::URLLoaderAssociatedRequest loader, 388 mojom::URLLoaderRequest loader,
389 const ResourceRequest& request, 389 const ResourceRequest& request,
390 mojom::URLLoaderClientPtr client, 390 mojom::URLLoaderClientPtr client,
391 std::unique_ptr<storage::BlobDataHandle> blob_handle, 391 std::unique_ptr<storage::BlobDataHandle> blob_handle,
392 storage::FileSystemContext* file_system_context) { 392 storage::FileSystemContext* file_system_context) {
393 new BlobURLLoader(std::move(loader), request, std::move(client), 393 new BlobURLLoader(std::move(loader), request, std::move(client),
394 std::move(blob_handle), file_system_context); 394 std::move(blob_handle), file_system_context);
395 } 395 }
396 396
397 void BlobURLLoaderFactory::CreateLoaderAndStart( 397 void BlobURLLoaderFactory::CreateLoaderAndStart(
398 mojom::URLLoaderAssociatedRequest loader, 398 mojom::URLLoaderRequest loader,
399 int32_t routing_id, 399 int32_t routing_id,
400 int32_t request_id, 400 int32_t request_id,
401 uint32_t options, 401 uint32_t options,
402 const ResourceRequest& request, 402 const ResourceRequest& request,
403 mojom::URLLoaderClientPtr client, 403 mojom::URLLoaderClientPtr client,
404 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) { 404 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) {
405 DCHECK_CURRENTLY_ON(BrowserThread::IO); 405 DCHECK_CURRENTLY_ON(BrowserThread::IO);
406 std::unique_ptr<storage::BlobDataHandle> blob_handle; 406 std::unique_ptr<storage::BlobDataHandle> blob_handle;
407 if (blob_storage_context_) { 407 if (blob_storage_context_) {
408 blob_handle = blob_storage_context_->GetBlobDataFromPublicURL(request.url); 408 blob_handle = blob_storage_context_->GetBlobDataFromPublicURL(request.url);
409 } 409 }
410 CreateLoaderAndStart(std::move(loader), request, std::move(client), 410 CreateLoaderAndStart(std::move(loader), request, std::move(client),
411 std::move(blob_handle), file_system_context_.get()); 411 std::move(blob_handle), file_system_context_.get());
412 } 412 }
413 413
414 void BlobURLLoaderFactory::SyncLoad(int32_t routing_id, 414 void BlobURLLoaderFactory::SyncLoad(int32_t routing_id,
415 int32_t request_id, 415 int32_t request_id,
416 const ResourceRequest& request, 416 const ResourceRequest& request,
417 SyncLoadCallback callback) { 417 SyncLoadCallback callback) {
418 NOTREACHED(); 418 NOTREACHED();
419 } 419 }
420 420
421 } // namespace content 421 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/blob_storage/blob_url_loader_factory.h ('k') | content/browser/blob_storage/blob_url_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698