Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(398)

Side by Side Diff: content/browser/loader/test_resource_handler.h

Issue 2668603003: Make ResourceHandler::OnWillRead able to complete asynchronously. (Closed)
Patch Set: Response to comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_TEST_RESOURCE_HANDLER_H_ 5 #ifndef CONTENT_BROWSER_LOADER_TEST_RESOURCE_HANDLER_H_
6 #define CONTENT_BROWSER_LOADER_TEST_RESOURCE_HANDLER_H_ 6 #define CONTENT_BROWSER_LOADER_TEST_RESOURCE_HANDLER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 // ResourceHandler implementation: 45 // ResourceHandler implementation:
46 void OnRequestRedirected( 46 void OnRequestRedirected(
47 const net::RedirectInfo& redirect_info, 47 const net::RedirectInfo& redirect_info,
48 ResourceResponse* response, 48 ResourceResponse* response,
49 std::unique_ptr<ResourceController> controller) override; 49 std::unique_ptr<ResourceController> controller) override;
50 void OnResponseStarted( 50 void OnResponseStarted(
51 ResourceResponse* response, 51 ResourceResponse* response,
52 std::unique_ptr<ResourceController> controller) override; 52 std::unique_ptr<ResourceController> controller) override;
53 void OnWillStart(const GURL& url, 53 void OnWillStart(const GURL& url,
54 std::unique_ptr<ResourceController> controller) override; 54 std::unique_ptr<ResourceController> controller) override;
55 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, 55 void OnWillRead(scoped_refptr<net::IOBuffer>* buf,
56 int* buf_size) override; 56 int* buf_size,
57 std::unique_ptr<ResourceController> controller) override;
57 void OnReadCompleted(int bytes_read, 58 void OnReadCompleted(int bytes_read,
58 std::unique_ptr<ResourceController> controller) override; 59 std::unique_ptr<ResourceController> controller) override;
59 void OnResponseCompleted( 60 void OnResponseCompleted(
60 const net::URLRequestStatus& status, 61 const net::URLRequestStatus& status,
61 std::unique_ptr<ResourceController> controller) override; 62 std::unique_ptr<ResourceController> controller) override;
62 void OnDataDownloaded(int bytes_downloaded) override; 63 void OnDataDownloaded(int bytes_downloaded) override;
63 64
64 void Resume(); 65 void Resume();
65 void CancelWithError(net::Error error_code); 66 void CancelWithError(net::Error error_code);
66 67
(...skipping 28 matching lines...) Expand all
95 96
96 void set_defer_on_will_start(bool defer_on_will_start) { 97 void set_defer_on_will_start(bool defer_on_will_start) {
97 defer_on_will_start_ = defer_on_will_start; 98 defer_on_will_start_ = defer_on_will_start;
98 } 99 }
99 void set_defer_on_request_redirected(bool defer_on_request_redirected) { 100 void set_defer_on_request_redirected(bool defer_on_request_redirected) {
100 defer_on_request_redirected_ = defer_on_request_redirected; 101 defer_on_request_redirected_ = defer_on_request_redirected;
101 } 102 }
102 void set_defer_on_response_started(bool defer_on_response_started) { 103 void set_defer_on_response_started(bool defer_on_response_started) {
103 defer_on_response_started_ = defer_on_response_started; 104 defer_on_response_started_ = defer_on_response_started;
104 } 105 }
106 // Only the next OnWillRead call will set |defer| to true.
107 void set_defer_on_will_read(bool defer_on_will_read) {
108 defer_on_will_read_ = defer_on_will_read;
109 }
105 // Only the next OnReadCompleted call will set |defer| to true. 110 // Only the next OnReadCompleted call will set |defer| to true.
106 void set_defer_on_read_completed(bool defer_on_read_completed) { 111 void set_defer_on_read_completed(bool defer_on_read_completed) {
107 defer_on_read_completed_ = defer_on_read_completed; 112 defer_on_read_completed_ = defer_on_read_completed;
108 } 113 }
109 // The final-byte read will set |defer| to true. 114 // The final-byte read will set |defer| to true.
110 void set_defer_on_read_eof(bool defer_on_read_eof) { 115 void set_defer_on_read_eof(bool defer_on_read_eof) {
111 defer_on_read_eof_ = defer_on_read_eof; 116 defer_on_read_eof_ = defer_on_read_eof;
112 } 117 }
113 void set_defer_on_response_completed(bool defer_on_response_completed) { 118 void set_defer_on_response_completed(bool defer_on_response_completed) {
114 defer_on_response_completed_ = defer_on_response_completed; 119 defer_on_response_completed_ = defer_on_response_completed;
(...skipping 12 matching lines...) Expand all
127 132
128 // Return the number of times the corresponding method was invoked. 133 // Return the number of times the corresponding method was invoked.
129 134
130 int on_will_start_called() const { return on_will_start_called_; } 135 int on_will_start_called() const { return on_will_start_called_; }
131 int on_request_redirected_called() const { 136 int on_request_redirected_called() const {
132 return on_request_redirected_called_; 137 return on_request_redirected_called_;
133 } 138 }
134 int on_response_started_called() const { return on_response_started_called_; } 139 int on_response_started_called() const { return on_response_started_called_; }
135 int on_will_read_called() const { return on_will_read_called_; } 140 int on_will_read_called() const { return on_will_read_called_; }
136 int on_read_completed_called() const { return on_read_completed_called_; } 141 int on_read_completed_called() const { return on_read_completed_called_; }
137 int on_read_eof() const { return on_read_eof_; } 142 int on_read_eof_called() const { return on_read_eof_called_; }
138 int on_response_completed_called() const { 143 int on_response_completed_called() const {
139 return on_response_completed_called_; 144 return on_response_completed_called_;
140 } 145 }
141 146
142 // URL passed to OnResponseStarted, if it was called. 147 // URL passed to OnResponseStarted, if it was called.
143 const GURL& start_url() const { return start_url_; } 148 const GURL& start_url() const { return start_url_; }
144 149
145 ResourceResponse* resource_response() { return resource_response_.get(); }; 150 ResourceResponse* resource_response() { return resource_response_.get(); };
146 151
147 int total_bytes_downloaded() const { return total_bytes_downloaded_; } 152 int total_bytes_downloaded() const { return total_bytes_downloaded_; }
(...skipping 26 matching lines...) Expand all
174 bool on_will_start_result_ = true; 179 bool on_will_start_result_ = true;
175 bool on_request_redirected_result_ = true; 180 bool on_request_redirected_result_ = true;
176 bool on_response_started_result_ = true; 181 bool on_response_started_result_ = true;
177 bool on_will_read_result_ = true; 182 bool on_will_read_result_ = true;
178 bool on_read_completed_result_ = true; 183 bool on_read_completed_result_ = true;
179 bool on_read_eof_result_ = true; 184 bool on_read_eof_result_ = true;
180 185
181 bool defer_on_will_start_ = false; 186 bool defer_on_will_start_ = false;
182 bool defer_on_request_redirected_ = false; 187 bool defer_on_request_redirected_ = false;
183 bool defer_on_response_started_ = false; 188 bool defer_on_response_started_ = false;
189 bool defer_on_will_read_ = false;
184 bool defer_on_read_completed_ = false; 190 bool defer_on_read_completed_ = false;
185 bool defer_on_read_eof_ = false; 191 bool defer_on_read_eof_ = false;
186 bool defer_on_response_completed_ = false; 192 bool defer_on_response_completed_ = false;
187 193
188 bool expect_on_data_downloaded_ = false; 194 bool expect_on_data_downloaded_ = false;
189 195
190 bool expect_eof_read_ = true; 196 bool expect_eof_read_ = true;
191 197
192 int on_will_start_called_ = 0; 198 int on_will_start_called_ = 0;
193 int on_request_redirected_called_ = 0; 199 int on_request_redirected_called_ = 0;
194 int on_response_started_called_ = 0; 200 int on_response_started_called_ = 0;
195 int on_will_read_called_ = 0; 201 int on_will_read_called_ = 0;
196 int on_read_completed_called_ = 0; 202 int on_read_completed_called_ = 0;
197 int on_read_eof_ = 0; 203 int on_read_eof_called_ = 0;
198 int on_response_completed_called_ = 0; 204 int on_response_completed_called_ = 0;
199 205
200 GURL start_url_; 206 GURL start_url_;
201 scoped_refptr<ResourceResponse> resource_response_; 207 scoped_refptr<ResourceResponse> resource_response_;
202 int total_bytes_downloaded_ = 0; 208 int total_bytes_downloaded_ = 0;
203 std::string body_; 209 std::string body_;
204 net::URLRequestStatus final_status_ = 210 net::URLRequestStatus final_status_ =
205 net::URLRequestStatus::FromError(net::ERR_UNEXPECTED); 211 net::URLRequestStatus::FromError(net::ERR_UNEXPECTED);
206 bool canceled_ = false; 212 bool canceled_ = false;
207 213
214 // Pointers to the parent's read buffer and size. Only non-NULL during
215 // OnWillRead call, until cancellation or resumption.
216 scoped_refptr<net::IOBuffer>* parent_read_buffer_ = nullptr;
217 int* parent_read_buffer_size_ = nullptr;
218
208 // Tracks recursive calls, which aren't allowed. 219 // Tracks recursive calls, which aren't allowed.
209 int call_depth_ = 0; 220 int call_depth_ = 0;
210 221
211 std::unique_ptr<base::RunLoop> deferred_run_loop_; 222 std::unique_ptr<base::RunLoop> deferred_run_loop_;
212 223
213 base::RunLoop response_complete_run_loop_; 224 base::RunLoop response_complete_run_loop_;
214 225
215 base::WeakPtrFactory<TestResourceHandler> weak_ptr_factory_; 226 base::WeakPtrFactory<TestResourceHandler> weak_ptr_factory_;
216 227
217 DISALLOW_COPY_AND_ASSIGN(TestResourceHandler); 228 DISALLOW_COPY_AND_ASSIGN(TestResourceHandler);
218 }; 229 };
219 230
220 } // namespace content 231 } // namespace content
221 232
222 #endif // CONTENT_BROWSER_LOADER_TEST_RESOURCE_HANDLER_H_ 233 #endif // CONTENT_BROWSER_LOADER_TEST_RESOURCE_HANDLER_H_
OLDNEW
« no previous file with comments | « content/browser/loader/sync_resource_handler.cc ('k') | content/browser/loader/test_resource_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698