| OLD | NEW |
| 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 | 14 |
| 15 #include "base/guid.h" |
| 15 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
| 16 #include "base/lazy_instance.h" | 17 #include "base/lazy_instance.h" |
| 17 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 18 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/time/default_clock.h" | 20 #include "base/time/default_clock.h" |
| 20 #include "base/values.h" | 21 #include "base/values.h" |
| 21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 22 #include "extensions/browser/api/cast_channel/cast_message_util.h" | 23 #include "extensions/browser/api/cast_channel/cast_message_util.h" |
| 23 #include "extensions/browser/api/cast_channel/cast_socket.h" | 24 #include "extensions/browser/api/cast_channel/cast_socket.h" |
| 24 #include "extensions/browser/api/cast_channel/keep_alive_delegate.h" | 25 #include "extensions/browser/api/cast_channel/keep_alive_delegate.h" |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 return sockets_->Get(extension_->id(), channel_id); | 236 return sockets_->Get(extension_->id(), channel_id); |
| 236 } | 237 } |
| 237 | 238 |
| 238 void CastChannelAsyncApiFunction::SetResultFromChannelInfo( | 239 void CastChannelAsyncApiFunction::SetResultFromChannelInfo( |
| 239 const ChannelInfo& channel_info) { | 240 const ChannelInfo& channel_info) { |
| 240 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 241 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 241 SetResult(channel_info.ToValue()); | 242 SetResult(channel_info.ToValue()); |
| 242 } | 243 } |
| 243 | 244 |
| 244 CastChannelOpenFunction::CastChannelOpenFunction() | 245 CastChannelOpenFunction::CastChannelOpenFunction() |
| 245 : new_channel_id_(0) { | 246 : new_channel_id_(0), nonce_(base::GenerateGUID()) {} |
| 246 } | |
| 247 | 247 |
| 248 CastChannelOpenFunction::~CastChannelOpenFunction() { } | 248 CastChannelOpenFunction::~CastChannelOpenFunction() { } |
| 249 | 249 |
| 250 net::IPEndPoint* CastChannelOpenFunction::ParseConnectInfo( | 250 net::IPEndPoint* CastChannelOpenFunction::ParseConnectInfo( |
| 251 const ConnectInfo& connect_info) { | 251 const ConnectInfo& connect_info) { |
| 252 net::IPAddress ip_address; | 252 net::IPAddress ip_address; |
| 253 CHECK(ip_address.AssignFromIPLiteral(connect_info.ip_address)); | 253 CHECK(ip_address.AssignFromIPLiteral(connect_info.ip_address)); |
| 254 return new net::IPEndPoint(ip_address, | 254 return new net::IPEndPoint(ip_address, |
| 255 static_cast<uint16_t>(connect_info.port)); | 255 static_cast<uint16_t>(connect_info.port)); |
| 256 } | 256 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 socket = test_socket.release(); | 310 socket = test_socket.release(); |
| 311 } else { | 311 } else { |
| 312 socket = new cast_channel::CastSocketImpl( | 312 socket = new cast_channel::CastSocketImpl( |
| 313 extension_->id(), *ip_endpoint_, channel_auth_, | 313 extension_->id(), *ip_endpoint_, channel_auth_, |
| 314 ExtensionsBrowserClient::Get()->GetNetLog(), | 314 ExtensionsBrowserClient::Get()->GetNetLog(), |
| 315 base::TimeDelta::FromMilliseconds(connect_info.timeout.get() | 315 base::TimeDelta::FromMilliseconds(connect_info.timeout.get() |
| 316 ? *connect_info.timeout | 316 ? *connect_info.timeout |
| 317 : kDefaultConnectTimeoutMillis), | 317 : kDefaultConnectTimeoutMillis), |
| 318 liveness_timeout_ > base::TimeDelta(), api_->GetLogger(), | 318 liveness_timeout_ > base::TimeDelta(), api_->GetLogger(), |
| 319 connect_info.capabilities.get() ? *connect_info.capabilities | 319 connect_info.capabilities.get() ? *connect_info.capabilities |
| 320 : CastDeviceCapability::NONE); | 320 : CastDeviceCapability::NONE, |
| 321 nonce_); |
| 321 } | 322 } |
| 322 new_channel_id_ = AddSocket(socket); | 323 new_channel_id_ = AddSocket(socket); |
| 323 api_->GetLogger()->LogNewSocketEvent(*socket); | 324 api_->GetLogger()->LogNewSocketEvent(*socket); |
| 324 | 325 |
| 325 // Construct read delegates. | 326 // Construct read delegates. |
| 326 std::unique_ptr<api::cast_channel::CastTransport::Delegate> delegate( | 327 std::unique_ptr<api::cast_channel::CastTransport::Delegate> delegate( |
| 327 base::MakeUnique<CastMessageHandler>( | 328 base::MakeUnique<CastMessageHandler>( |
| 328 base::Bind(&CastChannelAPI::SendEvent, api_->AsWeakPtr()), socket, | 329 base::Bind(&CastChannelAPI::SendEvent, api_->AsWeakPtr()), socket, |
| 329 api_->GetLogger())); | 330 api_->GetLogger())); |
| 330 if (socket->keep_alive()) { | 331 if (socket->keep_alive()) { |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 return true; | 558 return true; |
| 558 } | 559 } |
| 559 | 560 |
| 560 void CastChannelSetAuthorityKeysFunction::AsyncWorkStart() { | 561 void CastChannelSetAuthorityKeysFunction::AsyncWorkStart() { |
| 561 // TODO(eroman): crbug.com/601171: Delete this once the API is | 562 // TODO(eroman): crbug.com/601171: Delete this once the API is |
| 562 // removed. It is currently a no-op. | 563 // removed. It is currently a no-op. |
| 563 AsyncWorkCompleted(); | 564 AsyncWorkCompleted(); |
| 564 } | 565 } |
| 565 | 566 |
| 566 } // namespace extensions | 567 } // namespace extensions |
| OLD | NEW |