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

Unified Diff: extensions/browser/api/cast_channel/cast_channel_api.cc

Issue 2925053005: [cast_channel] Implement CastSocketService::OpenSocket() (Closed)
Patch Set: resolve code review comments from Mark 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 side-by-side diff with in-line comments
Download patch
Index: extensions/browser/api/cast_channel/cast_channel_api.cc
diff --git a/extensions/browser/api/cast_channel/cast_channel_api.cc b/extensions/browser/api/cast_channel/cast_channel_api.cc
index 44844998823895d8847dae9ad8b29b703039a578..ae250d7df3c22410d334f436d2a565a1b183466a 100644
--- a/extensions/browser/api/cast_channel/cast_channel_api.cc
+++ b/extensions/browser/api/cast_channel/cast_channel_api.cc
@@ -216,9 +216,7 @@ void CastChannelAsyncApiFunction::SetResultFromChannelInfo(
SetResult(channel_info.ToValue());
}
-CastChannelOpenFunction::CastChannelOpenFunction()
- : new_channel_id_(0) {
-}
+CastChannelOpenFunction::CastChannelOpenFunction() {}
CastChannelOpenFunction::~CastChannelOpenFunction() { }
@@ -278,21 +276,10 @@ void CastChannelOpenFunction::AsyncWorkStart() {
DCHECK(api_);
DCHECK(ip_endpoint_.get());
const ConnectInfo& connect_info = params_->connect_info;
- CastSocket* socket;
+
std::unique_ptr<CastSocket> test_socket = api_->GetSocketForTest();
- if (test_socket.get()) {
- socket = test_socket.release();
- } else {
- socket = new CastSocketImpl(
- *ip_endpoint_, ExtensionsBrowserClient::Get()->GetNetLog(),
- base::TimeDelta::FromMilliseconds(connect_info.timeout.get()
- ? *connect_info.timeout
- : kDefaultConnectTimeoutMillis),
- liveness_timeout_, ping_interval_, api_->GetLogger(),
- connect_info.capabilities.get() ? *connect_info.capabilities
- : CastDeviceCapability::NONE);
- }
- new_channel_id_ = cast_socket_service_->AddSocket(base::WrapUnique(socket));
+ if (test_socket.get())
+ cast_socket_service_->SetSocketForTest(std::move(test_socket));
auto* observer = cast_socket_service_->GetObserver(extension_->id());
if (!observer) {
@@ -303,25 +290,30 @@ void CastChannelOpenFunction::AsyncWorkStart() {
api_->GetLogger()));
}
- socket->AddObserver(observer);
- // Construct read delegates.
- socket->Connect(base::Bind(&CastChannelOpenFunction::OnOpen, this));
+ cast_socket_service_->OpenSocket(
+ *ip_endpoint_, ExtensionsBrowserClient::Get()->GetNetLog(),
+ base::TimeDelta::FromMilliseconds(connect_info.timeout.get()
+ ? *connect_info.timeout
+ : kDefaultConnectTimeoutMillis),
+ liveness_timeout_, ping_interval_, api_->GetLogger(),
+ connect_info.capabilities.get() ? *connect_info.capabilities
+ : CastDeviceCapability::NONE,
+ base::Bind(&CastChannelOpenFunction::OnOpen, this), observer);
}
-void CastChannelOpenFunction::OnOpen(ChannelError result) {
+void CastChannelOpenFunction::OnOpen(int channel_id, ChannelError result) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
VLOG(1) << "Connect finished, OnOpen invoked.";
// TODO: If we failed to open the CastSocket, we may want to clean up here,
// rather than relying on the extension to call close(). This can be done by
// calling RemoveSocket() and api_->GetLogger()->ClearLastError(channel_id).
if (result != ChannelError::UNKNOWN) {
- CastSocket* socket = cast_socket_service_->GetSocket(new_channel_id_);
+ CastSocket* socket = cast_socket_service_->GetSocket(channel_id);
CHECK(socket);
SetResultFromSocket(*socket);
} else {
// The socket is being destroyed.
- SetResultFromError(new_channel_id_,
- api::cast_channel::CHANNEL_ERROR_UNKNOWN);
+ SetResultFromError(channel_id, api::cast_channel::CHANNEL_ERROR_UNKNOWN);
}
AsyncWorkCompleted();

Powered by Google App Engine
This is Rietveld 408576698