Chromium Code Reviews| 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 18 matching lines...) Expand all Loading... | |
| 29 int AddSocket(std::unique_ptr<CastSocket> socket); | 29 int AddSocket(std::unique_ptr<CastSocket> socket); |
| 30 | 30 |
| 31 // Removes the CastSocket corresponding to |channel_id| from the | 31 // Removes the CastSocket corresponding to |channel_id| from the |
| 32 // CastSocketRegistry. Returns nullptr if no such CastSocket exists. | 32 // CastSocketRegistry. Returns nullptr if no such CastSocket exists. |
| 33 std::unique_ptr<CastSocket> RemoveSocket(int channel_id); | 33 std::unique_ptr<CastSocket> RemoveSocket(int channel_id); |
| 34 | 34 |
| 35 // Returns the socket corresponding to |channel_id| if one exists, or nullptr | 35 // Returns the socket corresponding to |channel_id| if one exists, or nullptr |
| 36 // otherwise. | 36 // otherwise. |
| 37 CastSocket* GetSocket(int channel_id) const; | 37 CastSocket* GetSocket(int channel_id) const; |
| 38 | 38 |
| 39 CastSocket* GetSocket(const net::IPEndPoint& ip_endpoint) const; | |
| 40 | |
| 41 // Opens cast socket with |ip_endpoint| and invokes |open_cb| when opening | |
| 42 // operation finishes. If cast socket with |ip_endpoint| already exists, | |
| 43 // invoke |open_cb| directly with existing socket's channel ID. | |
| 44 // Parameters: | |
| 45 // |ip_endpoint|: IP address of the remote host. | |
|
mark a. foltz
2017/06/21 17:41:42
Nit: an endpoint is both an address and a port
zhaobin
2017/06/21 21:58:25
Done.
| |
| 46 // |channel_auth|: Authentication method used for connecting to a Cast | |
|
mark a. foltz
2017/06/21 17:41:42
Remove this comment
zhaobin
2017/06/21 21:58:26
Done.
| |
| 47 // receiver. | |
| 48 // |net_log|: Log of socket events. | |
| 49 // |connect_timeout|: Connection timeout interval. | |
| 50 // |liveness_timeout|: Liveness timeout for connect calls. | |
| 51 // |ping_interval|: Ping interval. | |
| 52 // |logger|: Log of cast channel events. | |
| 53 // |device_capabilities|: Device capabilities. | |
| 54 // |open_cb|: Invoked when cast socket opens. | |
|
mark a. foltz
2017/06/21 17:41:42
Nit: OnOpenCallback invoked when cast socket is op
zhaobin
2017/06/21 21:58:26
Done.
| |
| 55 int OpenSocket(const net::IPEndPoint& ip_endpoint, | |
| 56 net::NetLog* net_log, | |
| 57 const base::TimeDelta& connect_timeout, | |
| 58 const base::TimeDelta& liveness_timeout, | |
| 59 const base::TimeDelta& ping_interval, | |
| 60 const scoped_refptr<Logger>& logger, | |
| 61 uint64_t device_capabilities, | |
| 62 const CastSocket::OnOpenCallback& open_cb, | |
| 63 CastSocket::Observer* observer); | |
|
mark a. foltz
2017/06/21 17:41:42
Please document |observer|.
Is ownership taken?
zhaobin
2017/06/21 21:58:25
No.
zhaobin
2017/06/21 21:58:25
Done.
| |
| 64 | |
| 65 // Opens cast socket with |ip_endpoint| and invokes |open_cb| when opening | |
| 66 // operation finishes. If cast socket with |ip_endpoint| already exists, | |
| 67 // invoke |open_cb| directly with existing socket's channel ID. | |
| 68 // |ip_endpoint|: IP endpoint to be connected to. | |
| 69 // |net_log|: Net log passed to cast socket. | |
| 70 // |open_cb|: first parameter is channel id of newly created socket; second | |
|
mark a. foltz
2017/06/21 17:41:42
Can the parameter comments here be copied from abo
zhaobin
2017/06/21 21:58:25
Done.
| |
| 71 // parameter is channel error encountered during channel opening. | |
| 72 int OpenSocket(const net::IPEndPoint& ip_endpoint, | |
|
mark a. foltz
2017/06/21 17:41:42
Is this ctor invoked anywhere outside of tests?
Ma
zhaobin
2017/06/21 21:58:26
CastMediaSinkService will call this in https://cod
| |
| 73 net::NetLog* net_log, | |
| 74 const CastSocket::OnOpenCallback& open_cb, | |
| 75 CastSocket::Observer* observer); | |
| 76 | |
| 39 // Returns an observer corresponding to |id|. | 77 // Returns an observer corresponding to |id|. |
| 40 CastSocket::Observer* GetObserver(const std::string& id); | 78 CastSocket::Observer* GetObserver(const std::string& id); |
| 41 | 79 |
| 42 // Adds |observer| to |socket_observer_map_| keyed by |id|. | 80 // Adds |observer| to |socket_observer_map_| keyed by |id|. |
| 43 void AddObserver(const std::string& id, | 81 void AddObserver(const std::string& id, |
| 44 std::unique_ptr<CastSocket::Observer> observer); | 82 std::unique_ptr<CastSocket::Observer> observer); |
| 45 | 83 |
| 84 void SetSocketForTest( | |
|
mark a. foltz
2017/06/21 17:41:42
Please document this method
zhaobin
2017/06/21 21:58:26
Done.
| |
| 85 std::unique_ptr<cast_channel::CastSocket> socket_for_test); | |
|
mark a. foltz
2017/06/21 17:41:42
Don't need cast_channel:: here and below
zhaobin
2017/06/21 21:58:26
Done.
| |
| 86 | |
| 46 private: | 87 private: |
| 47 ~CastSocketService() override; | 88 ~CastSocketService() override; |
| 48 | 89 |
| 49 // RefcountedKeyedService implementation. | 90 // RefcountedKeyedService implementation. |
| 50 void ShutdownOnUIThread() override; | 91 void ShutdownOnUIThread() override; |
| 51 | 92 |
| 52 // Used to generate CastSocket id. | 93 // Used to generate CastSocket id. |
| 53 static int last_channel_id_; | 94 static int last_channel_id_; |
| 54 | 95 |
| 55 // The collection of CastSocket keyed by channel_id. | 96 // The collection of CastSocket keyed by channel_id. |
| 56 std::map<int, std::unique_ptr<CastSocket>> sockets_; | 97 std::map<int, std::unique_ptr<CastSocket>> sockets_; |
| 57 | 98 |
| 58 // Map of CastSocket::Observer keyed by observer id. For extension side | 99 // Map of CastSocket::Observer keyed by observer id. For extension side |
| 59 // observers, id is extension_id; For browser side observers, id is a hard | 100 // observers, id is extension_id; For browser side observers, id is a hard |
| 60 // coded string. | 101 // coded string. |
| 61 std::map<std::string, std::unique_ptr<CastSocket::Observer>> | 102 std::map<std::string, std::unique_ptr<CastSocket::Observer>> |
| 62 socket_observer_map_; | 103 socket_observer_map_; |
| 63 | 104 |
| 105 scoped_refptr<cast_channel::Logger> logger_; | |
| 106 | |
| 107 std::unique_ptr<cast_channel::CastSocket> socket_for_test_; | |
| 108 | |
| 64 THREAD_CHECKER(thread_checker_); | 109 THREAD_CHECKER(thread_checker_); |
| 65 | 110 |
| 66 DISALLOW_COPY_AND_ASSIGN(CastSocketService); | 111 DISALLOW_COPY_AND_ASSIGN(CastSocketService); |
| 67 }; | 112 }; |
| 68 | 113 |
| 69 } // namespace cast_channel | 114 } // namespace cast_channel |
| 70 | 115 |
| 71 #endif // COMPONENTS_CAST_CHANNEL_CAST_CHANNEL_SERVICE_H_ | 116 #endif // COMPONENTS_CAST_CHANNEL_CAST_CHANNEL_SERVICE_H_ |
| OLD | NEW |