| 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" | |
| 17 #include "content/browser/loader/resource_handler.h" | 16 #include "content/browser/loader/resource_handler.h" |
| 17 #include "content/browser/loader/upload_progress_tracker.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 "content/public/common/resource_type.h" | 20 #include "content/public/common/resource_type.h" |
| 21 #include "mojo/public/cpp/bindings/associated_binding.h" | 21 #include "mojo/public/cpp/bindings/associated_binding.h" |
| 22 #include "mojo/public/cpp/system/data_pipe.h" | 22 #include "mojo/public/cpp/system/data_pipe.h" |
| 23 #include "mojo/public/cpp/system/watcher.h" | 23 #include "mojo/public/cpp/system/watcher.h" |
| 24 #include "net/base/io_buffer.h" | 24 #include "net/base/io_buffer.h" |
| 25 #include "url/gurl.h" | 25 |
| 26 class GURL; |
| 27 |
| 28 namespace tracked_objects { |
| 29 class Location; |
| 30 } |
| 26 | 31 |
| 27 namespace net { | 32 namespace net { |
| 28 class IOBufferWithSize; | 33 class IOBufferWithSize; |
| 29 class URLRequest; | 34 class URLRequest; |
| 30 } | 35 } |
| 31 | 36 |
| 32 namespace content { | 37 namespace content { |
| 33 class ResourceDispatcherHostImpl; | 38 class ResourceDispatcherHostImpl; |
| 34 struct ResourceResponse; | 39 struct ResourceResponse; |
| 35 | 40 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 60 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; | 65 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; |
| 61 bool OnWillStart(const GURL& url, bool* defer) override; | 66 bool OnWillStart(const GURL& url, bool* defer) override; |
| 62 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, | 67 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
| 63 int* buf_size, | 68 int* buf_size, |
| 64 int min_size) override; | 69 int min_size) override; |
| 65 bool OnReadCompleted(int bytes_read, bool* defer) override; | 70 bool OnReadCompleted(int bytes_read, bool* defer) override; |
| 66 void OnResponseCompleted(const net::URLRequestStatus& status, | 71 void OnResponseCompleted(const net::URLRequestStatus& status, |
| 67 bool* defer) override; | 72 bool* defer) override; |
| 68 void OnDataDownloaded(int bytes_downloaded) override; | 73 void OnDataDownloaded(int bytes_downloaded) override; |
| 69 | 74 |
| 70 // mojom::URLLoader implementation | 75 // mojom::URLLoader implementation: |
| 71 void FollowRedirect() override; | 76 void FollowRedirect() override; |
| 72 | 77 |
| 73 void OnWritableForTesting(); | 78 void OnWritableForTesting(); |
| 74 static void SetAllocationSizeForTesting(size_t size); | 79 static void SetAllocationSizeForTesting(size_t size); |
| 75 static constexpr size_t kDefaultAllocationSize = 512 * 1024; | 80 static constexpr size_t kDefaultAllocationSize = 512 * 1024; |
| 76 | 81 |
| 77 protected: | 82 protected: |
| 78 // These functions can be overriden only for tests. | 83 // These functions can be overriden only for tests. |
| 79 virtual MojoResult BeginWrite(void** data, uint32_t* available); | 84 virtual MojoResult BeginWrite(void** data, uint32_t* available); |
| 80 virtual MojoResult EndWrite(uint32_t written); | 85 virtual MojoResult EndWrite(uint32_t written); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 93 bool AllocateWriterIOBuffer(scoped_refptr<net::IOBufferWithSize>* buf, | 98 bool AllocateWriterIOBuffer(scoped_refptr<net::IOBufferWithSize>* buf, |
| 94 bool* defer); | 99 bool* defer); |
| 95 | 100 |
| 96 bool CheckForSufficientResource(); | 101 bool CheckForSufficientResource(); |
| 97 void OnWritable(MojoResult result); | 102 void OnWritable(MojoResult result); |
| 98 void Cancel(); | 103 void Cancel(); |
| 99 // Calculates the diff between URLRequest::GetTotalReceivedBytes() and | 104 // Calculates the diff between URLRequest::GetTotalReceivedBytes() and |
| 100 // |reported_total_received_bytes_|, returns it, and updates | 105 // |reported_total_received_bytes_|, returns it, and updates |
| 101 // |reported_total_received_bytes_|. | 106 // |reported_total_received_bytes_|. |
| 102 int64_t CalculateRecentlyReceivedBytes(); | 107 int64_t CalculateRecentlyReceivedBytes(); |
| 103 // This function can be overriden only for tests. | 108 |
| 109 // These functions can be overriden only for tests. |
| 104 virtual void ReportBadMessage(const std::string& error); | 110 virtual void ReportBadMessage(const std::string& error); |
| 111 virtual std::unique_ptr<UploadProgressTracker> CreateUploadProgressTracker( |
| 112 const tracked_objects::Location& from_here, |
| 113 UploadProgressTracker::UploadProgressReportCallback callback); |
| 105 | 114 |
| 106 void OnTransfer(mojom::URLLoaderAssociatedRequest mojo_request, | 115 void OnTransfer(mojom::URLLoaderAssociatedRequest mojo_request, |
| 107 mojom::URLLoaderClientAssociatedPtr url_loader_client); | 116 mojom::URLLoaderClientAssociatedPtr url_loader_client); |
| 117 void SendUploadProgress(const net::UploadProgress& progress); |
| 118 void OnUploadProgressACK(); |
| 108 | 119 |
| 109 ResourceDispatcherHostImpl* rdh_; | 120 ResourceDispatcherHostImpl* rdh_; |
| 110 mojo::AssociatedBinding<mojom::URLLoader> binding_; | 121 mojo::AssociatedBinding<mojom::URLLoader> binding_; |
| 111 | 122 |
| 112 bool has_checked_for_sufficient_resources_ = false; | 123 bool has_checked_for_sufficient_resources_ = false; |
| 113 bool sent_received_response_message_ = false; | 124 bool sent_received_response_message_ = false; |
| 114 bool is_using_io_buffer_not_from_writer_ = false; | 125 bool is_using_io_buffer_not_from_writer_ = false; |
| 115 bool did_defer_on_writing_ = false; | 126 bool did_defer_on_writing_ = false; |
| 116 bool did_defer_on_redirect_ = false; | 127 bool did_defer_on_redirect_ = false; |
| 117 base::TimeTicks response_started_ticks_; | 128 base::TimeTicks response_started_ticks_; |
| 118 int64_t reported_total_received_bytes_ = 0; | 129 int64_t reported_total_received_bytes_ = 0; |
| 119 | 130 |
| 120 mojo::Watcher handle_watcher_; | 131 mojo::Watcher handle_watcher_; |
| 121 std::unique_ptr<mojom::URLLoader> url_loader_; | 132 std::unique_ptr<mojom::URLLoader> url_loader_; |
| 122 mojom::URLLoaderClientAssociatedPtr url_loader_client_; | 133 mojom::URLLoaderClientAssociatedPtr url_loader_client_; |
| 123 scoped_refptr<net::IOBufferWithSize> buffer_; | 134 scoped_refptr<net::IOBufferWithSize> buffer_; |
| 124 size_t buffer_offset_ = 0; | 135 size_t buffer_offset_ = 0; |
| 125 size_t buffer_bytes_read_ = 0; | 136 size_t buffer_bytes_read_ = 0; |
| 126 scoped_refptr<SharedWriter> shared_writer_; | 137 scoped_refptr<SharedWriter> shared_writer_; |
| 127 mojo::ScopedDataPipeConsumerHandle response_body_consumer_handle_; | 138 mojo::ScopedDataPipeConsumerHandle response_body_consumer_handle_; |
| 128 | 139 |
| 140 std::unique_ptr<UploadProgressTracker> upload_progress_tracker_; |
| 141 |
| 129 base::WeakPtrFactory<MojoAsyncResourceHandler> weak_factory_; | 142 base::WeakPtrFactory<MojoAsyncResourceHandler> weak_factory_; |
| 130 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler); | 143 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler); |
| 131 }; | 144 }; |
| 132 | 145 |
| 133 } // namespace content | 146 } // namespace content |
| 134 | 147 |
| 135 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ | 148 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ |
| OLD | NEW |