| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ | 6 #define CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
| 17 #include "content/browser/loader/resource_handler.h" | 17 #include "content/browser/loader/resource_handler.h" |
| 18 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
| 19 #include "content/common/url_loader.mojom.h" | 19 #include "content/common/url_loader.mojom.h" |
| 20 #include "mojo/public/cpp/bindings/associated_binding.h" | 20 #include "mojo/public/cpp/bindings/associated_binding.h" |
| 21 #include "mojo/public/cpp/system/watcher.h" | 21 #include "mojo/public/cpp/system/watcher.h" |
| 22 #include "net/base/io_buffer.h" | 22 #include "net/base/io_buffer.h" |
| 23 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 24 | 24 |
| 25 namespace net { | 25 namespace net { |
| 26 class URLRequest; | 26 class URLRequest; |
| 27 } | 27 } |
| 28 | 28 |
| 29 namespace content { | 29 namespace content { |
| 30 class ResourceController; |
| 30 class ResourceDispatcherHostImpl; | 31 class ResourceDispatcherHostImpl; |
| 31 struct ResourceResponse; | 32 struct ResourceResponse; |
| 32 | 33 |
| 33 // Used to complete an asynchronous resource request in response to resource | 34 // Used to complete an asynchronous resource request in response to resource |
| 34 // load events from the resource dispatcher host. This class is used only | 35 // load events from the resource dispatcher host. This class is used only |
| 35 // when LoadingWithMojo runtime flag is enabled. | 36 // when LoadingWithMojo runtime flag is enabled. |
| 36 // | 37 // |
| 37 // TODO(yhirano): Add histograms. | 38 // TODO(yhirano): Add histograms. |
| 38 // TODO(yhirano): Send cached metadata. | 39 // TODO(yhirano): Send cached metadata. |
| 39 // | 40 // |
| 40 // This class can be inherited only for tests. | 41 // This class can be inherited only for tests. |
| 41 class CONTENT_EXPORT MojoAsyncResourceHandler | 42 class CONTENT_EXPORT MojoAsyncResourceHandler |
| 42 : public ResourceHandler, | 43 : public ResourceHandler, |
| 43 public NON_EXPORTED_BASE(mojom::URLLoader) { | 44 public NON_EXPORTED_BASE(mojom::URLLoader) { |
| 44 public: | 45 public: |
| 45 MojoAsyncResourceHandler( | 46 MojoAsyncResourceHandler( |
| 46 net::URLRequest* request, | 47 net::URLRequest* request, |
| 47 ResourceDispatcherHostImpl* rdh, | 48 ResourceDispatcherHostImpl* rdh, |
| 48 mojom::URLLoaderAssociatedRequest mojo_request, | 49 mojom::URLLoaderAssociatedRequest mojo_request, |
| 49 mojom::URLLoaderClientAssociatedPtr url_loader_client); | 50 mojom::URLLoaderClientAssociatedPtr url_loader_client); |
| 50 ~MojoAsyncResourceHandler() override; | 51 ~MojoAsyncResourceHandler() override; |
| 51 | 52 |
| 52 // ResourceHandler implementation: | 53 // ResourceHandler implementation: |
| 53 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, | 54 void OnRequestRedirected( |
| 54 ResourceResponse* response, | 55 const net::RedirectInfo& redirect_info, |
| 55 bool* defer) override; | 56 ResourceResponse* response, |
| 56 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; | 57 std::unique_ptr<ResourceController> controller) override; |
| 57 bool OnWillStart(const GURL& url, bool* defer) override; | 58 void OnResponseStarted( |
| 59 ResourceResponse* response, |
| 60 std::unique_ptr<ResourceController> controller) override; |
| 61 void OnWillStart(const GURL& url, |
| 62 std::unique_ptr<ResourceController> controller) override; |
| 58 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, | 63 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
| 59 int* buf_size, | 64 int* buf_size, |
| 60 int min_size) override; | 65 int min_size) override; |
| 61 bool OnReadCompleted(int bytes_read, bool* defer) override; | 66 void OnReadCompleted(int bytes_read, |
| 62 void OnResponseCompleted(const net::URLRequestStatus& status, | 67 std::unique_ptr<ResourceController> controller) override; |
| 63 bool* defer) override; | 68 void OnResponseCompleted( |
| 69 const net::URLRequestStatus& status, |
| 70 std::unique_ptr<ResourceController> controller) override; |
| 64 void OnDataDownloaded(int bytes_downloaded) override; | 71 void OnDataDownloaded(int bytes_downloaded) override; |
| 65 | 72 |
| 66 // mojom::URLLoader implementation | 73 // mojom::URLLoader implementation |
| 67 void FollowRedirect() override; | 74 void FollowRedirect() override; |
| 68 | 75 |
| 69 void OnWritableForTesting(); | 76 void OnWritableForTesting(); |
| 70 static void SetAllocationSizeForTesting(size_t size); | 77 static void SetAllocationSizeForTesting(size_t size); |
| 71 static constexpr size_t kDefaultAllocationSize = 512 * 1024; | 78 static constexpr size_t kDefaultAllocationSize = 512 * 1024; |
| 72 | 79 |
| 73 protected: | 80 protected: |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 size_t buffer_bytes_read_ = 0; | 123 size_t buffer_bytes_read_ = 0; |
| 117 scoped_refptr<SharedWriter> shared_writer_; | 124 scoped_refptr<SharedWriter> shared_writer_; |
| 118 | 125 |
| 119 base::WeakPtrFactory<MojoAsyncResourceHandler> weak_factory_; | 126 base::WeakPtrFactory<MojoAsyncResourceHandler> weak_factory_; |
| 120 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler); | 127 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler); |
| 121 }; | 128 }; |
| 122 | 129 |
| 123 } // namespace content | 130 } // namespace content |
| 124 | 131 |
| 125 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ | 132 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ |
| OLD | NEW |