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