| 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/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 ResourceDispatcherHostImpl; | 29 class ResourceDispatcherHostImpl; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 40 // TODO(yhirano): Send cached metadata. | 40 // TODO(yhirano): Send cached metadata. |
| 41 // | 41 // |
| 42 // This class can be inherited only for tests. | 42 // This class can be inherited only for tests. |
| 43 class CONTENT_EXPORT MojoAsyncResourceHandler | 43 class CONTENT_EXPORT MojoAsyncResourceHandler |
| 44 : public ResourceHandler, | 44 : public ResourceHandler, |
| 45 public NON_EXPORTED_BASE(mojom::URLLoader) { | 45 public NON_EXPORTED_BASE(mojom::URLLoader) { |
| 46 public: | 46 public: |
| 47 MojoAsyncResourceHandler( | 47 MojoAsyncResourceHandler( |
| 48 net::URLRequest* request, | 48 net::URLRequest* request, |
| 49 ResourceDispatcherHostImpl* rdh, | 49 ResourceDispatcherHostImpl* rdh, |
| 50 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, | 50 mojom::URLLoaderAssociatedRequest mojo_request, |
| 51 mojom::URLLoaderClientPtr url_loader_client); | 51 mojom::URLLoaderClientAssociatedPtr url_loader_client); |
| 52 ~MojoAsyncResourceHandler() override; | 52 ~MojoAsyncResourceHandler() override; |
| 53 | 53 |
| 54 // ResourceHandler implementation: | 54 // ResourceHandler implementation: |
| 55 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, | 55 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, |
| 56 ResourceResponse* response, | 56 ResourceResponse* response, |
| 57 bool* defer) override; | 57 bool* defer) override; |
| 58 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; | 58 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; |
| 59 bool OnWillStart(const GURL& url, bool* defer) override; | 59 bool OnWillStart(const GURL& url, bool* defer) override; |
| 60 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, | 60 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
| 61 int* buf_size, | 61 int* buf_size, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 90 // successfully. | 90 // successfully. |
| 91 bool AllocateWriterIOBuffer(scoped_refptr<net::IOBufferWithSize>* buf, | 91 bool AllocateWriterIOBuffer(scoped_refptr<net::IOBufferWithSize>* buf, |
| 92 bool* defer); | 92 bool* defer); |
| 93 | 93 |
| 94 void Resume(); | 94 void Resume(); |
| 95 void OnDefer(); | 95 void OnDefer(); |
| 96 bool CheckForSufficientResource(); | 96 bool CheckForSufficientResource(); |
| 97 void OnWritable(MojoResult result); | 97 void OnWritable(MojoResult result); |
| 98 | 98 |
| 99 ResourceDispatcherHostImpl* rdh_; | 99 ResourceDispatcherHostImpl* rdh_; |
| 100 mojo::Binding<mojom::URLLoader> binding_; | 100 mojo::AssociatedBinding<mojom::URLLoader> binding_; |
| 101 | 101 |
| 102 bool has_checked_for_sufficient_resources_ = false; | 102 bool has_checked_for_sufficient_resources_ = false; |
| 103 bool sent_received_response_message_ = false; | 103 bool sent_received_response_message_ = false; |
| 104 bool is_using_io_buffer_not_from_writer_ = false; | 104 bool is_using_io_buffer_not_from_writer_ = false; |
| 105 bool did_defer_ = false; | 105 bool did_defer_ = false; |
| 106 base::TimeTicks response_started_ticks_; | 106 base::TimeTicks response_started_ticks_; |
| 107 | 107 |
| 108 mojo::Watcher handle_watcher_; | 108 mojo::Watcher handle_watcher_; |
| 109 std::unique_ptr<mojom::URLLoader> url_loader_; | 109 std::unique_ptr<mojom::URLLoader> url_loader_; |
| 110 mojom::URLLoaderClientPtr url_loader_client_; | 110 mojom::URLLoaderClientAssociatedPtr url_loader_client_; |
| 111 scoped_refptr<net::IOBufferWithSize> buffer_; | 111 scoped_refptr<net::IOBufferWithSize> buffer_; |
| 112 size_t buffer_offset_ = 0; | 112 size_t buffer_offset_ = 0; |
| 113 size_t buffer_bytes_read_ = 0; | 113 size_t buffer_bytes_read_ = 0; |
| 114 scoped_refptr<SharedWriter> shared_writer_; | 114 scoped_refptr<SharedWriter> shared_writer_; |
| 115 | 115 |
| 116 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler); | 116 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler); |
| 117 }; | 117 }; |
| 118 | 118 |
| 119 } // namespace content | 119 } // namespace content |
| 120 | 120 |
| 121 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ | 121 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ |
| OLD | NEW |