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" |
18 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
19 #include "content/common/url_loader.mojom.h" | 18 #include "content/common/url_loader.mojom.h" |
20 #include "mojo/public/cpp/bindings/associated_binding.h" | 19 #include "mojo/public/cpp/bindings/associated_binding.h" |
21 #include "mojo/public/cpp/system/watcher.h" | 20 #include "mojo/public/cpp/system/watcher.h" |
22 #include "net/base/io_buffer.h" | 21 #include "net/base/io_buffer.h" |
23 #include "url/gurl.h" | 22 |
| 23 class GURL; |
24 | 24 |
25 namespace net { | 25 namespace net { |
26 class URLRequest; | 26 class URLRequest; |
27 } | 27 } |
28 | 28 |
29 namespace content { | 29 namespace content { |
30 class ResourceDispatcherHostImpl; | 30 class ResourceDispatcherHostImpl; |
| 31 class UploadProgressTracker; |
31 struct ResourceResponse; | 32 struct ResourceResponse; |
32 | 33 |
33 // Used to complete an asynchronous resource request in response to resource | 34 // Used to complete an asynchronous resource request in response to resource |
34 // load events from the resource dispatcher host. This class is used only | 35 // load events from the resource dispatcher host. This class is used only |
35 // when LoadingWithMojo runtime flag is enabled. | 36 // when LoadingWithMojo runtime flag is enabled. |
36 // | 37 // |
37 // TODO(yhirano): Add histograms. | 38 // TODO(yhirano): Add histograms. |
38 // TODO(yhirano): Send cached metadata. | 39 // TODO(yhirano): Send cached metadata. |
39 // | 40 // |
40 // This class can be inherited only for tests. | 41 // This class can be inherited only for tests. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 void Cancel(); | 94 void Cancel(); |
94 // Calculates the diff between URLRequest::GetTotalReceivedBytes() and | 95 // Calculates the diff between URLRequest::GetTotalReceivedBytes() and |
95 // |reported_total_received_bytes_|, returns it, and updates | 96 // |reported_total_received_bytes_|, returns it, and updates |
96 // |reported_total_received_bytes_|. | 97 // |reported_total_received_bytes_|. |
97 int64_t CalculateRecentlyReceivedBytes(); | 98 int64_t CalculateRecentlyReceivedBytes(); |
98 // This function can be overriden only for tests. | 99 // This function can be overriden only for tests. |
99 virtual void ReportBadMessage(const std::string& error); | 100 virtual void ReportBadMessage(const std::string& error); |
100 | 101 |
101 void OnTransfer(mojom::URLLoaderAssociatedRequest mojo_request, | 102 void OnTransfer(mojom::URLLoaderAssociatedRequest mojo_request, |
102 mojom::URLLoaderClientAssociatedPtr url_loader_client); | 103 mojom::URLLoaderClientAssociatedPtr url_loader_client); |
| 104 void OnUploadProgressACK(); |
| 105 void SendUploadProgress(int64_t current_position, int64_t total_size); |
103 | 106 |
104 ResourceDispatcherHostImpl* rdh_; | 107 ResourceDispatcherHostImpl* rdh_; |
105 mojo::AssociatedBinding<mojom::URLLoader> binding_; | 108 mojo::AssociatedBinding<mojom::URLLoader> binding_; |
106 | 109 |
107 bool has_checked_for_sufficient_resources_ = false; | 110 bool has_checked_for_sufficient_resources_ = false; |
108 bool sent_received_response_message_ = false; | 111 bool sent_received_response_message_ = false; |
109 bool is_using_io_buffer_not_from_writer_ = false; | 112 bool is_using_io_buffer_not_from_writer_ = false; |
110 bool did_defer_on_writing_ = false; | 113 bool did_defer_on_writing_ = false; |
111 bool did_defer_on_redirect_ = false; | 114 bool did_defer_on_redirect_ = false; |
112 base::TimeTicks response_started_ticks_; | 115 base::TimeTicks response_started_ticks_; |
113 int64_t reported_total_received_bytes_ = 0; | 116 int64_t reported_total_received_bytes_ = 0; |
114 | 117 |
115 mojo::Watcher handle_watcher_; | 118 mojo::Watcher handle_watcher_; |
116 std::unique_ptr<mojom::URLLoader> url_loader_; | 119 std::unique_ptr<mojom::URLLoader> url_loader_; |
117 mojom::URLLoaderClientAssociatedPtr url_loader_client_; | 120 mojom::URLLoaderClientAssociatedPtr url_loader_client_; |
118 scoped_refptr<net::IOBufferWithSize> buffer_; | 121 scoped_refptr<net::IOBufferWithSize> buffer_; |
119 size_t buffer_offset_ = 0; | 122 size_t buffer_offset_ = 0; |
120 size_t buffer_bytes_read_ = 0; | 123 size_t buffer_bytes_read_ = 0; |
121 scoped_refptr<SharedWriter> shared_writer_; | 124 scoped_refptr<SharedWriter> shared_writer_; |
122 | 125 |
| 126 std::unique_ptr<UploadProgressTracker> upload_progress_tracker_; |
| 127 |
123 base::WeakPtrFactory<MojoAsyncResourceHandler> weak_factory_; | 128 base::WeakPtrFactory<MojoAsyncResourceHandler> weak_factory_; |
124 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler); | 129 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler); |
125 }; | 130 }; |
126 | 131 |
127 } // namespace content | 132 } // namespace content |
128 | 133 |
129 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ | 134 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ |
OLD | NEW |