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) | |
101 : ApiResource(owner_extension_id) { | |
102 } | |
103 | |
104 bool CastSocket::IsPersistent() const { | |
105 return true; | |
106 } | |
107 | |
108 CastSocketImpl::CastSocketImpl(const std::string& owner_extension_id, | 88 CastSocketImpl::CastSocketImpl(const std::string& owner_extension_id, |
109 const net::IPEndPoint& ip_endpoint, | 89 const net::IPEndPoint& ip_endpoint, |
110 ChannelAuthType channel_auth, | 90 ChannelAuthType channel_auth, |
111 net::NetLog* net_log, | 91 net::NetLog* net_log, |
112 const base::TimeDelta& timeout, | 92 const base::TimeDelta& timeout, |
113 bool keep_alive, | 93 bool keep_alive, |
114 const scoped_refptr<Logger>& logger, | 94 const scoped_refptr<Logger>& logger, |
115 uint64_t device_capabilities) | 95 uint64_t device_capabilities) |
116 : CastSocketImpl(owner_extension_id, | 96 : CastSocketImpl(owner_extension_id, |
117 ip_endpoint, | 97 ip_endpoint, |
118 channel_auth, | 98 channel_auth, |
119 net_log, | 99 net_log, |
120 timeout, | 100 timeout, |
121 keep_alive, | 101 keep_alive, |
122 logger, | 102 logger, |
123 device_capabilities, | 103 device_capabilities, |
124 AuthContext::Create()) {} | 104 AuthContext::Create()) {} |
125 | 105 |
126 CastSocketImpl::CastSocketImpl(const std::string& owner_extension_id, | 106 CastSocketImpl::CastSocketImpl(const std::string& owner_extension_id, |
127 const net::IPEndPoint& ip_endpoint, | 107 const net::IPEndPoint& ip_endpoint, |
128 ChannelAuthType channel_auth, | 108 ChannelAuthType channel_auth, |
129 net::NetLog* net_log, | 109 net::NetLog* net_log, |
130 const base::TimeDelta& timeout, | 110 const base::TimeDelta& timeout, |
131 bool keep_alive, | 111 bool keep_alive, |
132 const scoped_refptr<Logger>& logger, | 112 const scoped_refptr<Logger>& logger, |
133 uint64_t device_capabilities, | 113 uint64_t device_capabilities, |
134 const AuthContext& auth_context) | 114 const AuthContext& auth_context) |
135 : CastSocket(owner_extension_id), | 115 : channel_id_(0), |
136 owner_extension_id_(owner_extension_id), | |
137 channel_id_(0), | |
138 ip_endpoint_(ip_endpoint), | 116 ip_endpoint_(ip_endpoint), |
139 channel_auth_(channel_auth), | 117 channel_auth_(channel_auth), |
140 net_log_(net_log), | 118 net_log_(net_log), |
141 keep_alive_(keep_alive), | 119 keep_alive_(keep_alive), |
142 logger_(logger), | 120 logger_(logger), |
143 auth_context_(auth_context), | 121 auth_context_(auth_context), |
144 connect_timeout_(timeout), | 122 connect_timeout_(timeout), |
145 connect_timeout_timer_(new base::OneShotTimer), | 123 connect_timeout_timer_(new base::OneShotTimer), |
146 is_canceled_(false), | 124 is_canceled_(false), |
147 device_capabilities_(device_capabilities), | 125 device_capabilities_(device_capabilities), |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 VLOG_WITH_CONNECTION(1) << "SetErrorState " << error_state; | 601 VLOG_WITH_CONNECTION(1) << "SetErrorState " << error_state; |
624 DCHECK_EQ(CHANNEL_ERROR_NONE, error_state_); | 602 DCHECK_EQ(CHANNEL_ERROR_NONE, error_state_); |
625 error_state_ = error_state; | 603 error_state_ = error_state; |
626 delegate_->OnError(error_state_); | 604 delegate_->OnError(error_state_); |
627 } | 605 } |
628 | 606 |
629 } // namespace cast_channel | 607 } // namespace cast_channel |
630 } // namespace api | 608 } // namespace api |
631 } // namespace extensions | 609 } // namespace extensions |
632 #undef VLOG_WITH_CONNECTION | 610 #undef VLOG_WITH_CONNECTION |
OLD | NEW |