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

Side by Side Diff: net/websockets/websocket_job.cc

Issue 14701005: Less indentation in WebSocketJob::SaveNextCookie() for readability (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 7 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 | « 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/websockets/websocket_job.h" 5 #include "net/websockets/websocket_job.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 467
468 handshake_response_->GetHeaders( 468 handshake_response_->GetHeaders(
469 kSetCookieHeaders, arraysize(kSetCookieHeaders), &response_cookies_); 469 kSetCookieHeaders, arraysize(kSetCookieHeaders), &response_cookies_);
470 470
471 // Now, loop over the response cookies, and attempt to persist each. 471 // Now, loop over the response cookies, and attempt to persist each.
472 SaveNextCookie(); 472 SaveNextCookie();
473 } 473 }
474 474
475 void WebSocketJob::NotifyHeadersComplete() { 475 void WebSocketJob::NotifyHeadersComplete() {
476 // Remove cookie headers, with malformed headers preserved. 476 // Remove cookie headers, with malformed headers preserved.
477 // Actual handshake should be done in WebKit. 477 // Actual handshake should be done in Blink.
478 handshake_response_->RemoveHeaders( 478 handshake_response_->RemoveHeaders(
479 kSetCookieHeaders, arraysize(kSetCookieHeaders)); 479 kSetCookieHeaders, arraysize(kSetCookieHeaders));
480 std::string handshake_response = handshake_response_->GetResponse(); 480 std::string handshake_response = handshake_response_->GetResponse();
481 handshake_response_.reset();
481 std::vector<char> received_data(handshake_response.begin(), 482 std::vector<char> received_data(handshake_response.begin(),
482 handshake_response.end()); 483 handshake_response.end());
483 received_data.insert(received_data.end(), 484 received_data.insert(received_data.end(),
484 received_data_after_handshake_.begin(), 485 received_data_after_handshake_.begin(),
485 received_data_after_handshake_.end()); 486 received_data_after_handshake_.end());
486 received_data_after_handshake_.clear(); 487 received_data_after_handshake_.clear();
487 488
488 state_ = OPEN; 489 state_ = OPEN;
489 490
490 DCHECK(!received_data.empty()); 491 DCHECK(!received_data.empty());
(...skipping 10 matching lines...) Expand all
501 void WebSocketJob::SaveNextCookie() { 502 void WebSocketJob::SaveNextCookie() {
502 if (response_cookies_save_index_ == response_cookies_.size()) { 503 if (response_cookies_save_index_ == response_cookies_.size()) {
503 response_cookies_.clear(); 504 response_cookies_.clear();
504 response_cookies_save_index_ = 0; 505 response_cookies_save_index_ = 0;
505 506
506 NotifyHeadersComplete(); 507 NotifyHeadersComplete();
507 508
508 return; 509 return;
509 } 510 }
510 511
511 bool allow = true; 512 if (!socket_ || !delegate_ || state_ != CONNECTING)
513 return;
514
512 CookieOptions options; 515 CookieOptions options;
513 GURL url = GetURLForCookies(); 516 GURL url = GetURLForCookies();
514 std::string cookie = response_cookies_[response_cookies_save_index_]; 517 std::string cookie = response_cookies_[response_cookies_save_index_];
515 if (delegate_ && !delegate_->CanSetCookie(socket_, url, cookie, &options)) 518 response_cookies_save_index_++;
516 allow = false;
517 519
518 if (socket_ && delegate_ && state_ == CONNECTING) { 520 // TODO(tyoshino): Use loop. See URLRequestHttpJob::SaveNextCookie().
519 response_cookies_save_index_++; 521 if (delegate_->CanSetCookie(socket_, url, cookie, &options) &&
520 if (allow && socket_->context()->cookie_store()) { 522 socket_->context()->cookie_store()) {
521 options.set_include_httponly(); 523 options.set_include_httponly();
522 socket_->context()->cookie_store()->SetCookieWithOptionsAsync( 524 socket_->context()->cookie_store()->SetCookieWithOptionsAsync(
523 url, cookie, options, 525 url, cookie, options,
524 base::Bind(&WebSocketJob::SaveCookieCallback, 526 base::Bind(&WebSocketJob::SaveCookieCallback,
525 weak_ptr_factory_.GetWeakPtr())); 527 weak_ptr_factory_.GetWeakPtr()));
526 } else { 528 } else {
527 SaveNextCookie(); 529 SaveNextCookie();
528 }
529 } 530 }
530 } 531 }
531 532
532 void WebSocketJob::SaveCookieCallback(bool cookie_status) { 533 void WebSocketJob::SaveCookieCallback(bool cookie_status) {
533 SaveNextCookie(); 534 SaveNextCookie();
534 } 535 }
535 536
536 GURL WebSocketJob::GetURLForCookies() const { 537 GURL WebSocketJob::GetURLForCookies() const {
537 GURL url = socket_->url(); 538 GURL url = socket_->url();
538 std::string scheme = socket_->is_secure() ? "https" : "http"; 539 std::string scheme = socket_->is_secure() ? "https" : "http";
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 665
665 scoped_refptr<IOBufferWithSize> next_buffer = send_buffer_queue_.front(); 666 scoped_refptr<IOBufferWithSize> next_buffer = send_buffer_queue_.front();
666 send_buffer_queue_.pop_front(); 667 send_buffer_queue_.pop_front();
667 current_send_buffer_ = new DrainableIOBuffer(next_buffer, 668 current_send_buffer_ = new DrainableIOBuffer(next_buffer,
668 next_buffer->size()); 669 next_buffer->size());
669 SendDataInternal(current_send_buffer_->data(), 670 SendDataInternal(current_send_buffer_->data(),
670 current_send_buffer_->BytesRemaining()); 671 current_send_buffer_->BytesRemaining());
671 } 672 }
672 673
673 } // namespace net 674 } // namespace net
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