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|. |
| 43 void AddObserver(const std::string& id, |
| 44 std::unique_ptr<CastSocket::Observer> observer); |
| 45 |
39 private: | 46 private: |
40 ~CastSocketService() override; | 47 ~CastSocketService() override; |
41 | 48 |
42 // RefcountedKeyedService implementation. | 49 // RefcountedKeyedService implementation. |
43 void ShutdownOnUIThread() override; | 50 void ShutdownOnUIThread() override; |
44 | 51 |
45 // Used to generate CastSocket id. | 52 // Used to generate CastSocket id. |
46 static int last_channel_id_; | 53 static int last_channel_id_; |
47 | 54 |
48 // The collection of CastSocket keyed by channel_id. | 55 // The collection of CastSocket keyed by channel_id. |
49 std::map<int, std::unique_ptr<CastSocket>> sockets_; | 56 std::map<int, std::unique_ptr<CastSocket>> sockets_; |
50 | 57 |
| 58 // 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 |
| 60 // coded string. |
| 61 std::map<std::string, std::unique_ptr<CastSocket::Observer>> |
| 62 socket_observer_map_; |
| 63 |
51 THREAD_CHECKER(thread_checker_); | 64 THREAD_CHECKER(thread_checker_); |
52 | 65 |
53 DISALLOW_COPY_AND_ASSIGN(CastSocketService); | 66 DISALLOW_COPY_AND_ASSIGN(CastSocketService); |
54 }; | 67 }; |
55 | 68 |
56 } // namespace cast_channel | 69 } // namespace cast_channel |
57 | 70 |
58 #endif // COMPONENTS_CAST_CHANNEL_CAST_CHANNEL_SERVICE_H_ | 71 #endif // COMPONENTS_CAST_CHANNEL_CAST_CHANNEL_SERVICE_H_ |
OLD | NEW |