| 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 13 matching lines...) Expand all Loading... |
| 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/bind_helpers.h" |
| 30 #include "base/lazy_instance.h" | 30 #include "base/lazy_instance.h" |
| 31 #include "base/logging.h" | 31 #include "base/logging.h" |
| 32 #include "base/memory/ref_counted.h" | 32 #include "base/memory/ref_counted.h" |
| 33 #include "base/memory/scoped_ptr.h" | 33 #include "base/memory/scoped_ptr.h" |
| 34 #include "base/memory/weak_ptr.h" |
| 34 #include "base/message_loop.h" | 35 #include "base/message_loop.h" |
| 35 #include "base/sha1.h" | 36 #include "base/sha1.h" |
| 36 #include "base/stl_util.h" | 37 #include "base/stl_util.h" |
| 37 #include "base/string_number_conversions.h" | 38 #include "base/string_number_conversions.h" |
| 38 #include "base/string_util.h" | 39 #include "base/string_util.h" |
| 39 #include "chrome/browser/chromeos/web_socket_proxy_helper.h" | 40 #include "chrome/browser/chromeos/web_socket_proxy_helper.h" |
| 40 #include "chrome/browser/internal_auth.h" | 41 #include "chrome/browser/internal_auth.h" |
| 41 #include "chrome/common/chrome_notification_types.h" | 42 #include "chrome/common/chrome_notification_types.h" |
| 42 #include "chrome/common/url_constants.h" | 43 #include "chrome/common/url_constants.h" |
| 43 #include "content/public/browser/browser_thread.h" | 44 #include "content/public/browser/browser_thread.h" |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 SSLChan(const net::AddressList address_list, | 548 SSLChan(const net::AddressList address_list, |
| 548 const net::HostPortPair host_port_pair, | 549 const net::HostPortPair host_port_pair, |
| 549 int read_pipe, | 550 int read_pipe, |
| 550 int write_pipe) | 551 int write_pipe) |
| 551 : phase_(PHASE_CONNECTING), | 552 : phase_(PHASE_CONNECTING), |
| 552 host_port_pair_(host_port_pair), | 553 host_port_pair_(host_port_pair), |
| 553 inbound_stream_(WebSocketProxy::kBufferLimit), | 554 inbound_stream_(WebSocketProxy::kBufferLimit), |
| 554 outbound_stream_(WebSocketProxy::kBufferLimit), | 555 outbound_stream_(WebSocketProxy::kBufferLimit), |
| 555 read_pipe_(read_pipe), | 556 read_pipe_(read_pipe), |
| 556 write_pipe_(write_pipe), | 557 write_pipe_(write_pipe), |
| 557 method_factory_(this) { | 558 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 558 if (!SetNonBlock(read_pipe_) || !SetNonBlock(write_pipe_)) { | 559 if (!SetNonBlock(read_pipe_) || !SetNonBlock(write_pipe_)) { |
| 559 Shut(net::ERR_UNEXPECTED); | 560 Shut(net::ERR_UNEXPECTED); |
| 560 return; | 561 return; |
| 561 } | 562 } |
| 562 net::ClientSocketFactory* factory = | 563 net::ClientSocketFactory* factory = |
| 563 net::ClientSocketFactory::GetDefaultFactory(); | 564 net::ClientSocketFactory::GetDefaultFactory(); |
| 564 socket_.reset(factory->CreateTransportClientSocket( | 565 socket_.reset(factory->CreateTransportClientSocket( |
| 565 address_list, NULL, net::NetLog::Source())); | 566 address_list, NULL, net::NetLog::Source())); |
| 566 if (socket_ == NULL) { | 567 if (socket_ == NULL) { |
| 567 Shut(net::ERR_FAILED); | 568 Shut(net::ERR_FAILED); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 583 | 584 |
| 584 void Shut(int ALLOW_UNUSED net_error_code) { | 585 void Shut(int ALLOW_UNUSED net_error_code) { |
| 585 if (phase_ != PHASE_CLOSED) { | 586 if (phase_ != PHASE_CLOSED) { |
| 586 phase_ = PHASE_CLOSING; | 587 phase_ = PHASE_CLOSING; |
| 587 scoped_refptr<net::IOBufferWithSize> buf[] = { | 588 scoped_refptr<net::IOBufferWithSize> buf[] = { |
| 588 outbound_stream_.GetIOBufferToProcess(), | 589 outbound_stream_.GetIOBufferToProcess(), |
| 589 inbound_stream_.GetIOBufferToProcess() | 590 inbound_stream_.GetIOBufferToProcess() |
| 590 }; | 591 }; |
| 591 for (int i = arraysize(buf); i--;) { | 592 for (int i = arraysize(buf); i--;) { |
| 592 if (buf[i] && buf[i]->size() > 0) { | 593 if (buf[i] && buf[i]->size() > 0) { |
| 593 MessageLoop::current()->PostTask(FROM_HERE, | 594 MessageLoop::current()->PostTask( |
| 594 method_factory_.NewRunnableMethod(&SSLChan::Proceed)); | 595 FROM_HERE, |
| 596 base::Bind(&SSLChan::Proceed, weak_factory_.GetWeakPtr())); |
| 595 return; | 597 return; |
| 596 } | 598 } |
| 597 } | 599 } |
| 598 phase_ = PHASE_CLOSED; | 600 phase_ = PHASE_CLOSED; |
| 599 if (socket_ != NULL) { | 601 if (socket_ != NULL) { |
| 600 socket_->Disconnect(); | 602 socket_->Disconnect(); |
| 601 socket_.reset(); | 603 socket_.reset(); |
| 602 } | 604 } |
| 603 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 605 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 604 } | 606 } |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 } | 727 } |
| 726 if (!is_socket_read_pending_ && phase_ == PHASE_RUNNING) { | 728 if (!is_socket_read_pending_ && phase_ == PHASE_RUNNING) { |
| 727 scoped_refptr<net::IOBufferWithSize> buf = | 729 scoped_refptr<net::IOBufferWithSize> buf = |
| 728 inbound_stream_.GetIOBufferToFill(); | 730 inbound_stream_.GetIOBufferToFill(); |
| 729 if (buf && buf->size() > 0) { | 731 if (buf && buf->size() > 0) { |
| 730 int rv = socket_->Read( | 732 int rv = socket_->Read( |
| 731 buf, buf->size(), | 733 buf, buf->size(), |
| 732 base::Bind(&SSLChan::OnSocketRead, base::Unretained(this))); | 734 base::Bind(&SSLChan::OnSocketRead, base::Unretained(this))); |
| 733 is_socket_read_pending_ = true; | 735 is_socket_read_pending_ = true; |
| 734 if (rv != net::ERR_IO_PENDING) { | 736 if (rv != net::ERR_IO_PENDING) { |
| 735 MessageLoop::current()->PostTask(FROM_HERE, | 737 MessageLoop::current()->PostTask( |
| 736 method_factory_.NewRunnableMethod(&SSLChan::OnSocketRead, rv)); | 738 FROM_HERE, base::Bind(&SSLChan::OnSocketRead, |
| 739 weak_factory_.GetWeakPtr(), rv)); |
| 737 } | 740 } |
| 738 } | 741 } |
| 739 } | 742 } |
| 740 if (!is_socket_write_pending_) { | 743 if (!is_socket_write_pending_) { |
| 741 scoped_refptr<net::IOBufferWithSize> buf = | 744 scoped_refptr<net::IOBufferWithSize> buf = |
| 742 outbound_stream_.GetIOBufferToProcess(); | 745 outbound_stream_.GetIOBufferToProcess(); |
| 743 if (buf && buf->size() > 0) { | 746 if (buf && buf->size() > 0) { |
| 744 int rv = socket_->Write( | 747 int rv = socket_->Write( |
| 745 buf, buf->size(), | 748 buf, buf->size(), |
| 746 base::Bind(&SSLChan::OnSocketWrite, base::Unretained(this))); | 749 base::Bind(&SSLChan::OnSocketWrite, base::Unretained(this))); |
| 747 is_socket_write_pending_ = true; | 750 is_socket_write_pending_ = true; |
| 748 if (rv != net::ERR_IO_PENDING) { | 751 if (rv != net::ERR_IO_PENDING) { |
| 749 MessageLoop::current()->PostTask(FROM_HERE, | 752 MessageLoop::current()->PostTask( |
| 750 method_factory_.NewRunnableMethod(&SSLChan::OnSocketWrite, rv)); | 753 FROM_HERE, base::Bind(&SSLChan::OnSocketWrite, |
| 754 weak_factory_.GetWeakPtr(), rv)); |
| 751 } | 755 } |
| 752 } else if (phase_ == PHASE_CLOSING) { | 756 } else if (phase_ == PHASE_CLOSING) { |
| 753 Shut(0); | 757 Shut(0); |
| 754 } | 758 } |
| 755 } | 759 } |
| 756 if (!is_write_pipe_blocked_) { | 760 if (!is_write_pipe_blocked_) { |
| 757 scoped_refptr<net::IOBufferWithSize> buf = | 761 scoped_refptr<net::IOBufferWithSize> buf = |
| 758 inbound_stream_.GetIOBufferToProcess(); | 762 inbound_stream_.GetIOBufferToProcess(); |
| 759 if (buf && buf->size() > 0) { | 763 if (buf && buf->size() > 0) { |
| 760 int rv = write(write_pipe_, buf->data(), buf->size()); | 764 int rv = write(write_pipe_, buf->data(), buf->size()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 785 scoped_ptr<net::CertVerifier> cert_verifier_; | 789 scoped_ptr<net::CertVerifier> cert_verifier_; |
| 786 net::SSLConfig ssl_config_; | 790 net::SSLConfig ssl_config_; |
| 787 IOBufferQueue inbound_stream_; | 791 IOBufferQueue inbound_stream_; |
| 788 IOBufferQueue outbound_stream_; | 792 IOBufferQueue outbound_stream_; |
| 789 int read_pipe_; | 793 int read_pipe_; |
| 790 int write_pipe_; | 794 int write_pipe_; |
| 791 bool is_socket_read_pending_; | 795 bool is_socket_read_pending_; |
| 792 bool is_socket_write_pending_; | 796 bool is_socket_write_pending_; |
| 793 bool is_read_pipe_blocked_; | 797 bool is_read_pipe_blocked_; |
| 794 bool is_write_pipe_blocked_; | 798 bool is_write_pipe_blocked_; |
| 795 ScopedRunnableMethodFactory<SSLChan> method_factory_; | 799 base::WeakPtrFactory<SSLChan> weak_factory_; |
| 796 MessageLoopForIO::FileDescriptorWatcher read_pipe_controller_; | 800 MessageLoopForIO::FileDescriptorWatcher read_pipe_controller_; |
| 797 MessageLoopForIO::FileDescriptorWatcher write_pipe_controller_; | 801 MessageLoopForIO::FileDescriptorWatcher write_pipe_controller_; |
| 798 | 802 |
| 799 friend class DeleteTask<SSLChan>; | 803 friend class DeleteTask<SSLChan>; |
| 800 DISALLOW_COPY_AND_ASSIGN(SSLChan); | 804 DISALLOW_COPY_AND_ASSIGN(SSLChan); |
| 801 }; | 805 }; |
| 802 | 806 |
| 803 Serv::Serv(const std::vector<std::string>& allowed_origins) | 807 Serv::Serv(const std::vector<std::string>& allowed_origins) |
| 804 : allowed_origins_(allowed_origins), | 808 : allowed_origins_(allowed_origins), |
| 805 evbase_(NULL), | 809 evbase_(NULL), |
| (...skipping 1105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1911 | 1915 |
| 1912 void WebSocketProxy::Shutdown() { | 1916 void WebSocketProxy::Shutdown() { |
| 1913 static_cast<Serv*>(impl_)->Shutdown(); | 1917 static_cast<Serv*>(impl_)->Shutdown(); |
| 1914 } | 1918 } |
| 1915 | 1919 |
| 1916 void WebSocketProxy::OnNetworkChange() { | 1920 void WebSocketProxy::OnNetworkChange() { |
| 1917 static_cast<Serv*>(impl_)->OnNetworkChange(); | 1921 static_cast<Serv*>(impl_)->OnNetworkChange(); |
| 1918 } | 1922 } |
| 1919 | 1923 |
| 1920 } // namespace chromeos | 1924 } // namespace chromeos |
| OLD | NEW |