| 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 |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
| 15 #include "extensions/browser/api/api_resource_manager.h" | |
| 16 #include "extensions/browser/api/async_api_function.h" | 15 #include "extensions/browser/api/async_api_function.h" |
| 17 #include "extensions/browser/api/cast_channel/cast_socket.h" | 16 #include "extensions/browser/api/cast_channel/cast_socket.h" |
| 18 #include "extensions/browser/browser_context_keyed_api_factory.h" | 17 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 19 #include "extensions/common/api/cast_channel.h" | 18 #include "extensions/common/api/cast_channel.h" |
| 20 | 19 |
| 21 class CastChannelAPITest; | 20 class CastChannelAPITest; |
| 22 | 21 |
| 23 namespace content { | 22 namespace content { |
| 24 class BrowserContext; | 23 class BrowserContext; |
| 25 } | 24 } |
| 26 | 25 |
| 27 namespace net { | 26 namespace net { |
| 28 class IPEndPoint; | 27 class IPEndPoint; |
| 29 } | 28 } |
| 30 | 29 |
| 31 namespace extensions { | 30 namespace extensions { |
| 32 | 31 |
| 33 struct Event; | 32 struct Event; |
| 34 | 33 |
| 35 namespace api { | 34 namespace api { |
| 36 namespace cast_channel { | 35 namespace cast_channel { |
| 36 class CastChannelService; |
| 37 class Logger; | 37 class Logger; |
| 38 } // namespace cast_channel | 38 } // namespace cast_channel |
| 39 } // namespace api | 39 } // namespace api |
| 40 | 40 |
| 41 namespace cast_channel = api::cast_channel; | 41 namespace cast_channel = api::cast_channel; |
| 42 | 42 |
| 43 class CastChannelAPI : public BrowserContextKeyedAPI, | 43 class CastChannelAPI : public BrowserContextKeyedAPI, |
| 44 public base::SupportsWeakPtr<CastChannelAPI> { | 44 public base::SupportsWeakPtr<CastChannelAPI> { |
| 45 public: | 45 public: |
| 46 explicit CastChannelAPI(content::BrowserContext* context); | 46 explicit CastChannelAPI(content::BrowserContext* context); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 std::unique_ptr<base::Timer> injected_timeout_timer_; | 95 std::unique_ptr<base::Timer> injected_timeout_timer_; |
| 96 | 96 |
| 97 DISALLOW_COPY_AND_ASSIGN(CastChannelAPI); | 97 DISALLOW_COPY_AND_ASSIGN(CastChannelAPI); |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 class CastChannelAsyncApiFunction : public AsyncApiFunction { | 100 class CastChannelAsyncApiFunction : public AsyncApiFunction { |
| 101 public: | 101 public: |
| 102 CastChannelAsyncApiFunction(); | 102 CastChannelAsyncApiFunction(); |
| 103 | 103 |
| 104 protected: | 104 protected: |
| 105 typedef ApiResourceManager<cast_channel::CastSocket>::ApiResourceData | |
| 106 SocketData; | |
| 107 | |
| 108 ~CastChannelAsyncApiFunction() override; | 105 ~CastChannelAsyncApiFunction() override; |
| 109 | 106 |
| 110 // AsyncApiFunction: | 107 // AsyncApiFunction: |
| 111 bool PrePrepare() override; | 108 bool PrePrepare() override; |
| 112 bool Respond() override; | 109 bool Respond() override; |
| 113 | 110 |
| 114 // Returns the socket corresponding to |channel_id| if one exists. Otherwise, | 111 // Returns the socket corresponding to |channel_id| if one exists. Otherwise, |
| 115 // sets the function result with CHANNEL_ERROR_INVALID_CHANNEL_ID, completes | 112 // sets the function result with CHANNEL_ERROR_INVALID_CHANNEL_ID, completes |
| 116 // the function, and returns null. | 113 // the function, and returns null. |
| 117 cast_channel::CastSocket* GetSocketOrCompleteWithError(int channel_id); | 114 cast_channel::CastSocket* GetSocketOrCompleteWithError(int channel_id); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 133 void SetResultFromError(int channel_id, cast_channel::ChannelError error); | 130 void SetResultFromError(int channel_id, cast_channel::ChannelError error); |
| 134 | 131 |
| 135 // Returns the socket corresponding to |channel_id| if one exists, or null | 132 // Returns the socket corresponding to |channel_id| if one exists, or null |
| 136 // otherwise. | 133 // otherwise. |
| 137 cast_channel::CastSocket* GetSocket(int channel_id) const; | 134 cast_channel::CastSocket* GetSocket(int channel_id) const; |
| 138 | 135 |
| 139 private: | 136 private: |
| 140 // Sets the function result from |channel_info|. | 137 // Sets the function result from |channel_info|. |
| 141 void SetResultFromChannelInfo(const cast_channel::ChannelInfo& channel_info); | 138 void SetResultFromChannelInfo(const cast_channel::ChannelInfo& channel_info); |
| 142 | 139 |
| 143 // The collection of CastSocket API resources. | 140 // Manages creating and removing cast sockets. |
| 144 scoped_refptr<SocketData> sockets_; | 141 api::cast_channel::CastChannelService* cast_channel_service_; |
| 145 }; | 142 }; |
| 146 | 143 |
| 147 class CastChannelOpenFunction : public CastChannelAsyncApiFunction { | 144 class CastChannelOpenFunction : public CastChannelAsyncApiFunction { |
| 148 public: | 145 public: |
| 149 CastChannelOpenFunction(); | 146 CastChannelOpenFunction(); |
| 150 | 147 |
| 151 protected: | 148 protected: |
| 152 ~CastChannelOpenFunction() override; | 149 ~CastChannelOpenFunction() override; |
| 153 | 150 |
| 154 // AsyncApiFunction: | 151 // AsyncApiFunction: |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 | 249 |
| 253 std::unique_ptr<cast_channel::Close::Params> params_; | 250 std::unique_ptr<cast_channel::Close::Params> params_; |
| 254 CastChannelAPI* api_; | 251 CastChannelAPI* api_; |
| 255 | 252 |
| 256 DISALLOW_COPY_AND_ASSIGN(CastChannelCloseFunction); | 253 DISALLOW_COPY_AND_ASSIGN(CastChannelCloseFunction); |
| 257 }; | 254 }; |
| 258 | 255 |
| 259 } // namespace extensions | 256 } // namespace extensions |
| 260 | 257 |
| 261 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ | 258 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ |
| OLD | NEW |