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

Side by Side Diff: net/url_request/url_request_test_util.cc

Issue 15829004: Update net/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: license twerk Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "net/url_request/url_request_test_util.h" 5 #include "net/url_request/url_request_test_util.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 NetworkDelegate* network_delegate) 128 NetworkDelegate* network_delegate)
129 : URLRequest(url, delegate, context, network_delegate) { 129 : URLRequest(url, delegate, context, network_delegate) {
130 } 130 }
131 131
132 TestURLRequest::~TestURLRequest() { 132 TestURLRequest::~TestURLRequest() {
133 } 133 }
134 134
135 TestURLRequestContextGetter::TestURLRequestContextGetter( 135 TestURLRequestContextGetter::TestURLRequestContextGetter(
136 const scoped_refptr<base::SingleThreadTaskRunner>& network_task_runner) 136 const scoped_refptr<base::SingleThreadTaskRunner>& network_task_runner)
137 : network_task_runner_(network_task_runner) { 137 : network_task_runner_(network_task_runner) {
138 DCHECK(network_task_runner_); 138 DCHECK(network_task_runner_.get());
139 } 139 }
140 140
141 TestURLRequestContextGetter::TestURLRequestContextGetter( 141 TestURLRequestContextGetter::TestURLRequestContextGetter(
142 const scoped_refptr<base::SingleThreadTaskRunner>& network_task_runner, 142 const scoped_refptr<base::SingleThreadTaskRunner>& network_task_runner,
143 scoped_ptr<TestURLRequestContext> context) 143 scoped_ptr<TestURLRequestContext> context)
144 : network_task_runner_(network_task_runner), context_(context.Pass()) { 144 : network_task_runner_(network_task_runner), context_(context.Pass()) {
145 DCHECK(network_task_runner_); 145 DCHECK(network_task_runner_.get());
146 } 146 }
147 147
148 TestURLRequestContextGetter::~TestURLRequestContextGetter() {} 148 TestURLRequestContextGetter::~TestURLRequestContextGetter() {}
149 149
150 TestURLRequestContext* TestURLRequestContextGetter::GetURLRequestContext() { 150 TestURLRequestContext* TestURLRequestContextGetter::GetURLRequestContext() {
151 if (!context_.get()) 151 if (!context_.get())
152 context_.reset(new TestURLRequestContext); 152 context_.reset(new TestURLRequestContext);
153 return context_.get(); 153 return context_.get();
154 } 154 }
155 155
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 request->Cancel(); 227 request->Cancel();
228 OnResponseCompleted(request); 228 OnResponseCompleted(request);
229 } else if (!request->status().is_success()) { 229 } else if (!request->status().is_success()) {
230 DCHECK(request->status().status() == URLRequestStatus::FAILED || 230 DCHECK(request->status().status() == URLRequestStatus::FAILED ||
231 request->status().status() == URLRequestStatus::CANCELED); 231 request->status().status() == URLRequestStatus::CANCELED);
232 request_failed_ = true; 232 request_failed_ = true;
233 OnResponseCompleted(request); 233 OnResponseCompleted(request);
234 } else { 234 } else {
235 // Initiate the first read. 235 // Initiate the first read.
236 int bytes_read = 0; 236 int bytes_read = 0;
237 if (request->Read(buf_, kBufferSize, &bytes_read)) 237 if (request->Read(buf_.get(), kBufferSize, &bytes_read))
238 OnReadCompleted(request, bytes_read); 238 OnReadCompleted(request, bytes_read);
239 else if (!request->status().is_io_pending()) 239 else if (!request->status().is_io_pending())
240 OnResponseCompleted(request); 240 OnResponseCompleted(request);
241 } 241 }
242 } 242 }
243 243
244 void TestDelegate::OnReadCompleted(URLRequest* request, int bytes_read) { 244 void TestDelegate::OnReadCompleted(URLRequest* request, int bytes_read) {
245 // It doesn't make sense for the request to have IO pending at this point. 245 // It doesn't make sense for the request to have IO pending at this point.
246 DCHECK(!request->status().is_io_pending()); 246 DCHECK(!request->status().is_io_pending());
247 247
248 if (response_started_count_ == 0) 248 if (response_started_count_ == 0)
249 received_data_before_response_ = true; 249 received_data_before_response_ = true;
250 250
251 if (cancel_in_rd_) 251 if (cancel_in_rd_)
252 request->Cancel(); 252 request->Cancel();
253 253
254 if (bytes_read >= 0) { 254 if (bytes_read >= 0) {
255 // There is data to read. 255 // There is data to read.
256 received_bytes_count_ += bytes_read; 256 received_bytes_count_ += bytes_read;
257 257
258 // consume the data 258 // consume the data
259 data_received_.append(buf_->data(), bytes_read); 259 data_received_.append(buf_->data(), bytes_read);
260 } 260 }
261 261
262 // If it was not end of stream, request to read more. 262 // If it was not end of stream, request to read more.
263 if (request->status().is_success() && bytes_read > 0) { 263 if (request->status().is_success() && bytes_read > 0) {
264 bytes_read = 0; 264 bytes_read = 0;
265 while (request->Read(buf_, kBufferSize, &bytes_read)) { 265 while (request->Read(buf_.get(), kBufferSize, &bytes_read)) {
266 if (bytes_read > 0) { 266 if (bytes_read > 0) {
267 data_received_.append(buf_->data(), bytes_read); 267 data_received_.append(buf_->data(), bytes_read);
268 received_bytes_count_ += bytes_read; 268 received_bytes_count_ += bytes_read;
269 } else { 269 } else {
270 break; 270 break;
271 } 271 }
272 } 272 }
273 } 273 }
274 if (!request->status().is_io_pending()) 274 if (!request->status().is_io_pending())
275 OnResponseCompleted(request); 275 OnResponseCompleted(request);
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 URLRequestJob* job = main_intercept_job_; 581 URLRequestJob* job = main_intercept_job_;
582 main_intercept_job_ = NULL; 582 main_intercept_job_ = NULL;
583 return job; 583 return job;
584 } 584 }
585 585
586 void TestJobInterceptor::set_main_intercept_job(URLRequestJob* job) { 586 void TestJobInterceptor::set_main_intercept_job(URLRequestJob* job) {
587 main_intercept_job_ = job; 587 main_intercept_job_ = job;
588 } 588 }
589 589
590 } // namespace net 590 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_test_job.cc ('k') | net/url_request/url_request_throttler_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698