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

Side by Side Diff: content/browser/service_worker/service_worker_fetch_dispatcher.cc

Issue 2954853002: Use Independent URLLoader
Patch Set: . Created 3 years, 5 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/service_worker/service_worker_fetch_dispatcher.h" 5 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 28 matching lines...) Expand all
39 #include "net/url_request/url_request.h" 39 #include "net/url_request/url_request.h"
40 40
41 namespace content { 41 namespace content {
42 42
43 namespace { 43 namespace {
44 44
45 // This class wraps a mojo::AssociatedInterfacePtr<URLLoader>. It also is a 45 // This class wraps a mojo::AssociatedInterfacePtr<URLLoader>. It also is a
46 // URLLoader implementation and delegates URLLoader calls to the wrapped loader. 46 // URLLoader implementation and delegates URLLoader calls to the wrapped loader.
47 class DelegatingURLLoader final : public mojom::URLLoader { 47 class DelegatingURLLoader final : public mojom::URLLoader {
48 public: 48 public:
49 explicit DelegatingURLLoader(mojom::URLLoaderAssociatedPtr loader) 49 explicit DelegatingURLLoader(mojom::URLLoaderPtr loader)
50 : binding_(this), loader_(std::move(loader)) {} 50 : binding_(this), loader_(std::move(loader)) {}
51 ~DelegatingURLLoader() override {} 51 ~DelegatingURLLoader() override {}
52 52
53 void FollowRedirect() override { loader_->FollowRedirect(); } 53 void FollowRedirect() override { loader_->FollowRedirect(); }
54 54
55 void SetPriority(net::RequestPriority priority, 55 void SetPriority(net::RequestPriority priority,
56 int intra_priority_value) override { 56 int intra_priority_value) override {
57 loader_->SetPriority(priority, intra_priority_value); 57 loader_->SetPriority(priority, intra_priority_value);
58 } 58 }
59 59
60 mojom::URLLoaderPtr CreateInterfacePtrAndBind() { 60 mojom::URLLoaderPtr CreateInterfacePtrAndBind() {
61 mojom::URLLoaderPtr loader; 61 mojom::URLLoaderPtr loader;
62 binding_.Bind(mojo::MakeRequest(&loader)); 62 binding_.Bind(mojo::MakeRequest(&loader));
63 // This unretained pointer is safe, because |binding_| is owned by |this| 63 // This unretained pointer is safe, because |binding_| is owned by |this|
64 // and the callback will never be called after |this| is destroyed. 64 // and the callback will never be called after |this| is destroyed.
65 binding_.set_connection_error_handler( 65 binding_.set_connection_error_handler(
66 base::Bind(&DelegatingURLLoader::Cancel, base::Unretained(this))); 66 base::Bind(&DelegatingURLLoader::Cancel, base::Unretained(this)));
67 return loader; 67 return loader;
68 } 68 }
69 69
70 private: 70 private:
71 // Called when the mojom::URLLoaderPtr in the service worker is deleted. 71 // Called when the mojom::URLLoaderPtr in the service worker is deleted.
72 void Cancel() { 72 void Cancel() {
73 // Cancel loading as stated in url_loader.mojom. 73 // Cancel loading as stated in url_loader.mojom.
74 loader_ = nullptr; 74 loader_ = nullptr;
75 } 75 }
76 76
77 mojo::Binding<mojom::URLLoader> binding_; 77 mojo::Binding<mojom::URLLoader> binding_;
78 mojom::URLLoaderAssociatedPtr loader_; 78 mojom::URLLoaderPtr loader_;
79 79
80 DISALLOW_COPY_AND_ASSIGN(DelegatingURLLoader); 80 DISALLOW_COPY_AND_ASSIGN(DelegatingURLLoader);
81 }; 81 };
82 82
83 ServiceWorkerDevToolsAgentHost* GetAgentHost( 83 ServiceWorkerDevToolsAgentHost* GetAgentHost(
84 const std::pair<int, int>& worker_id) { 84 const std::pair<int, int>& worker_id) {
85 return ServiceWorkerDevToolsManager::GetInstance() 85 return ServiceWorkerDevToolsManager::GetInstance()
86 ->GetDevToolsAgentHostForWorker(worker_id.first, worker_id.second); 86 ->GetDevToolsAgentHostForWorker(worker_id.first, worker_id.second);
87 } 87 }
88 88
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 DCHECK_LT(request_id, -1); 654 DCHECK_LT(request_id, -1);
655 655
656 preload_handle_ = mojom::FetchEventPreloadHandle::New(); 656 preload_handle_ = mojom::FetchEventPreloadHandle::New();
657 mojom::URLLoaderClientPtr url_loader_client_ptr; 657 mojom::URLLoaderClientPtr url_loader_client_ptr;
658 preload_handle_->url_loader_client_request = 658 preload_handle_->url_loader_client_request =
659 mojo::MakeRequest(&url_loader_client_ptr); 659 mojo::MakeRequest(&url_loader_client_ptr);
660 auto url_loader_client = base::MakeUnique<DelegatingURLLoaderClient>( 660 auto url_loader_client = base::MakeUnique<DelegatingURLLoaderClient>(
661 std::move(url_loader_client_ptr), std::move(on_response), request); 661 std::move(url_loader_client_ptr), std::move(on_response), request);
662 mojom::URLLoaderClientPtr url_loader_client_ptr_to_pass; 662 mojom::URLLoaderClientPtr url_loader_client_ptr_to_pass;
663 url_loader_client->Bind(&url_loader_client_ptr_to_pass); 663 url_loader_client->Bind(&url_loader_client_ptr_to_pass);
664 mojom::URLLoaderAssociatedPtr url_loader_associated_ptr; 664 mojom::URLLoaderPtr url_loader_associated_ptr;
665 665
666 url_loader_factory->CreateLoaderAndStart( 666 url_loader_factory->CreateLoaderAndStart(
667 mojo::MakeRequest(&url_loader_associated_ptr), 667 mojo::MakeRequest(&url_loader_associated_ptr),
668 original_info->GetRouteID(), request_id, mojom::kURLLoadOptionNone, 668 original_info->GetRouteID(), request_id, mojom::kURLLoadOptionNone,
669 request, std::move(url_loader_client_ptr_to_pass), 669 request, std::move(url_loader_client_ptr_to_pass),
670 net::MutableNetworkTrafficAnnotationTag( 670 net::MutableNetworkTrafficAnnotationTag(
671 original_request->traffic_annotation())); 671 original_request->traffic_annotation()));
672 672
673 std::unique_ptr<DelegatingURLLoader> url_loader( 673 std::unique_ptr<DelegatingURLLoader> url_loader(
674 base::MakeUnique<DelegatingURLLoader>( 674 base::MakeUnique<DelegatingURLLoader>(
(...skipping 17 matching lines...) Expand all
692 ServiceWorkerVersion* version, 692 ServiceWorkerVersion* version,
693 int event_finish_id, 693 int event_finish_id,
694 scoped_refptr<URLLoaderAssets> url_loader_assets, 694 scoped_refptr<URLLoaderAssets> url_loader_assets,
695 ServiceWorkerStatusCode status, 695 ServiceWorkerStatusCode status,
696 base::Time dispatch_event_time) { 696 base::Time dispatch_event_time) {
697 version->FinishRequest(event_finish_id, status != SERVICE_WORKER_ERROR_ABORT, 697 version->FinishRequest(event_finish_id, status != SERVICE_WORKER_ERROR_ABORT,
698 dispatch_event_time); 698 dispatch_event_time);
699 } 699 }
700 700
701 } // namespace content 701 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698