Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: extensions/browser/api/cast_channel/cast_channel_api.cc

Issue 2913033003: [cast_channel] Move cast_channel related files from //extensions to //components (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
43 namespace cast_channel = api::cast_channel;
mark a. foltz 2017/06/01 21:26:35 I think this ends up being very similar to ::cast_
zhaobin 2017/06/01 22:00:38 Done.
42 namespace Close = cast_channel::Close; 44 namespace Close = cast_channel::Close;
43 namespace OnError = cast_channel::OnError; 45 namespace OnError = cast_channel::OnError;
44 namespace OnMessage = cast_channel::OnMessage; 46 namespace OnMessage = cast_channel::OnMessage;
45 namespace Open = cast_channel::Open; 47 namespace Open = cast_channel::Open;
46 namespace Send = cast_channel::Send; 48 namespace Send = cast_channel::Send;
47 using ::cast_channel::ChannelError; 49 using ::cast_channel::ChannelError;
48 using cast_channel::CastDeviceCapability; 50 using ::cast_channel::CastDeviceCapability;
49 using cast_channel::CastMessage; 51 using ::cast_channel::CastMessage;
50 using cast_channel::CastSocket; 52 using ::cast_channel::CastSocket;
51 using cast_channel::CastSocketImpl; 53 using ::cast_channel::CastSocketImpl;
52 using cast_channel::CastTransport; 54 using ::cast_channel::CastTransport;
55 using ::cast_channel::KeepAliveDelegate;
56 using ::cast_channel::LastErrors;
57 using ::cast_channel::Logger;
53 using cast_channel::ChannelInfo; 58 using cast_channel::ChannelInfo;
54 using cast_channel::ConnectInfo; 59 using cast_channel::ConnectInfo;
55 using cast_channel::ErrorInfo; 60 using cast_channel::ErrorInfo;
56 using cast_channel::KeepAliveDelegate;
57 using cast_channel::LastErrors;
58 using cast_channel::Logger;
59 using cast_channel::MessageInfo; 61 using cast_channel::MessageInfo;
60 using content::BrowserThread; 62 using content::BrowserThread;
61 63
62 namespace { 64 namespace {
63 65
64 // T is an extension dictionary (MessageInfo or ChannelInfo) 66 // T is an extension dictionary (MessageInfo or ChannelInfo)
65 template <class T> 67 template <class T>
66 std::string ParamToString(const T& info) { 68 std::string ParamToString(const T& info) {
67 std::unique_ptr<base::DictionaryValue> dict = info.ToValue(); 69 std::unique_ptr<base::DictionaryValue> dict = info.ToValue();
68 std::string out; 70 std::string out;
(...skipping 15 matching lines...) Expand all
84 cast_channel::ToChannelError(socket.error_state()); 86 cast_channel::ToChannelError(socket.error_state());
85 channel_info->keep_alive = socket.keep_alive(); 87 channel_info->keep_alive = socket.keep_alive();
86 channel_info->audio_only = socket.audio_only(); 88 channel_info->audio_only = socket.audio_only();
87 } 89 }
88 90
89 // Fills |error_info| from |error_state| and |last_errors|. 91 // Fills |error_info| from |error_state| and |last_errors|.
90 void FillErrorInfo(cast_channel::ChannelError error_state, 92 void FillErrorInfo(cast_channel::ChannelError error_state,
91 const LastErrors& last_errors, 93 const LastErrors& last_errors,
92 ErrorInfo* error_info) { 94 ErrorInfo* error_info) {
93 error_info->error_state = error_state; 95 error_info->error_state = error_state;
94 if (last_errors.event_type != cast_channel::proto::EVENT_TYPE_UNKNOWN) 96 if (last_errors.event_type != ::cast_channel::proto::EVENT_TYPE_UNKNOWN)
95 error_info->event_type.reset(new int(last_errors.event_type)); 97 error_info->event_type.reset(new int(last_errors.event_type));
96 if (last_errors.challenge_reply_error_type != 98 if (last_errors.challenge_reply_error_type !=
97 cast_channel::proto::CHALLENGE_REPLY_ERROR_NONE) { 99 ::cast_channel::proto::CHALLENGE_REPLY_ERROR_NONE) {
98 error_info->challenge_reply_error_type.reset( 100 error_info->challenge_reply_error_type.reset(
99 new int(last_errors.challenge_reply_error_type)); 101 new int(last_errors.challenge_reply_error_type));
100 } 102 }
101 if (last_errors.net_return_value <= 0) 103 if (last_errors.net_return_value <= 0)
102 error_info->net_return_value.reset(new int(last_errors.net_return_value)); 104 error_info->net_return_value.reset(new int(last_errors.net_return_value));
103 } 105 }
104 106
105 bool IsValidConnectInfoPort(const ConnectInfo& connect_info) { 107 bool IsValidConnectInfoPort(const ConnectInfo& connect_info) {
106 return connect_info.port > 0 && connect_info.port < 108 return connect_info.port > 0 && connect_info.port <
107 std::numeric_limits<uint16_t>::max(); 109 std::numeric_limits<uint16_t>::max();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 } 172 }
171 173
172 CastChannelAPI::~CastChannelAPI() {} 174 CastChannelAPI::~CastChannelAPI() {}
173 175
174 CastChannelAsyncApiFunction::CastChannelAsyncApiFunction() 176 CastChannelAsyncApiFunction::CastChannelAsyncApiFunction()
175 : cast_socket_service_(nullptr) {} 177 : cast_socket_service_(nullptr) {}
176 178
177 CastChannelAsyncApiFunction::~CastChannelAsyncApiFunction() { } 179 CastChannelAsyncApiFunction::~CastChannelAsyncApiFunction() { }
178 180
179 bool CastChannelAsyncApiFunction::PrePrepare() { 181 bool CastChannelAsyncApiFunction::PrePrepare() {
180 cast_socket_service_ = 182 cast_socket_service_ = ::cast_channel::CastSocketServiceFactory::GetInstance()
181 api::cast_channel::CastSocketServiceFactory::GetInstance() 183 ->GetForBrowserContext(browser_context());
182 ->GetForBrowserContext(browser_context());
183 DCHECK(cast_socket_service_); 184 DCHECK(cast_socket_service_);
184 return true; 185 return true;
185 } 186 }
186 187
187 bool CastChannelAsyncApiFunction::Respond() { 188 bool CastChannelAsyncApiFunction::Respond() {
188 return GetError().empty(); 189 return GetError().empty();
189 } 190 }
190 191
191 CastSocket* CastChannelAsyncApiFunction::GetSocketOrCompleteWithError( 192 CastSocket* CastChannelAsyncApiFunction::GetSocketOrCompleteWithError(
192 int channel_id) { 193 int channel_id) {
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 std::move(results))); 524 std::move(results)));
524 BrowserThread::PostTask( 525 BrowserThread::PostTask(
525 BrowserThread::UI, FROM_HERE, 526 BrowserThread::UI, FROM_HERE,
526 base::Bind(ui_dispatch_cb_, base::Passed(std::move(event)))); 527 base::Bind(ui_dispatch_cb_, base::Passed(std::move(event))));
527 } 528 }
528 529
529 void CastChannelOpenFunction::CastMessageHandler::Start() { 530 void CastChannelOpenFunction::CastMessageHandler::Start() {
530 } 531 }
531 532
532 } // namespace extensions 533 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698