Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/cast_channel/cast_socket.h" | 5 #include "extensions/browser/api/cast_channel/cast_socket.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 GetTimer()->Start(FROM_HERE, | 202 GetTimer()->Start(FROM_HERE, |
| 203 connect_timeout_, | 203 connect_timeout_, |
| 204 connect_timeout_callback_.callback()); | 204 connect_timeout_callback_.callback()); |
| 205 } | 205 } |
| 206 DoConnectLoop(net::OK); | 206 DoConnectLoop(net::OK); |
| 207 } | 207 } |
| 208 | 208 |
| 209 void CastSocket::PostTaskToStartConnectLoop(int result) { | 209 void CastSocket::PostTaskToStartConnectLoop(int result) { |
| 210 DCHECK(CalledOnValidThread()); | 210 DCHECK(CalledOnValidThread()); |
| 211 DCHECK(connect_loop_callback_.IsCancelled()); | 211 DCHECK(connect_loop_callback_.IsCancelled()); |
| 212 connect_loop_callback_.Reset(base::Bind(&CastSocket::DoConnectLoop, | 212 connect_loop_callback_.Reset( |
| 213 base::Unretained(this), | 213 base::Bind(&CastSocket::DoConnectLoop, base::Unretained(this), result)); |
| 214 result)); | |
| 215 base::MessageLoop::current()->PostTask(FROM_HERE, | 214 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 216 connect_loop_callback_.callback()); | 215 connect_loop_callback_.callback()); |
| 217 } | 216 } |
| 218 | 217 |
| 219 void CastSocket::OnConnectTimeout() { | 218 void CastSocket::OnConnectTimeout() { |
| 220 DCHECK(CalledOnValidThread()); | 219 DCHECK(CalledOnValidThread()); |
| 221 // Stop all pending connection setup tasks and report back to the client. | 220 // Stop all pending connection setup tasks and report back to the client. |
| 222 is_canceled_ = true; | 221 is_canceled_ = true; |
| 223 logger_->LogSocketEvent(channel_id_, proto::CONNECT_TIMED_OUT); | 222 logger_->LogSocketEvent(channel_id_, proto::CONNECT_TIMED_OUT); |
| 224 VLOG_WITH_CONNECTION(1) << "Timeout while establishing a connection."; | 223 VLOG_WITH_CONNECTION(1) << "Timeout while establishing a connection."; |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 640 WriteRequest& request = write_queue_.front(); | 639 WriteRequest& request = write_queue_.front(); |
| 641 request.callback.Run(result); | 640 request.callback.Run(result); |
| 642 write_queue_.pop(); | 641 write_queue_.pop(); |
| 643 } | 642 } |
| 644 return net::ERR_FAILED; | 643 return net::ERR_FAILED; |
| 645 } | 644 } |
| 646 | 645 |
| 647 void CastSocket::PostTaskToStartReadLoop() { | 646 void CastSocket::PostTaskToStartReadLoop() { |
| 648 DCHECK(CalledOnValidThread()); | 647 DCHECK(CalledOnValidThread()); |
| 649 DCHECK(read_loop_callback_.IsCancelled()); | 648 DCHECK(read_loop_callback_.IsCancelled()); |
| 650 read_loop_callback_.Reset(base::Bind(&CastSocket::StartReadLoop, | 649 read_loop_callback_.Reset( |
| 651 base::Unretained(this))); | 650 base::Bind(&CastSocket::StartReadLoop, base::Unretained(this))); |
| 652 base::MessageLoop::current()->PostTask(FROM_HERE, | 651 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 653 read_loop_callback_.callback()); | 652 read_loop_callback_.callback()); |
| 654 } | 653 } |
| 655 | 654 |
| 656 void CastSocket::StartReadLoop() { | 655 void CastSocket::StartReadLoop() { |
| 657 read_loop_callback_.Cancel(); | 656 read_loop_callback_.Cancel(); |
| 658 // Read loop would have already been started if read state is not NONE | 657 // Read loop would have already been started if read state is not NONE |
| 659 if (read_state_ == proto::READ_STATE_NONE) { | 658 if (read_state_ == proto::READ_STATE_NONE) { |
| 660 SetReadState(proto::READ_STATE_READ); | 659 SetReadState(proto::READ_STATE_READ); |
| 661 DoReadLoop(net::OK); | 660 DoReadLoop(net::OK); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 855 } | 854 } |
| 856 | 855 |
| 857 void CastSocket::SetWriteState(proto::WriteState write_state) { | 856 void CastSocket::SetWriteState(proto::WriteState write_state) { |
| 858 if (write_state_ != write_state) { | 857 if (write_state_ != write_state) { |
| 859 write_state_ = write_state; | 858 write_state_ = write_state; |
| 860 logger_->LogSocketWriteState(channel_id_, write_state_); | 859 logger_->LogSocketWriteState(channel_id_, write_state_); |
| 861 } | 860 } |
| 862 } | 861 } |
| 863 | 862 |
| 864 CastSocket::WriteRequest::WriteRequest(const net::CompletionCallback& callback) | 863 CastSocket::WriteRequest::WriteRequest(const net::CompletionCallback& callback) |
| 865 : callback(callback) { } | 864 : callback(callback) { |
| 865 } | |
| 866 | 866 |
| 867 bool CastSocket::WriteRequest::SetContent(const CastMessage& message_proto) { | 867 bool CastSocket::WriteRequest::SetContent(const CastMessage& message_proto) { |
| 868 DCHECK(!io_buffer.get()); | 868 DCHECK(!io_buffer.get()); |
| 869 std::string message_data; | 869 std::string message_data; |
| 870 if (!MessageFramer::Serialize(message_proto, &message_data)) { | 870 if (!MessageFramer::Serialize(message_proto, &message_data)) { |
| 871 return false; | 871 return false; |
| 872 } | 872 } |
| 873 message_namespace = message_proto.namespace_(); | 873 message_namespace = message_proto.namespace_(); |
| 874 io_buffer = new net::DrainableIOBuffer(new net::StringIOBuffer(message_data), | 874 io_buffer = new net::DrainableIOBuffer(new net::StringIOBuffer(message_data), |
| 875 message_data.size()); | 875 message_data.size()); |
| 876 return true; | 876 return true; |
| 877 } | 877 } |
| 878 | 878 |
| 879 CastSocket::WriteRequest::~WriteRequest() { } | 879 CastSocket::WriteRequest::~WriteRequest() { |
| 880 } | |
|
Wez
2014/09/25 02:09:15
nit: Blank between this closing brace and the firs
Kevin M
2014/09/25 17:53:04
Done.
| |
| 880 } // namespace cast_channel | 881 } // namespace cast_channel |
| 881 } // namespace core_api | 882 } // namespace core_api |
| 882 } // namespace extensions | 883 } // namespace extensions |
| 883 | 884 |
| 884 #undef VLOG_WITH_CONNECTION | 885 #undef VLOG_WITH_CONNECTION |
| OLD | NEW |