| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_CHANNEL_SERVICE_H_ | 5 #ifndef COMPONENTS_CAST_CHANNEL_CAST_CHANNEL_SERVICE_H_ |
| 6 #define COMPONENTS_CAST_CHANNEL_CAST_CHANNEL_SERVICE_H_ | 6 #define COMPONENTS_CAST_CHANNEL_CAST_CHANNEL_SERVICE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 base::Callback<void(int channel_id, ChannelError error_state)>; | 53 base::Callback<void(int channel_id, ChannelError error_state)>; |
| 54 | 54 |
| 55 CastSocketService(); | 55 CastSocketService(); |
| 56 | 56 |
| 57 // Removes the CastSocket corresponding to |channel_id| from the | 57 // Removes the CastSocket corresponding to |channel_id| from the |
| 58 // CastSocketRegistry. Returns nullptr if no such CastSocket exists. | 58 // CastSocketRegistry. Returns nullptr if no such CastSocket exists. |
| 59 std::unique_ptr<CastSocket> RemoveSocket(int channel_id); | 59 std::unique_ptr<CastSocket> RemoveSocket(int channel_id); |
| 60 | 60 |
| 61 // Returns the socket corresponding to |channel_id| if one exists, or nullptr | 61 // Returns the socket corresponding to |channel_id| if one exists, or nullptr |
| 62 // otherwise. | 62 // otherwise. |
| 63 CastSocket* GetSocket(int channel_id) const; | 63 virtual CastSocket* GetSocket(int channel_id) const; |
| 64 | 64 |
| 65 // Opens cast socket with |ip_endpoint| and invokes |open_cb| when opening | 65 // Opens cast socket with |ip_endpoint| and invokes |open_cb| when opening |
| 66 // operation finishes. If cast socket with |ip_endpoint| already exists, | 66 // operation finishes. If cast socket with |ip_endpoint| already exists, |
| 67 // invoke |open_cb| directly with existing socket's channel ID. | 67 // invoke |open_cb| directly with existing socket's channel ID. |
| 68 // Parameters: | 68 // Parameters: |
| 69 // |ip_endpoint|: IP address of the remote host. | 69 // |ip_endpoint|: IP address of the remote host. |
| 70 // |channel_auth|: Authentication method used for connecting to a Cast | 70 // |channel_auth|: Authentication method used for connecting to a Cast |
| 71 // receiver. |channel_auth| must not be CHANNEL_AUTH_NONE. | 71 // receiver. |channel_auth| must not be CHANNEL_AUTH_NONE. |
| 72 // |net_log|: Log of socket events. | 72 // |net_log|: Log of socket events. |
| 73 // |connect_timeout|: Connection timeout interval. | 73 // |connect_timeout|: Connection timeout interval. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 86 uint64_t device_capabilities, | 86 uint64_t device_capabilities, |
| 87 const OnOpenCallback& open_cb); | 87 const OnOpenCallback& open_cb); |
| 88 | 88 |
| 89 // Opens cast socket with |ip_endpoint| and invokes |open_cb| when opening | 89 // Opens cast socket with |ip_endpoint| and invokes |open_cb| when opening |
| 90 // operation finishes. If cast socket with |ip_endpoint| already exists, | 90 // operation finishes. If cast socket with |ip_endpoint| already exists, |
| 91 // invoke |open_cb| directly with existing socket's channel ID. | 91 // invoke |open_cb| directly with existing socket's channel ID. |
| 92 // |ip_endpoint|: IP endpoint to be connected to. | 92 // |ip_endpoint|: IP endpoint to be connected to. |
| 93 // |net_log|: Net log passed to cast socket. | 93 // |net_log|: Net log passed to cast socket. |
| 94 // |open_cb|: first parameter is channel id of newly created socket; second | 94 // |open_cb|: first parameter is channel id of newly created socket; second |
| 95 // parameter is channel error encountered during channel opening. | 95 // parameter is channel error encountered during channel opening. |
| 96 int OpenSocket(const net::IPEndPoint& ip_endpoint, | 96 virtual int OpenSocket(const net::IPEndPoint& ip_endpoint, |
| 97 net::NetLog* net_log, | 97 net::NetLog* net_log, |
| 98 const OnOpenCallback& open_cb); | 98 const OnOpenCallback& open_cb); |
| 99 | 99 |
| 100 // Register read delegate to cast socket with |channel_id|. Returns false if | 100 // Register read delegate to cast socket with |channel_id|. Returns false if |
| 101 // such socket does not exist. | 101 // such socket does not exist. |
| 102 bool RegisterDelegate(int channel_id, | 102 bool RegisterDelegate(int channel_id, |
| 103 std::unique_ptr<CastTransport::Delegate> delegate); | 103 std::unique_ptr<CastTransport::Delegate> delegate); |
| 104 | 104 |
| 105 // Sets the CastSocket instance to be used for testing. | 105 // Sets the CastSocket instance to be used for testing. |
| 106 void SetSocketForTest( | 106 void SetSocketForTest( |
| 107 std::unique_ptr<cast_channel::CastSocket> socket_for_test); | 107 std::unique_ptr<cast_channel::CastSocket> socket_for_test); |
| 108 | 108 |
| 109 // Sets injected ping timeout timer for testing. | 109 // Sets injected ping timeout timer for testing. |
| 110 void SetPingTimeoutTimerForTest(std::unique_ptr<base::Timer> timer); | 110 void SetPingTimeoutTimerForTest(std::unique_ptr<base::Timer> timer); |
| 111 | 111 |
| 112 protected: |
| 113 ~CastSocketService() override; |
| 114 |
| 112 private: | 115 private: |
| 113 FRIEND_TEST_ALL_PREFIXES(CastSocketServiceTest, TestOpenChannel); | 116 FRIEND_TEST_ALL_PREFIXES(CastSocketServiceTest, TestOpenChannel); |
| 114 friend class CastSocketServiceTest; | 117 friend class CastSocketServiceTest; |
| 115 | 118 |
| 116 class CastSocketRecord { | 119 class CastSocketRecord { |
| 117 public: | 120 public: |
| 118 // Does not take ownership of |message_handler|. | 121 // Does not take ownership of |message_handler|. |
| 119 CastSocketRecord(std::unique_ptr<CastSocket> socket, | 122 CastSocketRecord(std::unique_ptr<CastSocket> socket, |
| 120 const OnOpenCallback& on_open_callback, | 123 const OnOpenCallback& on_open_callback, |
| 121 PassThroughMessageHandler* message_handler); | 124 PassThroughMessageHandler* message_handler); |
| 122 | 125 |
| 123 ~CastSocketRecord(); | 126 ~CastSocketRecord(); |
| 124 | 127 |
| 125 // Underlying cast socket. | 128 // Underlying cast socket. |
| 126 std::unique_ptr<CastSocket> cast_socket; | 129 std::unique_ptr<CastSocket> cast_socket; |
| 127 | 130 |
| 128 // Pending callbacks to be invoked when cast socket opens. | 131 // Pending callbacks to be invoked when cast socket opens. |
| 129 std::vector<OnOpenCallback> pending_on_open_callbacks; | 132 std::vector<OnOpenCallback> pending_on_open_callbacks; |
| 130 | 133 |
| 131 // Real read delegate for incoming errors and messages. Owned by |socket|'s | 134 // Real read delegate for incoming errors and messages. Owned by |socket|'s |
| 132 // keep alive delegate. | 135 // keep alive delegate. |
| 133 PassThroughMessageHandler* pass_through_message_handler; | 136 PassThroughMessageHandler* pass_through_message_handler; |
| 134 }; | 137 }; |
| 135 | 138 |
| 136 ~CastSocketService() override; | |
| 137 | |
| 138 // RefcountedKeyedService implementation. | 139 // RefcountedKeyedService implementation. |
| 139 void ShutdownOnUIThread() override; | 140 void ShutdownOnUIThread() override; |
| 140 | 141 |
| 141 // Creates a socket record, adds it to |socket_records_| and returns the | 142 // Creates a socket record, adds it to |socket_records_| and returns the |
| 142 // new channel_id. Takes ownership of |socket|. | 143 // new channel_id. Takes ownership of |socket|. |
| 143 // |socket|: Underlying cast socket. | 144 // |socket|: Underlying cast socket. |
| 144 // |on_open_callback|: Callback to be invoked when cast socket opens. | 145 // |on_open_callback|: Callback to be invoked when cast socket opens. |
| 145 // |message_handler|: Real read delegate for incoming errors and messages. | 146 // |message_handler|: Real read delegate for incoming errors and messages. |
| 146 // Does not take ownership of |message_handler|. | 147 // Does not take ownership of |message_handler|. |
| 147 int AddSocketRecord(std::unique_ptr<CastSocket> socket, | 148 int AddSocketRecord(std::unique_ptr<CastSocket> socket, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 175 std::unique_ptr<base::Timer> injected_timeout_timer_; | 176 std::unique_ptr<base::Timer> injected_timeout_timer_; |
| 176 | 177 |
| 177 THREAD_CHECKER(thread_checker_); | 178 THREAD_CHECKER(thread_checker_); |
| 178 | 179 |
| 179 DISALLOW_COPY_AND_ASSIGN(CastSocketService); | 180 DISALLOW_COPY_AND_ASSIGN(CastSocketService); |
| 180 }; | 181 }; |
| 181 | 182 |
| 182 } // namespace cast_channel | 183 } // namespace cast_channel |
| 183 | 184 |
| 184 #endif // COMPONENTS_CAST_CHANNEL_CAST_CHANNEL_SERVICE_H_ | 185 #endif // COMPONENTS_CAST_CHANNEL_CAST_CHANNEL_SERVICE_H_ |
| OLD | NEW |