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

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

Issue 2526983002: Refactor ResourceHandler API. (Closed)
Patch Set: Fix Created 4 years 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 24 matching lines...) Expand all
35 class TestResourceHandler : public ResourceHandler { 35 class TestResourceHandler : public ResourceHandler {
36 public: 36 public:
37 // If non-null, |request_status| will be updated when the response is complete 37 // If non-null, |request_status| will be updated when the response is complete
38 // with the final status of the request received by the handler and |body| 38 // with the final status of the request received by the handler and |body|
39 // will be updated on each OnReadCompleted call. 39 // will be updated on each OnReadCompleted call.
40 TestResourceHandler(net::URLRequestStatus* request_status, std::string* body); 40 TestResourceHandler(net::URLRequestStatus* request_status, std::string* body);
41 TestResourceHandler(); 41 TestResourceHandler();
42 ~TestResourceHandler() override; 42 ~TestResourceHandler() override;
43 43
44 // ResourceHandler implementation: 44 // ResourceHandler implementation:
45 void SetController(ResourceController* controller) override; 45 void OnRequestRedirected(
46 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, 46 const net::RedirectInfo& redirect_info,
47 ResourceResponse* response, 47 ResourceResponse* response,
48 bool* defer) override; 48 std::unique_ptr<ResourceController> controller) override;
49 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; 49 void OnResponseStarted(
50 bool OnWillStart(const GURL& url, bool* defer) override; 50 ResourceResponse* response,
51 std::unique_ptr<ResourceController> controller) override;
52 void OnWillStart(const GURL& url,
53 std::unique_ptr<ResourceController> controller) override;
51 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, 54 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf,
52 int* buf_size, 55 int* buf_size,
53 int min_size) override; 56 int min_size) override;
54 bool OnReadCompleted(int bytes_read, bool* defer) override; 57 void OnReadCompleted(int bytes_read,
55 void OnResponseCompleted(const net::URLRequestStatus& status, 58 std::unique_ptr<ResourceController> controller) override;
56 bool* defer) override; 59 void OnResponseCompleted(
60 const net::URLRequestStatus& status,
61 std::unique_ptr<ResourceController> controller) override;
57 void OnDataDownloaded(int bytes_downloaded) override; 62 void OnDataDownloaded(int bytes_downloaded) override;
58 63
59 // Invoke the corresponding methods on the ResourceHandler's
60 // ResourceController.
61 void Resume(); 64 void Resume();
62 void CancelWithError(net::Error net_error); 65 void CancelWithError(net::Error error_code);
63 66
64 // Sets the size of the read buffer returned by OnWillRead. Releases reference 67 // Sets the size of the read buffer returned by OnWillRead. Releases reference
65 // to previous read buffer. Default size is 2048 bytes. 68 // to previous read buffer. Default size is 2048 bytes.
66 void SetBufferSize(int buffer_size); 69 void SetBufferSize(int buffer_size);
67 70
68 scoped_refptr<net::IOBuffer> buffer() const { return buffer_; } 71 scoped_refptr<net::IOBuffer> buffer() const { return buffer_; }
69 72
70 // Sets the result returned by each method. All default to returning true. 73 // Sets the result returned by each method. All default to returning true.
71 void set_on_will_start_result(bool on_will_start_result) { 74 void set_on_will_start_result(bool on_will_start_result) {
72 on_will_start_result_ = on_will_start_result; 75 on_will_start_result_ = on_will_start_result;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 void WaitUntilResponseComplete(); 161 void WaitUntilResponseComplete();
159 162
160 private: 163 private:
161 // TODO(mmenke): Remove these, in favor of final_status_ and body_. 164 // TODO(mmenke): Remove these, in favor of final_status_ and body_.
162 net::URLRequestStatus* request_status_ptr_; 165 net::URLRequestStatus* request_status_ptr_;
163 std::string* body_ptr_; 166 std::string* body_ptr_;
164 167
165 scoped_refptr<net::IOBuffer> buffer_; 168 scoped_refptr<net::IOBuffer> buffer_;
166 size_t buffer_size_; 169 size_t buffer_size_;
167 170
168 ResourceController* controller_;
169
170 bool on_will_start_result_ = true; 171 bool on_will_start_result_ = true;
171 bool on_request_redirected_result_ = true; 172 bool on_request_redirected_result_ = true;
172 bool on_response_started_result_ = true; 173 bool on_response_started_result_ = true;
173 bool on_will_read_result_ = true; 174 bool on_will_read_result_ = true;
174 bool on_read_completed_result_ = true; 175 bool on_read_completed_result_ = true;
175 bool on_read_eof_result_ = true; 176 bool on_read_eof_result_ = true;
176 177
177 bool defer_on_will_start_ = false; 178 bool defer_on_will_start_ = false;
178 bool defer_on_request_redirected_ = false; 179 bool defer_on_request_redirected_ = false;
179 bool defer_on_response_started_ = false; 180 bool defer_on_response_started_ = false;
(...skipping 27 matching lines...) Expand all
207 std::unique_ptr<base::RunLoop> deferred_run_loop_; 208 std::unique_ptr<base::RunLoop> deferred_run_loop_;
208 209
209 base::RunLoop response_complete_run_loop_; 210 base::RunLoop response_complete_run_loop_;
210 211
211 DISALLOW_COPY_AND_ASSIGN(TestResourceHandler); 212 DISALLOW_COPY_AND_ASSIGN(TestResourceHandler);
212 }; 213 };
213 214
214 } // namespace content 215 } // namespace content
215 216
216 #endif // CONTENT_BROWSER_LOADER_TEST_RESOURCE_HANDLER_H_ 217 #endif // CONTENT_BROWSER_LOADER_TEST_RESOURCE_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698