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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 bool* defer); | 90 bool* defer); |
90 | 91 |
91 bool CheckForSufficientResource(); | 92 bool CheckForSufficientResource(); |
92 void OnWritable(MojoResult result); | 93 void OnWritable(MojoResult result); |
93 void Cancel(); | 94 void Cancel(); |
94 // This function can be overriden only for tests. | 95 // This function can be overriden only for tests. |
95 virtual void ReportBadMessage(const std::string& error); | 96 virtual void ReportBadMessage(const std::string& error); |
96 | 97 |
97 void OnTransfer(mojom::URLLoaderAssociatedRequest mojo_request, | 98 void OnTransfer(mojom::URLLoaderAssociatedRequest mojo_request, |
98 mojom::URLLoaderClientAssociatedPtr url_loader_client); | 99 mojom::URLLoaderClientAssociatedPtr url_loader_client); |
| 100 void OnUploadProgressACK(); |
| 101 void SendUploadProgress(int64_t current_position, int64_t total_size); |
99 | 102 |
100 ResourceDispatcherHostImpl* rdh_; | 103 ResourceDispatcherHostImpl* rdh_; |
101 mojo::AssociatedBinding<mojom::URLLoader> binding_; | 104 mojo::AssociatedBinding<mojom::URLLoader> binding_; |
102 | 105 |
103 bool has_checked_for_sufficient_resources_ = false; | 106 bool has_checked_for_sufficient_resources_ = false; |
104 bool sent_received_response_message_ = false; | 107 bool sent_received_response_message_ = false; |
105 bool is_using_io_buffer_not_from_writer_ = false; | 108 bool is_using_io_buffer_not_from_writer_ = false; |
106 bool did_defer_on_writing_ = false; | 109 bool did_defer_on_writing_ = false; |
107 bool did_defer_on_redirect_ = false; | 110 bool did_defer_on_redirect_ = false; |
108 base::TimeTicks response_started_ticks_; | 111 base::TimeTicks response_started_ticks_; |
109 int64_t reported_total_received_bytes_ = 0; | 112 int64_t reported_total_received_bytes_ = 0; |
110 | 113 |
111 mojo::Watcher handle_watcher_; | 114 mojo::Watcher handle_watcher_; |
112 std::unique_ptr<mojom::URLLoader> url_loader_; | 115 std::unique_ptr<mojom::URLLoader> url_loader_; |
113 mojom::URLLoaderClientAssociatedPtr url_loader_client_; | 116 mojom::URLLoaderClientAssociatedPtr url_loader_client_; |
114 scoped_refptr<net::IOBufferWithSize> buffer_; | 117 scoped_refptr<net::IOBufferWithSize> buffer_; |
115 size_t buffer_offset_ = 0; | 118 size_t buffer_offset_ = 0; |
116 size_t buffer_bytes_read_ = 0; | 119 size_t buffer_bytes_read_ = 0; |
117 scoped_refptr<SharedWriter> shared_writer_; | 120 scoped_refptr<SharedWriter> shared_writer_; |
118 | 121 |
| 122 std::unique_ptr<UploadProgressTracker> upload_progress_tracker_; |
| 123 |
119 base::WeakPtrFactory<MojoAsyncResourceHandler> weak_factory_; | 124 base::WeakPtrFactory<MojoAsyncResourceHandler> weak_factory_; |
120 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler); | 125 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandler); |
121 }; | 126 }; |
122 | 127 |
123 } // namespace content | 128 } // namespace content |
124 | 129 |
125 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ | 130 #endif // CONTENT_BROWSER_LOADER_MOJO_ASYNC_RESOURCE_HANDLER_H_ |
OLD | NEW |