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 #include "extensions/browser/api/cast_channel/cast_channel_api.h" | 5 #include "extensions/browser/api/cast_channel/cast_channel_api.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <limits> | 10 #include <limits> |
11 #include <memory> | 11 #include <memory> |
12 #include <string> | 12 #include <string> |
13 #include <utility> | 13 #include <utility> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
17 #include "base/lazy_instance.h" | 17 #include "base/lazy_instance.h" |
18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
20 #include "base/values.h" | 20 #include "base/values.h" |
| 21 #include "components/cast_channel/cast_message_util.h" |
| 22 #include "components/cast_channel/cast_socket.h" |
| 23 #include "components/cast_channel/cast_socket_service.h" |
| 24 #include "components/cast_channel/cast_socket_service_factory.h" |
| 25 #include "components/cast_channel/keep_alive_delegate.h" |
| 26 #include "components/cast_channel/logger.h" |
21 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
22 #include "extensions/browser/api/cast_channel/cast_channel_enum_util.h" | 28 #include "extensions/browser/api/cast_channel/cast_channel_enum_util.h" |
23 #include "extensions/browser/api/cast_channel/cast_message_util.h" | 29 #include "extensions/browser/api/cast_channel/cast_message_util.h" |
24 #include "extensions/browser/api/cast_channel/cast_socket.h" | |
25 #include "extensions/browser/api/cast_channel/cast_socket_service.h" | |
26 #include "extensions/browser/api/cast_channel/cast_socket_service_factory.h" | |
27 #include "extensions/browser/api/cast_channel/keep_alive_delegate.h" | |
28 #include "extensions/browser/api/cast_channel/logger.h" | |
29 #include "extensions/browser/event_router.h" | 30 #include "extensions/browser/event_router.h" |
30 #include "extensions/common/api/cast_channel/cast_channel.pb.h" | 31 #include "extensions/common/api/cast_channel/cast_channel.pb.h" |
31 #include "extensions/common/api/cast_channel/logging.pb.h" | 32 #include "extensions/common/api/cast_channel/logging.pb.h" |
32 #include "net/base/ip_address.h" | 33 #include "net/base/ip_address.h" |
33 #include "net/base/ip_endpoint.h" | 34 #include "net/base/ip_endpoint.h" |
34 #include "net/base/net_errors.h" | 35 #include "net/base/net_errors.h" |
35 | 36 |
36 // Default timeout interval for connection setup. | 37 // Default timeout interval for connection setup. |
37 // Used if not otherwise specified at ConnectInfo::timeout. | 38 // Used if not otherwise specified at ConnectInfo::timeout. |
38 const int kDefaultConnectTimeoutMillis = 5000; // 5 seconds. | 39 const int kDefaultConnectTimeoutMillis = 5000; // 5 seconds. |
39 | 40 |
40 namespace extensions { | 41 namespace extensions { |
41 | 42 |
42 namespace Close = cast_channel::Close; | 43 namespace Close = cast_channel::Close; |
43 namespace OnError = cast_channel::OnError; | 44 namespace OnError = cast_channel::OnError; |
44 namespace OnMessage = cast_channel::OnMessage; | 45 namespace OnMessage = cast_channel::OnMessage; |
45 namespace Open = cast_channel::Open; | 46 namespace Open = cast_channel::Open; |
46 namespace Send = cast_channel::Send; | 47 namespace Send = cast_channel::Send; |
47 using ::cast_channel::ChannelError; | 48 using ::cast_channel::ChannelError; |
48 using cast_channel::CastDeviceCapability; | 49 using ::cast_channel::CastDeviceCapability; |
49 using cast_channel::CastMessage; | 50 using ::cast_channel::CastMessage; |
50 using cast_channel::CastSocket; | 51 using ::cast_channel::CastSocket; |
51 using cast_channel::CastSocketImpl; | 52 using ::cast_channel::CastSocketImpl; |
52 using cast_channel::CastTransport; | 53 using ::cast_channel::CastTransport; |
| 54 using ::cast_channel::KeepAliveDelegate; |
| 55 using ::cast_channel::LastErrors; |
| 56 using ::cast_channel::Logger; |
53 using cast_channel::ChannelInfo; | 57 using cast_channel::ChannelInfo; |
54 using cast_channel::ConnectInfo; | 58 using cast_channel::ConnectInfo; |
55 using cast_channel::ErrorInfo; | 59 using cast_channel::ErrorInfo; |
56 using cast_channel::KeepAliveDelegate; | |
57 using cast_channel::LastErrors; | |
58 using cast_channel::Logger; | |
59 using cast_channel::MessageInfo; | 60 using cast_channel::MessageInfo; |
60 using content::BrowserThread; | 61 using content::BrowserThread; |
61 | 62 |
62 namespace { | 63 namespace { |
63 | 64 |
64 // T is an extension dictionary (MessageInfo or ChannelInfo) | 65 // T is an extension dictionary (MessageInfo or ChannelInfo) |
65 template <class T> | 66 template <class T> |
66 std::string ParamToString(const T& info) { | 67 std::string ParamToString(const T& info) { |
67 std::unique_ptr<base::DictionaryValue> dict = info.ToValue(); | 68 std::unique_ptr<base::DictionaryValue> dict = info.ToValue(); |
68 std::string out; | 69 std::string out; |
(...skipping 15 matching lines...) Expand all Loading... |
84 cast_channel::ToChannelError(socket.error_state()); | 85 cast_channel::ToChannelError(socket.error_state()); |
85 channel_info->keep_alive = socket.keep_alive(); | 86 channel_info->keep_alive = socket.keep_alive(); |
86 channel_info->audio_only = socket.audio_only(); | 87 channel_info->audio_only = socket.audio_only(); |
87 } | 88 } |
88 | 89 |
89 // Fills |error_info| from |error_state| and |last_errors|. | 90 // Fills |error_info| from |error_state| and |last_errors|. |
90 void FillErrorInfo(cast_channel::ChannelError error_state, | 91 void FillErrorInfo(cast_channel::ChannelError error_state, |
91 const LastErrors& last_errors, | 92 const LastErrors& last_errors, |
92 ErrorInfo* error_info) { | 93 ErrorInfo* error_info) { |
93 error_info->error_state = error_state; | 94 error_info->error_state = error_state; |
94 if (last_errors.event_type != cast_channel::proto::EVENT_TYPE_UNKNOWN) | 95 if (last_errors.event_type != ::cast_channel::proto::EVENT_TYPE_UNKNOWN) |
95 error_info->event_type.reset(new int(last_errors.event_type)); | 96 error_info->event_type.reset(new int(last_errors.event_type)); |
96 if (last_errors.challenge_reply_error_type != | 97 if (last_errors.challenge_reply_error_type != |
97 cast_channel::proto::CHALLENGE_REPLY_ERROR_NONE) { | 98 ::cast_channel::proto::CHALLENGE_REPLY_ERROR_NONE) { |
98 error_info->challenge_reply_error_type.reset( | 99 error_info->challenge_reply_error_type.reset( |
99 new int(last_errors.challenge_reply_error_type)); | 100 new int(last_errors.challenge_reply_error_type)); |
100 } | 101 } |
101 if (last_errors.net_return_value <= 0) | 102 if (last_errors.net_return_value <= 0) |
102 error_info->net_return_value.reset(new int(last_errors.net_return_value)); | 103 error_info->net_return_value.reset(new int(last_errors.net_return_value)); |
103 } | 104 } |
104 | 105 |
105 bool IsValidConnectInfoPort(const ConnectInfo& connect_info) { | 106 bool IsValidConnectInfoPort(const ConnectInfo& connect_info) { |
106 return connect_info.port > 0 && connect_info.port < | 107 return connect_info.port > 0 && connect_info.port < |
107 std::numeric_limits<uint16_t>::max(); | 108 std::numeric_limits<uint16_t>::max(); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 } | 171 } |
171 | 172 |
172 CastChannelAPI::~CastChannelAPI() {} | 173 CastChannelAPI::~CastChannelAPI() {} |
173 | 174 |
174 CastChannelAsyncApiFunction::CastChannelAsyncApiFunction() | 175 CastChannelAsyncApiFunction::CastChannelAsyncApiFunction() |
175 : cast_socket_service_(nullptr) {} | 176 : cast_socket_service_(nullptr) {} |
176 | 177 |
177 CastChannelAsyncApiFunction::~CastChannelAsyncApiFunction() { } | 178 CastChannelAsyncApiFunction::~CastChannelAsyncApiFunction() { } |
178 | 179 |
179 bool CastChannelAsyncApiFunction::PrePrepare() { | 180 bool CastChannelAsyncApiFunction::PrePrepare() { |
180 cast_socket_service_ = | 181 cast_socket_service_ = ::cast_channel::CastSocketServiceFactory::GetInstance() |
181 api::cast_channel::CastSocketServiceFactory::GetInstance() | 182 ->GetForBrowserContext(browser_context()); |
182 ->GetForBrowserContext(browser_context()); | |
183 DCHECK(cast_socket_service_); | 183 DCHECK(cast_socket_service_); |
184 return true; | 184 return true; |
185 } | 185 } |
186 | 186 |
187 bool CastChannelAsyncApiFunction::Respond() { | 187 bool CastChannelAsyncApiFunction::Respond() { |
188 return GetError().empty(); | 188 return GetError().empty(); |
189 } | 189 } |
190 | 190 |
191 CastSocket* CastChannelAsyncApiFunction::GetSocketOrCompleteWithError( | 191 CastSocket* CastChannelAsyncApiFunction::GetSocketOrCompleteWithError( |
192 int channel_id) { | 192 int channel_id) { |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 std::move(results))); | 523 std::move(results))); |
524 BrowserThread::PostTask( | 524 BrowserThread::PostTask( |
525 BrowserThread::UI, FROM_HERE, | 525 BrowserThread::UI, FROM_HERE, |
526 base::Bind(ui_dispatch_cb_, base::Passed(std::move(event)))); | 526 base::Bind(ui_dispatch_cb_, base::Passed(std::move(event)))); |
527 } | 527 } |
528 | 528 |
529 void CastChannelOpenFunction::CastMessageHandler::Start() { | 529 void CastChannelOpenFunction::CastMessageHandler::Start() { |
530 } | 530 } |
531 | 531 |
532 } // namespace extensions | 532 } // namespace extensions |
OLD | NEW |