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

Side by Side Diff: chrome/browser/chromeos/web_socket_proxy.cc

Issue 8801004: base::Bind: Convert StreamSocket::Connect. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes Created 9 years 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 | content/browser/renderer_host/p2p/socket_host_test_utils.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 "chrome/browser/chromeos/web_socket_proxy.h" 5 #include "chrome/browser/chromeos/web_socket_proxy.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <string.h> 9 #include <string.h>
10 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <limits> 12 #include <limits>
13 #include <list> 13 #include <list>
14 #include <map> 14 #include <map>
15 #include <vector> 15 #include <vector>
16 16
17 #include <arpa/inet.h> 17 #include <arpa/inet.h>
18 #include <errno.h> 18 #include <errno.h>
19 #include <fcntl.h> 19 #include <fcntl.h>
20 #include <netinet/in.h> 20 #include <netinet/in.h>
21 #include <signal.h> 21 #include <signal.h>
22 #include <sys/socket.h> 22 #include <sys/socket.h>
23 #include <sys/types.h> 23 #include <sys/types.h>
24 #include <sys/wait.h> 24 #include <sys/wait.h>
25 25
26 #include "base/base64.h" 26 #include "base/base64.h"
27 #include "base/basictypes.h" 27 #include "base/basictypes.h"
28 #include "base/bind.h" 28 #include "base/bind.h"
29 #include "base/bind_helpers.h"
29 #include "base/lazy_instance.h" 30 #include "base/lazy_instance.h"
30 #include "base/logging.h" 31 #include "base/logging.h"
31 #include "base/memory/ref_counted.h" 32 #include "base/memory/ref_counted.h"
32 #include "base/memory/scoped_ptr.h" 33 #include "base/memory/scoped_ptr.h"
33 #include "base/message_loop.h" 34 #include "base/message_loop.h"
34 #include "base/sha1.h" 35 #include "base/sha1.h"
35 #include "base/stl_util.h" 36 #include "base/stl_util.h"
36 #include "base/string_number_conversions.h" 37 #include "base/string_number_conversions.h"
37 #include "base/string_util.h" 38 #include "base/string_util.h"
38 #include "chrome/browser/chromeos/web_socket_proxy_helper.h" 39 #include "chrome/browser/chromeos/web_socket_proxy_helper.h"
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 const net::HostPortPair host_port_pair, 548 const net::HostPortPair host_port_pair,
548 int read_pipe, 549 int read_pipe,
549 int write_pipe) 550 int write_pipe)
550 : phase_(PHASE_CONNECTING), 551 : phase_(PHASE_CONNECTING),
551 host_port_pair_(host_port_pair), 552 host_port_pair_(host_port_pair),
552 inbound_stream_(WebSocketProxy::kBufferLimit), 553 inbound_stream_(WebSocketProxy::kBufferLimit),
553 outbound_stream_(WebSocketProxy::kBufferLimit), 554 outbound_stream_(WebSocketProxy::kBufferLimit),
554 read_pipe_(read_pipe), 555 read_pipe_(read_pipe),
555 write_pipe_(write_pipe), 556 write_pipe_(write_pipe),
556 method_factory_(this), 557 method_factory_(this),
557 socket_connect_callback_(NewCallback(this, &SSLChan::OnSocketConnect)), 558 socket_connect_callback_(
559 base::Bind(&SSLChan::OnSocketConnect, base::Unretained(this))),
558 ssl_handshake_callback_( 560 ssl_handshake_callback_(
559 NewCallback(this, &SSLChan::OnSSLHandshakeCompleted)), 561 base::Bind(&SSLChan::OnSSLHandshakeCompleted,
562 base::Unretained(this))),
560 socket_read_callback_(NewCallback(this, &SSLChan::OnSocketRead)), 563 socket_read_callback_(NewCallback(this, &SSLChan::OnSocketRead)),
561 socket_write_callback_(NewCallback(this, &SSLChan::OnSocketWrite)) { 564 socket_write_callback_(NewCallback(this, &SSLChan::OnSocketWrite)) {
562 if (!SetNonBlock(read_pipe_) || !SetNonBlock(write_pipe_)) { 565 if (!SetNonBlock(read_pipe_) || !SetNonBlock(write_pipe_)) {
563 Shut(net::ERR_UNEXPECTED); 566 Shut(net::ERR_UNEXPECTED);
564 return; 567 return;
565 } 568 }
566 net::ClientSocketFactory* factory = 569 net::ClientSocketFactory* factory =
567 net::ClientSocketFactory::GetDefaultFactory(); 570 net::ClientSocketFactory::GetDefaultFactory();
568 socket_.reset(factory->CreateTransportClientSocket( 571 socket_.reset(factory->CreateTransportClientSocket(
569 address_list, NULL, net::NetLog::Source())); 572 address_list, NULL, net::NetLog::Source()));
570 if (socket_ == NULL) { 573 if (socket_ == NULL) {
571 Shut(net::ERR_FAILED); 574 Shut(net::ERR_FAILED);
572 return; 575 return;
573 } 576 }
574 int result = socket_->Connect(socket_connect_callback_.get()); 577 int result = socket_->Connect(socket_connect_callback_);
575 if (result != net::ERR_IO_PENDING) 578 if (result != net::ERR_IO_PENDING)
576 OnSocketConnect(result); 579 OnSocketConnect(result);
577 } 580 }
578 581
579 ~SSLChan() { 582 ~SSLChan() {
580 phase_ = PHASE_CLOSED; 583 phase_ = PHASE_CLOSED;
581 write_pipe_controller_.StopWatchingFileDescriptor(); 584 write_pipe_controller_.StopWatchingFileDescriptor();
582 read_pipe_controller_.StopWatchingFileDescriptor(); 585 read_pipe_controller_.StopWatchingFileDescriptor();
583 close(write_pipe_); 586 close(write_pipe_);
584 close(read_pipe_); 587 close(read_pipe_);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 if (!cert_verifier_.get()) 627 if (!cert_verifier_.get())
625 cert_verifier_.reset(new net::CertVerifier()); 628 cert_verifier_.reset(new net::CertVerifier());
626 ssl_context.cert_verifier = cert_verifier_.get(); 629 ssl_context.cert_verifier = cert_verifier_.get();
627 socket_.reset(factory->CreateSSLClientSocket( 630 socket_.reset(factory->CreateSSLClientSocket(
628 handle, host_port_pair_, ssl_config_, NULL, ssl_context)); 631 handle, host_port_pair_, ssl_config_, NULL, ssl_context));
629 if (!socket_.get()) { 632 if (!socket_.get()) {
630 LOG(WARNING) << "Failed to create an SSL client socket."; 633 LOG(WARNING) << "Failed to create an SSL client socket.";
631 OnSSLHandshakeCompleted(net::ERR_UNEXPECTED); 634 OnSSLHandshakeCompleted(net::ERR_UNEXPECTED);
632 return; 635 return;
633 } 636 }
634 result = socket_->Connect(ssl_handshake_callback_.get()); 637 result = socket_->Connect(ssl_handshake_callback_);
635 if (result != net::ERR_IO_PENDING) 638 if (result != net::ERR_IO_PENDING)
636 OnSSLHandshakeCompleted(result); 639 OnSSLHandshakeCompleted(result);
637 } 640 }
638 641
639 void OnSSLHandshakeCompleted(int result) { 642 void OnSSLHandshakeCompleted(int result) {
640 if (result) { 643 if (result) {
641 Shut(result); 644 Shut(result);
642 return; 645 return;
643 } 646 }
644 is_socket_read_pending_ = false; 647 is_socket_read_pending_ = false;
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 net::SSLConfig ssl_config_; 788 net::SSLConfig ssl_config_;
786 IOBufferQueue inbound_stream_; 789 IOBufferQueue inbound_stream_;
787 IOBufferQueue outbound_stream_; 790 IOBufferQueue outbound_stream_;
788 int read_pipe_; 791 int read_pipe_;
789 int write_pipe_; 792 int write_pipe_;
790 bool is_socket_read_pending_; 793 bool is_socket_read_pending_;
791 bool is_socket_write_pending_; 794 bool is_socket_write_pending_;
792 bool is_read_pipe_blocked_; 795 bool is_read_pipe_blocked_;
793 bool is_write_pipe_blocked_; 796 bool is_write_pipe_blocked_;
794 ScopedRunnableMethodFactory<SSLChan> method_factory_; 797 ScopedRunnableMethodFactory<SSLChan> method_factory_;
795 scoped_ptr<net::OldCompletionCallback> socket_connect_callback_; 798 net::CompletionCallback socket_connect_callback_;
796 scoped_ptr<net::OldCompletionCallback> ssl_handshake_callback_; 799 net::CompletionCallback ssl_handshake_callback_;
797 scoped_ptr<net::OldCompletionCallback> socket_read_callback_; 800 scoped_ptr<net::OldCompletionCallback> socket_read_callback_;
798 scoped_ptr<net::OldCompletionCallback> socket_write_callback_; 801 scoped_ptr<net::OldCompletionCallback> socket_write_callback_;
799 MessageLoopForIO::FileDescriptorWatcher read_pipe_controller_; 802 MessageLoopForIO::FileDescriptorWatcher read_pipe_controller_;
800 MessageLoopForIO::FileDescriptorWatcher write_pipe_controller_; 803 MessageLoopForIO::FileDescriptorWatcher write_pipe_controller_;
801 804
802 friend class DeleteTask<SSLChan>; 805 friend class DeleteTask<SSLChan>;
803 DISALLOW_COPY_AND_ASSIGN(SSLChan); 806 DISALLOW_COPY_AND_ASSIGN(SSLChan);
804 }; 807 };
805 808
806 Serv::Serv(const std::vector<std::string>& allowed_origins) 809 Serv::Serv(const std::vector<std::string>& allowed_origins)
(...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1914 1917
1915 void WebSocketProxy::Shutdown() { 1918 void WebSocketProxy::Shutdown() {
1916 static_cast<Serv*>(impl_)->Shutdown(); 1919 static_cast<Serv*>(impl_)->Shutdown();
1917 } 1920 }
1918 1921
1919 void WebSocketProxy::OnNetworkChange() { 1922 void WebSocketProxy::OnNetworkChange() {
1920 static_cast<Serv*>(impl_)->OnNetworkChange(); 1923 static_cast<Serv*>(impl_)->OnNetworkChange();
1921 } 1924 }
1922 1925
1923 } // namespace chromeos 1926 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/p2p/socket_host_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698