| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/singleton.h" | 9 #include "base/singleton.h" |
| 10 #include "base/stats_counters.h" | 10 #include "base/stats_counters.h" |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 void URLRequest::Start() { | 252 void URLRequest::Start() { |
| 253 StartJob(GetJobManager()->CreateJob(this)); | 253 StartJob(GetJobManager()->CreateJob(this)); |
| 254 } | 254 } |
| 255 | 255 |
| 256 /////////////////////////////////////////////////////////////////////////////// | 256 /////////////////////////////////////////////////////////////////////////////// |
| 257 | 257 |
| 258 void URLRequest::StartJob(URLRequestJob* job) { | 258 void URLRequest::StartJob(URLRequestJob* job) { |
| 259 DCHECK(!is_pending_); | 259 DCHECK(!is_pending_); |
| 260 DCHECK(!job_); | 260 DCHECK(!job_); |
| 261 | 261 |
| 262 net_log_.BeginEventWithString(net::NetLog::TYPE_URL_REQUEST_START, | 262 net_log_.BeginEvent( |
| 263 "url", original_url().possibly_invalid_spec()); | 263 net::NetLog::TYPE_URL_REQUEST_START, |
| 264 new net::NetLogStringParameter( |
| 265 "url", original_url().possibly_invalid_spec())); |
| 264 | 266 |
| 265 job_ = job; | 267 job_ = job; |
| 266 job_->SetExtraRequestHeaders(extra_request_headers_); | 268 job_->SetExtraRequestHeaders(extra_request_headers_); |
| 267 | 269 |
| 268 if (upload_.get()) | 270 if (upload_.get()) |
| 269 job_->SetUpload(upload_.get()); | 271 job_->SetUpload(upload_.get()); |
| 270 | 272 |
| 271 is_pending_ = true; | 273 is_pending_ = true; |
| 272 | 274 |
| 273 response_info_.request_time = Time::Now(); | 275 response_info_.request_time = Time::Now(); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 URLRequestJob* job = GetJobManager()->MaybeInterceptRedirect(this, location); | 362 URLRequestJob* job = GetJobManager()->MaybeInterceptRedirect(this, location); |
| 361 if (job) { | 363 if (job) { |
| 362 RestartWithJob(job); | 364 RestartWithJob(job); |
| 363 } else if (delegate_) { | 365 } else if (delegate_) { |
| 364 delegate_->OnReceivedRedirect(this, location, defer_redirect); | 366 delegate_->OnReceivedRedirect(this, location, defer_redirect); |
| 365 } | 367 } |
| 366 } | 368 } |
| 367 | 369 |
| 368 void URLRequest::ResponseStarted() { | 370 void URLRequest::ResponseStarted() { |
| 369 if (!status_.is_success()) { | 371 if (!status_.is_success()) { |
| 370 net_log_.EndEventWithInteger(net::NetLog::TYPE_URL_REQUEST_START, | 372 net_log_.EndEvent( |
| 371 "net_error", status_.os_error()); | 373 net::NetLog::TYPE_URL_REQUEST_START, |
| 374 new net::NetLogIntegerParameter("net_error", status_.os_error())); |
| 372 } else { | 375 } else { |
| 373 net_log_.EndEvent(net::NetLog::TYPE_URL_REQUEST_START); | 376 net_log_.EndEvent(net::NetLog::TYPE_URL_REQUEST_START, NULL); |
| 374 } | 377 } |
| 375 | 378 |
| 376 URLRequestJob* job = GetJobManager()->MaybeInterceptResponse(this); | 379 URLRequestJob* job = GetJobManager()->MaybeInterceptResponse(this); |
| 377 if (job) { | 380 if (job) { |
| 378 RestartWithJob(job); | 381 RestartWithJob(job); |
| 379 } else if (delegate_) { | 382 } else if (delegate_) { |
| 380 delegate_->OnResponseStarted(this); | 383 delegate_->OnResponseStarted(this); |
| 381 } | 384 } |
| 382 } | 385 } |
| 383 | 386 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 "content-type", | 441 "content-type", |
| 439 "content-length", | 442 "content-length", |
| 440 "origin" | 443 "origin" |
| 441 }; | 444 }; |
| 442 return net::HttpUtil::StripHeaders( | 445 return net::HttpUtil::StripHeaders( |
| 443 headers, kPostHeaders, arraysize(kPostHeaders)); | 446 headers, kPostHeaders, arraysize(kPostHeaders)); |
| 444 } | 447 } |
| 445 | 448 |
| 446 int URLRequest::Redirect(const GURL& location, int http_status_code) { | 449 int URLRequest::Redirect(const GURL& location, int http_status_code) { |
| 447 if (net_log_.HasListener()) { | 450 if (net_log_.HasListener()) { |
| 448 net_log_.AddEventWithString(net::NetLog::TYPE_URL_REQUEST_REDIRECTED, | 451 net_log_.AddEvent( |
| 449 "location", location.possibly_invalid_spec()); | 452 net::NetLog::TYPE_URL_REQUEST_REDIRECTED, |
| 453 new net::NetLogStringParameter( |
| 454 "location", location.possibly_invalid_spec())); |
| 450 } | 455 } |
| 451 if (redirect_limit_ <= 0) { | 456 if (redirect_limit_ <= 0) { |
| 452 DLOG(INFO) << "disallowing redirect: exceeds limit"; | 457 DLOG(INFO) << "disallowing redirect: exceeds limit"; |
| 453 return net::ERR_TOO_MANY_REDIRECTS; | 458 return net::ERR_TOO_MANY_REDIRECTS; |
| 454 } | 459 } |
| 455 | 460 |
| 456 if (!location.is_valid()) | 461 if (!location.is_valid()) |
| 457 return net::ERR_INVALID_URL; | 462 return net::ERR_INVALID_URL; |
| 458 | 463 |
| 459 if (!job_->IsSafeRedirect(location)) { | 464 if (!job_->IsSafeRedirect(location)) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 return context_.get(); | 510 return context_.get(); |
| 506 } | 511 } |
| 507 | 512 |
| 508 void URLRequest::set_context(URLRequestContext* context) { | 513 void URLRequest::set_context(URLRequestContext* context) { |
| 509 scoped_refptr<URLRequestContext> prev_context = context_; | 514 scoped_refptr<URLRequestContext> prev_context = context_; |
| 510 | 515 |
| 511 context_ = context; | 516 context_ = context; |
| 512 | 517 |
| 513 // If the context this request belongs to has changed, update the tracker. | 518 // If the context this request belongs to has changed, update the tracker. |
| 514 if (prev_context != context) { | 519 if (prev_context != context) { |
| 515 net_log_.EndEvent(net::NetLog::TYPE_REQUEST_ALIVE); | 520 net_log_.EndEvent(net::NetLog::TYPE_REQUEST_ALIVE, NULL); |
| 516 net_log_ = net::BoundNetLog(); | 521 net_log_ = net::BoundNetLog(); |
| 517 | 522 |
| 518 if (context) { | 523 if (context) { |
| 519 net_log_ = net::BoundNetLog::Make(context->net_log(), | 524 net_log_ = net::BoundNetLog::Make(context->net_log(), |
| 520 net::NetLog::SOURCE_URL_REQUEST); | 525 net::NetLog::SOURCE_URL_REQUEST); |
| 521 net_log_.BeginEvent(net::NetLog::TYPE_REQUEST_ALIVE); | 526 net_log_.BeginEvent(net::NetLog::TYPE_REQUEST_ALIVE, NULL); |
| 522 } | 527 } |
| 523 } | 528 } |
| 524 } | 529 } |
| 525 | 530 |
| 526 int64 URLRequest::GetExpectedContentSize() const { | 531 int64 URLRequest::GetExpectedContentSize() const { |
| 527 int64 expected_content_size = -1; | 532 int64 expected_content_size = -1; |
| 528 if (job_) | 533 if (job_) |
| 529 expected_content_size = job_->expected_content_size(); | 534 expected_content_size = job_->expected_content_size(); |
| 530 | 535 |
| 531 return expected_content_size; | 536 return expected_content_size; |
| 532 } | 537 } |
| 533 | 538 |
| 534 URLRequest::UserData* URLRequest::GetUserData(const void* key) const { | 539 URLRequest::UserData* URLRequest::GetUserData(const void* key) const { |
| 535 UserDataMap::const_iterator found = user_data_.find(key); | 540 UserDataMap::const_iterator found = user_data_.find(key); |
| 536 if (found != user_data_.end()) | 541 if (found != user_data_.end()) |
| 537 return found->second.get(); | 542 return found->second.get(); |
| 538 return NULL; | 543 return NULL; |
| 539 } | 544 } |
| 540 | 545 |
| 541 void URLRequest::SetUserData(const void* key, UserData* data) { | 546 void URLRequest::SetUserData(const void* key, UserData* data) { |
| 542 user_data_[key] = linked_ptr<UserData>(data); | 547 user_data_[key] = linked_ptr<UserData>(data); |
| 543 } | 548 } |
| OLD | NEW |