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

Side by Side Diff: chrome/browser/net/url_fetcher.cc

Issue 377041: Add instrumentation to track down a crash.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: make a comment more descriptive Created 11 years, 1 month 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 | « no previous file | no next file » | 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "chrome/browser/net/url_fetcher.h" 5 #include "chrome/browser/net/url_fetcher.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/thread.h" 9 #include "base/thread.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // incrementally back off how rapidly we'll send requests to a particular 88 // incrementally back off how rapidly we'll send requests to a particular
89 // URL, to avoid placing too much demand on the remote resource. We update 89 // URL, to avoid placing too much demand on the remote resource. We update
90 // this with the status of all requests as they return, and in turn use it 90 // this with the status of all requests as they return, and in turn use it
91 // to determine how long to wait before making another request. 91 // to determine how long to wait before making another request.
92 URLFetcherProtectEntry* protect_entry_; 92 URLFetcherProtectEntry* protect_entry_;
93 // |num_retries_| indicates how many times we've failed to successfully 93 // |num_retries_| indicates how many times we've failed to successfully
94 // fetch this URL. Once this value exceeds the maximum number of retries 94 // fetch this URL. Once this value exceeds the maximum number of retries
95 // specified by the protection manager, we'll give up. 95 // specified by the protection manager, we'll give up.
96 int num_retries_; 96 int num_retries_;
97 97
98 // Temporary member variable to test whether requests are being started
99 // after they have already been cancelled.
100 // TODO(eroman): Remove this after done investigating 27074.
101 bool was_cancelled_;
wtc 2009/11/10 01:09:25 You explained what this member is for, but you sho
102
98 friend class URLFetcher; 103 friend class URLFetcher;
99 DISALLOW_COPY_AND_ASSIGN(Core); 104 DISALLOW_COPY_AND_ASSIGN(Core);
100 }; 105 };
101 106
102 // static 107 // static
103 URLFetcher::Factory* URLFetcher::factory_ = NULL; 108 URLFetcher::Factory* URLFetcher::factory_ = NULL;
104 109
105 URLFetcher::URLFetcher(const GURL& url, 110 URLFetcher::URLFetcher(const GURL& url,
106 RequestType request_type, 111 RequestType request_type,
107 Delegate* d) 112 Delegate* d)
(...skipping 20 matching lines...) Expand all
128 original_url_(original_url), 133 original_url_(original_url),
129 request_type_(request_type), 134 request_type_(request_type),
130 delegate_(d), 135 delegate_(d),
131 delegate_loop_(MessageLoop::current()), 136 delegate_loop_(MessageLoop::current()),
132 request_(NULL), 137 request_(NULL),
133 load_flags_(net::LOAD_NORMAL), 138 load_flags_(net::LOAD_NORMAL),
134 response_code_(-1), 139 response_code_(-1),
135 buffer_(new net::IOBuffer(kBufferSize)), 140 buffer_(new net::IOBuffer(kBufferSize)),
136 protect_entry_(URLFetcherProtectManager::GetInstance()->Register( 141 protect_entry_(URLFetcherProtectManager::GetInstance()->Register(
137 original_url_.host())), 142 original_url_.host())),
138 num_retries_(0) { 143 num_retries_(0),
144 was_cancelled_(false) {
139 } 145 }
140 146
141 void URLFetcher::Core::Start() { 147 void URLFetcher::Core::Start() {
142 DCHECK(delegate_loop_); 148 DCHECK(delegate_loop_);
143 DCHECK(request_context_getter_) << "We need an URLRequestContext!"; 149 CHECK(request_context_getter_) << "We need an URLRequestContext!";
144 ChromeThread::PostDelayedTask( 150 ChromeThread::PostDelayedTask(
145 ChromeThread::IO, FROM_HERE, 151 ChromeThread::IO, FROM_HERE,
146 NewRunnableMethod(this, &Core::StartURLRequest), 152 NewRunnableMethod(this, &Core::StartURLRequest),
147 protect_entry_->UpdateBackoff(URLFetcherProtectEntry::SEND)); 153 protect_entry_->UpdateBackoff(URLFetcherProtectEntry::SEND));
148 } 154 }
149 155
150 void URLFetcher::Core::Stop() { 156 void URLFetcher::Core::Stop() {
151 DCHECK_EQ(MessageLoop::current(), delegate_loop_); 157 DCHECK_EQ(MessageLoop::current(), delegate_loop_);
152 delegate_ = NULL; 158 delegate_ = NULL;
153 ChromeThread::PostTask( 159 ChromeThread::PostTask(
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 if (!request_->status().is_io_pending() || (request_type_ == HEAD)) { 198 if (!request_->status().is_io_pending() || (request_type_ == HEAD)) {
193 delegate_loop_->PostTask(FROM_HERE, NewRunnableMethod( 199 delegate_loop_->PostTask(FROM_HERE, NewRunnableMethod(
194 this, &Core::OnCompletedURLRequest, request_->status())); 200 this, &Core::OnCompletedURLRequest, request_->status()));
195 delete request_; 201 delete request_;
196 request_ = NULL; 202 request_ = NULL;
197 } 203 }
198 } 204 }
199 205
200 void URLFetcher::Core::StartURLRequest() { 206 void URLFetcher::Core::StartURLRequest() {
201 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); 207 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
202 DCHECK(!request_); 208 CHECK(!was_cancelled_);
209 CHECK(request_context_getter_);
210 CHECK(!request_);
203 211
204 request_ = new URLRequest(original_url_, this); 212 request_ = new URLRequest(original_url_, this);
205 int flags = request_->load_flags() | load_flags_; 213 int flags = request_->load_flags() | load_flags_;
206 if (!g_interception_enabled) { 214 if (!g_interception_enabled) {
207 flags = flags | net::LOAD_DISABLE_INTERCEPT; 215 flags = flags | net::LOAD_DISABLE_INTERCEPT;
208 } 216 }
209 request_->set_load_flags(flags); 217 request_->set_load_flags(flags);
210 request_->set_context(request_context_getter_->GetURLRequestContext()); 218 request_->set_context(request_context_getter_->GetURLRequestContext());
211 219
212 switch (request_type_) { 220 switch (request_type_) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 if (request_) { 253 if (request_) {
246 request_->Cancel(); 254 request_->Cancel();
247 delete request_; 255 delete request_;
248 request_ = NULL; 256 request_ = NULL;
249 } 257 }
250 // Release the reference to the request context. There could be multiple 258 // Release the reference to the request context. There could be multiple
251 // references to URLFetcher::Core at this point so it may take a while to 259 // references to URLFetcher::Core at this point so it may take a while to
252 // delete the object, but we cannot delay the destruction of the request 260 // delete the object, but we cannot delay the destruction of the request
253 // context. 261 // context.
254 request_context_getter_ = NULL; 262 request_context_getter_ = NULL;
263 was_cancelled_ = true;
255 } 264 }
256 265
257 void URLFetcher::Core::OnCompletedURLRequest(const URLRequestStatus& status) { 266 void URLFetcher::Core::OnCompletedURLRequest(const URLRequestStatus& status) {
258 DCHECK(MessageLoop::current() == delegate_loop_); 267 DCHECK(MessageLoop::current() == delegate_loop_);
259 268
260 // Checks the response from server. 269 // Checks the response from server.
261 if (response_code_ >= 500) { 270 if (response_code_ >= 500) {
262 // When encountering a server error, we will send the request again 271 // When encountering a server error, we will send the request again
263 // after backoff time. 272 // after backoff time.
264 const int64 wait = 273 const int64 wait =
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 core_->Start(); 324 core_->Start();
316 } 325 }
317 326
318 const GURL& URLFetcher::url() const { 327 const GURL& URLFetcher::url() const {
319 return core_->url_; 328 return core_->url_;
320 } 329 }
321 330
322 URLFetcher::Delegate* URLFetcher::delegate() const { 331 URLFetcher::Delegate* URLFetcher::delegate() const {
323 return core_->delegate(); 332 return core_->delegate();
324 } 333 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698