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

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

Issue 6749044: Remove async functionality from net::CookiePolicy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge Created 9 years, 8 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_http_job.h ('k') | net/url_request/url_request_test_util.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_http_job.h" 5 #include "net/url_request/url_request_http_job.h"
6 6
7 #include "base/base_switches.h" 7 #include "base/base_switches.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 return new URLRequestHttpJob(request); 199 return new URLRequestHttpJob(request);
200 } 200 }
201 201
202 202
203 URLRequestHttpJob::URLRequestHttpJob(URLRequest* request) 203 URLRequestHttpJob::URLRequestHttpJob(URLRequest* request)
204 : URLRequestJob(request), 204 : URLRequestJob(request),
205 response_info_(NULL), 205 response_info_(NULL),
206 response_cookies_save_index_(0), 206 response_cookies_save_index_(0),
207 proxy_auth_state_(AUTH_STATE_DONT_NEED_AUTH), 207 proxy_auth_state_(AUTH_STATE_DONT_NEED_AUTH),
208 server_auth_state_(AUTH_STATE_DONT_NEED_AUTH), 208 server_auth_state_(AUTH_STATE_DONT_NEED_AUTH),
209 ALLOW_THIS_IN_INITIALIZER_LIST(can_get_cookies_callback_(
210 this, &URLRequestHttpJob::OnCanGetCookiesCompleted)),
211 ALLOW_THIS_IN_INITIALIZER_LIST(can_set_cookie_callback_(
212 this, &URLRequestHttpJob::OnCanSetCookieCompleted)),
213 ALLOW_THIS_IN_INITIALIZER_LIST(start_callback_( 209 ALLOW_THIS_IN_INITIALIZER_LIST(start_callback_(
214 this, &URLRequestHttpJob::OnStartCompleted)), 210 this, &URLRequestHttpJob::OnStartCompleted)),
215 ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_( 211 ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_(
216 this, &URLRequestHttpJob::OnReadCompleted)), 212 this, &URLRequestHttpJob::OnReadCompleted)),
217 read_in_progress_(false), 213 read_in_progress_(false),
218 transaction_(NULL), 214 transaction_(NULL),
219 throttling_entry_(URLRequestThrottlerManager::GetInstance()-> 215 throttling_entry_(URLRequestThrottlerManager::GetInstance()->
220 RegisterRequestUrl(request->url())), 216 RegisterRequestUrl(request->url())),
221 sdch_dictionary_advertised_(false), 217 sdch_dictionary_advertised_(false),
222 sdch_test_activated_(false), 218 sdch_test_activated_(false),
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 context->accept_charset()); 407 context->accept_charset());
412 } 408 }
413 } 409 }
414 } 410 }
415 411
416 void URLRequestHttpJob::AddCookieHeaderAndStart() { 412 void URLRequestHttpJob::AddCookieHeaderAndStart() {
417 // No matter what, we want to report our status as IO pending since we will 413 // No matter what, we want to report our status as IO pending since we will
418 // be notifying our consumer asynchronously via OnStartCompleted. 414 // be notifying our consumer asynchronously via OnStartCompleted.
419 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); 415 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
420 416
421 AddRef(); // Balanced in OnCanGetCookiesCompleted
422
423 int policy = OK; 417 int policy = OK;
424 418
425 if (request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES) { 419 if (request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES) {
426 policy = ERR_FAILED; 420 policy = ERR_FAILED;
427 } else if (request_->context()->cookie_policy()) { 421 } else if (request_->context()->cookie_policy()) {
428 policy = request_->context()->cookie_policy()->CanGetCookies( 422 policy = request_->context()->cookie_policy()->CanGetCookies(
429 request_->url(), 423 request_->url(),
430 request_->first_party_for_cookies(), 424 request_->first_party_for_cookies());
431 &can_get_cookies_callback_);
432 if (policy == ERR_IO_PENDING)
433 return; // Wait for completion callback
434 } 425 }
435 426
436 OnCanGetCookiesCompleted(policy); 427 OnCanGetCookiesCompleted(policy);
437 } 428 }
438 429
439 void URLRequestHttpJob::SaveCookiesAndNotifyHeadersComplete() { 430 void URLRequestHttpJob::SaveCookiesAndNotifyHeadersComplete() {
440 DCHECK(transaction_.get()); 431 DCHECK(transaction_.get());
441 432
442 const HttpResponseInfo* response_info = transaction_->GetResponseInfo(); 433 const HttpResponseInfo* response_info = transaction_->GetResponseInfo();
443 DCHECK(response_info); 434 DCHECK(response_info);
(...skipping 13 matching lines...) Expand all
457 response_cookies_save_index_ = 0; 448 response_cookies_save_index_ = 0;
458 SetStatus(URLRequestStatus()); // Clear the IO_PENDING status 449 SetStatus(URLRequestStatus()); // Clear the IO_PENDING status
459 NotifyHeadersComplete(); 450 NotifyHeadersComplete();
460 return; 451 return;
461 } 452 }
462 453
463 // No matter what, we want to report our status as IO pending since we will 454 // No matter what, we want to report our status as IO pending since we will
464 // be notifying our consumer asynchronously via OnStartCompleted. 455 // be notifying our consumer asynchronously via OnStartCompleted.
465 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); 456 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
466 457
467 AddRef(); // Balanced in OnCanSetCookieCompleted
468
469 int policy = OK; 458 int policy = OK;
470 459
471 if (request_info_.load_flags & LOAD_DO_NOT_SAVE_COOKIES) { 460 if (request_info_.load_flags & LOAD_DO_NOT_SAVE_COOKIES) {
472 policy = ERR_FAILED; 461 policy = ERR_FAILED;
473 } else if (request_->context()->cookie_policy()) { 462 } else if (request_->context()->cookie_policy()) {
474 policy = request_->context()->cookie_policy()->CanSetCookie( 463 policy = request_->context()->cookie_policy()->CanSetCookie(
475 request_->url(), 464 request_->url(),
476 request_->first_party_for_cookies(), 465 request_->first_party_for_cookies(),
477 response_cookies_[response_cookies_save_index_], 466 response_cookies_[response_cookies_save_index_]);
478 &can_set_cookie_callback_);
479 if (policy == ERR_IO_PENDING)
480 return; // Wait for completion callback
481 } 467 }
482 468
483 OnCanSetCookieCompleted(policy); 469 OnCanSetCookieCompleted(policy);
484 } 470 }
485 471
486 void URLRequestHttpJob::FetchResponseCookies( 472 void URLRequestHttpJob::FetchResponseCookies(
487 const HttpResponseInfo* response_info, 473 const HttpResponseInfo* response_info,
488 std::vector<std::string>* cookies) { 474 std::vector<std::string>* cookies) {
489 std::string name = "Set-Cookie"; 475 std::string name = "Set-Cookie";
490 std::string value; 476 std::string value;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 } 589 }
604 } 590 }
605 } 591 }
606 // We may have been canceled within OnGetCookies. 592 // We may have been canceled within OnGetCookies.
607 if (GetStatus().is_success()) { 593 if (GetStatus().is_success()) {
608 StartTransaction(); 594 StartTransaction();
609 } else { 595 } else {
610 NotifyCanceled(); 596 NotifyCanceled();
611 } 597 }
612 } 598 }
613 Release(); // Balance AddRef taken in AddCookieHeaderAndStart
614 } 599 }
615 600
616 void URLRequestHttpJob::OnCanSetCookieCompleted(int policy) { 601 void URLRequestHttpJob::OnCanSetCookieCompleted(int policy) {
617 // If the request was destroyed, then there is no more work to do. 602 // If the request was destroyed, then there is no more work to do.
618 if (request_ && request_->delegate()) { 603 if (request_ && request_->delegate()) {
619 if (request_->context()->cookie_store()) { 604 if (request_->context()->cookie_store()) {
620 if (policy == ERR_ACCESS_DENIED) { 605 if (policy == ERR_ACCESS_DENIED) {
621 CookieOptions options; 606 CookieOptions options;
622 options.set_include_httponly(); 607 options.set_include_httponly();
623 request_->delegate()->OnSetCookie( 608 request_->delegate()->OnSetCookie(
(...skipping 18 matching lines...) Expand all
642 } 627 }
643 } 628 }
644 response_cookies_save_index_++; 629 response_cookies_save_index_++;
645 // We may have been canceled within OnSetCookie. 630 // We may have been canceled within OnSetCookie.
646 if (GetStatus().is_success()) { 631 if (GetStatus().is_success()) {
647 SaveNextCookie(); 632 SaveNextCookie();
648 } else { 633 } else {
649 NotifyCanceled(); 634 NotifyCanceled();
650 } 635 }
651 } 636 }
652 Release(); // Balance AddRef taken in SaveNextCookie
653 } 637 }
654 638
655 void URLRequestHttpJob::OnStartCompleted(int result) { 639 void URLRequestHttpJob::OnStartCompleted(int result) {
656 RecordTimer(); 640 RecordTimer();
657 641
658 // If the request was destroyed, then there is no more work to do. 642 // If the request was destroyed, then there is no more work to do.
659 if (!request_ || !request_->delegate()) 643 if (!request_ || !request_->delegate())
660 return; 644 return;
661 645
662 // If the transaction was destroyed, then the job was cancelled, and 646 // If the transaction was destroyed, then the job was cancelled, and
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 } 1343 }
1360 1344
1361 bool URLRequestHttpJob::IsCompressibleContent() const { 1345 bool URLRequestHttpJob::IsCompressibleContent() const {
1362 std::string mime_type; 1346 std::string mime_type;
1363 return GetMimeType(&mime_type) && 1347 return GetMimeType(&mime_type) &&
1364 (IsSupportedJavascriptMimeType(mime_type.c_str()) || 1348 (IsSupportedJavascriptMimeType(mime_type.c_str()) ||
1365 IsSupportedNonImageMimeType(mime_type.c_str())); 1349 IsSupportedNonImageMimeType(mime_type.c_str()));
1366 } 1350 }
1367 1351
1368 } // namespace net 1352 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_http_job.h ('k') | net/url_request/url_request_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698