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

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

Issue 393023003: Added connection timeout functionality to CastSocket. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added missing initializer for CastSocket unit tests. Created 6 years, 5 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: chrome/browser/extensions/api/cast_channel/cast_channel_api.cc
diff --git a/chrome/browser/extensions/api/cast_channel/cast_channel_api.cc b/chrome/browser/extensions/api/cast_channel/cast_channel_api.cc
index b4378ea0ac060e0d54c3e80295f20686c62641c0..1c3a3116bf262d7d38c5e87b9945f5be132d8a3b 100644
--- a/chrome/browser/extensions/api/cast_channel/cast_channel_api.cc
+++ b/chrome/browser/extensions/api/cast_channel/cast_channel_api.cc
@@ -21,6 +21,10 @@
#include "net/base/net_util.h"
#include "url/gurl.h"
+// Default timeout interval for connection setup.
+// Used if not otherwise specified at ConnectInfo::timeout.
+const int kDefaultConnectTimeoutMillis = 5000; // 5 seconds.
+
namespace extensions {
namespace Close = cast_channel::Close;
@@ -99,13 +103,14 @@ CastChannelAPI::GetFactoryInstance() {
scoped_ptr<CastSocket> CastChannelAPI::CreateCastSocket(
const std::string& extension_id, const net::IPEndPoint& ip_endpoint,
- ChannelAuthType channel_auth) {
+ ChannelAuthType channel_auth, const base::TimeDelta& timeout) {
if (socket_for_test_.get()) {
return socket_for_test_.Pass();
} else {
return scoped_ptr<CastSocket>(
new CastSocket(extension_id, ip_endpoint, channel_auth, this,
- g_browser_process->net_log()));
+ g_browser_process->net_log(),
+ timeout));
}
}
@@ -321,7 +326,12 @@ void CastChannelOpenFunction::AsyncWorkStart() {
DCHECK(api_);
DCHECK(ip_endpoint_.get());
scoped_ptr<CastSocket> socket = api_->CreateCastSocket(
- extension_->id(), *ip_endpoint_, channel_auth_);
+ extension_->id(),
+ *ip_endpoint_,
+ channel_auth_,
+ base::TimeDelta::FromMilliseconds(connect_info_->timeout.get()
+ ? *connect_info_->timeout
+ : kDefaultConnectTimeoutMillis));
new_channel_id_ = AddSocket(socket.release());
GetSocket(new_channel_id_)->Connect(
base::Bind(&CastChannelOpenFunction::OnOpen, this));
@@ -329,6 +339,7 @@ void CastChannelOpenFunction::AsyncWorkStart() {
void CastChannelOpenFunction::OnOpen(int result) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ VLOG(1) << "Connect finished, OnOpen invoked.";
SetResultFromSocket(new_channel_id_);
AsyncWorkCompleted();
}

Powered by Google App Engine
This is Rietveld 408576698