| 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 <string> |
| 9 |
| 8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/threading/thread_checker.h" | 12 #include "base/threading/thread_checker.h" |
| 11 #include "chrome/browser/extensions/api/cast_channel/cast_socket.h" | 13 #include "chrome/browser/extensions/api/cast_channel/cast_socket.h" |
| 12 #include "chrome/common/extensions/api/cast_channel.h" | 14 #include "chrome/common/extensions/api/cast_channel.h" |
| 13 #include "extensions/browser/api/api_resource_manager.h" | 15 #include "extensions/browser/api/api_resource_manager.h" |
| 14 #include "extensions/browser/api/async_api_function.h" | 16 #include "extensions/browser/api/async_api_function.h" |
| 15 #include "extensions/browser/browser_context_keyed_api_factory.h" | 17 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 16 | 18 |
| 17 class GURL; | 19 class GURL; |
| 18 class CastChannelAPITest; | 20 class CastChannelAPITest; |
| 19 | 21 |
| 20 namespace content { | 22 namespace content { |
| 21 class BrowserContext; | 23 class BrowserContext; |
| 22 } | 24 } |
| 23 | 25 |
| 24 namespace net { | 26 namespace net { |
| 25 class IPEndPoint; | 27 class IPEndPoint; |
| 26 } | 28 } |
| 27 | 29 |
| 28 namespace extensions { | 30 namespace extensions { |
| 29 | 31 |
| 30 namespace cast_channel = api::cast_channel; | 32 namespace cast_channel = api::cast_channel; |
| 31 | 33 |
| 32 class CastChannelAPI : public BrowserContextKeyedAPI, | 34 class CastChannelAPI : public BrowserContextKeyedAPI, |
| 33 public cast_channel::CastSocket::Delegate { | 35 public cast_channel::CastSocket::Delegate { |
| 34 | |
| 35 public: | 36 public: |
| 36 explicit CastChannelAPI(content::BrowserContext* context); | 37 explicit CastChannelAPI(content::BrowserContext* context); |
| 37 | 38 |
| 38 static CastChannelAPI* Get(content::BrowserContext* context); | 39 static CastChannelAPI* Get(content::BrowserContext* context); |
| 39 | 40 |
| 40 // BrowserContextKeyedAPI implementation. | 41 // BrowserContextKeyedAPI implementation. |
| 41 static BrowserContextKeyedAPIFactory<CastChannelAPI>* GetFactoryInstance(); | 42 static BrowserContextKeyedAPIFactory<CastChannelAPI>* GetFactoryInstance(); |
| 42 | 43 |
| 43 // Returns a new CastSocket that connects to |ip_endpoint| with authentication | 44 // Returns a new CastSocket that connects to |ip_endpoint| with authentication |
| 44 // |channel_auth| and is to be owned by |extension_id|. | 45 // |channel_auth| and is to be owned by |extension_id|. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 virtual bool Prepare() OVERRIDE; | 131 virtual bool Prepare() OVERRIDE; |
| 131 virtual void AsyncWorkStart() OVERRIDE; | 132 virtual void AsyncWorkStart() OVERRIDE; |
| 132 | 133 |
| 133 private: | 134 private: |
| 134 DECLARE_EXTENSION_FUNCTION("cast.channel.open", CAST_CHANNEL_OPEN) | 135 DECLARE_EXTENSION_FUNCTION("cast.channel.open", CAST_CHANNEL_OPEN) |
| 135 | 136 |
| 136 // Parses the cast:// or casts:// |url|, fills |connect_info| with the | 137 // Parses the cast:// or casts:// |url|, fills |connect_info| with the |
| 137 // corresponding details, and returns true. Returns false if |url| is not a | 138 // corresponding details, and returns true. Returns false if |url| is not a |
| 138 // valid Cast URL. | 139 // valid Cast URL. |
| 139 static bool ParseChannelUrl(const GURL& url, | 140 static bool ParseChannelUrl(const GURL& url, |
| 140 api::cast_channel::ConnectInfo* connect_info); | 141 cast_channel::ConnectInfo* connect_info); |
| 141 | 142 |
| 142 // Validates that |connect_info| represents a valid IP end point and returns a | 143 // Validates that |connect_info| represents a valid IP end point and returns a |
| 143 // new IPEndPoint if so. Otherwise returns NULL. | 144 // new IPEndPoint if so. Otherwise returns NULL. |
| 144 static net::IPEndPoint* ParseConnectInfo( | 145 static net::IPEndPoint* ParseConnectInfo( |
| 145 const api::cast_channel::ConnectInfo& connect_info); | 146 const cast_channel::ConnectInfo& connect_info); |
| 146 | 147 |
| 147 void OnOpen(int result); | 148 void OnOpen(int result); |
| 148 | 149 |
| 149 scoped_ptr<cast_channel::Open::Params> params_; | 150 scoped_ptr<cast_channel::Open::Params> params_; |
| 150 // The id of the newly opened socket. | 151 // The id of the newly opened socket. |
| 151 int new_channel_id_; | 152 int new_channel_id_; |
| 152 CastChannelAPI* api_; | 153 CastChannelAPI* api_; |
| 153 scoped_ptr<api::cast_channel::ConnectInfo> connect_info_; | 154 scoped_ptr<cast_channel::ConnectInfo> connect_info_; |
| 154 scoped_ptr<net::IPEndPoint> ip_endpoint_; | 155 scoped_ptr<net::IPEndPoint> ip_endpoint_; |
| 155 api::cast_channel::ChannelAuthType channel_auth_; | 156 cast_channel::ChannelAuthType channel_auth_; |
| 156 | 157 |
| 157 FRIEND_TEST_ALL_PREFIXES(CastChannelOpenFunctionTest, TestParseChannelUrl); | 158 FRIEND_TEST_ALL_PREFIXES(CastChannelOpenFunctionTest, TestParseChannelUrl); |
| 158 FRIEND_TEST_ALL_PREFIXES(CastChannelOpenFunctionTest, TestParseConnectInfo); | 159 FRIEND_TEST_ALL_PREFIXES(CastChannelOpenFunctionTest, TestParseConnectInfo); |
| 159 DISALLOW_COPY_AND_ASSIGN(CastChannelOpenFunction); | 160 DISALLOW_COPY_AND_ASSIGN(CastChannelOpenFunction); |
| 160 }; | 161 }; |
| 161 | 162 |
| 162 class CastChannelSendFunction : public CastChannelAsyncApiFunction { | 163 class CastChannelSendFunction : public CastChannelAsyncApiFunction { |
| 163 public: | 164 public: |
| 164 CastChannelSendFunction(); | 165 CastChannelSendFunction(); |
| 165 | 166 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 void OnClose(int result); | 198 void OnClose(int result); |
| 198 | 199 |
| 199 scoped_ptr<cast_channel::Close::Params> params_; | 200 scoped_ptr<cast_channel::Close::Params> params_; |
| 200 | 201 |
| 201 DISALLOW_COPY_AND_ASSIGN(CastChannelCloseFunction); | 202 DISALLOW_COPY_AND_ASSIGN(CastChannelCloseFunction); |
| 202 }; | 203 }; |
| 203 | 204 |
| 204 } // namespace extensions | 205 } // namespace extensions |
| 205 | 206 |
| 206 #endif // CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ | 207 #endif // CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ |
| OLD | NEW |