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

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

Issue 2937153002: [cast_channel] Create KeepAliveDelegate in CastSocket instead of in CastChannelOpenFunction (Closed)
Patch Set: rebase with master 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>
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 157 }
158 158
159 std::unique_ptr<CastSocket> CastChannelAPI::GetSocketForTest() { 159 std::unique_ptr<CastSocket> CastChannelAPI::GetSocketForTest() {
160 return std::move(socket_for_test_); 160 return std::move(socket_for_test_);
161 } 161 }
162 162
163 content::BrowserContext* CastChannelAPI::GetBrowserContext() const { 163 content::BrowserContext* CastChannelAPI::GetBrowserContext() const {
164 return browser_context_; 164 return browser_context_;
165 } 165 }
166 166
167 void CastChannelAPI::SetPingTimeoutTimerForTest(
168 std::unique_ptr<base::Timer> timer) {
169 injected_timeout_timer_ = std::move(timer);
170 }
171
172 std::unique_ptr<base::Timer> CastChannelAPI::GetInjectedTimeoutTimerForTest() {
173 return std::move(injected_timeout_timer_);
174 }
175
176 CastChannelAPI::~CastChannelAPI() {} 167 CastChannelAPI::~CastChannelAPI() {}
177 168
178 CastChannelAsyncApiFunction::CastChannelAsyncApiFunction() 169 CastChannelAsyncApiFunction::CastChannelAsyncApiFunction()
179 : cast_socket_service_(nullptr) {} 170 : cast_socket_service_(nullptr) {}
180 171
181 CastChannelAsyncApiFunction::~CastChannelAsyncApiFunction() { } 172 CastChannelAsyncApiFunction::~CastChannelAsyncApiFunction() { }
182 173
183 bool CastChannelAsyncApiFunction::PrePrepare() { 174 bool CastChannelAsyncApiFunction::PrePrepare() {
184 cast_socket_service_ = 175 cast_socket_service_ =
185 cast_channel::CastSocketServiceFactory::GetForBrowserContext( 176 cast_channel::CastSocketServiceFactory::GetForBrowserContext(
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 CastSocket* socket; 281 CastSocket* socket;
291 std::unique_ptr<CastSocket> test_socket = api_->GetSocketForTest(); 282 std::unique_ptr<CastSocket> test_socket = api_->GetSocketForTest();
292 if (test_socket.get()) { 283 if (test_socket.get()) {
293 socket = test_socket.release(); 284 socket = test_socket.release();
294 } else { 285 } else {
295 socket = new CastSocketImpl( 286 socket = new CastSocketImpl(
296 *ip_endpoint_, ExtensionsBrowserClient::Get()->GetNetLog(), 287 *ip_endpoint_, ExtensionsBrowserClient::Get()->GetNetLog(),
297 base::TimeDelta::FromMilliseconds(connect_info.timeout.get() 288 base::TimeDelta::FromMilliseconds(connect_info.timeout.get()
298 ? *connect_info.timeout 289 ? *connect_info.timeout
299 : kDefaultConnectTimeoutMillis), 290 : kDefaultConnectTimeoutMillis),
300 liveness_timeout_ > base::TimeDelta(), api_->GetLogger(), 291 liveness_timeout_, ping_interval_, api_->GetLogger(),
301 connect_info.capabilities.get() ? *connect_info.capabilities 292 connect_info.capabilities.get() ? *connect_info.capabilities
302 : CastDeviceCapability::NONE); 293 : CastDeviceCapability::NONE);
303 } 294 }
304 new_channel_id_ = cast_socket_service_->AddSocket(base::WrapUnique(socket)); 295 new_channel_id_ = cast_socket_service_->AddSocket(base::WrapUnique(socket));
305 296
306 // Construct read delegates. 297 // Construct read delegates.
307 std::unique_ptr<CastTransport::Delegate> delegate( 298 std::unique_ptr<CastTransport::Delegate> delegate(
308 base::MakeUnique<CastMessageHandler>( 299 base::MakeUnique<CastMessageHandler>(
309 base::Bind(&CastChannelAPI::SendEvent, api_->AsWeakPtr(), 300 base::Bind(&CastChannelAPI::SendEvent, api_->AsWeakPtr(),
310 extension_->id()), 301 extension_->id()),
311 socket, api_->GetLogger())); 302 socket, api_->GetLogger()));
312 if (socket->keep_alive()) {
313 // Wrap read delegate in a KeepAliveDelegate for timeout handling.
314 KeepAliveDelegate* keep_alive =
315 new KeepAliveDelegate(socket, api_->GetLogger(), std::move(delegate),
316 ping_interval_, liveness_timeout_);
317 std::unique_ptr<base::Timer> injected_timer =
318 api_->GetInjectedTimeoutTimerForTest();
319 if (injected_timer) {
320 keep_alive->SetTimersForTest(base::MakeUnique<base::Timer>(false, false),
321 std::move(injected_timer));
322 }
323 delegate.reset(keep_alive);
324 }
325
326 socket->Connect(std::move(delegate), 303 socket->Connect(std::move(delegate),
327 base::Bind(&CastChannelOpenFunction::OnOpen, this)); 304 base::Bind(&CastChannelOpenFunction::OnOpen, this));
328 } 305 }
329 306
330 void CastChannelOpenFunction::OnOpen(ChannelError result) { 307 void CastChannelOpenFunction::OnOpen(ChannelError result) {
331 DCHECK_CURRENTLY_ON(BrowserThread::IO); 308 DCHECK_CURRENTLY_ON(BrowserThread::IO);
332 VLOG(1) << "Connect finished, OnOpen invoked."; 309 VLOG(1) << "Connect finished, OnOpen invoked.";
333 // TODO: If we failed to open the CastSocket, we may want to clean up here, 310 // TODO: If we failed to open the CastSocket, we may want to clean up here,
334 // rather than relying on the extension to call close(). This can be done by 311 // rather than relying on the extension to call close(). This can be done by
335 // calling RemoveSocket() and api_->GetLogger()->ClearLastError(channel_id). 312 // calling RemoveSocket() and api_->GetLogger()->ClearLastError(channel_id).
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 std::move(results))); 480 std::move(results)));
504 BrowserThread::PostTask( 481 BrowserThread::PostTask(
505 BrowserThread::UI, FROM_HERE, 482 BrowserThread::UI, FROM_HERE,
506 base::Bind(ui_dispatch_cb_, base::Passed(std::move(event)))); 483 base::Bind(ui_dispatch_cb_, base::Passed(std::move(event))));
507 } 484 }
508 485
509 void CastChannelOpenFunction::CastMessageHandler::Start() { 486 void CastChannelOpenFunction::CastMessageHandler::Start() {
510 } 487 }
511 488
512 } // namespace extensions 489 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/cast_channel/cast_channel_api.h ('k') | extensions/browser/api/cast_channel/cast_channel_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698