| 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 // Returns an observer corresponding to |id|. |
| 40 CastSocket::Observer* GetObserver(const std::string& id); |
| 41 |
| 42 // Adds |observer| to |socket_observer_map_| keyed by |id|. Return raw pointer |
| 43 // of the newly added observer. |
| 44 CastSocket::Observer* AddObserver( |
| 45 const std::string& id, |
| 46 std::unique_ptr<CastSocket::Observer> observer); |
| 47 |
| 39 private: | 48 private: |
| 40 ~CastSocketService() override; | 49 ~CastSocketService() override; |
| 41 | 50 |
| 42 // RefcountedKeyedService implementation. | 51 // RefcountedKeyedService implementation. |
| 43 void ShutdownOnUIThread() override; | 52 void ShutdownOnUIThread() override; |
| 44 | 53 |
| 45 // Used to generate CastSocket id. | 54 // Used to generate CastSocket id. |
| 46 static int last_channel_id_; | 55 static int last_channel_id_; |
| 47 | 56 |
| 48 // The collection of CastSocket keyed by channel_id. | 57 // The collection of CastSocket keyed by channel_id. |
| 49 std::map<int, std::unique_ptr<CastSocket>> sockets_; | 58 std::map<int, std::unique_ptr<CastSocket>> sockets_; |
| 50 | 59 |
| 60 // Map of CastSocket::Observer keyed by observer id. For extension side |
| 61 // observers, id is extension_id; For browser side observers, id is a hard |
| 62 // coded string. |
| 63 std::map<std::string, std::unique_ptr<CastSocket::Observer>> |
| 64 socket_observer_map_; |
| 65 |
| 51 THREAD_CHECKER(thread_checker_); | 66 THREAD_CHECKER(thread_checker_); |
| 52 | 67 |
| 53 DISALLOW_COPY_AND_ASSIGN(CastSocketService); | 68 DISALLOW_COPY_AND_ASSIGN(CastSocketService); |
| 54 }; | 69 }; |
| 55 | 70 |
| 56 } // namespace cast_channel | 71 } // namespace cast_channel |
| 57 | 72 |
| 58 #endif // COMPONENTS_CAST_CHANNEL_CAST_CHANNEL_SERVICE_H_ | 73 #endif // COMPONENTS_CAST_CHANNEL_CAST_CHANNEL_SERVICE_H_ |
| OLD | NEW |