| 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> |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, | 61 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
| 62 int* buf_size, | 62 int* buf_size, |
| 63 int min_size) override; | 63 int min_size) override; |
| 64 bool OnReadCompleted(int bytes_read, bool* defer) override; | 64 bool OnReadCompleted(int bytes_read, bool* defer) override; |
| 65 void OnResponseCompleted(const net::URLRequestStatus& status, | 65 void OnResponseCompleted(const net::URLRequestStatus& status, |
| 66 bool* defer) override; | 66 bool* defer) override; |
| 67 void OnDataDownloaded(int bytes_downloaded) override; | 67 void OnDataDownloaded(int bytes_downloaded) override; |
| 68 | 68 |
| 69 // mojom::URLLoader implementation | 69 // mojom::URLLoader implementation |
| 70 void FollowRedirect() override; | 70 void FollowRedirect() override; |
| 71 void Cancel() override; | |
| 72 | 71 |
| 73 void ResumeForTesting(); | 72 void ResumeForTesting(); |
| 74 static void SetAllocationSizeForTesting(size_t size); | 73 static void SetAllocationSizeForTesting(size_t size); |
| 75 static constexpr size_t kDefaultAllocationSize = 512 * 1024; | 74 static constexpr size_t kDefaultAllocationSize = 512 * 1024; |
| 76 | 75 |
| 77 protected: | 76 protected: |
| 78 // These functions can be overriden only for tests. | 77 // These functions can be overriden only for tests. |
| 79 virtual MojoResult BeginWrite(void** data, uint32_t* available); | 78 virtual MojoResult BeginWrite(void** data, uint32_t* available); |
| 80 virtual MojoResult EndWrite(uint32_t written); | 79 virtual MojoResult EndWrite(uint32_t written); |
| 81 | 80 |
| 82 private: | 81 private: |
| 83 class SharedWriter; | 82 class SharedWriter; |
| 84 class WriterIOBuffer; | 83 class WriterIOBuffer; |
| 85 | 84 |
| 86 // This funcion copies data stored in |buffer_| to |shared_writer_| and | 85 // This funcion copies data stored in |buffer_| to |shared_writer_| and |
| 87 // resets |buffer_| to a WriterIOBuffer when all bytes are copied. Returns | 86 // resets |buffer_| to a WriterIOBuffer when all bytes are copied. Returns |
| 88 // true when done successfully. | 87 // true when done successfully. |
| 89 bool CopyReadDataToDataPipe(bool* defer); | 88 bool CopyReadDataToDataPipe(bool* defer); |
| 90 // Allocates a WriterIOBuffer and set it to |*buf|. Returns true when done | 89 // Allocates a WriterIOBuffer and set it to |*buf|. Returns true when done |
| 91 // successfully. | 90 // successfully. |
| 92 bool AllocateWriterIOBuffer(scoped_refptr<net::IOBufferWithSize>* buf, | 91 bool AllocateWriterIOBuffer(scoped_refptr<net::IOBufferWithSize>* buf, |
| 93 bool* defer); | 92 bool* defer); |
| 94 | 93 |
| 95 void Resume(); | 94 void Resume(); |
| 96 void OnDefer(); | 95 void OnDefer(); |
| 97 bool CheckForSufficientResource(); | 96 bool CheckForSufficientResource(); |
| 98 void OnWritable(MojoResult result); | 97 void OnWritable(MojoResult result); |
| 98 void Cancel(); |
| 99 | 99 |
| 100 ResourceDispatcherHostImpl* rdh_; | 100 ResourceDispatcherHostImpl* rdh_; |
| 101 mojo::Binding<mojom::URLLoader> binding_; | 101 mojo::Binding<mojom::URLLoader> binding_; |
| 102 | 102 |
| 103 bool has_checked_for_sufficient_resources_ = false; | 103 bool has_checked_for_sufficient_resources_ = false; |
| 104 bool sent_received_response_message_ = false; | 104 bool sent_received_response_message_ = false; |
| 105 bool is_using_io_buffer_not_from_writer_ = false; | 105 bool is_using_io_buffer_not_from_writer_ = false; |
| 106 bool did_defer_ = false; | 106 bool did_defer_ = false; |
| 107 base::TimeTicks response_started_ticks_; | 107 base::TimeTicks response_started_ticks_; |
| 108 | 108 |
| 109 mojo::Watcher handle_watcher_; | 109 mojo::Watcher handle_watcher_; |
| 110 std::unique_ptr<mojom::URLLoader> url_loader_; | 110 std::unique_ptr<mojom::URLLoader> url_loader_; |
| 111 mojom::URLLoaderClientPtr url_loader_client_; | 111 mojom::URLLoaderClientPtr url_loader_client_; |
| 112 scoped_refptr<net::IOBufferWithSize> buffer_; | 112 scoped_refptr<net::IOBufferWithSize> buffer_; |
| 113 size_t buffer_offset_ = 0; | 113 size_t buffer_offset_ = 0; |
| 114 size_t buffer_bytes_read_ = 0; | 114 size_t buffer_bytes_read_ = 0; |
| 115 scoped_refptr<SharedWriter> shared_writer_; | 115 scoped_refptr<SharedWriter> shared_writer_; |
| 116 | 116 |
| 117 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler); | 117 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler); |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 } // namespace content | 120 } // namespace content |
| 121 | 121 |
| 122 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ | 122 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ |
| OLD | NEW |