| OLD | NEW |
| 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 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 #include "chrome/common/url_constants.h" | 42 #include "chrome/common/url_constants.h" |
| 43 #include "content/public/browser/browser_thread.h" | 43 #include "content/public/browser/browser_thread.h" |
| 44 #include "content/public/browser/notification_details.h" | 44 #include "content/public/browser/notification_details.h" |
| 45 #include "content/public/browser/notification_service.h" | 45 #include "content/public/browser/notification_service.h" |
| 46 #include "content/public/browser/notification_types.h" | 46 #include "content/public/browser/notification_types.h" |
| 47 #include "content/public/common/url_constants.h" | 47 #include "content/public/common/url_constants.h" |
| 48 #include "googleurl/src/gurl.h" | 48 #include "googleurl/src/gurl.h" |
| 49 #include "googleurl/src/url_parse.h" | 49 #include "googleurl/src/url_parse.h" |
| 50 #include "net/base/address_list.h" | 50 #include "net/base/address_list.h" |
| 51 #include "net/base/cert_verifier.h" | 51 #include "net/base/cert_verifier.h" |
| 52 #include "net/base/completion_callback.h" | |
| 53 #include "net/base/host_port_pair.h" | 52 #include "net/base/host_port_pair.h" |
| 54 #include "net/base/io_buffer.h" | 53 #include "net/base/io_buffer.h" |
| 55 #include "net/base/net_errors.h" | 54 #include "net/base/net_errors.h" |
| 56 #include "net/base/ssl_config_service.h" | 55 #include "net/base/ssl_config_service.h" |
| 57 #include "net/socket/client_socket_factory.h" | 56 #include "net/socket/client_socket_factory.h" |
| 58 #include "net/socket/client_socket_handle.h" | 57 #include "net/socket/client_socket_handle.h" |
| 59 #include "net/socket/ssl_client_socket.h" | 58 #include "net/socket/ssl_client_socket.h" |
| 60 #include "net/socket/stream_socket.h" | 59 #include "net/socket/stream_socket.h" |
| 61 #include "third_party/libevent/evdns.h" | 60 #include "third_party/libevent/evdns.h" |
| 62 #include "third_party/libevent/event.h" | 61 #include "third_party/libevent/event.h" |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 SSLChan(const net::AddressList address_list, | 547 SSLChan(const net::AddressList address_list, |
| 549 const net::HostPortPair host_port_pair, | 548 const net::HostPortPair host_port_pair, |
| 550 int read_pipe, | 549 int read_pipe, |
| 551 int write_pipe) | 550 int write_pipe) |
| 552 : phase_(PHASE_CONNECTING), | 551 : phase_(PHASE_CONNECTING), |
| 553 host_port_pair_(host_port_pair), | 552 host_port_pair_(host_port_pair), |
| 554 inbound_stream_(WebSocketProxy::kBufferLimit), | 553 inbound_stream_(WebSocketProxy::kBufferLimit), |
| 555 outbound_stream_(WebSocketProxy::kBufferLimit), | 554 outbound_stream_(WebSocketProxy::kBufferLimit), |
| 556 read_pipe_(read_pipe), | 555 read_pipe_(read_pipe), |
| 557 write_pipe_(write_pipe), | 556 write_pipe_(write_pipe), |
| 558 method_factory_(this), | 557 method_factory_(this) { |
| 559 ALLOW_THIS_IN_INITIALIZER_LIST(socket_connect_callback_( | |
| 560 base::Bind(&SSLChan::OnSocketConnect, base::Unretained(this)))), | |
| 561 ALLOW_THIS_IN_INITIALIZER_LIST(ssl_handshake_callback_( | |
| 562 base::Bind(&SSLChan::OnSSLHandshakeCompleted, | |
| 563 base::Unretained(this)))), | |
| 564 ALLOW_THIS_IN_INITIALIZER_LIST(socket_read_callback_( | |
| 565 base::Bind(&SSLChan::OnSocketRead, base::Unretained(this)))), | |
| 566 socket_write_callback_(NewCallback(this, &SSLChan::OnSocketWrite)) { | |
| 567 if (!SetNonBlock(read_pipe_) || !SetNonBlock(write_pipe_)) { | 558 if (!SetNonBlock(read_pipe_) || !SetNonBlock(write_pipe_)) { |
| 568 Shut(net::ERR_UNEXPECTED); | 559 Shut(net::ERR_UNEXPECTED); |
| 569 return; | 560 return; |
| 570 } | 561 } |
| 571 net::ClientSocketFactory* factory = | 562 net::ClientSocketFactory* factory = |
| 572 net::ClientSocketFactory::GetDefaultFactory(); | 563 net::ClientSocketFactory::GetDefaultFactory(); |
| 573 socket_.reset(factory->CreateTransportClientSocket( | 564 socket_.reset(factory->CreateTransportClientSocket( |
| 574 address_list, NULL, net::NetLog::Source())); | 565 address_list, NULL, net::NetLog::Source())); |
| 575 if (socket_ == NULL) { | 566 if (socket_ == NULL) { |
| 576 Shut(net::ERR_FAILED); | 567 Shut(net::ERR_FAILED); |
| 577 return; | 568 return; |
| 578 } | 569 } |
| 579 int result = socket_->Connect(socket_connect_callback_); | 570 int result = socket_->Connect(base::Bind(&SSLChan::OnSocketConnect, |
| 571 base::Unretained(this))); |
| 580 if (result != net::ERR_IO_PENDING) | 572 if (result != net::ERR_IO_PENDING) |
| 581 OnSocketConnect(result); | 573 OnSocketConnect(result); |
| 582 } | 574 } |
| 583 | 575 |
| 584 ~SSLChan() { | 576 ~SSLChan() { |
| 585 phase_ = PHASE_CLOSED; | 577 phase_ = PHASE_CLOSED; |
| 586 write_pipe_controller_.StopWatchingFileDescriptor(); | 578 write_pipe_controller_.StopWatchingFileDescriptor(); |
| 587 read_pipe_controller_.StopWatchingFileDescriptor(); | 579 read_pipe_controller_.StopWatchingFileDescriptor(); |
| 588 close(write_pipe_); | 580 close(write_pipe_); |
| 589 close(read_pipe_); | 581 close(read_pipe_); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 if (!cert_verifier_.get()) | 621 if (!cert_verifier_.get()) |
| 630 cert_verifier_.reset(new net::CertVerifier()); | 622 cert_verifier_.reset(new net::CertVerifier()); |
| 631 ssl_context.cert_verifier = cert_verifier_.get(); | 623 ssl_context.cert_verifier = cert_verifier_.get(); |
| 632 socket_.reset(factory->CreateSSLClientSocket( | 624 socket_.reset(factory->CreateSSLClientSocket( |
| 633 handle, host_port_pair_, ssl_config_, NULL, ssl_context)); | 625 handle, host_port_pair_, ssl_config_, NULL, ssl_context)); |
| 634 if (!socket_.get()) { | 626 if (!socket_.get()) { |
| 635 LOG(WARNING) << "Failed to create an SSL client socket."; | 627 LOG(WARNING) << "Failed to create an SSL client socket."; |
| 636 OnSSLHandshakeCompleted(net::ERR_UNEXPECTED); | 628 OnSSLHandshakeCompleted(net::ERR_UNEXPECTED); |
| 637 return; | 629 return; |
| 638 } | 630 } |
| 639 result = socket_->Connect(ssl_handshake_callback_); | 631 result = socket_->Connect(base::Bind(&SSLChan::OnSSLHandshakeCompleted, |
| 632 base::Unretained(this))); |
| 640 if (result != net::ERR_IO_PENDING) | 633 if (result != net::ERR_IO_PENDING) |
| 641 OnSSLHandshakeCompleted(result); | 634 OnSSLHandshakeCompleted(result); |
| 642 } | 635 } |
| 643 | 636 |
| 644 void OnSSLHandshakeCompleted(int result) { | 637 void OnSSLHandshakeCompleted(int result) { |
| 645 if (result) { | 638 if (result) { |
| 646 Shut(result); | 639 Shut(result); |
| 647 return; | 640 return; |
| 648 } | 641 } |
| 649 is_socket_read_pending_ = false; | 642 is_socket_read_pending_ = false; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 DCHECK_LT(rv, 0); | 720 DCHECK_LT(rv, 0); |
| 728 Shut(net::ERR_UNEXPECTED); | 721 Shut(net::ERR_UNEXPECTED); |
| 729 return; | 722 return; |
| 730 } | 723 } |
| 731 } | 724 } |
| 732 } | 725 } |
| 733 if (!is_socket_read_pending_ && phase_ == PHASE_RUNNING) { | 726 if (!is_socket_read_pending_ && phase_ == PHASE_RUNNING) { |
| 734 scoped_refptr<net::IOBufferWithSize> buf = | 727 scoped_refptr<net::IOBufferWithSize> buf = |
| 735 inbound_stream_.GetIOBufferToFill(); | 728 inbound_stream_.GetIOBufferToFill(); |
| 736 if (buf && buf->size() > 0) { | 729 if (buf && buf->size() > 0) { |
| 737 int rv = socket_->Read(buf, buf->size(), socket_read_callback_); | 730 int rv = socket_->Read( |
| 731 buf, buf->size(), |
| 732 base::Bind(&SSLChan::OnSocketRead, base::Unretained(this))); |
| 738 is_socket_read_pending_ = true; | 733 is_socket_read_pending_ = true; |
| 739 if (rv != net::ERR_IO_PENDING) { | 734 if (rv != net::ERR_IO_PENDING) { |
| 740 MessageLoop::current()->PostTask(FROM_HERE, | 735 MessageLoop::current()->PostTask(FROM_HERE, |
| 741 method_factory_.NewRunnableMethod(&SSLChan::OnSocketRead, rv)); | 736 method_factory_.NewRunnableMethod(&SSLChan::OnSocketRead, rv)); |
| 742 } | 737 } |
| 743 } | 738 } |
| 744 } | 739 } |
| 745 if (!is_socket_write_pending_) { | 740 if (!is_socket_write_pending_) { |
| 746 scoped_refptr<net::IOBufferWithSize> buf = | 741 scoped_refptr<net::IOBufferWithSize> buf = |
| 747 outbound_stream_.GetIOBufferToProcess(); | 742 outbound_stream_.GetIOBufferToProcess(); |
| 748 if (buf && buf->size() > 0) { | 743 if (buf && buf->size() > 0) { |
| 749 int rv = socket_->Write( | 744 int rv = socket_->Write( |
| 750 buf, buf->size(), socket_write_callback_.get()); | 745 buf, buf->size(), |
| 746 base::Bind(&SSLChan::OnSocketWrite, base::Unretained(this))); |
| 751 is_socket_write_pending_ = true; | 747 is_socket_write_pending_ = true; |
| 752 if (rv != net::ERR_IO_PENDING) { | 748 if (rv != net::ERR_IO_PENDING) { |
| 753 MessageLoop::current()->PostTask(FROM_HERE, | 749 MessageLoop::current()->PostTask(FROM_HERE, |
| 754 method_factory_.NewRunnableMethod(&SSLChan::OnSocketWrite, rv)); | 750 method_factory_.NewRunnableMethod(&SSLChan::OnSocketWrite, rv)); |
| 755 } | 751 } |
| 756 } else if (phase_ == PHASE_CLOSING) { | 752 } else if (phase_ == PHASE_CLOSING) { |
| 757 Shut(0); | 753 Shut(0); |
| 758 } | 754 } |
| 759 } | 755 } |
| 760 if (!is_write_pipe_blocked_) { | 756 if (!is_write_pipe_blocked_) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 790 net::SSLConfig ssl_config_; | 786 net::SSLConfig ssl_config_; |
| 791 IOBufferQueue inbound_stream_; | 787 IOBufferQueue inbound_stream_; |
| 792 IOBufferQueue outbound_stream_; | 788 IOBufferQueue outbound_stream_; |
| 793 int read_pipe_; | 789 int read_pipe_; |
| 794 int write_pipe_; | 790 int write_pipe_; |
| 795 bool is_socket_read_pending_; | 791 bool is_socket_read_pending_; |
| 796 bool is_socket_write_pending_; | 792 bool is_socket_write_pending_; |
| 797 bool is_read_pipe_blocked_; | 793 bool is_read_pipe_blocked_; |
| 798 bool is_write_pipe_blocked_; | 794 bool is_write_pipe_blocked_; |
| 799 ScopedRunnableMethodFactory<SSLChan> method_factory_; | 795 ScopedRunnableMethodFactory<SSLChan> method_factory_; |
| 800 net::CompletionCallback socket_connect_callback_; | |
| 801 net::CompletionCallback ssl_handshake_callback_; | |
| 802 net::CompletionCallback socket_read_callback_; | |
| 803 scoped_ptr<net::OldCompletionCallback> socket_write_callback_; | |
| 804 MessageLoopForIO::FileDescriptorWatcher read_pipe_controller_; | 796 MessageLoopForIO::FileDescriptorWatcher read_pipe_controller_; |
| 805 MessageLoopForIO::FileDescriptorWatcher write_pipe_controller_; | 797 MessageLoopForIO::FileDescriptorWatcher write_pipe_controller_; |
| 806 | 798 |
| 807 friend class DeleteTask<SSLChan>; | 799 friend class DeleteTask<SSLChan>; |
| 808 DISALLOW_COPY_AND_ASSIGN(SSLChan); | 800 DISALLOW_COPY_AND_ASSIGN(SSLChan); |
| 809 }; | 801 }; |
| 810 | 802 |
| 811 Serv::Serv(const std::vector<std::string>& allowed_origins) | 803 Serv::Serv(const std::vector<std::string>& allowed_origins) |
| 812 : allowed_origins_(allowed_origins), | 804 : allowed_origins_(allowed_origins), |
| 813 evbase_(NULL), | 805 evbase_(NULL), |
| (...skipping 1105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1919 | 1911 |
| 1920 void WebSocketProxy::Shutdown() { | 1912 void WebSocketProxy::Shutdown() { |
| 1921 static_cast<Serv*>(impl_)->Shutdown(); | 1913 static_cast<Serv*>(impl_)->Shutdown(); |
| 1922 } | 1914 } |
| 1923 | 1915 |
| 1924 void WebSocketProxy::OnNetworkChange() { | 1916 void WebSocketProxy::OnNetworkChange() { |
| 1925 static_cast<Serv*>(impl_)->OnNetworkChange(); | 1917 static_cast<Serv*>(impl_)->OnNetworkChange(); |
| 1926 } | 1918 } |
| 1927 | 1919 |
| 1928 } // namespace chromeos | 1920 } // namespace chromeos |
| OLD | NEW |