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

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

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