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

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

Issue 6730034: Remove all "net::" prefixes under net/url_request for code that's (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed indentation Created 9 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 | Annotate | Revision Log
« no previous file with comments | « net/url_request/url_request.h ('k') | net/url_request/url_request_context.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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.h" 5 #include "net/url_request/url_request.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/metrics/stats_counters.h" 9 #include "base/metrics/stats_counters.h"
10 #include "base/singleton.h" 10 #include "base/singleton.h"
11 #include "base/synchronization/lock.h" 11 #include "base/synchronization/lock.h"
12 #include "net/base/host_port_pair.h" 12 #include "net/base/host_port_pair.h"
13 #include "net/base/load_flags.h" 13 #include "net/base/load_flags.h"
14 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
15 #include "net/base/net_log.h" 15 #include "net/base/net_log.h"
16 #include "net/base/network_delegate.h" 16 #include "net/base/network_delegate.h"
17 #include "net/base/ssl_cert_request_info.h" 17 #include "net/base/ssl_cert_request_info.h"
18 #include "net/base/upload_data.h" 18 #include "net/base/upload_data.h"
19 #include "net/http/http_response_headers.h" 19 #include "net/http/http_response_headers.h"
20 #include "net/http/http_util.h" 20 #include "net/http/http_util.h"
21 #include "net/url_request/url_request_context.h" 21 #include "net/url_request/url_request_context.h"
22 #include "net/url_request/url_request_error_job.h" 22 #include "net/url_request/url_request_error_job.h"
23 #include "net/url_request/url_request_job.h" 23 #include "net/url_request/url_request_job.h"
24 #include "net/url_request/url_request_job_manager.h" 24 #include "net/url_request/url_request_job_manager.h"
25 #include "net/url_request/url_request_netlog_params.h" 25 #include "net/url_request/url_request_netlog_params.h"
26 26
27 using base::Time; 27 using base::Time;
28 using net::UploadData;
29 using std::string; 28 using std::string;
30 29
30 namespace net {
31
31 namespace { 32 namespace {
32 33
33 // Max number of http redirects to follow. Same number as gecko. 34 // Max number of http redirects to follow. Same number as gecko.
34 const int kMaxRedirects = 20; 35 const int kMaxRedirects = 20;
35 36
36 // Discard headers which have meaning in POST (Content-Length, Content-Type, 37 // Discard headers which have meaning in POST (Content-Length, Content-Type,
37 // Origin). 38 // Origin).
38 void StripPostSpecificHeaders(net::HttpRequestHeaders* headers) { 39 void StripPostSpecificHeaders(HttpRequestHeaders* headers) {
39 // These are headers that may be attached to a POST. 40 // These are headers that may be attached to a POST.
40 headers->RemoveHeader(net::HttpRequestHeaders::kContentLength); 41 headers->RemoveHeader(HttpRequestHeaders::kContentLength);
41 headers->RemoveHeader(net::HttpRequestHeaders::kContentType); 42 headers->RemoveHeader(HttpRequestHeaders::kContentType);
42 headers->RemoveHeader(net::HttpRequestHeaders::kOrigin); 43 headers->RemoveHeader(HttpRequestHeaders::kOrigin);
43 } 44 }
44 45
45 // This counter keeps track of the identifiers used for URL requests so far. 46 // This counter keeps track of the identifiers used for URL requests so far.
46 uint64 g_next_url_request_identifier = 0; 47 uint64 g_next_url_request_identifier = 0;
47 48
48 // This lock protects g_next_url_request_identifier. 49 // This lock protects g_next_url_request_identifier.
49 base::Lock g_next_url_request_identifier_lock; 50 base::Lock g_next_url_request_identifier_lock;
50 51
51 // Returns an prior unused identifier for URL requests. 52 // Returns an prior unused identifier for URL requests.
52 uint64 GenerateURLRequestIdentifier() { 53 uint64 GenerateURLRequestIdentifier() {
53 base::AutoLock lock(g_next_url_request_identifier_lock); 54 base::AutoLock lock(g_next_url_request_identifier_lock);
54 return g_next_url_request_identifier++; 55 return g_next_url_request_identifier++;
55 } 56 }
56 57
57 } // namespace 58 } // namespace
58 59
59 namespace net {
60
61 /////////////////////////////////////////////////////////////////////////////// 60 ///////////////////////////////////////////////////////////////////////////////
62 // URLRequest::Interceptor 61 // URLRequest::Interceptor
63 62
64 URLRequestJob* URLRequest::Interceptor::MaybeInterceptRedirect( 63 URLRequestJob* URLRequest::Interceptor::MaybeInterceptRedirect(
65 URLRequest* request, 64 URLRequest* request,
66 const GURL& location) { 65 const GURL& location) {
67 return NULL; 66 return NULL;
68 } 67 }
69 68
70 URLRequestJob* URLRequest::Interceptor::MaybeInterceptResponse( 69 URLRequestJob* URLRequest::Interceptor::MaybeInterceptResponse(
71 URLRequest* request) { 70 URLRequest* request) {
72 return NULL; 71 return NULL;
73 } 72 }
74 73
75 /////////////////////////////////////////////////////////////////////////////// 74 ///////////////////////////////////////////////////////////////////////////////
76 // URLRequest::Delegate 75 // URLRequest::Delegate
77 76
78 void URLRequest::Delegate::OnReceivedRedirect(URLRequest* request, 77 void URLRequest::Delegate::OnReceivedRedirect(URLRequest* request,
79 const GURL& new_url, 78 const GURL& new_url,
80 bool* defer_redirect) { 79 bool* defer_redirect) {
81 } 80 }
82 81
83 void URLRequest::Delegate::OnAuthRequired(URLRequest* request, 82 void URLRequest::Delegate::OnAuthRequired(URLRequest* request,
84 net::AuthChallengeInfo* auth_info) { 83 AuthChallengeInfo* auth_info) {
85 request->CancelAuth(); 84 request->CancelAuth();
86 } 85 }
87 86
88 void URLRequest::Delegate::OnCertificateRequested( 87 void URLRequest::Delegate::OnCertificateRequested(
89 URLRequest* request, 88 URLRequest* request,
90 net::SSLCertRequestInfo* cert_request_info) { 89 SSLCertRequestInfo* cert_request_info) {
91 request->ContinueWithCertificate(NULL); 90 request->ContinueWithCertificate(NULL);
92 } 91 }
93 92
94 void URLRequest::Delegate::OnSSLCertificateError(URLRequest* request, 93 void URLRequest::Delegate::OnSSLCertificateError(URLRequest* request,
95 int cert_error, 94 int cert_error,
96 net::X509Certificate* cert) { 95 X509Certificate* cert) {
97 request->Cancel(); 96 request->Cancel();
98 } 97 }
99 98
100 void URLRequest::Delegate::OnGetCookies(URLRequest* request, 99 void URLRequest::Delegate::OnGetCookies(URLRequest* request,
101 bool blocked_by_policy) { 100 bool blocked_by_policy) {
102 } 101 }
103 102
104 void URLRequest::Delegate::OnSetCookie(URLRequest* request, 103 void URLRequest::Delegate::OnSetCookie(URLRequest* request,
105 const std::string& cookie_line, 104 const std::string& cookie_line,
106 const net::CookieOptions& options, 105 const CookieOptions& options,
107 bool blocked_by_policy) { 106 bool blocked_by_policy) {
108 } 107 }
109 108
110 /////////////////////////////////////////////////////////////////////////////// 109 ///////////////////////////////////////////////////////////////////////////////
111 // URLRequest 110 // URLRequest
112 111
113 URLRequest::URLRequest(const GURL& url, Delegate* delegate) 112 URLRequest::URLRequest(const GURL& url, Delegate* delegate)
114 : url_(url), 113 : url_(url),
115 original_url_(url), 114 original_url_(url),
116 method_("GET"), 115 method_("GET"),
117 load_flags_(net::LOAD_NORMAL), 116 load_flags_(LOAD_NORMAL),
118 delegate_(delegate), 117 delegate_(delegate),
119 is_pending_(false), 118 is_pending_(false),
120 redirect_limit_(kMaxRedirects), 119 redirect_limit_(kMaxRedirects),
121 final_upload_progress_(0), 120 final_upload_progress_(0),
122 priority_(net::LOWEST), 121 priority_(LOWEST),
123 identifier_(GenerateURLRequestIdentifier()) { 122 identifier_(GenerateURLRequestIdentifier()) {
124 SIMPLE_STATS_COUNTER("URLRequestCount"); 123 SIMPLE_STATS_COUNTER("URLRequestCount");
125 124
126 // Sanity check out environment. 125 // Sanity check out environment.
127 DCHECK(MessageLoop::current()) << 126 DCHECK(MessageLoop::current()) <<
128 "The current MessageLoop must exist"; 127 "The current MessageLoop must exist";
129 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << 128 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) <<
130 "The current MessageLoop must be TYPE_IO"; 129 "The current MessageLoop must be TYPE_IO";
131 } 130 }
132 131
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 188
190 void URLRequest::AppendChunkToUpload(const char* bytes, 189 void URLRequest::AppendChunkToUpload(const char* bytes,
191 int bytes_len, 190 int bytes_len,
192 bool is_last_chunk) { 191 bool is_last_chunk) {
193 DCHECK(upload_); 192 DCHECK(upload_);
194 DCHECK(upload_->is_chunked()); 193 DCHECK(upload_->is_chunked());
195 DCHECK_GT(bytes_len, 0); 194 DCHECK_GT(bytes_len, 0);
196 upload_->AppendChunk(bytes, bytes_len, is_last_chunk); 195 upload_->AppendChunk(bytes, bytes_len, is_last_chunk);
197 } 196 }
198 197
199 void URLRequest::set_upload(net::UploadData* upload) { 198 void URLRequest::set_upload(UploadData* upload) {
200 upload_ = upload; 199 upload_ = upload;
201 } 200 }
202 201
203 // Get the upload data directly. 202 // Get the upload data directly.
204 net::UploadData* URLRequest::get_upload() { 203 UploadData* URLRequest::get_upload() {
205 return upload_.get(); 204 return upload_.get();
206 } 205 }
207 206
208 bool URLRequest::has_upload() const { 207 bool URLRequest::has_upload() const {
209 return upload_ != NULL; 208 return upload_ != NULL;
210 } 209 }
211 210
212 void URLRequest::SetExtraRequestHeaderById(int id, const string& value, 211 void URLRequest::SetExtraRequestHeaderById(int id, const string& value,
213 bool overwrite) { 212 bool overwrite) {
214 DCHECK(!is_pending_); 213 DCHECK(!is_pending_);
215 NOTREACHED() << "implement me!"; 214 NOTREACHED() << "implement me!";
216 } 215 }
217 216
218 void URLRequest::SetExtraRequestHeaderByName(const string& name, 217 void URLRequest::SetExtraRequestHeaderByName(const string& name,
219 const string& value, 218 const string& value,
220 bool overwrite) { 219 bool overwrite) {
221 DCHECK(!is_pending_); 220 DCHECK(!is_pending_);
222 NOTREACHED() << "implement me!"; 221 NOTREACHED() << "implement me!";
223 } 222 }
224 223
225 void URLRequest::SetExtraRequestHeaders( 224 void URLRequest::SetExtraRequestHeaders(
226 const net::HttpRequestHeaders& headers) { 225 const HttpRequestHeaders& headers) {
227 DCHECK(!is_pending_); 226 DCHECK(!is_pending_);
228 extra_request_headers_ = headers; 227 extra_request_headers_ = headers;
229 228
230 // NOTE: This method will likely become non-trivial once the other setters 229 // NOTE: This method will likely become non-trivial once the other setters
231 // for request headers are implemented. 230 // for request headers are implemented.
232 } 231 }
233 232
234 net::LoadState URLRequest::GetLoadState() const { 233 LoadState URLRequest::GetLoadState() const {
235 return job_ ? job_->GetLoadState() : net::LOAD_STATE_IDLE; 234 return job_ ? job_->GetLoadState() : LOAD_STATE_IDLE;
236 } 235 }
237 236
238 uint64 URLRequest::GetUploadProgress() const { 237 uint64 URLRequest::GetUploadProgress() const {
239 if (!job_) { 238 if (!job_) {
240 // We haven't started or the request was cancelled 239 // We haven't started or the request was cancelled
241 return 0; 240 return 0;
242 } 241 }
243 if (final_upload_progress_) { 242 if (final_upload_progress_) {
244 // The first job completed and none of the subsequent series of 243 // The first job completed and none of the subsequent series of
245 // GETs when following redirects will upload anything, so we return the 244 // GETs when following redirects will upload anything, so we return the
(...skipping 24 matching lines...) Expand all
270 } else { 269 } else {
271 headers->clear(); 270 headers->clear();
272 } 271 }
273 } 272 }
274 273
275 HostPortPair URLRequest::GetSocketAddress() const { 274 HostPortPair URLRequest::GetSocketAddress() const {
276 DCHECK(job_); 275 DCHECK(job_);
277 return job_->GetSocketAddress(); 276 return job_->GetSocketAddress();
278 } 277 }
279 278
280 net::HttpResponseHeaders* URLRequest::response_headers() const { 279 HttpResponseHeaders* URLRequest::response_headers() const {
281 return response_info_.headers.get(); 280 return response_info_.headers.get();
282 } 281 }
283 282
284 bool URLRequest::GetResponseCookies(ResponseCookies* cookies) { 283 bool URLRequest::GetResponseCookies(ResponseCookies* cookies) {
285 DCHECK(job_); 284 DCHECK(job_);
286 return job_->GetResponseCookies(cookies); 285 return job_->GetResponseCookies(cookies);
287 } 286 }
288 287
289 void URLRequest::GetMimeType(string* mime_type) { 288 void URLRequest::GetMimeType(string* mime_type) {
290 DCHECK(job_); 289 DCHECK(job_);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 StartJob(URLRequestJobManager::GetInstance()->CreateJob(this)); 372 StartJob(URLRequestJobManager::GetInstance()->CreateJob(this));
374 } 373 }
375 374
376 /////////////////////////////////////////////////////////////////////////////// 375 ///////////////////////////////////////////////////////////////////////////////
377 376
378 void URLRequest::StartJob(URLRequestJob* job) { 377 void URLRequest::StartJob(URLRequestJob* job) {
379 DCHECK(!is_pending_); 378 DCHECK(!is_pending_);
380 DCHECK(!job_); 379 DCHECK(!job_);
381 380
382 net_log_.BeginEvent( 381 net_log_.BeginEvent(
383 net::NetLog::TYPE_URL_REQUEST_START_JOB, 382 NetLog::TYPE_URL_REQUEST_START_JOB,
384 make_scoped_refptr(new URLRequestStartEventParameters( 383 make_scoped_refptr(new URLRequestStartEventParameters(
385 url_, method_, load_flags_, priority_))); 384 url_, method_, load_flags_, priority_)));
386 385
387 job_ = job; 386 job_ = job;
388 job_->SetExtraRequestHeaders(extra_request_headers_); 387 job_->SetExtraRequestHeaders(extra_request_headers_);
389 388
390 if (upload_.get()) 389 if (upload_.get())
391 job_->SetUpload(upload_.get()); 390 job_->SetUpload(upload_.get());
392 391
393 is_pending_ = true; 392 is_pending_ = true;
394 393
395 response_info_.was_cached = false; 394 response_info_.was_cached = false;
396 395
397 // Don't allow errors to be sent from within Start(). 396 // Don't allow errors to be sent from within Start().
398 // TODO(brettw) this may cause NotifyDone to be sent synchronously, 397 // TODO(brettw) this may cause NotifyDone to be sent synchronously,
399 // we probably don't want this: they should be sent asynchronously so 398 // we probably don't want this: they should be sent asynchronously so
400 // the caller does not get reentered. 399 // the caller does not get reentered.
401 job_->Start(); 400 job_->Start();
402 } 401 }
403 402
404 void URLRequest::BeforeRequestComplete(int error) { 403 void URLRequest::BeforeRequestComplete(int error) {
405 DCHECK(!job_); 404 DCHECK(!job_);
406 405
407 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_EXTENSION, NULL); 406 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_EXTENSION, NULL);
408 before_request_callback_->Release(); // balanced in Start 407 before_request_callback_->Release(); // balanced in Start
409 if (error != net::OK) { 408 if (error != OK) {
410 StartJob(new URLRequestErrorJob(this, error)); 409 StartJob(new URLRequestErrorJob(this, error));
411 } else { 410 } else {
412 StartJob(URLRequestJobManager::GetInstance()->CreateJob(this)); 411 StartJob(URLRequestJobManager::GetInstance()->CreateJob(this));
413 } 412 }
414 } 413 }
415 414
416 void URLRequest::Restart() { 415 void URLRequest::Restart() {
417 // Should only be called if the original job didn't make any progress. 416 // Should only be called if the original job didn't make any progress.
418 DCHECK(job_ && !job_->has_response_started()); 417 DCHECK(job_ && !job_->has_response_started());
419 RestartWithJob(URLRequestJobManager::GetInstance()->CreateJob(this)); 418 RestartWithJob(URLRequestJobManager::GetInstance()->CreateJob(this));
420 } 419 }
421 420
422 void URLRequest::RestartWithJob(URLRequestJob *job) { 421 void URLRequest::RestartWithJob(URLRequestJob *job) {
423 DCHECK(job->request() == this); 422 DCHECK(job->request() == this);
424 PrepareToRestart(); 423 PrepareToRestart();
425 StartJob(job); 424 StartJob(job);
426 } 425 }
427 426
428 void URLRequest::Cancel() { 427 void URLRequest::Cancel() {
429 DoCancel(net::ERR_ABORTED, net::SSLInfo()); 428 DoCancel(ERR_ABORTED, SSLInfo());
430 } 429 }
431 430
432 void URLRequest::SimulateError(int os_error) { 431 void URLRequest::SimulateError(int os_error) {
433 DoCancel(os_error, net::SSLInfo()); 432 DoCancel(os_error, SSLInfo());
434 } 433 }
435 434
436 void URLRequest::SimulateSSLError(int os_error, const net::SSLInfo& ssl_info) { 435 void URLRequest::SimulateSSLError(int os_error, const SSLInfo& ssl_info) {
437 // This should only be called on a started request. 436 // This should only be called on a started request.
438 if (!is_pending_ || !job_ || job_->has_response_started()) { 437 if (!is_pending_ || !job_ || job_->has_response_started()) {
439 NOTREACHED(); 438 NOTREACHED();
440 return; 439 return;
441 } 440 }
442 DoCancel(os_error, ssl_info); 441 DoCancel(os_error, ssl_info);
443 } 442 }
444 443
445 void URLRequest::DoCancel(int os_error, const net::SSLInfo& ssl_info) { 444 void URLRequest::DoCancel(int os_error, const SSLInfo& ssl_info) {
446 DCHECK(os_error < 0); 445 DCHECK(os_error < 0);
447 446
448 // If the URL request already has an error status, then canceling is a no-op. 447 // If the URL request already has an error status, then canceling is a no-op.
449 // Plus, we don't want to change the error status once it has been set. 448 // Plus, we don't want to change the error status once it has been set.
450 if (status_.is_success()) { 449 if (status_.is_success()) {
451 status_.set_status(URLRequestStatus::CANCELED); 450 status_.set_status(URLRequestStatus::CANCELED);
452 status_.set_os_error(os_error); 451 status_.set_os_error(os_error);
453 response_info_.ssl_info = ssl_info; 452 response_info_.ssl_info = ssl_info;
454 } 453 }
455 454
456 // There's nothing to do if we are not waiting on a Job. 455 // There's nothing to do if we are not waiting on a Job.
457 if (!is_pending_ || !job_) 456 if (!is_pending_ || !job_)
458 return; 457 return;
459 458
460 job_->Kill(); 459 job_->Kill();
461 460
462 // The Job will call our NotifyDone method asynchronously. This is done so 461 // The Job will call our NotifyDone method asynchronously. This is done so
463 // that the Delegate implementation can call Cancel without having to worry 462 // that the Delegate implementation can call Cancel without having to worry
464 // about being called recursively. 463 // about being called recursively.
465 } 464 }
466 465
467 bool URLRequest::Read(net::IOBuffer* dest, int dest_size, int* bytes_read) { 466 bool URLRequest::Read(IOBuffer* dest, int dest_size, int* bytes_read) {
468 DCHECK(job_); 467 DCHECK(job_);
469 DCHECK(bytes_read); 468 DCHECK(bytes_read);
470 DCHECK(!job_->is_done()); 469 DCHECK(!job_->is_done());
471 *bytes_read = 0; 470 *bytes_read = 0;
472 471
473 if (dest_size == 0) { 472 if (dest_size == 0) {
474 // Caller is not too bright. I guess we've done what they asked. 473 // Caller is not too bright. I guess we've done what they asked.
475 return true; 474 return true;
476 } 475 }
477 476
(...skipping 16 matching lines...) Expand all
494 URLRequestJobManager::GetInstance()->MaybeInterceptRedirect(this, 493 URLRequestJobManager::GetInstance()->MaybeInterceptRedirect(this,
495 location); 494 location);
496 if (job) { 495 if (job) {
497 RestartWithJob(job); 496 RestartWithJob(job);
498 } else if (delegate_) { 497 } else if (delegate_) {
499 delegate_->OnReceivedRedirect(this, location, defer_redirect); 498 delegate_->OnReceivedRedirect(this, location, defer_redirect);
500 } 499 }
501 } 500 }
502 501
503 void URLRequest::ResponseStarted() { 502 void URLRequest::ResponseStarted() {
504 scoped_refptr<net::NetLog::EventParameters> params; 503 scoped_refptr<NetLog::EventParameters> params;
505 if (!status_.is_success()) 504 if (!status_.is_success())
506 params = new net::NetLogIntegerParameter("net_error", status_.os_error()); 505 params = new NetLogIntegerParameter("net_error", status_.os_error());
507 net_log_.EndEvent(net::NetLog::TYPE_URL_REQUEST_START_JOB, params); 506 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_START_JOB, params);
508 507
509 URLRequestJob* job = 508 URLRequestJob* job =
510 URLRequestJobManager::GetInstance()->MaybeInterceptResponse(this); 509 URLRequestJobManager::GetInstance()->MaybeInterceptResponse(this);
511 if (job) { 510 if (job) {
512 RestartWithJob(job); 511 RestartWithJob(job);
513 } else { 512 } else {
514 if (context_ && context_->network_delegate()) 513 if (context_ && context_->network_delegate())
515 context_->network_delegate()->NotifyResponseStarted(this); 514 context_->network_delegate()->NotifyResponseStarted(this);
516 if (delegate_) 515 if (delegate_)
517 delegate_->OnResponseStarted(this); 516 delegate_->OnResponseStarted(this);
(...skipping 14 matching lines...) Expand all
532 job_->SetAuth(username, password); 531 job_->SetAuth(username, password);
533 } 532 }
534 533
535 void URLRequest::CancelAuth() { 534 void URLRequest::CancelAuth() {
536 DCHECK(job_); 535 DCHECK(job_);
537 DCHECK(job_->NeedsAuth()); 536 DCHECK(job_->NeedsAuth());
538 537
539 job_->CancelAuth(); 538 job_->CancelAuth();
540 } 539 }
541 540
542 void URLRequest::ContinueWithCertificate(net::X509Certificate* client_cert) { 541 void URLRequest::ContinueWithCertificate(X509Certificate* client_cert) {
543 DCHECK(job_); 542 DCHECK(job_);
544 543
545 job_->ContinueWithCertificate(client_cert); 544 job_->ContinueWithCertificate(client_cert);
546 } 545 }
547 546
548 void URLRequest::ContinueDespiteLastError() { 547 void URLRequest::ContinueDespiteLastError() {
549 DCHECK(job_); 548 DCHECK(job_);
550 549
551 job_->ContinueDespiteLastError(); 550 job_->ContinueDespiteLastError();
552 } 551 }
553 552
554 void URLRequest::PrepareToRestart() { 553 void URLRequest::PrepareToRestart() {
555 DCHECK(job_); 554 DCHECK(job_);
556 555
557 // Close the current URL_REQUEST_START_JOB, since we will be starting a new 556 // Close the current URL_REQUEST_START_JOB, since we will be starting a new
558 // one. 557 // one.
559 net_log_.EndEvent(net::NetLog::TYPE_URL_REQUEST_START_JOB, NULL); 558 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_START_JOB, NULL);
560 559
561 OrphanJob(); 560 OrphanJob();
562 561
563 response_info_ = net::HttpResponseInfo(); 562 response_info_ = HttpResponseInfo();
564 response_info_.request_time = Time::Now(); 563 response_info_.request_time = Time::Now();
565 status_ = URLRequestStatus(); 564 status_ = URLRequestStatus();
566 is_pending_ = false; 565 is_pending_ = false;
567 } 566 }
568 567
569 void URLRequest::OrphanJob() { 568 void URLRequest::OrphanJob() {
570 job_->Kill(); 569 job_->Kill();
571 job_->DetachRequest(); // ensures that the job will not call us again 570 job_->DetachRequest(); // ensures that the job will not call us again
572 job_ = NULL; 571 job_ = NULL;
573 } 572 }
574 573
575 int URLRequest::Redirect(const GURL& location, int http_status_code) { 574 int URLRequest::Redirect(const GURL& location, int http_status_code) {
576 if (net_log_.IsLoggingAllEvents()) { 575 if (net_log_.IsLoggingAllEvents()) {
577 net_log_.AddEvent( 576 net_log_.AddEvent(
578 net::NetLog::TYPE_URL_REQUEST_REDIRECTED, 577 NetLog::TYPE_URL_REQUEST_REDIRECTED,
579 make_scoped_refptr(new net::NetLogStringParameter( 578 make_scoped_refptr(new NetLogStringParameter(
580 "location", location.possibly_invalid_spec()))); 579 "location", location.possibly_invalid_spec())));
581 } 580 }
582 if (redirect_limit_ <= 0) { 581 if (redirect_limit_ <= 0) {
583 DVLOG(1) << "disallowing redirect: exceeds limit"; 582 DVLOG(1) << "disallowing redirect: exceeds limit";
584 return net::ERR_TOO_MANY_REDIRECTS; 583 return ERR_TOO_MANY_REDIRECTS;
585 } 584 }
586 585
587 if (!location.is_valid()) 586 if (!location.is_valid())
588 return net::ERR_INVALID_URL; 587 return ERR_INVALID_URL;
589 588
590 if (!job_->IsSafeRedirect(location)) { 589 if (!job_->IsSafeRedirect(location)) {
591 DVLOG(1) << "disallowing redirect: unsafe protocol"; 590 DVLOG(1) << "disallowing redirect: unsafe protocol";
592 return net::ERR_UNSAFE_REDIRECT; 591 return ERR_UNSAFE_REDIRECT;
593 } 592 }
594 593
595 bool strip_post_specific_headers = false; 594 bool strip_post_specific_headers = false;
596 if (http_status_code != 307) { 595 if (http_status_code != 307) {
597 // NOTE: Even though RFC 2616 says to preserve the request method when 596 // NOTE: Even though RFC 2616 says to preserve the request method when
598 // following a 302 redirect, normal browsers don't do that. Instead, they 597 // following a 302 redirect, normal browsers don't do that. Instead, they
599 // all convert a POST into a GET in response to a 302 and so shall we. For 598 // all convert a POST into a GET in response to a 302 and so shall we. For
600 // 307 redirects, browsers preserve the method. The RFC says to prompt the 599 // 307 redirects, browsers preserve the method. The RFC says to prompt the
601 // user to confirm the generation of a new POST request, but IE omits this 600 // user to confirm the generation of a new POST request, but IE omits this
602 // prompt and so shall we. 601 // prompt and so shall we.
(...skipping 16 matching lines...) Expand all
619 // problems with some servers: 618 // problems with some servers:
620 // http://code.google.com/p/chromium/issues/detail?id=843 619 // http://code.google.com/p/chromium/issues/detail?id=843
621 StripPostSpecificHeaders(&extra_request_headers_); 620 StripPostSpecificHeaders(&extra_request_headers_);
622 } 621 }
623 622
624 if (!final_upload_progress_) 623 if (!final_upload_progress_)
625 final_upload_progress_ = job_->GetUploadProgress(); 624 final_upload_progress_ = job_->GetUploadProgress();
626 625
627 PrepareToRestart(); 626 PrepareToRestart();
628 Start(); 627 Start();
629 return net::OK; 628 return OK;
630 } 629 }
631 630
632 URLRequestContext* URLRequest::context() const { 631 URLRequestContext* URLRequest::context() const {
633 return context_.get(); 632 return context_.get();
634 } 633 }
635 634
636 void URLRequest::set_context(URLRequestContext* context) { 635 void URLRequest::set_context(URLRequestContext* context) {
637 scoped_refptr<URLRequestContext> prev_context = context_; 636 scoped_refptr<URLRequestContext> prev_context = context_;
638 637
639 context_ = context; 638 context_ = context;
640 639
641 // If the context this request belongs to has changed, update the tracker. 640 // If the context this request belongs to has changed, update the tracker.
642 if (prev_context != context) { 641 if (prev_context != context) {
643 net_log_.EndEvent(net::NetLog::TYPE_REQUEST_ALIVE, NULL); 642 net_log_.EndEvent(NetLog::TYPE_REQUEST_ALIVE, NULL);
644 net_log_ = net::BoundNetLog(); 643 net_log_ = BoundNetLog();
645 644
646 if (context) { 645 if (context) {
647 net_log_ = net::BoundNetLog::Make(context->net_log(), 646 net_log_ = BoundNetLog::Make(context->net_log(),
648 net::NetLog::SOURCE_URL_REQUEST); 647 NetLog::SOURCE_URL_REQUEST);
649 net_log_.BeginEvent(net::NetLog::TYPE_REQUEST_ALIVE, NULL); 648 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE, NULL);
650 } 649 }
651 } 650 }
652 } 651 }
653 652
654 int64 URLRequest::GetExpectedContentSize() const { 653 int64 URLRequest::GetExpectedContentSize() const {
655 int64 expected_content_size = -1; 654 int64 expected_content_size = -1;
656 if (job_) 655 if (job_)
657 expected_content_size = job_->expected_content_size(); 656 expected_content_size = job_->expected_content_size();
658 657
659 return expected_content_size; 658 return expected_content_size;
660 } 659 }
661 660
662 URLRequest::UserData* URLRequest::GetUserData(const void* key) const { 661 URLRequest::UserData* URLRequest::GetUserData(const void* key) const {
663 UserDataMap::const_iterator found = user_data_.find(key); 662 UserDataMap::const_iterator found = user_data_.find(key);
664 if (found != user_data_.end()) 663 if (found != user_data_.end())
665 return found->second.get(); 664 return found->second.get();
666 return NULL; 665 return NULL;
667 } 666 }
668 667
669 void URLRequest::SetUserData(const void* key, UserData* data) { 668 void URLRequest::SetUserData(const void* key, UserData* data) {
670 user_data_[key] = linked_ptr<UserData>(data); 669 user_data_[key] = linked_ptr<UserData>(data);
671 } 670 }
672 671
673 } // namespace net 672 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request.h ('k') | net/url_request/url_request_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698