| 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 "components/cast_channel/cast_channel_enum.h" |
| 16 #include "extensions/browser/api/api_resource_manager.h" |
| 15 #include "extensions/browser/api/async_api_function.h" | 17 #include "extensions/browser/api/async_api_function.h" |
| 16 #include "extensions/browser/api/cast_channel/cast_socket.h" | 18 #include "extensions/browser/api/cast_channel/cast_socket.h" |
| 17 #include "extensions/browser/browser_context_keyed_api_factory.h" | 19 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 18 #include "extensions/common/api/cast_channel.h" | 20 #include "extensions/common/api/cast_channel.h" |
| 19 | 21 |
| 20 class CastChannelAPITest; | 22 class CastChannelAPITest; |
| 21 | 23 |
| 22 namespace content { | 24 namespace content { |
| 23 class BrowserContext; | 25 class BrowserContext; |
| 24 } | 26 } |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 // Receives incoming messages and errors and provides additional API and | 166 // Receives incoming messages and errors and provides additional API and |
| 165 // origin socket context. | 167 // origin socket context. |
| 166 class CastMessageHandler : public cast_channel::CastTransport::Delegate { | 168 class CastMessageHandler : public cast_channel::CastTransport::Delegate { |
| 167 public: | 169 public: |
| 168 CastMessageHandler(const EventDispatchCallback& ui_dispatch_cb, | 170 CastMessageHandler(const EventDispatchCallback& ui_dispatch_cb, |
| 169 cast_channel::CastSocket* socket, | 171 cast_channel::CastSocket* socket, |
| 170 scoped_refptr<api::cast_channel::Logger> logger); | 172 scoped_refptr<api::cast_channel::Logger> logger); |
| 171 ~CastMessageHandler() override; | 173 ~CastMessageHandler() override; |
| 172 | 174 |
| 173 // CastTransport::Delegate implementation. | 175 // CastTransport::Delegate implementation. |
| 174 void OnError(cast_channel::ChannelError error_state) override; | 176 void OnError(::cast_channel::ChannelError error_state) override; |
| 175 void OnMessage(const cast_channel::CastMessage& message) override; | 177 void OnMessage(const cast_channel::CastMessage& message) override; |
| 176 void Start() override; | 178 void Start() override; |
| 177 | 179 |
| 178 private: | 180 private: |
| 179 // Callback for sending events to the extension. | 181 // Callback for sending events to the extension. |
| 180 // Should be bound to a weak pointer, to prevent any use-after-free | 182 // Should be bound to a weak pointer, to prevent any use-after-free |
| 181 // conditions. | 183 // conditions. |
| 182 EventDispatchCallback const ui_dispatch_cb_; | 184 EventDispatchCallback const ui_dispatch_cb_; |
| 183 cast_channel::CastSocket* const socket_; | 185 cast_channel::CastSocket* const socket_; |
| 184 // Logger object for reporting error details. | 186 // Logger object for reporting error details. |
| 185 scoped_refptr<api::cast_channel::Logger> logger_; | 187 scoped_refptr<api::cast_channel::Logger> logger_; |
| 186 | 188 |
| 187 DISALLOW_COPY_AND_ASSIGN(CastMessageHandler); | 189 DISALLOW_COPY_AND_ASSIGN(CastMessageHandler); |
| 188 }; | 190 }; |
| 189 | 191 |
| 190 // Validates that |connect_info| represents a valid IP end point and returns a | 192 // Validates that |connect_info| represents a valid IP end point and returns a |
| 191 // new IPEndPoint if so. Otherwise returns nullptr. | 193 // new IPEndPoint if so. Otherwise returns nullptr. |
| 192 static net::IPEndPoint* ParseConnectInfo( | 194 static net::IPEndPoint* ParseConnectInfo( |
| 193 const cast_channel::ConnectInfo& connect_info); | 195 const cast_channel::ConnectInfo& connect_info); |
| 194 | 196 |
| 195 void OnOpen(cast_channel::ChannelError result); | 197 void OnOpen(::cast_channel::ChannelError result); |
| 196 | 198 |
| 197 std::unique_ptr<cast_channel::Open::Params> params_; | 199 std::unique_ptr<cast_channel::Open::Params> params_; |
| 198 // The id of the newly opened socket. | 200 // The id of the newly opened socket. |
| 199 int new_channel_id_; | 201 int new_channel_id_; |
| 200 CastChannelAPI* api_; | 202 CastChannelAPI* api_; |
| 201 std::unique_ptr<net::IPEndPoint> ip_endpoint_; | 203 std::unique_ptr<net::IPEndPoint> ip_endpoint_; |
| 202 cast_channel::ChannelAuthType channel_auth_; | 204 ::cast_channel::ChannelAuthType channel_auth_; |
| 203 base::TimeDelta liveness_timeout_; | 205 base::TimeDelta liveness_timeout_; |
| 204 base::TimeDelta ping_interval_; | 206 base::TimeDelta ping_interval_; |
| 205 | 207 |
| 206 FRIEND_TEST_ALL_PREFIXES(CastChannelOpenFunctionTest, TestParseConnectInfo); | 208 FRIEND_TEST_ALL_PREFIXES(CastChannelOpenFunctionTest, TestParseConnectInfo); |
| 207 DISALLOW_COPY_AND_ASSIGN(CastChannelOpenFunction); | 209 DISALLOW_COPY_AND_ASSIGN(CastChannelOpenFunction); |
| 208 }; | 210 }; |
| 209 | 211 |
| 210 class CastChannelSendFunction : public CastChannelAsyncApiFunction { | 212 class CastChannelSendFunction : public CastChannelAsyncApiFunction { |
| 211 public: | 213 public: |
| 212 CastChannelSendFunction(); | 214 CastChannelSendFunction(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 | 249 |
| 248 std::unique_ptr<cast_channel::Close::Params> params_; | 250 std::unique_ptr<cast_channel::Close::Params> params_; |
| 249 CastChannelAPI* api_; | 251 CastChannelAPI* api_; |
| 250 | 252 |
| 251 DISALLOW_COPY_AND_ASSIGN(CastChannelCloseFunction); | 253 DISALLOW_COPY_AND_ASSIGN(CastChannelCloseFunction); |
| 252 }; | 254 }; |
| 253 | 255 |
| 254 } // namespace extensions | 256 } // namespace extensions |
| 255 | 257 |
| 256 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ | 258 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ |
| OLD | NEW |