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

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

Issue 173049: Revert r23616 from 172. (Closed) Base URL: svn://chrome-svn.corp.google.com/chrome/branches/172/src/
Patch Set: Created 11 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
« no previous file with comments | « net/url_request/url_request.h ('k') | net/url_request/url_request_job.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/process_util.h" 8 #include "base/process_util.h"
9 #include "base/singleton.h" 9 #include "base/singleton.h"
10 #include "base/stats_counters.h" 10 #include "base/stats_counters.h"
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 DCHECK(!is_pending_); 243 DCHECK(!is_pending_);
244 DCHECK(!job_); 244 DCHECK(!job_);
245 245
246 job_ = GetJobManager()->CreateJob(this); 246 job_ = GetJobManager()->CreateJob(this);
247 job_->SetExtraRequestHeaders(extra_request_headers_); 247 job_->SetExtraRequestHeaders(extra_request_headers_);
248 248
249 if (upload_.get()) 249 if (upload_.get())
250 job_->SetUpload(upload_.get()); 250 job_->SetUpload(upload_.get());
251 251
252 is_pending_ = true; 252 is_pending_ = true;
253
254 response_info_.request_time = Time::Now(); 253 response_info_.request_time = Time::Now();
255 response_info_.was_cached = false; 254 response_info_.was_cached = false;
256 255
257 // Don't allow errors to be sent from within Start(). 256 // Don't allow errors to be sent from within Start().
258 // TODO(brettw) this may cause NotifyDone to be sent synchronously, 257 // TODO(brettw) this may cause NotifyDone to be sent synchronously,
259 // we probably don't want this: they should be sent asynchronously so 258 // we probably don't want this: they should be sent asynchronously so
260 // the caller does not get reentered. 259 // the caller does not get reentered.
261 job_->Start(); 260 job_->Start();
262 } 261 }
263 262
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 312
314 // Once the request fails or is cancelled, read will just return 0 bytes 313 // Once the request fails or is cancelled, read will just return 0 bytes
315 // to indicate end of stream. 314 // to indicate end of stream.
316 if (!status_.is_success()) { 315 if (!status_.is_success()) {
317 return true; 316 return true;
318 } 317 }
319 318
320 return job_->Read(dest, dest_size, bytes_read); 319 return job_->Read(dest, dest_size, bytes_read);
321 } 320 }
322 321
323 void URLRequest::FollowDeferredRedirect() {
324 DCHECK(job_);
325
326 job_->FollowDeferredRedirect();
327 }
328
329 void URLRequest::SetAuth(const wstring& username, const wstring& password) { 322 void URLRequest::SetAuth(const wstring& username, const wstring& password) {
330 DCHECK(job_); 323 DCHECK(job_);
331 DCHECK(job_->NeedsAuth()); 324 DCHECK(job_->NeedsAuth());
332 325
333 job_->SetAuth(username, password); 326 job_->SetAuth(username, password);
334 } 327 }
335 328
336 void URLRequest::CancelAuth() { 329 void URLRequest::CancelAuth() {
337 DCHECK(job_); 330 DCHECK(job_);
338 DCHECK(job_->NeedsAuth()); 331 DCHECK(job_->NeedsAuth());
339 332
340 job_->CancelAuth(); 333 job_->CancelAuth();
341 } 334 }
342 335
343 void URLRequest::ContinueDespiteLastError() { 336 void URLRequest::ContinueDespiteLastError() {
344 DCHECK(job_); 337 DCHECK(job_);
345 338
346 job_->ContinueDespiteLastError(); 339 job_->ContinueDespiteLastError();
347 } 340 }
348 341
349 void URLRequest::OrphanJob() { 342 void URLRequest::OrphanJob() {
350 job_->Kill();
351 job_->DetachRequest(); // ensures that the job will not call us again 343 job_->DetachRequest(); // ensures that the job will not call us again
352 job_ = NULL; 344 job_ = NULL;
353 } 345 }
354 346
355 // static 347 // static
356 std::string URLRequest::StripPostSpecificHeaders(const std::string& headers) { 348 std::string URLRequest::StripPostSpecificHeaders(const std::string& headers) {
357 // These are headers that may be attached to a POST. 349 // These are headers that may be attached to a POST.
358 static const char* const kPostHeaders[] = { 350 static const char* const kPostHeaders[] = {
359 "content-type", 351 "content-type",
360 "content-length", 352 "content-length",
(...skipping 20 matching lines...) Expand all
381 // following a 302 redirect, normal browsers don't do that. Instead, they 373 // following a 302 redirect, normal browsers don't do that. Instead, they
382 // all convert a POST into a GET in response to a 302 and so shall we. For 374 // all convert a POST into a GET in response to a 302 and so shall we. For
383 // 307 redirects, browsers preserve the method. The RFC says to prompt the 375 // 307 redirects, browsers preserve the method. The RFC says to prompt the
384 // user to confirm the generation of a new POST request, but IE omits this 376 // user to confirm the generation of a new POST request, but IE omits this
385 // prompt and so shall we. 377 // prompt and so shall we.
386 strip_post_specific_headers = method_ == "POST"; 378 strip_post_specific_headers = method_ == "POST";
387 method_ = "GET"; 379 method_ = "GET";
388 } 380 }
389 url_ = location; 381 url_ = location;
390 upload_ = NULL; 382 upload_ = NULL;
383 status_ = URLRequestStatus();
391 --redirect_limit_; 384 --redirect_limit_;
392 385
393 if (strip_post_specific_headers) { 386 if (strip_post_specific_headers) {
394 // If being switched from POST to GET, must remove headers that were 387 // If being switched from POST to GET, must remove headers that were
395 // specific to the POST and don't have meaning in GET. For example 388 // specific to the POST and don't have meaning in GET. For example
396 // the inclusion of a multipart Content-Type header in GET can cause 389 // the inclusion of a multipart Content-Type header in GET can cause
397 // problems with some servers: 390 // problems with some servers:
398 // http://code.google.com/p/chromium/issues/detail?id=843 391 // http://code.google.com/p/chromium/issues/detail?id=843
399 // 392 //
400 // TODO(eroman): It would be better if this data was structured into 393 // TODO(eroman): It would be better if this data was structured into
401 // specific fields/flags, rather than a stew of extra headers. 394 // specific fields/flags, rather than a stew of extra headers.
402 extra_request_headers_ = StripPostSpecificHeaders(extra_request_headers_); 395 extra_request_headers_ = StripPostSpecificHeaders(extra_request_headers_);
403 } 396 }
404 397
405 if (!final_upload_progress_) { 398 if (!final_upload_progress_) {
406 final_upload_progress_ = job_->GetUploadProgress(); 399 final_upload_progress_ = job_->GetUploadProgress();
407 } 400 }
408 401
409 job_->Kill();
410 OrphanJob(); 402 OrphanJob();
411 403
412 status_ = URLRequestStatus();
413 is_pending_ = false; 404 is_pending_ = false;
414 Start(); 405 Start();
415 return net::OK; 406 return net::OK;
416 } 407 }
417 408
418 URLRequestContext* URLRequest::context() { 409 URLRequestContext* URLRequest::context() {
419 return context_.get(); 410 return context_.get();
420 } 411 }
421 412
422 void URLRequest::set_context(URLRequestContext* context) { 413 void URLRequest::set_context(URLRequestContext* context) {
423 context_ = context; 414 context_ = context;
424 } 415 }
425 416
426 int64 URLRequest::GetExpectedContentSize() const { 417 int64 URLRequest::GetExpectedContentSize() const {
427 int64 expected_content_size = -1; 418 int64 expected_content_size = -1;
428 if (job_) 419 if (job_)
429 expected_content_size = job_->expected_content_size(); 420 expected_content_size = job_->expected_content_size();
430 421
431 return expected_content_size; 422 return expected_content_size;
432 } 423 }
433 424
434 #ifndef NDEBUG 425 #ifndef NDEBUG
435 426
436 URLRequestMetrics::~URLRequestMetrics() { 427 URLRequestMetrics::~URLRequestMetrics() {
437 DLOG_IF(WARNING, object_count != 0) << 428 DLOG_IF(WARNING, object_count != 0) <<
438 "Leaking " << object_count << " URLRequest object(s)"; 429 "Leaking " << object_count << " URLRequest object(s)";
439 } 430 }
440 431
441 #endif 432 #endif
OLDNEW
« no previous file with comments | « net/url_request/url_request.h ('k') | net/url_request/url_request_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698