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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 | 55 |
| 56 std::string FormatTimeForLogging(base::Time time) { | 56 std::string FormatTimeForLogging(base::Time time) { |
| 57 base::Time::Exploded exploded; | 57 base::Time::Exploded exploded; |
| 58 time.UTCExplode(&exploded); | 58 time.UTCExplode(&exploded); |
| 59 return base::StringPrintf( | 59 return base::StringPrintf( |
| 60 "%04d-%02d-%02d %02d:%02d:%02d.%03d UTC", exploded.year, exploded.month, | 60 "%04d-%02d-%02d %02d:%02d:%02d.%03d UTC", exploded.year, exploded.month, |
| 61 exploded.day_of_month, exploded.hour, exploded.minute, exploded.second, | 61 exploded.day_of_month, exploded.hour, exploded.minute, exploded.second, |
| 62 exploded.millisecond); | 62 exploded.millisecond); |
| 63 } | 63 } |
| 64 | 64 |
| 65 // Cast device capabilities. | |
| 66 enum CastDeviceCapability { | |
| 67 VIDEO_OUT = 1 << 0, | |
| 68 VIDEO_IN = 1 << 1, | |
| 69 AUDIO_OUT = 1 << 2, | |
| 70 AUDIO_IN = 1 << 3, | |
| 71 DEV_MODE = 1 << 4 | |
| 72 }; | |
| 73 | |
| 65 } // namespace | 74 } // namespace |
| 66 | 75 |
| 67 namespace extensions { | 76 namespace extensions { |
| 68 static base::LazyInstance<BrowserContextKeyedAPIFactory< | 77 static base::LazyInstance<BrowserContextKeyedAPIFactory< |
| 69 ApiResourceManager<core_api::cast_channel::CastSocket> > > g_factory = | 78 ApiResourceManager<core_api::cast_channel::CastSocket> > > g_factory = |
| 70 LAZY_INSTANCE_INITIALIZER; | 79 LAZY_INSTANCE_INITIALIZER; |
| 71 | 80 |
| 72 // static | 81 // static |
| 73 template <> | 82 template <> |
| 74 BrowserContextKeyedAPIFactory< | 83 BrowserContextKeyedAPIFactory< |
| 75 ApiResourceManager<core_api::cast_channel::CastSocket> >* | 84 ApiResourceManager<core_api::cast_channel::CastSocket> >* |
| 76 ApiResourceManager<core_api::cast_channel::CastSocket>::GetFactoryInstance() { | 85 ApiResourceManager<core_api::cast_channel::CastSocket>::GetFactoryInstance() { |
| 77 return g_factory.Pointer(); | 86 return g_factory.Pointer(); |
| 78 } | 87 } |
| 79 | 88 |
| 80 namespace core_api { | 89 namespace core_api { |
| 81 namespace cast_channel { | 90 namespace cast_channel { |
| 82 | 91 |
| 83 CastSocket::CastSocket(const std::string& owner_extension_id) | 92 CastSocket::CastSocket(const std::string& owner_extension_id) |
| 84 : ApiResource(owner_extension_id) { | 93 : ApiResource(owner_extension_id) { |
| 85 } | 94 } |
| 86 | 95 |
| 87 CastSocketImpl::CastSocketImpl(const std::string& owner_extension_id, | 96 CastSocketImpl::CastSocketImpl(const std::string& owner_extension_id, |
| 88 const net::IPEndPoint& ip_endpoint, | 97 const net::IPEndPoint& ip_endpoint, |
| 89 ChannelAuthType channel_auth, | 98 ChannelAuthType channel_auth, |
| 90 net::NetLog* net_log, | 99 net::NetLog* net_log, |
| 91 const base::TimeDelta& timeout, | 100 const base::TimeDelta& timeout, |
| 92 const scoped_refptr<Logger>& logger) | 101 const scoped_refptr<Logger>& logger, |
| 102 long device_capabilities) | |
| 93 : CastSocket(owner_extension_id), | 103 : CastSocket(owner_extension_id), |
| 94 auth_delegate_(this), | 104 auth_delegate_(this), |
| 95 owner_extension_id_(owner_extension_id), | 105 owner_extension_id_(owner_extension_id), |
| 96 channel_id_(0), | 106 channel_id_(0), |
| 97 ip_endpoint_(ip_endpoint), | 107 ip_endpoint_(ip_endpoint), |
| 98 channel_auth_(channel_auth), | 108 channel_auth_(channel_auth), |
| 99 net_log_(net_log), | 109 net_log_(net_log), |
| 100 logger_(logger), | 110 logger_(logger), |
| 101 connect_timeout_(timeout), | 111 connect_timeout_(timeout), |
| 102 connect_timeout_timer_(new base::OneShotTimer<CastSocketImpl>), | 112 connect_timeout_timer_(new base::OneShotTimer<CastSocketImpl>), |
| 103 is_canceled_(false), | 113 is_canceled_(false), |
| 114 device_capabilities_(device_capabilities), | |
| 104 connect_state_(proto::CONN_STATE_NONE), | 115 connect_state_(proto::CONN_STATE_NONE), |
| 105 error_state_(CHANNEL_ERROR_NONE), | 116 error_state_(CHANNEL_ERROR_NONE), |
| 106 ready_state_(READY_STATE_NONE) { | 117 ready_state_(READY_STATE_NONE) { |
| 107 DCHECK(net_log_); | 118 DCHECK(net_log_); |
| 108 DCHECK(channel_auth_ == CHANNEL_AUTH_TYPE_SSL || | 119 DCHECK(channel_auth_ == CHANNEL_AUTH_TYPE_SSL || |
| 109 channel_auth_ == CHANNEL_AUTH_TYPE_SSL_VERIFIED); | 120 channel_auth_ == CHANNEL_AUTH_TYPE_SSL_VERIFIED); |
| 110 net_log_source_.type = net::NetLog::SOURCE_SOCKET; | 121 net_log_source_.type = net::NetLog::SOURCE_SOCKET; |
| 111 net_log_source_.id = net_log_->NextID(); | 122 net_log_source_.id = net_log_->NextID(); |
| 112 } | 123 } |
| 113 | 124 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 ssl_info.cert->os_cert_handle(), cert); | 220 ssl_info.cert->os_cert_handle(), cert); |
| 210 if (result) { | 221 if (result) { |
| 211 VLOG_WITH_CONNECTION(1) << "Successfully extracted peer certificate"; | 222 VLOG_WITH_CONNECTION(1) << "Successfully extracted peer certificate"; |
| 212 } | 223 } |
| 213 | 224 |
| 214 logger_->LogSocketEventWithRv( | 225 logger_->LogSocketEventWithRv( |
| 215 channel_id_, proto::DER_ENCODED_CERT_OBTAIN, result ? 1 : 0); | 226 channel_id_, proto::DER_ENCODED_CERT_OBTAIN, result ? 1 : 0); |
| 216 return result; | 227 return result; |
| 217 } | 228 } |
| 218 | 229 |
| 230 bool CastSocketImpl::VerifyChannelPolicy(const AuthResult& result) { | |
| 231 if ((device_capabilities_ & CastDeviceCapability::VIDEO_OUT) != 0) { | |
|
mark a. foltz
2015/01/13 01:42:19
No reason to have nested if() statements; use &&
vadimgo
2015/01/13 02:21:44
Done.
| |
| 232 if ((result.channel_policy & AuthResult::POLICY_AUDIO_ONLY) != 0) { | |
| 233 LOG(ERROR) << "Audio only policy enforced"; | |
| 234 logger_->LogSocketEventWithDetails( | |
| 235 channel_id_, proto::CHANNEL_POLICY_ENFORCED, std::string()); | |
| 236 return false; | |
| 237 } | |
| 238 } | |
| 239 return true; | |
| 240 } | |
| 241 | |
| 219 bool CastSocketImpl::VerifyChallengeReply() { | 242 bool CastSocketImpl::VerifyChallengeReply() { |
| 220 AuthResult result = AuthenticateChallengeReply(*challenge_reply_, peer_cert_); | 243 AuthResult result = AuthenticateChallengeReply(*challenge_reply_, peer_cert_); |
| 221 if (result.success()) { | 244 if (result.success()) { |
| 222 VLOG(1) << result.error_message; | 245 VLOG(1) << result.error_message; |
| 246 if (!VerifyChannelPolicy(result)) { | |
| 247 return false; | |
| 248 } | |
| 223 } | 249 } |
| 224 logger_->LogSocketChallengeReplyEvent(channel_id_, result); | 250 logger_->LogSocketChallengeReplyEvent(channel_id_, result); |
| 225 return result.success(); | 251 return result.success(); |
| 226 } | 252 } |
| 227 | 253 |
| 228 void CastSocketImpl::SetTransportForTesting( | 254 void CastSocketImpl::SetTransportForTesting( |
| 229 scoped_ptr<CastTransport> transport) { | 255 scoped_ptr<CastTransport> transport) { |
| 230 transport_ = transport.Pass(); | 256 transport_ = transport.Pass(); |
| 231 } | 257 } |
| 232 | 258 |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 void CastSocketImpl::SetErrorState(ChannelError error_state) { | 586 void CastSocketImpl::SetErrorState(ChannelError error_state) { |
| 561 VLOG_WITH_CONNECTION(1) << "SetErrorState " << error_state; | 587 VLOG_WITH_CONNECTION(1) << "SetErrorState " << error_state; |
| 562 DCHECK_EQ(CHANNEL_ERROR_NONE, error_state_); | 588 DCHECK_EQ(CHANNEL_ERROR_NONE, error_state_); |
| 563 error_state_ = error_state; | 589 error_state_ = error_state; |
| 564 logger_->LogSocketErrorState(channel_id_, ErrorStateToProto(error_state_)); | 590 logger_->LogSocketErrorState(channel_id_, ErrorStateToProto(error_state_)); |
| 565 } | 591 } |
| 566 } // namespace cast_channel | 592 } // namespace cast_channel |
| 567 } // namespace core_api | 593 } // namespace core_api |
| 568 } // namespace extensions | 594 } // namespace extensions |
| 569 #undef VLOG_WITH_CONNECTION | 595 #undef VLOG_WITH_CONNECTION |
| OLD | NEW |