| OLD | NEW |
| 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 Loading... |
| 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 // Called when the mojom::URLLoaderPtr in the service worker is deleted. |
| 61 void Cancel() { |
| 62 // Cancel loading as stated in url_loader.mojom. |
| 63 loader_ = nullptr; |
| 64 } |
| 65 |
| 56 mojo::Binding<mojom::URLLoader> binding_; | 66 mojo::Binding<mojom::URLLoader> binding_; |
| 57 mojom::URLLoaderAssociatedPtr loader_; | 67 mojom::URLLoaderAssociatedPtr loader_; |
| 58 | 68 |
| 59 DISALLOW_COPY_AND_ASSIGN(DelegatingURLLoader); | 69 DISALLOW_COPY_AND_ASSIGN(DelegatingURLLoader); |
| 60 }; | 70 }; |
| 61 | 71 |
| 62 // This class wraps a mojo::InterfacePtr<URLLoaderClient>. It also is a | 72 // This class wraps a mojo::InterfacePtr<URLLoaderClient>. It also is a |
| 63 // URLLoaderClient implementation and delegates URLLoaderClient calls to the | 73 // URLLoaderClient implementation and delegates URLLoaderClient calls to the |
| 64 // wrapped client. | 74 // wrapped client. |
| 65 class DelegatingURLLoaderClient final : public mojom::URLLoaderClient { | 75 class DelegatingURLLoaderClient final : public mojom::URLLoaderClient { |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 } | 444 } |
| 435 | 445 |
| 436 ServiceWorkerMetrics::EventType ServiceWorkerFetchDispatcher::GetEventType() | 446 ServiceWorkerMetrics::EventType ServiceWorkerFetchDispatcher::GetEventType() |
| 437 const { | 447 const { |
| 438 if (request_->fetch_type == ServiceWorkerFetchType::FOREIGN_FETCH) | 448 if (request_->fetch_type == ServiceWorkerFetchType::FOREIGN_FETCH) |
| 439 return ServiceWorkerMetrics::EventType::FOREIGN_FETCH; | 449 return ServiceWorkerMetrics::EventType::FOREIGN_FETCH; |
| 440 return ResourceTypeToEventType(resource_type_); | 450 return ResourceTypeToEventType(resource_type_); |
| 441 } | 451 } |
| 442 | 452 |
| 443 } // namespace content | 453 } // namespace content |
| OLD | NEW |