OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/threading/thread_checker.h" | 10 #include "base/threading/thread_checker.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 virtual bool Prepare() OVERRIDE; | 130 virtual bool Prepare() OVERRIDE; |
131 virtual void AsyncWorkStart() OVERRIDE; | 131 virtual void AsyncWorkStart() OVERRIDE; |
132 | 132 |
133 private: | 133 private: |
134 DECLARE_EXTENSION_FUNCTION("cast.channel.open", CAST_CHANNEL_OPEN) | 134 DECLARE_EXTENSION_FUNCTION("cast.channel.open", CAST_CHANNEL_OPEN) |
135 | 135 |
136 // Parses the cast:// or casts:// |url|, fills |connect_info| with the | 136 // Parses the cast:// or casts:// |url|, fills |connect_info| with the |
137 // corresponding details, and returns true. Returns false if |url| is not a | 137 // corresponding details, and returns true. Returns false if |url| is not a |
138 // valid Cast URL. | 138 // valid Cast URL. |
139 static bool ParseChannelUrl(const GURL& url, | 139 static bool ParseChannelUrl(const GURL& url, |
140 api::cast_channel::ConnectInfo* connect_info); | 140 cast_channel::ConnectInfo* connect_info); |
141 | 141 |
142 // Validates that |connect_info| represents a valid IP end point and returns a | 142 // Validates that |connect_info| represents a valid IP end point and returns a |
143 // new IPEndPoint if so. Otherwise returns NULL. | 143 // new IPEndPoint if so. Otherwise returns NULL. |
144 static net::IPEndPoint* ParseConnectInfo( | 144 static net::IPEndPoint* ParseConnectInfo( |
145 const api::cast_channel::ConnectInfo& connect_info); | 145 const cast_channel::ConnectInfo& connect_info); |
146 | 146 |
147 void OnOpen(int result); | 147 void OnOpen(int result); |
148 | 148 |
149 scoped_ptr<cast_channel::Open::Params> params_; | 149 scoped_ptr<cast_channel::Open::Params> params_; |
150 // The id of the newly opened socket. | 150 // The id of the newly opened socket. |
151 int new_channel_id_; | 151 int new_channel_id_; |
152 CastChannelAPI* api_; | 152 CastChannelAPI* api_; |
153 scoped_ptr<api::cast_channel::ConnectInfo> connect_info_; | 153 scoped_ptr<cast_channel::ConnectInfo> connect_info_; |
154 scoped_ptr<net::IPEndPoint> ip_endpoint_; | 154 scoped_ptr<net::IPEndPoint> ip_endpoint_; |
155 api::cast_channel::ChannelAuthType channel_auth_; | 155 cast_channel::ChannelAuthType channel_auth_; |
156 | 156 |
157 FRIEND_TEST_ALL_PREFIXES(CastChannelOpenFunctionTest, TestParseChannelUrl); | 157 FRIEND_TEST_ALL_PREFIXES(CastChannelOpenFunctionTest, TestParseChannelUrl); |
158 FRIEND_TEST_ALL_PREFIXES(CastChannelOpenFunctionTest, TestParseConnectInfo); | 158 FRIEND_TEST_ALL_PREFIXES(CastChannelOpenFunctionTest, TestParseConnectInfo); |
| 159 FRIEND_TEST_ALL_PREFIXES(CastChannelOpenFunctionTest, TestPrepareValidUrl); |
| 160 FRIEND_TEST_ALL_PREFIXES(CastChannelOpenFunctionTest, TestPrepareInvalidUrl); |
| 161 FRIEND_TEST_ALL_PREFIXES(CastChannelOpenFunctionTest, |
| 162 TestPrepareValidConnectInfo); |
| 163 FRIEND_TEST_ALL_PREFIXES(CastChannelOpenFunctionTest, |
| 164 TestPrepareInvalidConnectInfo); |
159 DISALLOW_COPY_AND_ASSIGN(CastChannelOpenFunction); | 165 DISALLOW_COPY_AND_ASSIGN(CastChannelOpenFunction); |
160 }; | 166 }; |
161 | 167 |
162 class CastChannelSendFunction : public CastChannelAsyncApiFunction { | 168 class CastChannelSendFunction : public CastChannelAsyncApiFunction { |
163 public: | 169 public: |
164 CastChannelSendFunction(); | 170 CastChannelSendFunction(); |
165 | 171 |
166 protected: | 172 protected: |
167 virtual ~CastChannelSendFunction(); | 173 virtual ~CastChannelSendFunction(); |
168 | 174 |
169 // AsyncApiFunction: | 175 // AsyncApiFunction: |
170 virtual bool Prepare() OVERRIDE; | 176 virtual bool Prepare() OVERRIDE; |
171 virtual void AsyncWorkStart() OVERRIDE; | 177 virtual void AsyncWorkStart() OVERRIDE; |
172 | 178 |
173 private: | 179 private: |
174 DECLARE_EXTENSION_FUNCTION("cast.channel.send", CAST_CHANNEL_SEND) | 180 DECLARE_EXTENSION_FUNCTION("cast.channel.send", CAST_CHANNEL_SEND) |
175 | 181 |
176 void OnSend(int result); | 182 void OnSend(int result); |
177 | 183 |
178 scoped_ptr<cast_channel::Send::Params> params_; | 184 scoped_ptr<cast_channel::Send::Params> params_; |
179 | 185 |
| 186 FRIEND_TEST_ALL_PREFIXES(CastChannelSendFunctionTest, |
| 187 TestPrepareValidMessageInfo); |
| 188 FRIEND_TEST_ALL_PREFIXES(CastChannelSendFunctionTest, |
| 189 TestPrepareInvalidMessageInfo); |
180 DISALLOW_COPY_AND_ASSIGN(CastChannelSendFunction); | 190 DISALLOW_COPY_AND_ASSIGN(CastChannelSendFunction); |
181 }; | 191 }; |
182 | 192 |
183 class CastChannelCloseFunction : public CastChannelAsyncApiFunction { | 193 class CastChannelCloseFunction : public CastChannelAsyncApiFunction { |
184 public: | 194 public: |
185 CastChannelCloseFunction(); | 195 CastChannelCloseFunction(); |
186 | 196 |
187 protected: | 197 protected: |
188 virtual ~CastChannelCloseFunction(); | 198 virtual ~CastChannelCloseFunction(); |
189 | 199 |
190 // AsyncApiFunction: | 200 // AsyncApiFunction: |
191 virtual bool Prepare() OVERRIDE; | 201 virtual bool Prepare() OVERRIDE; |
192 virtual void AsyncWorkStart() OVERRIDE; | 202 virtual void AsyncWorkStart() OVERRIDE; |
193 | 203 |
194 private: | 204 private: |
195 DECLARE_EXTENSION_FUNCTION("cast.channel.close", CAST_CHANNEL_CLOSE) | 205 DECLARE_EXTENSION_FUNCTION("cast.channel.close", CAST_CHANNEL_CLOSE) |
196 | 206 |
197 void OnClose(int result); | 207 void OnClose(int result); |
198 | 208 |
199 scoped_ptr<cast_channel::Close::Params> params_; | 209 scoped_ptr<cast_channel::Close::Params> params_; |
200 | 210 |
201 DISALLOW_COPY_AND_ASSIGN(CastChannelCloseFunction); | 211 DISALLOW_COPY_AND_ASSIGN(CastChannelCloseFunction); |
202 }; | 212 }; |
203 | 213 |
204 } // namespace extensions | 214 } // namespace extensions |
205 | 215 |
206 #endif // CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ | 216 #endif // CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ |
OLD | NEW |