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