| 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 <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback_helpers.h" | 13 #include "base/callback_helpers.h" |
| 14 #include "base/format_macros.h" | 14 #include "base/format_macros.h" |
| 15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
| 16 #include "base/location.h" |
| 16 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 17 #include "base/message_loop/message_loop.h" | |
| 18 #include "base/numerics/safe_conversions.h" | 18 #include "base/numerics/safe_conversions.h" |
| 19 #include "base/single_thread_task_runner.h" |
| 19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
| 21 #include "base/sys_byteorder.h" | 22 #include "base/sys_byteorder.h" |
| 23 #include "base/threading/thread_task_runner_handle.h" |
| 22 #include "base/time/time.h" | 24 #include "base/time/time.h" |
| 23 #include "extensions/browser/api/cast_channel/cast_auth_util.h" | 25 #include "extensions/browser/api/cast_channel/cast_auth_util.h" |
| 24 #include "extensions/browser/api/cast_channel/cast_framer.h" | 26 #include "extensions/browser/api/cast_channel/cast_framer.h" |
| 25 #include "extensions/browser/api/cast_channel/cast_message_util.h" | 27 #include "extensions/browser/api/cast_channel/cast_message_util.h" |
| 26 #include "extensions/browser/api/cast_channel/cast_transport.h" | 28 #include "extensions/browser/api/cast_channel/cast_transport.h" |
| 27 #include "extensions/browser/api/cast_channel/logger.h" | 29 #include "extensions/browser/api/cast_channel/logger.h" |
| 28 #include "extensions/browser/api/cast_channel/logger_util.h" | 30 #include "extensions/browser/api/cast_channel/logger_util.h" |
| 29 #include "extensions/common/api/cast_channel/cast_channel.pb.h" | 31 #include "extensions/common/api/cast_channel/cast_channel.pb.h" |
| 30 #include "net/base/address_list.h" | 32 #include "net/base/address_list.h" |
| 31 #include "net/base/host_port_pair.h" | 33 #include "net/base/host_port_pair.h" |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 VLOG_WITH_CONNECTION(1) << "Timeout while establishing a connection."; | 292 VLOG_WITH_CONNECTION(1) << "Timeout while establishing a connection."; |
| 291 SetErrorState(CHANNEL_ERROR_CONNECT_TIMEOUT); | 293 SetErrorState(CHANNEL_ERROR_CONNECT_TIMEOUT); |
| 292 DoConnectCallback(); | 294 DoConnectCallback(); |
| 293 } | 295 } |
| 294 | 296 |
| 295 void CastSocketImpl::PostTaskToStartConnectLoop(int result) { | 297 void CastSocketImpl::PostTaskToStartConnectLoop(int result) { |
| 296 DCHECK(CalledOnValidThread()); | 298 DCHECK(CalledOnValidThread()); |
| 297 DCHECK(connect_loop_callback_.IsCancelled()); | 299 DCHECK(connect_loop_callback_.IsCancelled()); |
| 298 connect_loop_callback_.Reset(base::Bind(&CastSocketImpl::DoConnectLoop, | 300 connect_loop_callback_.Reset(base::Bind(&CastSocketImpl::DoConnectLoop, |
| 299 base::Unretained(this), result)); | 301 base::Unretained(this), result)); |
| 300 base::MessageLoop::current()->PostTask(FROM_HERE, | 302 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 301 connect_loop_callback_.callback()); | 303 FROM_HERE, connect_loop_callback_.callback()); |
| 302 } | 304 } |
| 303 | 305 |
| 304 // This method performs the state machine transitions for connection flow. | 306 // This method performs the state machine transitions for connection flow. |
| 305 // There are two entry points to this method: | 307 // There are two entry points to this method: |
| 306 // 1. Connect method: this starts the flow | 308 // 1. Connect method: this starts the flow |
| 307 // 2. Callback from network operations that finish asynchronously. | 309 // 2. Callback from network operations that finish asynchronously. |
| 308 void CastSocketImpl::DoConnectLoop(int result) { | 310 void CastSocketImpl::DoConnectLoop(int result) { |
| 309 connect_loop_callback_.Cancel(); | 311 connect_loop_callback_.Cancel(); |
| 310 if (is_canceled_) { | 312 if (is_canceled_) { |
| 311 LOG_WITH_CONNECTION(ERROR) << "CANCELLED - Aborting DoConnectLoop."; | 313 LOG_WITH_CONNECTION(ERROR) << "CANCELLED - Aborting DoConnectLoop."; |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 VLOG_WITH_CONNECTION(1) << "SetErrorState " << error_state; | 618 VLOG_WITH_CONNECTION(1) << "SetErrorState " << error_state; |
| 617 DCHECK_EQ(CHANNEL_ERROR_NONE, error_state_); | 619 DCHECK_EQ(CHANNEL_ERROR_NONE, error_state_); |
| 618 error_state_ = error_state; | 620 error_state_ = error_state; |
| 619 logger_->LogSocketErrorState(channel_id_, ErrorStateToProto(error_state_)); | 621 logger_->LogSocketErrorState(channel_id_, ErrorStateToProto(error_state_)); |
| 620 delegate_->OnError(error_state_); | 622 delegate_->OnError(error_state_); |
| 621 } | 623 } |
| 622 } // namespace cast_channel | 624 } // namespace cast_channel |
| 623 } // namespace api | 625 } // namespace api |
| 624 } // namespace extensions | 626 } // namespace extensions |
| 625 #undef VLOG_WITH_CONNECTION | 627 #undef VLOG_WITH_CONNECTION |
| OLD | NEW |