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

Side by Side Diff: components/cast_channel/cast_socket.cc

Issue 2942743002: [cast_channel] Clean up CastSocketImpl ctor parameters (Closed)
Patch Set: fix compile error Created 3 years, 6 months 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
« no previous file with comments | « components/cast_channel/cast_socket.h ('k') | components/cast_channel/cast_socket_unittest.cc » ('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 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 "components/cast_channel/cast_socket.h" 5 #include "components/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>
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "net/socket/client_socket_handle.h" 43 #include "net/socket/client_socket_handle.h"
44 #include "net/socket/ssl_client_socket.h" 44 #include "net/socket/ssl_client_socket.h"
45 #include "net/socket/stream_socket.h" 45 #include "net/socket/stream_socket.h"
46 #include "net/socket/tcp_client_socket.h" 46 #include "net/socket/tcp_client_socket.h"
47 #include "net/ssl/ssl_config_service.h" 47 #include "net/ssl/ssl_config_service.h"
48 #include "net/ssl/ssl_info.h" 48 #include "net/ssl/ssl_info.h"
49 49
50 // Helper for logging data with remote host IP and authentication state. 50 // Helper for logging data with remote host IP and authentication state.
51 // Assumes |ip_endpoint_| of type net::IPEndPoint and |channel_auth_| of enum 51 // Assumes |ip_endpoint_| of type net::IPEndPoint and |channel_auth_| of enum
52 // type ChannelAuthType are available in the current scope. 52 // type ChannelAuthType are available in the current scope.
53 #define CONNECTION_INFO() \ 53 #define CONNECTION_INFO() \
54 "[" << ip_endpoint_.ToString() \ 54 "[" << ip_endpoint_.ToString() << ", auth=SSL_VERIFIED" \
55 << ", auth=" << ::cast_channel::ChannelAuthTypeToString(channel_auth_) \
56 << "] " 55 << "] "
57 #define VLOG_WITH_CONNECTION(level) VLOG(level) << CONNECTION_INFO() 56 #define VLOG_WITH_CONNECTION(level) VLOG(level) << CONNECTION_INFO()
58 #define LOG_WITH_CONNECTION(level) LOG(level) << CONNECTION_INFO() 57 #define LOG_WITH_CONNECTION(level) LOG(level) << CONNECTION_INFO()
59 58
60 namespace cast_channel { 59 namespace cast_channel {
61 namespace { 60 namespace {
62 61
63 bool IsTerminalState(ConnectionState state) { 62 bool IsTerminalState(ConnectionState state) {
64 return state == ConnectionState::FINISHED || 63 return state == ConnectionState::FINISHED ||
65 state == ConnectionState::CONNECT_ERROR || 64 state == ConnectionState::CONNECT_ERROR ||
(...skipping 13 matching lines...) Expand all
79 std::unique_ptr<Request>*, 78 std::unique_ptr<Request>*,
80 const net::NetLogWithSource&) override { 79 const net::NetLogWithSource&) override {
81 verify_result->Reset(); 80 verify_result->Reset();
82 verify_result->verified_cert = params.certificate(); 81 verify_result->verified_cert = params.certificate();
83 return net::OK; 82 return net::OK;
84 } 83 }
85 }; 84 };
86 85
87 } // namespace 86 } // namespace
88 87
89 using ChannelError = ::cast_channel::ChannelError; 88 CastSocketImpl::CastSocketImpl(const net::IPEndPoint& ip_endpoint,
90 using ChannelAuthType = ::cast_channel::ChannelAuthType;
91 using ReadyState = ::cast_channel::ReadyState;
92
93 CastSocketImpl::CastSocketImpl(const std::string& owner_extension_id,
94 const net::IPEndPoint& ip_endpoint,
95 ChannelAuthType channel_auth,
96 net::NetLog* net_log, 89 net::NetLog* net_log,
97 const base::TimeDelta& timeout, 90 const base::TimeDelta& timeout,
98 bool keep_alive, 91 bool keep_alive,
99 const scoped_refptr<Logger>& logger, 92 const scoped_refptr<Logger>& logger,
100 uint64_t device_capabilities) 93 uint64_t device_capabilities)
101 : CastSocketImpl(owner_extension_id, 94 : CastSocketImpl(ip_endpoint,
102 ip_endpoint,
103 channel_auth,
104 net_log, 95 net_log,
105 timeout, 96 timeout,
106 keep_alive, 97 keep_alive,
107 logger, 98 logger,
108 device_capabilities, 99 device_capabilities,
109 AuthContext::Create()) {} 100 AuthContext::Create()) {}
110 101
111 CastSocketImpl::CastSocketImpl(const std::string& owner_extension_id, 102 CastSocketImpl::CastSocketImpl(const net::IPEndPoint& ip_endpoint,
112 const net::IPEndPoint& ip_endpoint,
113 ChannelAuthType channel_auth,
114 net::NetLog* net_log, 103 net::NetLog* net_log,
115 const base::TimeDelta& timeout, 104 const base::TimeDelta& timeout,
116 bool keep_alive, 105 bool keep_alive,
117 const scoped_refptr<Logger>& logger, 106 const scoped_refptr<Logger>& logger,
118 uint64_t device_capabilities, 107 uint64_t device_capabilities,
119 const AuthContext& auth_context) 108 const AuthContext& auth_context)
120 : channel_id_(0), 109 : channel_id_(0),
121 ip_endpoint_(ip_endpoint), 110 ip_endpoint_(ip_endpoint),
122 channel_auth_(channel_auth),
123 net_log_(net_log), 111 net_log_(net_log),
124 keep_alive_(keep_alive), 112 keep_alive_(keep_alive),
125 logger_(logger), 113 logger_(logger),
126 auth_context_(auth_context), 114 auth_context_(auth_context),
127 connect_timeout_(timeout), 115 connect_timeout_(timeout),
128 connect_timeout_timer_(new base::OneShotTimer), 116 connect_timeout_timer_(new base::OneShotTimer),
129 is_canceled_(false), 117 is_canceled_(false),
130 device_capabilities_(device_capabilities), 118 device_capabilities_(device_capabilities),
131 audio_only_(false), 119 audio_only_(false),
132 connect_state_(ConnectionState::START_CONNECT), 120 connect_state_(ConnectionState::START_CONNECT),
(...skipping 27 matching lines...) Expand all
160 } 148 }
161 149
162 int CastSocketImpl::id() const { 150 int CastSocketImpl::id() const {
163 return channel_id_; 151 return channel_id_;
164 } 152 }
165 153
166 void CastSocketImpl::set_id(int id) { 154 void CastSocketImpl::set_id(int id) {
167 channel_id_ = id; 155 channel_id_ = id;
168 } 156 }
169 157
170 ChannelAuthType CastSocketImpl::channel_auth() const {
171 return channel_auth_;
172 }
173
174 bool CastSocketImpl::keep_alive() const { 158 bool CastSocketImpl::keep_alive() const {
175 return keep_alive_; 159 return keep_alive_;
176 } 160 }
177 161
178 bool CastSocketImpl::audio_only() const { 162 bool CastSocketImpl::audio_only() const {
179 return audio_only_; 163 return audio_only_;
180 } 164 }
181 165
182 std::unique_ptr<net::TCPClientSocket> CastSocketImpl::CreateTcpSocket() { 166 std::unique_ptr<net::TCPClientSocket> CastSocketImpl::CreateTcpSocket() {
183 net::AddressList addresses(ip_endpoint_); 167 net::AddressList addresses(ip_endpoint_);
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 SetConnectState(ConnectionState::FINISHED); 409 SetConnectState(ConnectionState::FINISHED);
426 SetErrorState(ChannelError::AUTHENTICATION_ERROR); 410 SetErrorState(ChannelError::AUTHENTICATION_ERROR);
427 return net::ERR_CERT_INVALID; 411 return net::ERR_CERT_INVALID;
428 } 412 }
429 413
430 // SSL connection succeeded. 414 // SSL connection succeeded.
431 if (!transport_.get()) { 415 if (!transport_.get()) {
432 // Create a channel transport if one wasn't already set (e.g. by test 416 // Create a channel transport if one wasn't already set (e.g. by test
433 // code). 417 // code).
434 transport_.reset(new CastTransportImpl(this->socket_.get(), channel_id_, 418 transport_.reset(new CastTransportImpl(this->socket_.get(), channel_id_,
435 ip_endpoint_, channel_auth_, 419 ip_endpoint_, logger_));
436 logger_));
437 } 420 }
438 auth_delegate_ = new AuthTransportDelegate(this); 421 auth_delegate_ = new AuthTransportDelegate(this);
439 transport_->SetReadDelegate(base::WrapUnique(auth_delegate_)); 422 transport_->SetReadDelegate(base::WrapUnique(auth_delegate_));
440 SetConnectState(ConnectionState::AUTH_CHALLENGE_SEND); 423 SetConnectState(ConnectionState::AUTH_CHALLENGE_SEND);
441 } else if (result == net::ERR_CONNECTION_TIMED_OUT) { 424 } else if (result == net::ERR_CONNECTION_TIMED_OUT) {
442 SetConnectState(ConnectionState::FINISHED); 425 SetConnectState(ConnectionState::FINISHED);
443 SetErrorState(ChannelError::CONNECT_TIMEOUT); 426 SetErrorState(ChannelError::CONNECT_TIMEOUT);
444 } else { 427 } else {
445 SetConnectState(ConnectionState::FINISHED); 428 SetConnectState(ConnectionState::FINISHED);
446 SetErrorState(ChannelError::AUTHENTICATION_ERROR); 429 SetErrorState(ChannelError::AUTHENTICATION_ERROR);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 void CastSocketImpl::SetErrorState(ChannelError error_state) { 587 void CastSocketImpl::SetErrorState(ChannelError error_state) {
605 VLOG_WITH_CONNECTION(1) << "SetErrorState " 588 VLOG_WITH_CONNECTION(1) << "SetErrorState "
606 << ::cast_channel::ChannelErrorToString(error_state); 589 << ::cast_channel::ChannelErrorToString(error_state);
607 DCHECK_EQ(ChannelError::NONE, error_state_); 590 DCHECK_EQ(ChannelError::NONE, error_state_);
608 error_state_ = error_state; 591 error_state_ = error_state;
609 delegate_->OnError(error_state_); 592 delegate_->OnError(error_state_);
610 } 593 }
611 594
612 } // namespace cast_channel 595 } // namespace cast_channel
613 #undef VLOG_WITH_CONNECTION 596 #undef VLOG_WITH_CONNECTION
OLDNEW
« no previous file with comments | « components/cast_channel/cast_socket.h ('k') | components/cast_channel/cast_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698