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

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

Issue 7523042: Add a status message "Waiting for extension Foo..." when there's a request (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 9 years, 4 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) 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/memory/singleton.h" 8 #include "base/memory/singleton.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/metrics/stats_counters.h" 10 #include "base/metrics/stats_counters.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 URLRequest::URLRequest(const GURL& url, Delegate* delegate) 133 URLRequest::URLRequest(const GURL& url, Delegate* delegate)
134 : url_chain_(1, url), 134 : url_chain_(1, url),
135 method_("GET"), 135 method_("GET"),
136 load_flags_(LOAD_NORMAL), 136 load_flags_(LOAD_NORMAL),
137 delegate_(delegate), 137 delegate_(delegate),
138 is_pending_(false), 138 is_pending_(false),
139 redirect_limit_(kMaxRedirects), 139 redirect_limit_(kMaxRedirects),
140 final_upload_progress_(0), 140 final_upload_progress_(0),
141 priority_(LOWEST), 141 priority_(LOWEST),
142 identifier_(GenerateURLRequestIdentifier()), 142 identifier_(GenerateURLRequestIdentifier()),
143 blocked_on_delegate_(false),
143 ALLOW_THIS_IN_INITIALIZER_LIST( 144 ALLOW_THIS_IN_INITIALIZER_LIST(
144 before_request_callback_(this, &URLRequest::BeforeRequestComplete)), 145 before_request_callback_(this, &URLRequest::BeforeRequestComplete)),
145 has_notified_completion_(false) { 146 has_notified_completion_(false) {
146 SIMPLE_STATS_COUNTER("URLRequestCount"); 147 SIMPLE_STATS_COUNTER("URLRequestCount");
147 148
148 // Sanity check out environment. 149 // Sanity check out environment.
149 DCHECK(MessageLoop::current()) << 150 DCHECK(MessageLoop::current()) <<
150 "The current MessageLoop must exist"; 151 "The current MessageLoop must exist";
151 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << 152 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) <<
152 "The current MessageLoop must be TYPE_IO"; 153 "The current MessageLoop must be TYPE_IO";
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 247
247 void URLRequest::SetExtraRequestHeaders( 248 void URLRequest::SetExtraRequestHeaders(
248 const HttpRequestHeaders& headers) { 249 const HttpRequestHeaders& headers) {
249 DCHECK(!is_pending_); 250 DCHECK(!is_pending_);
250 extra_request_headers_ = headers; 251 extra_request_headers_ = headers;
251 252
252 // NOTE: This method will likely become non-trivial once the other setters 253 // NOTE: This method will likely become non-trivial once the other setters
253 // for request headers are implemented. 254 // for request headers are implemented.
254 } 255 }
255 256
256 LoadState URLRequest::GetLoadState() const { 257 LoadStateWithParam URLRequest::GetLoadState() const {
257 return job_ ? job_->GetLoadState() : LOAD_STATE_IDLE; 258 if (blocked_on_delegate_) {
259 return net::LoadStateWithParam(LOAD_STATE_WAITING_FOR_DELEGATE,
260 load_state_param_);
261 }
262 return net::LoadStateWithParam(job_ ? job_->GetLoadState() : LOAD_STATE_IDLE,
263 "");
258 } 264 }
259 265
260 uint64 URLRequest::GetUploadProgress() const { 266 uint64 URLRequest::GetUploadProgress() const {
261 if (!job_) { 267 if (!job_) {
262 // We haven't started or the request was cancelled 268 // We haven't started or the request was cancelled
263 return 0; 269 return 0;
264 } 270 }
265 if (final_upload_progress_) { 271 if (final_upload_progress_) {
266 // The first job completed and none of the subsequent series of 272 // The first job completed and none of the subsequent series of
267 // GETs when following redirects will upload anything, so we return the 273 // GETs when following redirects will upload anything, so we return the
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 } 398 }
393 399
394 void URLRequest::Start() { 400 void URLRequest::Start() {
395 response_info_.request_time = Time::Now(); 401 response_info_.request_time = Time::Now();
396 402
397 // Only notify the delegate for the initial request. 403 // Only notify the delegate for the initial request.
398 if (context_ && context_->network_delegate()) { 404 if (context_ && context_->network_delegate()) {
399 if (context_->network_delegate()->NotifyBeforeURLRequest( 405 if (context_->network_delegate()->NotifyBeforeURLRequest(
400 this, &before_request_callback_, &delegate_redirect_url_) == 406 this, &before_request_callback_, &delegate_redirect_url_) ==
401 net::ERR_IO_PENDING) { 407 net::ERR_IO_PENDING) {
402 net_log_.BeginEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); 408 SetBlockedOnDelegate();
403 return; // paused 409 return; // paused
404 } 410 }
405 } 411 }
406 412
407 StartJob(URLRequestJobManager::GetInstance()->CreateJob(this)); 413 StartJob(URLRequestJobManager::GetInstance()->CreateJob(this));
408 } 414 }
409 415
410 /////////////////////////////////////////////////////////////////////////////// 416 ///////////////////////////////////////////////////////////////////////////////
411 417
412 void URLRequest::BeforeRequestComplete(int error) { 418 void URLRequest::BeforeRequestComplete(int error) {
413 DCHECK(!job_); 419 DCHECK(!job_);
414 DCHECK_NE(ERR_IO_PENDING, error); 420 DCHECK_NE(ERR_IO_PENDING, error);
415 421
416 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); 422 SetUnblockedOnDelegate();
417 if (error != OK) { 423 if (error != OK) {
418 net_log_.AddEvent(NetLog::TYPE_CANCELLED, 424 net_log_.AddEvent(NetLog::TYPE_CANCELLED,
419 make_scoped_refptr(new NetLogStringParameter("source", "delegate"))); 425 make_scoped_refptr(new NetLogStringParameter("source", "delegate")));
420 StartJob(new URLRequestErrorJob(this, error)); 426 StartJob(new URLRequestErrorJob(this, error));
421 } else if (!delegate_redirect_url_.is_empty()) { 427 } else if (!delegate_redirect_url_.is_empty()) {
422 GURL new_url; 428 GURL new_url;
423 new_url.Swap(&delegate_redirect_url_); 429 new_url.Swap(&delegate_redirect_url_);
424 StartJob(new URLRequestRedirectJob(this, new_url)); 430 StartJob(new URLRequestRedirectJob(this, new_url));
425 } else { 431 } else {
426 StartJob(URLRequestJobManager::GetInstance()->CreateJob(this)); 432 StartJob(URLRequestJobManager::GetInstance()->CreateJob(this));
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 // not be needed. 800 // not be needed.
795 if (has_notified_completion_) 801 if (has_notified_completion_)
796 return; 802 return;
797 803
798 is_pending_ = false; 804 is_pending_ = false;
799 has_notified_completion_ = true; 805 has_notified_completion_ = true;
800 if (context_ && context_->network_delegate()) 806 if (context_ && context_->network_delegate())
801 context_->network_delegate()->NotifyCompleted(this); 807 context_->network_delegate()->NotifyCompleted(this);
802 } 808 }
803 809
810 void URLRequest::SetBlockedOnDelegate() {
811 blocked_on_delegate_ = true;
812 net_log_.BeginEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL);
813 }
814
815 void URLRequest::SetUnblockedOnDelegate() {
816 blocked_on_delegate_ = false;
817 load_state_param_.clear();
818 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL);
819 }
820
804 } // namespace net 821 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698