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 EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_CHANNEL_SERVICE_H_ | 5 #ifndef COMPONENTS_CAST_CHANNEL_CAST_CHANNEL_SERVICE_H_ |
6 #define EXTENSIONS_BROWSER_API_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 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/threading/thread_checker.h" | 12 #include "base/threading/thread_checker.h" |
| 13 #include "components/cast_channel/cast_socket.h" |
13 #include "components/keyed_service/core/keyed_service.h" | 14 #include "components/keyed_service/core/keyed_service.h" |
14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
15 #include "extensions/browser/api/cast_channel/cast_socket.h" | |
16 | 16 |
17 namespace extensions { | |
18 namespace api { | |
19 namespace cast_channel { | 17 namespace cast_channel { |
20 | 18 |
21 // This class adds, removes, and returns cast sockets created by CastChannelAPI | 19 // This class adds, removes, and returns cast sockets created by CastChannelAPI |
22 // to underlying storage. | 20 // to underlying storage. |
23 // This class is not thread safe. All methods must be called from the IO thread. | 21 // This class is not thread safe. All methods must be called from the IO thread. |
24 class CastSocketRegistry { | 22 class CastSocketRegistry { |
25 public: | 23 public: |
| 24 using CastSocket = ::cast_channel::CastSocket; |
| 25 |
26 CastSocketRegistry(); | 26 CastSocketRegistry(); |
27 ~CastSocketRegistry(); | 27 ~CastSocketRegistry(); |
28 | 28 |
29 // Adds |socket| to |sockets_| and returns the new channel_id. Takes ownership | 29 // Adds |socket| to |sockets_| and returns the new channel_id. Takes ownership |
30 // of |socket|. | 30 // of |socket|. |
31 int AddSocket(std::unique_ptr<CastSocket> socket); | 31 int AddSocket(std::unique_ptr<CastSocket> socket); |
32 | 32 |
33 // Removes the CastSocket corresponding to |channel_id| from the | 33 // Removes the CastSocket corresponding to |channel_id| from the |
34 // CastSocketRegistry. Returns nullptr if no such CastSocket exists. | 34 // CastSocketRegistry. Returns nullptr if no such CastSocket exists. |
35 std::unique_ptr<CastSocket> RemoveSocket(int channel_id); | 35 std::unique_ptr<CastSocket> RemoveSocket(int channel_id); |
(...skipping 28 matching lines...) Expand all Loading... |
64 CastSocketRegistry* GetOrCreateSocketRegistry(); | 64 CastSocketRegistry* GetOrCreateSocketRegistry(); |
65 | 65 |
66 private: | 66 private: |
67 std::unique_ptr<CastSocketRegistry, content::BrowserThread::DeleteOnIOThread> | 67 std::unique_ptr<CastSocketRegistry, content::BrowserThread::DeleteOnIOThread> |
68 sockets_; | 68 sockets_; |
69 | 69 |
70 DISALLOW_COPY_AND_ASSIGN(CastSocketService); | 70 DISALLOW_COPY_AND_ASSIGN(CastSocketService); |
71 }; | 71 }; |
72 | 72 |
73 } // namespace cast_channel | 73 } // namespace cast_channel |
74 } // namespace api | |
75 } // namespace extensions | |
76 | 74 |
77 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_CHANNEL_SERVICE_H_ | 75 #endif // COMPONENTS_CAST_CHANNEL_CAST_CHANNEL_SERVICE_H_ |
OLD | NEW |