Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/extensions/api/cast_channel/cast_channel_api.h" | 5 #include "chrome/browser/extensions/api/cast_channel/cast_channel_api.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/extensions/api/cast_channel/cast_socket.h" | 14 #include "chrome/browser/extensions/api/cast_channel/cast_socket.h" |
| 15 #include "chrome/browser/net/chrome_net_log.h" | 15 #include "chrome/browser/net/chrome_net_log.h" |
| 16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "extensions/browser/event_router.h" | 17 #include "extensions/browser/event_router.h" |
| 18 #include "net/base/ip_endpoint.h" | 18 #include "net/base/ip_endpoint.h" |
| 19 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 20 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" |
| 21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 22 | 22 |
| 23 // Default timeout interval for connection setup. | |
| 24 // TODO(kmarshall): add Javascript plumbing so clients can set the timeout. | |
|
mark a. foltz
2014/07/15 22:18:15
Can this be done as part of this change? It shoul
Kevin M
2014/07/16 22:59:41
Done.
| |
| 25 const int64 kDefaultConnectTimeoutMillis = 10000; // 10 seconds. | |
|
haibinlu
2014/07/15 22:10:45
5 seconds? we have been using this value.
Kevin M
2014/07/16 22:59:41
Done.
| |
| 26 | |
| 23 namespace extensions { | 27 namespace extensions { |
| 24 | 28 |
| 25 namespace Close = cast_channel::Close; | 29 namespace Close = cast_channel::Close; |
| 26 namespace OnError = cast_channel::OnError; | 30 namespace OnError = cast_channel::OnError; |
| 27 namespace OnMessage = cast_channel::OnMessage; | 31 namespace OnMessage = cast_channel::OnMessage; |
| 28 namespace Open = cast_channel::Open; | 32 namespace Open = cast_channel::Open; |
| 29 namespace Send = cast_channel::Send; | 33 namespace Send = cast_channel::Send; |
| 30 using cast_channel::CastSocket; | 34 using cast_channel::CastSocket; |
| 31 using cast_channel::ChannelAuthType; | 35 using cast_channel::ChannelAuthType; |
| 32 using cast_channel::ChannelError; | 36 using cast_channel::ChannelError; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 } | 86 } |
| 83 | 87 |
| 84 scoped_ptr<CastSocket> CastChannelAPI::CreateCastSocket( | 88 scoped_ptr<CastSocket> CastChannelAPI::CreateCastSocket( |
| 85 const std::string& extension_id, const net::IPEndPoint& ip_endpoint, | 89 const std::string& extension_id, const net::IPEndPoint& ip_endpoint, |
| 86 ChannelAuthType channel_auth) { | 90 ChannelAuthType channel_auth) { |
| 87 if (socket_for_test_.get()) { | 91 if (socket_for_test_.get()) { |
| 88 return socket_for_test_.Pass(); | 92 return socket_for_test_.Pass(); |
| 89 } else { | 93 } else { |
| 90 return scoped_ptr<CastSocket>( | 94 return scoped_ptr<CastSocket>( |
| 91 new CastSocket(extension_id, ip_endpoint, channel_auth, this, | 95 new CastSocket(extension_id, ip_endpoint, channel_auth, this, |
| 92 g_browser_process->net_log())); | 96 g_browser_process->net_log(), |
| 97 kDefaultConnectTimeoutMillis)); | |
| 93 } | 98 } |
| 94 } | 99 } |
| 95 | 100 |
| 96 void CastChannelAPI::SetSocketForTest(scoped_ptr<CastSocket> socket_for_test) { | 101 void CastChannelAPI::SetSocketForTest(scoped_ptr<CastSocket> socket_for_test) { |
| 97 socket_for_test_ = socket_for_test.Pass(); | 102 socket_for_test_ = socket_for_test.Pass(); |
| 98 } | 103 } |
| 99 | 104 |
| 100 void CastChannelAPI::OnError(const CastSocket* socket, | 105 void CastChannelAPI::OnError(const CastSocket* socket, |
| 101 cast_channel::ChannelError error) { | 106 cast_channel::ChannelError error) { |
| 102 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 107 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 VLOG(2) << "IP: " << ip_address_str << " Port: " << port_str; | 242 VLOG(2) << "IP: " << ip_address_str << " Port: " << port_str; |
| 238 int port; | 243 int port; |
| 239 if (!base::StringToInt(port_str, &port)) | 244 if (!base::StringToInt(port_str, &port)) |
| 240 return false; | 245 return false; |
| 241 connect_info->ip_address = ip_address_str; | 246 connect_info->ip_address = ip_address_str; |
| 242 connect_info->port = port; | 247 connect_info->port = port; |
| 243 connect_info->auth = auth_required ? | 248 connect_info->auth = auth_required ? |
| 244 cast_channel::CHANNEL_AUTH_TYPE_SSL_VERIFIED : | 249 cast_channel::CHANNEL_AUTH_TYPE_SSL_VERIFIED : |
| 245 cast_channel::CHANNEL_AUTH_TYPE_SSL; | 250 cast_channel::CHANNEL_AUTH_TYPE_SSL; |
| 246 return true; | 251 return true; |
| 247 }; | 252 } |
| 248 | 253 |
| 249 net::IPEndPoint* CastChannelOpenFunction::ParseConnectInfo( | 254 net::IPEndPoint* CastChannelOpenFunction::ParseConnectInfo( |
| 250 const ConnectInfo& connect_info) { | 255 const ConnectInfo& connect_info) { |
| 251 net::IPAddressNumber ip_address; | 256 net::IPAddressNumber ip_address; |
| 252 if (!net::ParseIPLiteralToNumber(connect_info.ip_address, &ip_address)) { | 257 if (!net::ParseIPLiteralToNumber(connect_info.ip_address, &ip_address)) { |
| 253 return NULL; | 258 return NULL; |
| 254 } | 259 } |
| 255 if (connect_info.port < 0 || connect_info.port > | 260 if (connect_info.port < 0 || connect_info.port > |
| 256 std::numeric_limits<unsigned short>::max()) { | 261 std::numeric_limits<unsigned short>::max()) { |
| 257 return NULL; | 262 return NULL; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 SetResultFromError(cast_channel::CHANNEL_ERROR_SOCKET_ERROR); | 369 SetResultFromError(cast_channel::CHANNEL_ERROR_SOCKET_ERROR); |
| 365 } else { | 370 } else { |
| 366 int channel_id = params_->channel.channel_id; | 371 int channel_id = params_->channel.channel_id; |
| 367 SetResultFromSocket(channel_id); | 372 SetResultFromSocket(channel_id); |
| 368 RemoveSocket(channel_id); | 373 RemoveSocket(channel_id); |
| 369 } | 374 } |
| 370 AsyncWorkCompleted(); | 375 AsyncWorkCompleted(); |
| 371 } | 376 } |
| 372 | 377 |
| 373 } // namespace extensions | 378 } // namespace extensions |
| OLD | NEW |