| 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> |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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() << ", auth=" << channel_auth_ << "] " | 54 "[" << ip_endpoint_.ToString() << ", auth=" << channel_auth_ << "] " |
| 55 #define VLOG_WITH_CONNECTION(level) VLOG(level) << CONNECTION_INFO() | 55 #define VLOG_WITH_CONNECTION(level) VLOG(level) << CONNECTION_INFO() |
| 56 #define LOG_WITH_CONNECTION(level) LOG(level) << CONNECTION_INFO() | 56 #define LOG_WITH_CONNECTION(level) LOG(level) << CONNECTION_INFO() |
| 57 | 57 |
| 58 namespace extensions { | 58 namespace extensions { |
| 59 static base::LazyInstance<BrowserContextKeyedAPIFactory< | |
| 60 ApiResourceManager<api::cast_channel::CastSocket>>>::DestructorAtExit | |
| 61 g_factory = LAZY_INSTANCE_INITIALIZER; | |
| 62 | |
| 63 // static | |
| 64 template <> | |
| 65 BrowserContextKeyedAPIFactory< | |
| 66 ApiResourceManager<api::cast_channel::CastSocket>>* | |
| 67 ApiResourceManager<api::cast_channel::CastSocket>::GetFactoryInstance() { | |
| 68 return g_factory.Pointer(); | |
| 69 } | |
| 70 | |
| 71 namespace api { | 59 namespace api { |
| 72 namespace cast_channel { | 60 namespace cast_channel { |
| 73 namespace { | 61 namespace { |
| 74 | 62 |
| 75 bool IsTerminalState(proto::ConnectionState state) { | 63 bool IsTerminalState(proto::ConnectionState state) { |
| 76 return state == proto::CONN_STATE_FINISHED || | 64 return state == proto::CONN_STATE_FINISHED || |
| 77 state == proto::CONN_STATE_ERROR || state == proto::CONN_STATE_TIMEOUT; | 65 state == proto::CONN_STATE_ERROR || state == proto::CONN_STATE_TIMEOUT; |
| 78 } | 66 } |
| 79 | 67 |
| 80 // Cert verifier which blindly accepts all certificates, regardless of validity. | 68 // Cert verifier which blindly accepts all certificates, regardless of validity. |
| 81 class FakeCertVerifier : public net::CertVerifier { | 69 class FakeCertVerifier : public net::CertVerifier { |
| 82 public: | 70 public: |
| 83 FakeCertVerifier() {} | 71 FakeCertVerifier() {} |
| 84 ~FakeCertVerifier() override {} | 72 ~FakeCertVerifier() override {} |
| 85 | 73 |
| 86 int Verify(const RequestParams& params, | 74 int Verify(const RequestParams& params, |
| 87 net::CRLSet*, | 75 net::CRLSet*, |
| 88 net::CertVerifyResult* verify_result, | 76 net::CertVerifyResult* verify_result, |
| 89 const net::CompletionCallback&, | 77 const net::CompletionCallback&, |
| 90 std::unique_ptr<Request>*, | 78 std::unique_ptr<Request>*, |
| 91 const net::NetLogWithSource&) override { | 79 const net::NetLogWithSource&) override { |
| 92 verify_result->Reset(); | 80 verify_result->Reset(); |
| 93 verify_result->verified_cert = params.certificate(); | 81 verify_result->verified_cert = params.certificate(); |
| 94 return net::OK; | 82 return net::OK; |
| 95 } | 83 } |
| 96 }; | 84 }; |
| 97 | 85 |
| 98 } // namespace | 86 } // namespace |
| 99 | 87 |
| 100 CastSocket::CastSocket(const std::string& owner_extension_id) | 88 CastSocket::CastSocket() {} |
| 101 : ApiResource(owner_extension_id) { | |
| 102 } | |
| 103 | |
| 104 bool CastSocket::IsPersistent() const { | |
| 105 return true; | |
| 106 } | |
| 107 | 89 |
| 108 CastSocketImpl::CastSocketImpl(const std::string& owner_extension_id, | 90 CastSocketImpl::CastSocketImpl(const std::string& owner_extension_id, |
| 109 const net::IPEndPoint& ip_endpoint, | 91 const net::IPEndPoint& ip_endpoint, |
| 110 ChannelAuthType channel_auth, | 92 ChannelAuthType channel_auth, |
| 111 net::NetLog* net_log, | 93 net::NetLog* net_log, |
| 112 const base::TimeDelta& timeout, | 94 const base::TimeDelta& timeout, |
| 113 bool keep_alive, | 95 bool keep_alive, |
| 114 const scoped_refptr<Logger>& logger, | 96 const scoped_refptr<Logger>& logger, |
| 115 uint64_t device_capabilities) | 97 uint64_t device_capabilities) |
| 116 : CastSocketImpl(owner_extension_id, | 98 : CastSocketImpl(owner_extension_id, |
| 117 ip_endpoint, | 99 ip_endpoint, |
| 118 channel_auth, | 100 channel_auth, |
| 119 net_log, | 101 net_log, |
| 120 timeout, | 102 timeout, |
| 121 keep_alive, | 103 keep_alive, |
| 122 logger, | 104 logger, |
| 123 device_capabilities, | 105 device_capabilities, |
| 124 AuthContext::Create()) {} | 106 AuthContext::Create()) {} |
| 125 | 107 |
| 126 CastSocketImpl::CastSocketImpl(const std::string& owner_extension_id, | 108 CastSocketImpl::CastSocketImpl(const std::string& owner_extension_id, |
| 127 const net::IPEndPoint& ip_endpoint, | 109 const net::IPEndPoint& ip_endpoint, |
| 128 ChannelAuthType channel_auth, | 110 ChannelAuthType channel_auth, |
| 129 net::NetLog* net_log, | 111 net::NetLog* net_log, |
| 130 const base::TimeDelta& timeout, | 112 const base::TimeDelta& timeout, |
| 131 bool keep_alive, | 113 bool keep_alive, |
| 132 const scoped_refptr<Logger>& logger, | 114 const scoped_refptr<Logger>& logger, |
| 133 uint64_t device_capabilities, | 115 uint64_t device_capabilities, |
| 134 const AuthContext& auth_context) | 116 const AuthContext& auth_context) |
| 135 : CastSocket(owner_extension_id), | 117 : owner_extension_id_(owner_extension_id), |
| 136 owner_extension_id_(owner_extension_id), | |
| 137 channel_id_(0), | 118 channel_id_(0), |
| 138 ip_endpoint_(ip_endpoint), | 119 ip_endpoint_(ip_endpoint), |
| 139 channel_auth_(channel_auth), | 120 channel_auth_(channel_auth), |
| 140 net_log_(net_log), | 121 net_log_(net_log), |
| 141 keep_alive_(keep_alive), | 122 keep_alive_(keep_alive), |
| 142 logger_(logger), | 123 logger_(logger), |
| 143 auth_context_(auth_context), | 124 auth_context_(auth_context), |
| 144 connect_timeout_(timeout), | 125 connect_timeout_(timeout), |
| 145 connect_timeout_timer_(new base::OneShotTimer), | 126 connect_timeout_timer_(new base::OneShotTimer), |
| 146 is_canceled_(false), | 127 is_canceled_(false), |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 } | 170 } |
| 190 | 171 |
| 191 bool CastSocketImpl::keep_alive() const { | 172 bool CastSocketImpl::keep_alive() const { |
| 192 return keep_alive_; | 173 return keep_alive_; |
| 193 } | 174 } |
| 194 | 175 |
| 195 bool CastSocketImpl::audio_only() const { | 176 bool CastSocketImpl::audio_only() const { |
| 196 return audio_only_; | 177 return audio_only_; |
| 197 } | 178 } |
| 198 | 179 |
| 180 const std::string& CastSocketImpl::owner_extension_id() const { |
| 181 return owner_extension_id_; |
| 182 } |
| 183 |
| 199 std::unique_ptr<net::TCPClientSocket> CastSocketImpl::CreateTcpSocket() { | 184 std::unique_ptr<net::TCPClientSocket> CastSocketImpl::CreateTcpSocket() { |
| 200 net::AddressList addresses(ip_endpoint_); | 185 net::AddressList addresses(ip_endpoint_); |
| 201 return std::unique_ptr<net::TCPClientSocket>( | 186 return std::unique_ptr<net::TCPClientSocket>( |
| 202 new net::TCPClientSocket(addresses, nullptr, net_log_, net_log_source_)); | 187 new net::TCPClientSocket(addresses, nullptr, net_log_, net_log_source_)); |
| 203 // Options cannot be set on the TCPClientSocket yet, because the | 188 // Options cannot be set on the TCPClientSocket yet, because the |
| 204 // underlying platform socket will not be created until Bind() | 189 // underlying platform socket will not be created until Bind() |
| 205 // or Connect() is called. | 190 // or Connect() is called. |
| 206 } | 191 } |
| 207 | 192 |
| 208 std::unique_ptr<net::SSLClientSocket> CastSocketImpl::CreateSslSocket( | 193 std::unique_ptr<net::SSLClientSocket> CastSocketImpl::CreateSslSocket( |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 VLOG_WITH_CONNECTION(1) << "SetErrorState " << error_state; | 608 VLOG_WITH_CONNECTION(1) << "SetErrorState " << error_state; |
| 624 DCHECK_EQ(CHANNEL_ERROR_NONE, error_state_); | 609 DCHECK_EQ(CHANNEL_ERROR_NONE, error_state_); |
| 625 error_state_ = error_state; | 610 error_state_ = error_state; |
| 626 delegate_->OnError(error_state_); | 611 delegate_->OnError(error_state_); |
| 627 } | 612 } |
| 628 | 613 |
| 629 } // namespace cast_channel | 614 } // namespace cast_channel |
| 630 } // namespace api | 615 } // namespace api |
| 631 } // namespace extensions | 616 } // namespace extensions |
| 632 #undef VLOG_WITH_CONNECTION | 617 #undef VLOG_WITH_CONNECTION |
| OLD | NEW |