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

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

Issue 2466843002: Cancel the request when URLLoader is gone (Closed)
Patch Set: fix Created 4 years, 1 month 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 39
40 // This class wraps a mojo::AssociatedInterfacePtr<URLLoader>. It also is a 40 // This class wraps a mojo::AssociatedInterfacePtr<URLLoader>. It also is a
41 // URLLoader implementation and delegates URLLoader calls to the wrapped loader. 41 // URLLoader implementation and delegates URLLoader calls to the wrapped loader.
42 class DelegatingURLLoader final : public mojom::URLLoader { 42 class DelegatingURLLoader final : public mojom::URLLoader {
43 public: 43 public:
44 explicit DelegatingURLLoader(mojom::URLLoaderAssociatedPtr loader) 44 explicit DelegatingURLLoader(mojom::URLLoaderAssociatedPtr loader)
45 : binding_(this), loader_(std::move(loader)) {} 45 : binding_(this), loader_(std::move(loader)) {}
46 ~DelegatingURLLoader() override {} 46 ~DelegatingURLLoader() override {}
47 47
48 void FollowRedirect() override { loader_->FollowRedirect(); } 48 void FollowRedirect() override { loader_->FollowRedirect(); }
49 void Cancel() override { loader_->Cancel(); }
50 49
51 mojom::URLLoaderPtr CreateInterfacePtrAndBind() { 50 mojom::URLLoaderPtr CreateInterfacePtrAndBind() {
52 return binding_.CreateInterfacePtrAndBind(); 51 auto p = binding_.CreateInterfacePtrAndBind();
52 // This unretained pointer is safe, because |binding_| is owned by |this|
53 // and the callback will never be called after |this| is destroyed.
54 binding_.set_connection_error_handler(
55 base::Bind(&DelegatingURLLoader::Cancel, base::Unretained(this)));
56 return p;
53 } 57 }
54 58
55 private: 59 private:
60 void Cancel() { loader_ = nullptr; }
horo 2016/11/09 10:02:08 Please add comments. // Called when the mojom::
yhirano 2016/11/11 04:22:22 Done.
61
56 mojo::Binding<mojom::URLLoader> binding_; 62 mojo::Binding<mojom::URLLoader> binding_;
57 mojom::URLLoaderAssociatedPtr loader_; 63 mojom::URLLoaderAssociatedPtr loader_;
58 64
59 DISALLOW_COPY_AND_ASSIGN(DelegatingURLLoader); 65 DISALLOW_COPY_AND_ASSIGN(DelegatingURLLoader);
60 }; 66 };
61 67
62 // This class wraps a mojo::InterfacePtr<URLLoaderClient>. It also is a 68 // This class wraps a mojo::InterfacePtr<URLLoaderClient>. It also is a
63 // URLLoaderClient implementation and delegates URLLoaderClient calls to the 69 // URLLoaderClient implementation and delegates URLLoaderClient calls to the
64 // wrapped client. 70 // wrapped client.
65 class DelegatingURLLoaderClient final : public mojom::URLLoaderClient { 71 class DelegatingURLLoaderClient final : public mojom::URLLoaderClient {
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 } 440 }
435 441
436 ServiceWorkerMetrics::EventType ServiceWorkerFetchDispatcher::GetEventType() 442 ServiceWorkerMetrics::EventType ServiceWorkerFetchDispatcher::GetEventType()
437 const { 443 const {
438 if (request_->fetch_type == ServiceWorkerFetchType::FOREIGN_FETCH) 444 if (request_->fetch_type == ServiceWorkerFetchType::FOREIGN_FETCH)
439 return ServiceWorkerMetrics::EventType::FOREIGN_FETCH; 445 return ServiceWorkerMetrics::EventType::FOREIGN_FETCH;
440 return ResourceTypeToEventType(resource_type_); 446 return ResourceTypeToEventType(resource_type_);
441 } 447 }
442 448
443 } // namespace content 449 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/url_loader_factory_impl_unittest.cc ('k') | content/common/url_loader.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698