OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_API_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ |
6 #define EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ | 6 #define EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 28 matching lines...) Expand all Loading... |
39 class CastChannelAPI : public BrowserContextKeyedAPI, | 39 class CastChannelAPI : public BrowserContextKeyedAPI, |
40 public base::SupportsWeakPtr<CastChannelAPI> { | 40 public base::SupportsWeakPtr<CastChannelAPI> { |
41 public: | 41 public: |
42 explicit CastChannelAPI(content::BrowserContext* context); | 42 explicit CastChannelAPI(content::BrowserContext* context); |
43 | 43 |
44 static CastChannelAPI* Get(content::BrowserContext* context); | 44 static CastChannelAPI* Get(content::BrowserContext* context); |
45 | 45 |
46 // BrowserContextKeyedAPI implementation. | 46 // BrowserContextKeyedAPI implementation. |
47 static BrowserContextKeyedAPIFactory<CastChannelAPI>* GetFactoryInstance(); | 47 static BrowserContextKeyedAPIFactory<CastChannelAPI>* GetFactoryInstance(); |
48 | 48 |
49 // Returns a pointer to the Logger member variable. | |
50 // TODO(imcheng): Consider whether it is possible for this class to own the | |
51 // CastSockets and make this class the sole owner of Logger. | |
52 // Alternatively, | |
53 // consider making Logger not ref-counted by passing a weak | |
54 // reference of Logger to the CastSockets instead. | |
55 scoped_refptr<cast_channel::Logger> GetLogger(); | |
56 | |
57 // Sets the CastSocket instance to be used for testing. | 49 // Sets the CastSocket instance to be used for testing. |
58 void SetSocketForTest( | 50 void SetSocketForTest( |
59 std::unique_ptr<cast_channel::CastSocket> socket_for_test); | 51 std::unique_ptr<cast_channel::CastSocket> socket_for_test); |
60 | 52 |
61 // Returns a test CastSocket instance, if it is defined. | 53 // Returns a test CastSocket instance, if it is defined. |
62 // Otherwise returns a scoped_ptr with a nullptr value. | 54 // Otherwise returns a scoped_ptr with a nullptr value. |
63 std::unique_ptr<cast_channel::CastSocket> GetSocketForTest(); | 55 std::unique_ptr<cast_channel::CastSocket> GetSocketForTest(); |
64 | 56 |
65 // Returns the API browser context. | 57 // Returns the API browser context. |
66 content::BrowserContext* GetBrowserContext() const; | 58 content::BrowserContext* GetBrowserContext() const; |
67 | 59 |
68 // Sends an event to the extension's EventRouter, if it exists. | 60 // Sends an event to the extension's EventRouter, if it exists. |
69 void SendEvent(const std::string& extension_id, std::unique_ptr<Event> event); | 61 void SendEvent(const std::string& extension_id, std::unique_ptr<Event> event); |
70 | 62 |
71 private: | 63 private: |
72 friend class BrowserContextKeyedAPIFactory<CastChannelAPI>; | 64 friend class BrowserContextKeyedAPIFactory<CastChannelAPI>; |
73 friend class ::CastChannelAPITest; | 65 friend class ::CastChannelAPITest; |
74 friend class CastTransportDelegate; | 66 friend class CastTransportDelegate; |
75 | 67 |
76 ~CastChannelAPI() override; | 68 ~CastChannelAPI() override; |
77 | 69 |
78 // BrowserContextKeyedAPI implementation. | 70 // BrowserContextKeyedAPI implementation. |
79 static const char* service_name() { return "CastChannelAPI"; } | 71 static const char* service_name() { return "CastChannelAPI"; } |
80 | 72 |
81 content::BrowserContext* const browser_context_; | 73 content::BrowserContext* const browser_context_; |
82 scoped_refptr<cast_channel::Logger> logger_; | |
83 std::unique_ptr<cast_channel::CastSocket> socket_for_test_; | 74 std::unique_ptr<cast_channel::CastSocket> socket_for_test_; |
84 | 75 |
85 DISALLOW_COPY_AND_ASSIGN(CastChannelAPI); | 76 DISALLOW_COPY_AND_ASSIGN(CastChannelAPI); |
86 }; | 77 }; |
87 | 78 |
88 class CastChannelAsyncApiFunction : public AsyncApiFunction { | 79 class CastChannelAsyncApiFunction : public AsyncApiFunction { |
89 public: | 80 public: |
90 CastChannelAsyncApiFunction(); | 81 CastChannelAsyncApiFunction(); |
91 | 82 |
92 protected: | 83 protected: |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 scoped_refptr<cast_channel::Logger> logger_; | 147 scoped_refptr<cast_channel::Logger> logger_; |
157 | 148 |
158 DISALLOW_COPY_AND_ASSIGN(CastMessageHandler); | 149 DISALLOW_COPY_AND_ASSIGN(CastMessageHandler); |
159 }; | 150 }; |
160 | 151 |
161 // Validates that |connect_info| represents a valid IP end point and returns a | 152 // Validates that |connect_info| represents a valid IP end point and returns a |
162 // new IPEndPoint if so. Otherwise returns nullptr. | 153 // new IPEndPoint if so. Otherwise returns nullptr. |
163 static net::IPEndPoint* ParseConnectInfo( | 154 static net::IPEndPoint* ParseConnectInfo( |
164 const api::cast_channel::ConnectInfo& connect_info); | 155 const api::cast_channel::ConnectInfo& connect_info); |
165 | 156 |
166 void OnOpen(cast_channel::ChannelError result); | 157 void OnOpen(int channel_id, cast_channel::ChannelError result); |
167 | 158 |
168 std::unique_ptr<api::cast_channel::Open::Params> params_; | 159 std::unique_ptr<api::cast_channel::Open::Params> params_; |
169 // The id of the newly opened socket. | |
170 int new_channel_id_; | |
171 CastChannelAPI* api_; | 160 CastChannelAPI* api_; |
172 std::unique_ptr<net::IPEndPoint> ip_endpoint_; | 161 std::unique_ptr<net::IPEndPoint> ip_endpoint_; |
173 base::TimeDelta liveness_timeout_; | 162 base::TimeDelta liveness_timeout_; |
174 base::TimeDelta ping_interval_; | 163 base::TimeDelta ping_interval_; |
175 | 164 |
176 FRIEND_TEST_ALL_PREFIXES(CastChannelOpenFunctionTest, TestParseConnectInfo); | 165 FRIEND_TEST_ALL_PREFIXES(CastChannelOpenFunctionTest, TestParseConnectInfo); |
177 DISALLOW_COPY_AND_ASSIGN(CastChannelOpenFunction); | 166 DISALLOW_COPY_AND_ASSIGN(CastChannelOpenFunction); |
178 }; | 167 }; |
179 | 168 |
180 class CastChannelSendFunction : public CastChannelAsyncApiFunction { | 169 class CastChannelSendFunction : public CastChannelAsyncApiFunction { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 206 |
218 std::unique_ptr<api::cast_channel::Close::Params> params_; | 207 std::unique_ptr<api::cast_channel::Close::Params> params_; |
219 CastChannelAPI* api_; | 208 CastChannelAPI* api_; |
220 | 209 |
221 DISALLOW_COPY_AND_ASSIGN(CastChannelCloseFunction); | 210 DISALLOW_COPY_AND_ASSIGN(CastChannelCloseFunction); |
222 }; | 211 }; |
223 | 212 |
224 } // namespace extensions | 213 } // namespace extensions |
225 | 214 |
226 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ | 215 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ |
OLD | NEW |