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 #ifndef EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_SOCKET_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_SOCKET_H_ |
6 #define EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_SOCKET_H_ | 6 #define EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_SOCKET_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 } | 35 } |
36 | 36 |
37 namespace extensions { | 37 namespace extensions { |
38 namespace core_api { | 38 namespace core_api { |
39 namespace cast_channel { | 39 namespace cast_channel { |
40 class CastMessage; | 40 class CastMessage; |
41 class Logger; | 41 class Logger; |
42 struct LastErrors; | 42 struct LastErrors; |
43 class MessageFramer; | 43 class MessageFramer; |
44 | 44 |
| 45 // Cast device capabilities. |
| 46 enum CastDeviceCapability { |
| 47 NONE = 0, |
| 48 VIDEO_OUT = 1 << 0, |
| 49 VIDEO_IN = 1 << 1, |
| 50 AUDIO_OUT = 1 << 2, |
| 51 AUDIO_IN = 1 << 3, |
| 52 DEV_MODE = 1 << 4 |
| 53 }; |
| 54 |
45 // Public interface of the CastSocket class. | 55 // Public interface of the CastSocket class. |
46 class CastSocket : public ApiResource { | 56 class CastSocket : public ApiResource { |
47 public: | 57 public: |
48 explicit CastSocket(const std::string& owner_extension_id); | 58 explicit CastSocket(const std::string& owner_extension_id); |
49 ~CastSocket() override {} | 59 ~CastSocket() override {} |
50 | 60 |
51 // Used by BrowserContextKeyedAPIFactory. | 61 // Used by BrowserContextKeyedAPIFactory. |
52 static const char* service_name() { return "CastSocketImplManager"; } | 62 static const char* service_name() { return "CastSocketImplManager"; } |
53 | 63 |
54 // Connects the channel to the peer. If successful, the channel will be in | 64 // Connects the channel to the peer. If successful, the channel will be in |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 // |channel_auth|: Authentication method used for connecting to a Cast | 128 // |channel_auth|: Authentication method used for connecting to a Cast |
119 // receiver. | 129 // receiver. |
120 // |net_log|: Log of socket events. | 130 // |net_log|: Log of socket events. |
121 // |connect_timeout|: Connection timeout interval. | 131 // |connect_timeout|: Connection timeout interval. |
122 // |logger|: Log of cast channel events. | 132 // |logger|: Log of cast channel events. |
123 CastSocketImpl(const std::string& owner_extension_id, | 133 CastSocketImpl(const std::string& owner_extension_id, |
124 const net::IPEndPoint& ip_endpoint, | 134 const net::IPEndPoint& ip_endpoint, |
125 ChannelAuthType channel_auth, | 135 ChannelAuthType channel_auth, |
126 net::NetLog* net_log, | 136 net::NetLog* net_log, |
127 const base::TimeDelta& connect_timeout, | 137 const base::TimeDelta& connect_timeout, |
128 const scoped_refptr<Logger>& logger); | 138 const scoped_refptr<Logger>& logger, |
| 139 long device_capabilities); |
129 | 140 |
130 // Ensures that the socket is closed. | 141 // Ensures that the socket is closed. |
131 ~CastSocketImpl() override; | 142 ~CastSocketImpl() override; |
132 | 143 |
133 // CastSocket interface. | 144 // CastSocket interface. |
134 void Connect(scoped_ptr<CastTransport::Delegate> delegate, | 145 void Connect(scoped_ptr<CastTransport::Delegate> delegate, |
135 base::Callback<void(ChannelError)> callback) override; | 146 base::Callback<void(ChannelError)> callback) override; |
136 CastTransport* transport() const override; | 147 CastTransport* transport() const override; |
137 void Close(const net::CompletionCallback& callback) override; | 148 void Close(const net::CompletionCallback& callback) override; |
138 const net::IPEndPoint& ip_endpoint() const override; | 149 const net::IPEndPoint& ip_endpoint() const override; |
(...skipping 19 matching lines...) Expand all Loading... |
158 void OnMessage(const CastMessage& message) override; | 169 void OnMessage(const CastMessage& message) override; |
159 | 170 |
160 private: | 171 private: |
161 CastSocketImpl* socket_; | 172 CastSocketImpl* socket_; |
162 }; | 173 }; |
163 | 174 |
164 // Replaces the internally-constructed transport object with one provided | 175 // Replaces the internally-constructed transport object with one provided |
165 // by the caller (e.g. a mock). | 176 // by the caller (e.g. a mock). |
166 void SetTransportForTesting(scoped_ptr<CastTransport> transport); | 177 void SetTransportForTesting(scoped_ptr<CastTransport> transport); |
167 | 178 |
| 179 // Verifies whether the socket complies with cast channel policy. |
| 180 // Audio only channel policy mandates that a device declaring a video out |
| 181 // capability must not have a certificate with audio only policy. |
| 182 bool VerifyChannelPolicy(const AuthResult& result); |
| 183 |
168 // Delegate for receiving handshake messages/errors. | 184 // Delegate for receiving handshake messages/errors. |
169 AuthTransportDelegate auth_delegate_; | 185 AuthTransportDelegate auth_delegate_; |
170 | 186 |
171 private: | 187 private: |
172 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestConnectAuthMessageCorrupted); | 188 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestConnectAuthMessageCorrupted); |
173 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, | 189 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, |
174 TestConnectChallengeReplyReceiveError); | 190 TestConnectChallengeReplyReceiveError); |
175 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, | 191 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, |
176 TestConnectChallengeVerificationFails); | 192 TestConnectChallengeVerificationFails); |
177 friend class AuthTransportDelegate; | 193 friend class AuthTransportDelegate; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 // Duration to wait before timing out. | 303 // Duration to wait before timing out. |
288 base::TimeDelta connect_timeout_; | 304 base::TimeDelta connect_timeout_; |
289 | 305 |
290 // Timer invoked when the connection has timed out. | 306 // Timer invoked when the connection has timed out. |
291 scoped_ptr<base::Timer> connect_timeout_timer_; | 307 scoped_ptr<base::Timer> connect_timeout_timer_; |
292 | 308 |
293 // Set when a timeout is triggered and the connection process has | 309 // Set when a timeout is triggered and the connection process has |
294 // canceled. | 310 // canceled. |
295 bool is_canceled_; | 311 bool is_canceled_; |
296 | 312 |
| 313 // Capabilities declared by the cast device. |
| 314 long device_capabilities_; |
| 315 |
297 // Connection flow state machine state. | 316 // Connection flow state machine state. |
298 proto::ConnectionState connect_state_; | 317 proto::ConnectionState connect_state_; |
299 | 318 |
300 // Write flow state machine state. | 319 // Write flow state machine state. |
301 proto::WriteState write_state_; | 320 proto::WriteState write_state_; |
302 | 321 |
303 // Read flow state machine state. | 322 // Read flow state machine state. |
304 proto::ReadState read_state_; | 323 proto::ReadState read_state_; |
305 | 324 |
306 // The last error encountered by the channel. | 325 // The last error encountered by the channel. |
(...skipping 16 matching lines...) Expand all Loading... |
323 // Caller's message read and error handling delegate. | 342 // Caller's message read and error handling delegate. |
324 scoped_ptr<CastTransport::Delegate> read_delegate_; | 343 scoped_ptr<CastTransport::Delegate> read_delegate_; |
325 | 344 |
326 DISALLOW_COPY_AND_ASSIGN(CastSocketImpl); | 345 DISALLOW_COPY_AND_ASSIGN(CastSocketImpl); |
327 }; | 346 }; |
328 } // namespace cast_channel | 347 } // namespace cast_channel |
329 } // namespace core_api | 348 } // namespace core_api |
330 } // namespace extensions | 349 } // namespace extensions |
331 | 350 |
332 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_SOCKET_H_ | 351 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_SOCKET_H_ |
OLD | NEW |