| 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" |
| 11 #include "chrome/browser/extensions/api/api_resource_manager.h" | |
| 12 #include "chrome/browser/extensions/api/cast_channel/cast_socket.h" | 11 #include "chrome/browser/extensions/api/cast_channel/cast_socket.h" |
| 13 #include "chrome/common/extensions/api/cast_channel.h" | 12 #include "chrome/common/extensions/api/cast_channel.h" |
| 13 #include "extensions/browser/api/api_resource_manager.h" |
| 14 #include "extensions/browser/api/async_api_function.h" | 14 #include "extensions/browser/api/async_api_function.h" |
| 15 #include "extensions/browser/browser_context_keyed_api_factory.h" | 15 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 16 | 16 |
| 17 class GURL; | 17 class GURL; |
| 18 class CastChannelAPITest; | 18 class CastChannelAPITest; |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 class BrowserContext; | 21 class BrowserContext; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace extensions { | 24 namespace extensions { |
| 25 | 25 |
| 26 namespace cast_channel = api::cast_channel; | 26 namespace cast_channel = api::cast_channel; |
| 27 | 27 |
| 28 class CastChannelAPI : public BrowserContextKeyedAPI, | 28 class CastChannelAPI : public BrowserContextKeyedAPI, |
| 29 public cast_channel::CastSocket::Delegate { | 29 public cast_channel::CastSocket::Delegate { |
| 30 | 30 |
| 31 public: | 31 public: |
| 32 explicit CastChannelAPI(content::BrowserContext* context); | 32 explicit CastChannelAPI(content::BrowserContext* context); |
| 33 | 33 |
| 34 static CastChannelAPI* Get(content::BrowserContext* context); | 34 static CastChannelAPI* Get(content::BrowserContext* context); |
| 35 | 35 |
| 36 // BrowserContextKeyedAPI implementation. | 36 // BrowserContextKeyedAPI implementation. |
| 37 static BrowserContextKeyedAPIFactory<CastChannelAPI>* GetFactoryInstance(); | 37 static BrowserContextKeyedAPIFactory<CastChannelAPI>* GetFactoryInstance(); |
| 38 | 38 |
| 39 // Returns a new CastSocket that connects to |url| and is to be owned by | 39 // Returns a new CastSocket that connects to |url| and is to be owned by |
| 40 // |extension_id|. | 40 // |extension_id|. |
| 41 scoped_ptr<cast_channel::CastSocket> CreateCastSocket( | 41 scoped_ptr<cast_channel::CastSocket> CreateCastSocket( |
| 42 const std::string& extension_id, const GURL& gurl); | 42 const std::string& extension_id, |
| 43 const GURL& gurl); |
| 43 | 44 |
| 44 // Sets the CastSocket instance to be returned by CreateCastSocket for | 45 // Sets the CastSocket instance to be returned by CreateCastSocket for |
| 45 // testing. | 46 // testing. |
| 46 void SetSocketForTest(scoped_ptr<cast_channel::CastSocket> socket_for_test); | 47 void SetSocketForTest(scoped_ptr<cast_channel::CastSocket> socket_for_test); |
| 47 | 48 |
| 48 private: | 49 private: |
| 49 friend class BrowserContextKeyedAPIFactory<CastChannelAPI>; | 50 friend class BrowserContextKeyedAPIFactory<CastChannelAPI>; |
| 50 friend class ::CastChannelAPITest; | 51 friend class ::CastChannelAPITest; |
| 51 | 52 |
| 52 virtual ~CastChannelAPI(); | 53 virtual ~CastChannelAPI(); |
| 53 | 54 |
| 54 // CastSocket::Delegate. Called on IO thread. | 55 // CastSocket::Delegate. Called on IO thread. |
| 55 virtual void OnError(const cast_channel::CastSocket* socket, | 56 virtual void OnError(const cast_channel::CastSocket* socket, |
| 56 cast_channel::ChannelError error) OVERRIDE; | 57 cast_channel::ChannelError error) OVERRIDE; |
| 57 virtual void OnMessage(const cast_channel::CastSocket* socket, | 58 virtual void OnMessage(const cast_channel::CastSocket* socket, |
| 58 const cast_channel::MessageInfo& message) OVERRIDE; | 59 const cast_channel::MessageInfo& message) OVERRIDE; |
| 59 | 60 |
| 60 // BrowserContextKeyedAPI implementation. | 61 // BrowserContextKeyedAPI implementation. |
| 61 static const char* service_name() { | 62 static const char* service_name() { return "CastChannelAPI"; } |
| 62 return "CastChannelAPI"; | |
| 63 } | |
| 64 | 63 |
| 65 content::BrowserContext* const browser_context_; | 64 content::BrowserContext* const browser_context_; |
| 66 scoped_ptr<cast_channel::CastSocket> socket_for_test_; | 65 scoped_ptr<cast_channel::CastSocket> socket_for_test_; |
| 67 | 66 |
| 68 DISALLOW_COPY_AND_ASSIGN(CastChannelAPI); | 67 DISALLOW_COPY_AND_ASSIGN(CastChannelAPI); |
| 69 }; | 68 }; |
| 70 | 69 |
| 71 class CastChannelAsyncApiFunction : public AsyncApiFunction { | 70 class CastChannelAsyncApiFunction : public AsyncApiFunction { |
| 72 public: | 71 public: |
| 73 CastChannelAsyncApiFunction(); | 72 CastChannelAsyncApiFunction(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 98 | 97 |
| 99 // Sets the function result to a ChannelInfo with |error|. | 98 // Sets the function result to a ChannelInfo with |error|. |
| 100 void SetResultFromError(cast_channel::ChannelError error); | 99 void SetResultFromError(cast_channel::ChannelError error); |
| 101 | 100 |
| 102 // Returns the socket corresponding to |channel_id| if one exists, or null | 101 // Returns the socket corresponding to |channel_id| if one exists, or null |
| 103 // otherwise. | 102 // otherwise. |
| 104 cast_channel::CastSocket* GetSocket(int channel_id); | 103 cast_channel::CastSocket* GetSocket(int channel_id); |
| 105 | 104 |
| 106 private: | 105 private: |
| 107 // Sets the function result from |channel_info|. | 106 // Sets the function result from |channel_info|. |
| 108 void SetResultFromChannelInfo( | 107 void SetResultFromChannelInfo(const cast_channel::ChannelInfo& channel_info); |
| 109 const cast_channel::ChannelInfo& channel_info); | |
| 110 | 108 |
| 111 // The API resource manager for CastSockets. | 109 // The API resource manager for CastSockets. |
| 112 ApiResourceManager<cast_channel::CastSocket>* manager_; | 110 ApiResourceManager<cast_channel::CastSocket>* manager_; |
| 113 | 111 |
| 114 // The result of the function. | 112 // The result of the function. |
| 115 cast_channel::ChannelError error_; | 113 cast_channel::ChannelError error_; |
| 116 }; | 114 }; |
| 117 | 115 |
| 118 class CastChannelOpenFunction : public CastChannelAsyncApiFunction { | 116 class CastChannelOpenFunction : public CastChannelAsyncApiFunction { |
| 119 public: | 117 public: |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 void OnClose(int result); | 176 void OnClose(int result); |
| 179 | 177 |
| 180 scoped_ptr<cast_channel::Close::Params> params_; | 178 scoped_ptr<cast_channel::Close::Params> params_; |
| 181 | 179 |
| 182 DISALLOW_COPY_AND_ASSIGN(CastChannelCloseFunction); | 180 DISALLOW_COPY_AND_ASSIGN(CastChannelCloseFunction); |
| 183 }; | 181 }; |
| 184 | 182 |
| 185 } // namespace extensions | 183 } // namespace extensions |
| 186 | 184 |
| 187 #endif // CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ | 185 #endif // CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ |
| OLD | NEW |