| 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 COMPONENTS_CAST_CHANNEL_CAST_SOCKET_H_ | 5 #ifndef COMPONENTS_CAST_CHANNEL_CAST_SOCKET_H_ |
| 6 #define COMPONENTS_CAST_CHANNEL_CAST_SOCKET_H_ | 6 #define COMPONENTS_CAST_CHANNEL_CAST_SOCKET_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <queue> | 10 #include <queue> |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 VIDEO_OUT = 1 << 0, | 49 VIDEO_OUT = 1 << 0, |
| 50 VIDEO_IN = 1 << 1, | 50 VIDEO_IN = 1 << 1, |
| 51 AUDIO_OUT = 1 << 2, | 51 AUDIO_OUT = 1 << 2, |
| 52 AUDIO_IN = 1 << 3, | 52 AUDIO_IN = 1 << 3, |
| 53 DEV_MODE = 1 << 4 | 53 DEV_MODE = 1 << 4 |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 // Public interface of the CastSocket class. | 56 // Public interface of the CastSocket class. |
| 57 class CastSocket { | 57 class CastSocket { |
| 58 public: | 58 public: |
| 59 using OnOpenCallback = |
| 60 base::Callback<void(int channel_id, ChannelError error_state)>; |
| 61 |
| 59 class Observer { | 62 class Observer { |
| 60 public: | 63 public: |
| 61 virtual ~Observer() {} | 64 virtual ~Observer() {} |
| 62 | 65 |
| 63 // Invoked when an error occurs on |socket|. | 66 // Invoked when an error occurs on |socket|. |
| 64 virtual void OnError(const CastSocket& socket, | 67 virtual void OnError(const CastSocket& socket, |
| 65 ChannelError error_state) = 0; | 68 ChannelError error_state) = 0; |
| 66 | 69 |
| 67 // Invoked when |socket| receives a message. | 70 // Invoked when |socket| receives a message. |
| 68 virtual void OnMessage(const CastSocket& socket, | 71 virtual void OnMessage(const CastSocket& socket, |
| 69 const CastMessage& message) = 0; | 72 const CastMessage& message) = 0; |
| 70 }; | 73 }; |
| 71 | 74 |
| 72 virtual ~CastSocket() {} | 75 virtual ~CastSocket() {} |
| 73 | 76 |
| 74 // Used by BrowserContextKeyedAPIFactory. | 77 // Used by BrowserContextKeyedAPIFactory. |
| 75 static const char* service_name() { return "CastSocketImplManager"; } | 78 static const char* service_name() { return "CastSocketImplManager"; } |
| 76 | 79 |
| 77 // Connects the channel to the peer. If successful, the channel will be in | 80 // Connects the channel to the peer. If successful, the channel will be in |
| 78 // READY_STATE_OPEN. DO NOT delete the CastSocket object in |callback|. | 81 // READY_STATE_OPEN. DO NOT delete the CastSocket object in |callback|. |
| 79 // Instead use Close(). | 82 // Instead use Close(). |
| 80 // |callback| will be invoked with any ChannelError that occurred, or | 83 // |callback| will be invoked with any ChannelError that occurred, or |
| 81 // CHANNEL_ERROR_NONE if successful. | 84 // CHANNEL_ERROR_NONE if successful. |
| 82 // If the CastSocket is destroyed while the connection is pending, |callback| | 85 // If the CastSocket is destroyed while the connection is pending, |callback| |
| 83 // will be invoked with CHANNEL_ERROR_UNKNOWN. In this case, invoking | 86 // will be invoked with CHANNEL_ERROR_UNKNOWN. In this case, invoking |
| 84 // |callback| must not result in any re-entrancy behavior. | 87 // |callback| must not result in any re-entrancy behavior. |
| 85 virtual void Connect(base::Callback<void(ChannelError)> callback) = 0; | 88 virtual void Connect(const OnOpenCallback& callback) = 0; |
| 86 | 89 |
| 87 // Closes the channel if not already closed. On completion, the channel will | 90 // Closes the channel if not already closed. On completion, the channel will |
| 88 // be in READY_STATE_CLOSED. | 91 // be in READY_STATE_CLOSED. |
| 89 // | 92 // |
| 90 // It is fine to delete this object in |callback|. | 93 // It is fine to delete this object in |callback|. |
| 91 virtual void Close(const net::CompletionCallback& callback) = 0; | 94 virtual void Close(const net::CompletionCallback& callback) = 0; |
| 92 | 95 |
| 93 // The IP endpoint for the destination of the channel. | 96 // The IP endpoint for the destination of the channel. |
| 94 virtual const net::IPEndPoint& ip_endpoint() const = 0; | 97 virtual const net::IPEndPoint& ip_endpoint() const = 0; |
| 95 | 98 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 base::TimeDelta liveness_timeout, | 163 base::TimeDelta liveness_timeout, |
| 161 base::TimeDelta ping_interval, | 164 base::TimeDelta ping_interval, |
| 162 const scoped_refptr<Logger>& logger, | 165 const scoped_refptr<Logger>& logger, |
| 163 uint64_t device_capabilities, | 166 uint64_t device_capabilities, |
| 164 const AuthContext& auth_context); | 167 const AuthContext& auth_context); |
| 165 | 168 |
| 166 // Ensures that the socket is closed. | 169 // Ensures that the socket is closed. |
| 167 ~CastSocketImpl() override; | 170 ~CastSocketImpl() override; |
| 168 | 171 |
| 169 // CastSocket interface. | 172 // CastSocket interface. |
| 170 void Connect(base::Callback<void(ChannelError)> callback) override; | 173 void Connect(const OnOpenCallback& callback) override; |
| 171 CastTransport* transport() const override; | 174 CastTransport* transport() const override; |
| 172 void Close(const net::CompletionCallback& callback) override; | 175 void Close(const net::CompletionCallback& callback) override; |
| 173 const net::IPEndPoint& ip_endpoint() const override; | 176 const net::IPEndPoint& ip_endpoint() const override; |
| 174 int id() const override; | 177 int id() const override; |
| 175 void set_id(int channel_id) override; | 178 void set_id(int channel_id) override; |
| 176 ReadyState ready_state() const override; | 179 ReadyState ready_state() const override; |
| 177 ChannelError error_state() const override; | 180 ChannelError error_state() const override; |
| 178 bool keep_alive() const override; | 181 bool keep_alive() const override; |
| 179 bool audio_only() const override; | 182 bool audio_only() const override; |
| 180 void AddObserver(Observer* observer) override; | 183 void AddObserver(Observer* observer) override; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 | 224 |
| 222 // Replaces the internally-constructed transport object with one provided | 225 // Replaces the internally-constructed transport object with one provided |
| 223 // by the caller (e.g. a mock). | 226 // by the caller (e.g. a mock). |
| 224 void SetTransportForTesting(std::unique_ptr<CastTransport> transport); | 227 void SetTransportForTesting(std::unique_ptr<CastTransport> transport); |
| 225 | 228 |
| 226 // Verifies whether the socket complies with cast channel policy. | 229 // Verifies whether the socket complies with cast channel policy. |
| 227 // Audio only channel policy mandates that a device declaring a video out | 230 // Audio only channel policy mandates that a device declaring a video out |
| 228 // capability must not have a certificate with audio only policy. | 231 // capability must not have a certificate with audio only policy. |
| 229 bool VerifyChannelPolicy(const AuthResult& result); | 232 bool VerifyChannelPolicy(const AuthResult& result); |
| 230 | 233 |
| 234 void Connect(); |
| 235 |
| 231 private: | 236 private: |
| 232 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestConnectAuthMessageCorrupted); | 237 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestConnectAuthMessageCorrupted); |
| 233 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, | 238 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, |
| 234 TestConnectChallengeReplyReceiveError); | 239 TestConnectChallengeReplyReceiveError); |
| 235 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, | 240 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, |
| 236 TestConnectChallengeVerificationFails); | 241 TestConnectChallengeVerificationFails); |
| 237 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestObservers); | 242 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestObservers); |
| 238 friend class AuthTransportDelegate; | 243 friend class AuthTransportDelegate; |
| 239 friend class CastSocketMessageDelegate; | 244 friend class CastSocketMessageDelegate; |
| 240 friend class CastSocketTest; | 245 friend class CastSocketTest; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 // Certificate of the peer. This field may be empty if the peer | 352 // Certificate of the peer. This field may be empty if the peer |
| 348 // certificate is not yet fetched. | 353 // certificate is not yet fetched. |
| 349 scoped_refptr<net::X509Certificate> peer_cert_; | 354 scoped_refptr<net::X509Certificate> peer_cert_; |
| 350 | 355 |
| 351 // The challenge context for the current connection. | 356 // The challenge context for the current connection. |
| 352 const AuthContext auth_context_; | 357 const AuthContext auth_context_; |
| 353 | 358 |
| 354 // Reply received from the receiver to a challenge request. | 359 // Reply received from the receiver to a challenge request. |
| 355 std::unique_ptr<CastMessage> challenge_reply_; | 360 std::unique_ptr<CastMessage> challenge_reply_; |
| 356 | 361 |
| 357 // Callback invoked when the socket is connected or fails to connect. | 362 // Callbacks invoked when the socket is connected or fails to connect. |
| 358 base::Callback<void(ChannelError)> connect_callback_; | 363 std::vector<OnOpenCallback> connect_callbacks_; |
| 359 | 364 |
| 360 // Callback invoked by |connect_timeout_timer_| to cancel the connection. | 365 // Callback invoked by |connect_timeout_timer_| to cancel the connection. |
| 361 base::CancelableClosure connect_timeout_callback_; | 366 base::CancelableClosure connect_timeout_callback_; |
| 362 | 367 |
| 363 // Duration to wait before timing out. | 368 // Duration to wait before timing out. |
| 364 base::TimeDelta connect_timeout_; | 369 base::TimeDelta connect_timeout_; |
| 365 | 370 |
| 366 // Timer invoked when the connection has timed out. | 371 // Timer invoked when the connection has timed out. |
| 367 std::unique_ptr<base::Timer> connect_timeout_timer_; | 372 std::unique_ptr<base::Timer> connect_timeout_timer_; |
| 368 | 373 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 AuthTransportDelegate* auth_delegate_; | 415 AuthTransportDelegate* auth_delegate_; |
| 411 | 416 |
| 412 // List of socket observers. | 417 // List of socket observers. |
| 413 base::ObserverList<Observer> observers_; | 418 base::ObserverList<Observer> observers_; |
| 414 | 419 |
| 415 DISALLOW_COPY_AND_ASSIGN(CastSocketImpl); | 420 DISALLOW_COPY_AND_ASSIGN(CastSocketImpl); |
| 416 }; | 421 }; |
| 417 } // namespace cast_channel | 422 } // namespace cast_channel |
| 418 | 423 |
| 419 #endif // COMPONENTS_CAST_CHANNEL_CAST_SOCKET_H_ | 424 #endif // COMPONENTS_CAST_CHANNEL_CAST_SOCKET_H_ |
| OLD | NEW |