| 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 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
| 17 #include "base/lazy_instance.h" | 17 #include "base/lazy_instance.h" |
| 18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/values.h" | 20 #include "base/values.h" |
| 21 #include "components/cast_channel/cast_message_util.h" |
| 22 #include "components/cast_channel/cast_socket.h" |
| 23 #include "components/cast_channel/cast_socket_service.h" |
| 24 #include "components/cast_channel/cast_socket_service_factory.h" |
| 25 #include "components/cast_channel/keep_alive_delegate.h" |
| 26 #include "components/cast_channel/logger.h" |
| 27 #include "components/cast_channel/proto/cast_channel.pb.h" |
| 28 #include "components/cast_channel/proto/logging.pb.h" |
| 21 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 22 #include "extensions/browser/api/cast_channel/cast_channel_enum_util.h" | 30 #include "extensions/browser/api/cast_channel/cast_channel_enum_util.h" |
| 23 #include "extensions/browser/api/cast_channel/cast_message_util.h" | 31 #include "extensions/browser/api/cast_channel/cast_message_util.h" |
| 24 #include "extensions/browser/api/cast_channel/cast_socket.h" | |
| 25 #include "extensions/browser/api/cast_channel/cast_socket_service.h" | |
| 26 #include "extensions/browser/api/cast_channel/cast_socket_service_factory.h" | |
| 27 #include "extensions/browser/api/cast_channel/keep_alive_delegate.h" | |
| 28 #include "extensions/browser/api/cast_channel/logger.h" | |
| 29 #include "extensions/browser/event_router.h" | 32 #include "extensions/browser/event_router.h" |
| 30 #include "extensions/common/api/cast_channel/cast_channel.pb.h" | |
| 31 #include "extensions/common/api/cast_channel/logging.pb.h" | |
| 32 #include "net/base/ip_address.h" | 33 #include "net/base/ip_address.h" |
| 33 #include "net/base/ip_endpoint.h" | 34 #include "net/base/ip_endpoint.h" |
| 34 #include "net/base/net_errors.h" | 35 #include "net/base/net_errors.h" |
| 35 | 36 |
| 36 // Default timeout interval for connection setup. | 37 // Default timeout interval for connection setup. |
| 37 // Used if not otherwise specified at ConnectInfo::timeout. | 38 // Used if not otherwise specified at ConnectInfo::timeout. |
| 38 const int kDefaultConnectTimeoutMillis = 5000; // 5 seconds. | 39 const int kDefaultConnectTimeoutMillis = 5000; // 5 seconds. |
| 39 | 40 |
| 40 namespace extensions { | 41 namespace extensions { |
| 41 | 42 |
| 42 namespace Close = cast_channel::Close; | 43 namespace Close = api::cast_channel::Close; |
| 43 namespace OnError = cast_channel::OnError; | 44 namespace OnError = api::cast_channel::OnError; |
| 44 namespace OnMessage = cast_channel::OnMessage; | 45 namespace OnMessage = api::cast_channel::OnMessage; |
| 45 namespace Open = cast_channel::Open; | 46 namespace Open = api::cast_channel::Open; |
| 46 namespace Send = cast_channel::Send; | 47 namespace Send = api::cast_channel::Send; |
| 47 using ::cast_channel::ChannelError; | 48 using api::cast_channel::ChannelInfo; |
| 49 using api::cast_channel::ConnectInfo; |
| 50 using api::cast_channel::ErrorInfo; |
| 51 using api::cast_channel::MessageInfo; |
| 52 using cast_channel::ChannelError; |
| 48 using cast_channel::CastDeviceCapability; | 53 using cast_channel::CastDeviceCapability; |
| 49 using cast_channel::CastMessage; | 54 using cast_channel::CastMessage; |
| 50 using cast_channel::CastSocket; | 55 using cast_channel::CastSocket; |
| 51 using cast_channel::CastSocketImpl; | 56 using cast_channel::CastSocketImpl; |
| 52 using cast_channel::CastTransport; | 57 using cast_channel::CastTransport; |
| 53 using cast_channel::ChannelInfo; | |
| 54 using cast_channel::ConnectInfo; | |
| 55 using cast_channel::ErrorInfo; | |
| 56 using cast_channel::KeepAliveDelegate; | 58 using cast_channel::KeepAliveDelegate; |
| 57 using cast_channel::LastErrors; | 59 using cast_channel::LastErrors; |
| 58 using cast_channel::Logger; | 60 using cast_channel::Logger; |
| 59 using cast_channel::MessageInfo; | 61 |
| 60 using content::BrowserThread; | 62 using content::BrowserThread; |
| 61 | 63 |
| 62 namespace { | 64 namespace { |
| 63 | 65 |
| 64 // T is an extension dictionary (MessageInfo or ChannelInfo) | 66 // T is an extension dictionary (MessageInfo or ChannelInfo) |
| 65 template <class T> | 67 template <class T> |
| 66 std::string ParamToString(const T& info) { | 68 std::string ParamToString(const T& info) { |
| 67 std::unique_ptr<base::DictionaryValue> dict = info.ToValue(); | 69 std::unique_ptr<base::DictionaryValue> dict = info.ToValue(); |
| 68 std::string out; | 70 std::string out; |
| 69 base::JSONWriter::Write(*dict, &out); | 71 base::JSONWriter::Write(*dict, &out); |
| 70 return out; | 72 return out; |
| 71 } | 73 } |
| 72 | 74 |
| 73 // Fills |channel_info| from the destination and state of |socket|. | 75 // Fills |channel_info| from the destination and state of |socket|. |
| 74 void FillChannelInfo(const CastSocket& socket, ChannelInfo* channel_info) { | 76 void FillChannelInfo(const CastSocket& socket, ChannelInfo* channel_info) { |
| 75 DCHECK(channel_info); | 77 DCHECK(channel_info); |
| 76 channel_info->channel_id = socket.id(); | 78 channel_info->channel_id = socket.id(); |
| 77 const net::IPEndPoint& ip_endpoint = socket.ip_endpoint(); | 79 const net::IPEndPoint& ip_endpoint = socket.ip_endpoint(); |
| 78 channel_info->connect_info.ip_address = ip_endpoint.ToStringWithoutPort(); | 80 channel_info->connect_info.ip_address = ip_endpoint.ToStringWithoutPort(); |
| 79 channel_info->connect_info.port = ip_endpoint.port(); | 81 channel_info->connect_info.port = ip_endpoint.port(); |
| 80 channel_info->connect_info.auth = | 82 channel_info->connect_info.auth = |
| 81 cast_channel::ToChannelAuthType(socket.channel_auth()); | 83 api::cast_channel::ToChannelAuthType(socket.channel_auth()); |
| 82 channel_info->ready_state = cast_channel::ToReadyState(socket.ready_state()); | 84 channel_info->ready_state = |
| 85 api::cast_channel::ToReadyState(socket.ready_state()); |
| 83 channel_info->error_state = | 86 channel_info->error_state = |
| 84 cast_channel::ToChannelError(socket.error_state()); | 87 api::cast_channel::ToChannelError(socket.error_state()); |
| 85 channel_info->keep_alive = socket.keep_alive(); | 88 channel_info->keep_alive = socket.keep_alive(); |
| 86 channel_info->audio_only = socket.audio_only(); | 89 channel_info->audio_only = socket.audio_only(); |
| 87 } | 90 } |
| 88 | 91 |
| 89 // Fills |error_info| from |error_state| and |last_errors|. | 92 // Fills |error_info| from |error_state| and |last_errors|. |
| 90 void FillErrorInfo(cast_channel::ChannelError error_state, | 93 void FillErrorInfo(api::cast_channel::ChannelError error_state, |
| 91 const LastErrors& last_errors, | 94 const LastErrors& last_errors, |
| 92 ErrorInfo* error_info) { | 95 ErrorInfo* error_info) { |
| 93 error_info->error_state = error_state; | 96 error_info->error_state = error_state; |
| 94 if (last_errors.event_type != cast_channel::proto::EVENT_TYPE_UNKNOWN) | 97 if (last_errors.event_type != cast_channel::proto::EVENT_TYPE_UNKNOWN) |
| 95 error_info->event_type.reset(new int(last_errors.event_type)); | 98 error_info->event_type.reset(new int(last_errors.event_type)); |
| 96 if (last_errors.challenge_reply_error_type != | 99 if (last_errors.challenge_reply_error_type != |
| 97 cast_channel::proto::CHALLENGE_REPLY_ERROR_NONE) { | 100 cast_channel::proto::CHALLENGE_REPLY_ERROR_NONE) { |
| 98 error_info->challenge_reply_error_type.reset( | 101 error_info->challenge_reply_error_type.reset( |
| 99 new int(last_errors.challenge_reply_error_type)); | 102 new int(last_errors.challenge_reply_error_type)); |
| 100 } | 103 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 174 |
| 172 CastChannelAPI::~CastChannelAPI() {} | 175 CastChannelAPI::~CastChannelAPI() {} |
| 173 | 176 |
| 174 CastChannelAsyncApiFunction::CastChannelAsyncApiFunction() | 177 CastChannelAsyncApiFunction::CastChannelAsyncApiFunction() |
| 175 : cast_socket_service_(nullptr) {} | 178 : cast_socket_service_(nullptr) {} |
| 176 | 179 |
| 177 CastChannelAsyncApiFunction::~CastChannelAsyncApiFunction() { } | 180 CastChannelAsyncApiFunction::~CastChannelAsyncApiFunction() { } |
| 178 | 181 |
| 179 bool CastChannelAsyncApiFunction::PrePrepare() { | 182 bool CastChannelAsyncApiFunction::PrePrepare() { |
| 180 cast_socket_service_ = | 183 cast_socket_service_ = |
| 181 api::cast_channel::CastSocketServiceFactory::GetForBrowserContext( | 184 cast_channel::CastSocketServiceFactory::GetForBrowserContext( |
| 182 browser_context()); | 185 browser_context()); |
| 183 DCHECK(cast_socket_service_); | 186 DCHECK(cast_socket_service_); |
| 184 return true; | 187 return true; |
| 185 } | 188 } |
| 186 | 189 |
| 187 bool CastChannelAsyncApiFunction::Respond() { | 190 bool CastChannelAsyncApiFunction::Respond() { |
| 188 return GetError().empty(); | 191 return GetError().empty(); |
| 189 } | 192 } |
| 190 | 193 |
| 191 void CastChannelAsyncApiFunction::SetResultFromSocket( | 194 void CastChannelAsyncApiFunction::SetResultFromSocket( |
| 192 const CastSocket& socket) { | 195 const CastSocket& socket) { |
| 193 ChannelInfo channel_info; | 196 ChannelInfo channel_info; |
| 194 FillChannelInfo(socket, &channel_info); | 197 FillChannelInfo(socket, &channel_info); |
| 195 cast_channel::ChannelError error = | 198 api::cast_channel::ChannelError error = |
| 196 cast_channel::ToChannelError(socket.error_state()); | 199 api::cast_channel::ToChannelError(socket.error_state()); |
| 197 if (error != cast_channel::CHANNEL_ERROR_NONE) { | 200 if (error != api::cast_channel::CHANNEL_ERROR_NONE) { |
| 198 SetError("Channel socket error = " + base::IntToString(error)); | 201 SetError("Channel socket error = " + base::IntToString(error)); |
| 199 } | 202 } |
| 200 SetResultFromChannelInfo(channel_info); | 203 SetResultFromChannelInfo(channel_info); |
| 201 } | 204 } |
| 202 | 205 |
| 203 void CastChannelAsyncApiFunction::SetResultFromError( | 206 void CastChannelAsyncApiFunction::SetResultFromError( |
| 204 int channel_id, | 207 int channel_id, |
| 205 cast_channel::ChannelError error) { | 208 api::cast_channel::ChannelError error) { |
| 206 ChannelInfo channel_info; | 209 ChannelInfo channel_info; |
| 207 channel_info.channel_id = channel_id; | 210 channel_info.channel_id = channel_id; |
| 208 channel_info.ready_state = cast_channel::READY_STATE_CLOSED; | 211 channel_info.ready_state = api::cast_channel::READY_STATE_CLOSED; |
| 209 channel_info.error_state = error; | 212 channel_info.error_state = error; |
| 210 channel_info.connect_info.ip_address = ""; | 213 channel_info.connect_info.ip_address = ""; |
| 211 channel_info.connect_info.port = 0; | 214 channel_info.connect_info.port = 0; |
| 212 channel_info.connect_info.auth = cast_channel::CHANNEL_AUTH_TYPE_SSL_VERIFIED; | 215 channel_info.connect_info.auth = |
| 216 api::cast_channel::CHANNEL_AUTH_TYPE_SSL_VERIFIED; |
| 213 SetResultFromChannelInfo(channel_info); | 217 SetResultFromChannelInfo(channel_info); |
| 214 SetError("Channel error = " + base::IntToString(error)); | 218 SetError("Channel error = " + base::IntToString(error)); |
| 215 } | 219 } |
| 216 | 220 |
| 217 void CastChannelAsyncApiFunction::SetResultFromChannelInfo( | 221 void CastChannelAsyncApiFunction::SetResultFromChannelInfo( |
| 218 const ChannelInfo& channel_info) { | 222 const ChannelInfo& channel_info) { |
| 219 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 223 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 220 SetResult(channel_info.ToValue()); | 224 SetResult(channel_info.ToValue()); |
| 221 } | 225 } |
| 222 | 226 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 SetError("livenessTimeout and pingInterval must be set together."); | 271 SetError("livenessTimeout and pingInterval must be set together."); |
| 268 } else if (liveness_timeout_ < ping_interval_) { | 272 } else if (liveness_timeout_ < ping_interval_) { |
| 269 SetError("livenessTimeout must be longer than pingTimeout."); | 273 SetError("livenessTimeout must be longer than pingTimeout."); |
| 270 } | 274 } |
| 271 } | 275 } |
| 272 | 276 |
| 273 if (!GetError().empty()) { | 277 if (!GetError().empty()) { |
| 274 return false; | 278 return false; |
| 275 } | 279 } |
| 276 | 280 |
| 277 channel_auth_ = cast_channel::ToChannelAuthTypeInternal(connect_info.auth); | 281 channel_auth_ = |
| 282 api::cast_channel::ToChannelAuthTypeInternal(connect_info.auth); |
| 278 ip_endpoint_.reset(ParseConnectInfo(connect_info)); | 283 ip_endpoint_.reset(ParseConnectInfo(connect_info)); |
| 279 return true; | 284 return true; |
| 280 } | 285 } |
| 281 | 286 |
| 282 void CastChannelOpenFunction::AsyncWorkStart() { | 287 void CastChannelOpenFunction::AsyncWorkStart() { |
| 283 DCHECK(api_); | 288 DCHECK(api_); |
| 284 DCHECK(ip_endpoint_.get()); | 289 DCHECK(ip_endpoint_.get()); |
| 285 const ConnectInfo& connect_info = params_->connect_info; | 290 const ConnectInfo& connect_info = params_->connect_info; |
| 286 CastSocket* socket; | 291 CastSocket* socket; |
| 287 std::unique_ptr<CastSocket> test_socket = api_->GetSocketForTest(); | 292 std::unique_ptr<CastSocket> test_socket = api_->GetSocketForTest(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 VLOG(1) << "Connect finished, OnOpen invoked."; | 334 VLOG(1) << "Connect finished, OnOpen invoked."; |
| 330 // TODO: If we failed to open the CastSocket, we may want to clean up here, | 335 // TODO: If we failed to open the CastSocket, we may want to clean up here, |
| 331 // rather than relying on the extension to call close(). This can be done by | 336 // rather than relying on the extension to call close(). This can be done by |
| 332 // calling RemoveSocket() and api_->GetLogger()->ClearLastErrors(channel_id). | 337 // calling RemoveSocket() and api_->GetLogger()->ClearLastErrors(channel_id). |
| 333 if (result != ChannelError::UNKNOWN) { | 338 if (result != ChannelError::UNKNOWN) { |
| 334 CastSocket* socket = cast_socket_service_->GetSocket(new_channel_id_); | 339 CastSocket* socket = cast_socket_service_->GetSocket(new_channel_id_); |
| 335 CHECK(socket); | 340 CHECK(socket); |
| 336 SetResultFromSocket(*socket); | 341 SetResultFromSocket(*socket); |
| 337 } else { | 342 } else { |
| 338 // The socket is being destroyed. | 343 // The socket is being destroyed. |
| 339 SetResultFromError(new_channel_id_, cast_channel::CHANNEL_ERROR_UNKNOWN); | 344 SetResultFromError(new_channel_id_, |
| 345 api::cast_channel::CHANNEL_ERROR_UNKNOWN); |
| 340 } | 346 } |
| 341 | 347 |
| 342 AsyncWorkCompleted(); | 348 AsyncWorkCompleted(); |
| 343 } | 349 } |
| 344 | 350 |
| 345 CastChannelSendFunction::CastChannelSendFunction() { } | 351 CastChannelSendFunction::CastChannelSendFunction() { } |
| 346 | 352 |
| 347 CastChannelSendFunction::~CastChannelSendFunction() { } | 353 CastChannelSendFunction::~CastChannelSendFunction() { } |
| 348 | 354 |
| 349 bool CastChannelSendFunction::Prepare() { | 355 bool CastChannelSendFunction::Prepare() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 370 return false; | 376 return false; |
| 371 } | 377 } |
| 372 return true; | 378 return true; |
| 373 } | 379 } |
| 374 | 380 |
| 375 void CastChannelSendFunction::AsyncWorkStart() { | 381 void CastChannelSendFunction::AsyncWorkStart() { |
| 376 CastSocket* socket = | 382 CastSocket* socket = |
| 377 cast_socket_service_->GetSocket(params_->channel.channel_id); | 383 cast_socket_service_->GetSocket(params_->channel.channel_id); |
| 378 if (!socket) { | 384 if (!socket) { |
| 379 SetResultFromError(params_->channel.channel_id, | 385 SetResultFromError(params_->channel.channel_id, |
| 380 cast_channel::CHANNEL_ERROR_INVALID_CHANNEL_ID); | 386 api::cast_channel::CHANNEL_ERROR_INVALID_CHANNEL_ID); |
| 381 AsyncWorkCompleted(); | 387 AsyncWorkCompleted(); |
| 382 return; | 388 return; |
| 383 } | 389 } |
| 384 CastMessage message_to_send; | 390 CastMessage message_to_send; |
| 385 if (!MessageInfoToCastMessage(params_->message, &message_to_send)) { | 391 if (!MessageInfoToCastMessage(params_->message, &message_to_send)) { |
| 386 SetResultFromError(params_->channel.channel_id, | 392 SetResultFromError(params_->channel.channel_id, |
| 387 cast_channel::CHANNEL_ERROR_INVALID_MESSAGE); | 393 api::cast_channel::CHANNEL_ERROR_INVALID_MESSAGE); |
| 388 AsyncWorkCompleted(); | 394 AsyncWorkCompleted(); |
| 389 return; | 395 return; |
| 390 } | 396 } |
| 391 socket->transport()->SendMessage( | 397 socket->transport()->SendMessage( |
| 392 message_to_send, base::Bind(&CastChannelSendFunction::OnSend, this)); | 398 message_to_send, base::Bind(&CastChannelSendFunction::OnSend, this)); |
| 393 } | 399 } |
| 394 | 400 |
| 395 void CastChannelSendFunction::OnSend(int result) { | 401 void CastChannelSendFunction::OnSend(int result) { |
| 396 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 402 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 397 int channel_id = params_->channel.channel_id; | 403 int channel_id = params_->channel.channel_id; |
| 398 CastSocket* socket = cast_socket_service_->GetSocket(channel_id); | 404 CastSocket* socket = cast_socket_service_->GetSocket(channel_id); |
| 399 if (result < 0 || !socket) { | 405 if (result < 0 || !socket) { |
| 400 SetResultFromError(channel_id, | 406 SetResultFromError(channel_id, |
| 401 cast_channel::CHANNEL_ERROR_SOCKET_ERROR); | 407 api::cast_channel::CHANNEL_ERROR_SOCKET_ERROR); |
| 402 } else { | 408 } else { |
| 403 SetResultFromSocket(*socket); | 409 SetResultFromSocket(*socket); |
| 404 } | 410 } |
| 405 AsyncWorkCompleted(); | 411 AsyncWorkCompleted(); |
| 406 } | 412 } |
| 407 | 413 |
| 408 CastChannelCloseFunction::CastChannelCloseFunction() { } | 414 CastChannelCloseFunction::CastChannelCloseFunction() { } |
| 409 | 415 |
| 410 CastChannelCloseFunction::~CastChannelCloseFunction() { } | 416 CastChannelCloseFunction::~CastChannelCloseFunction() { } |
| 411 | 417 |
| 412 bool CastChannelCloseFunction::PrePrepare() { | 418 bool CastChannelCloseFunction::PrePrepare() { |
| 413 api_ = CastChannelAPI::Get(browser_context()); | 419 api_ = CastChannelAPI::Get(browser_context()); |
| 414 return CastChannelAsyncApiFunction::PrePrepare(); | 420 return CastChannelAsyncApiFunction::PrePrepare(); |
| 415 } | 421 } |
| 416 | 422 |
| 417 bool CastChannelCloseFunction::Prepare() { | 423 bool CastChannelCloseFunction::Prepare() { |
| 418 params_ = Close::Params::Create(*args_); | 424 params_ = Close::Params::Create(*args_); |
| 419 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 425 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 420 return true; | 426 return true; |
| 421 } | 427 } |
| 422 | 428 |
| 423 void CastChannelCloseFunction::AsyncWorkStart() { | 429 void CastChannelCloseFunction::AsyncWorkStart() { |
| 424 CastSocket* socket = | 430 CastSocket* socket = |
| 425 cast_socket_service_->GetSocket(params_->channel.channel_id); | 431 cast_socket_service_->GetSocket(params_->channel.channel_id); |
| 426 if (!socket) { | 432 if (!socket) { |
| 427 SetResultFromError(params_->channel.channel_id, | 433 SetResultFromError(params_->channel.channel_id, |
| 428 cast_channel::CHANNEL_ERROR_INVALID_CHANNEL_ID); | 434 api::cast_channel::CHANNEL_ERROR_INVALID_CHANNEL_ID); |
| 429 AsyncWorkCompleted(); | 435 AsyncWorkCompleted(); |
| 430 } else { | 436 } else { |
| 431 socket->Close(base::Bind(&CastChannelCloseFunction::OnClose, this)); | 437 socket->Close(base::Bind(&CastChannelCloseFunction::OnClose, this)); |
| 432 } | 438 } |
| 433 } | 439 } |
| 434 | 440 |
| 435 void CastChannelCloseFunction::OnClose(int result) { | 441 void CastChannelCloseFunction::OnClose(int result) { |
| 436 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 442 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 437 VLOG(1) << "CastChannelCloseFunction::OnClose result = " << result; | 443 VLOG(1) << "CastChannelCloseFunction::OnClose result = " << result; |
| 438 int channel_id = params_->channel.channel_id; | 444 int channel_id = params_->channel.channel_id; |
| 439 CastSocket* socket = cast_socket_service_->GetSocket(channel_id); | 445 CastSocket* socket = cast_socket_service_->GetSocket(channel_id); |
| 440 if (result < 0 || !socket) { | 446 if (result < 0 || !socket) { |
| 441 SetResultFromError(channel_id, | 447 SetResultFromError(channel_id, |
| 442 cast_channel::CHANNEL_ERROR_SOCKET_ERROR); | 448 api::cast_channel::CHANNEL_ERROR_SOCKET_ERROR); |
| 443 } else { | 449 } else { |
| 444 SetResultFromSocket(*socket); | 450 SetResultFromSocket(*socket); |
| 445 // This will delete |socket|. | 451 // This will delete |socket|. |
| 446 cast_socket_service_->RemoveSocket(channel_id); | 452 cast_socket_service_->RemoveSocket(channel_id); |
| 447 api_->GetLogger()->ClearLastErrors(channel_id); | 453 api_->GetLogger()->ClearLastErrors(channel_id); |
| 448 } | 454 } |
| 449 AsyncWorkCompleted(); | 455 AsyncWorkCompleted(); |
| 450 } | 456 } |
| 451 | 457 |
| 452 CastChannelOpenFunction::CastMessageHandler::CastMessageHandler( | 458 CastChannelOpenFunction::CastMessageHandler::CastMessageHandler( |
| 453 const EventDispatchCallback& ui_dispatch_cb, | 459 const EventDispatchCallback& ui_dispatch_cb, |
| 454 CastSocket* socket, | 460 CastSocket* socket, |
| 455 scoped_refptr<Logger> logger) | 461 scoped_refptr<Logger> logger) |
| 456 : ui_dispatch_cb_(ui_dispatch_cb), socket_(socket), logger_(logger) { | 462 : ui_dispatch_cb_(ui_dispatch_cb), socket_(socket), logger_(logger) { |
| 457 DCHECK(socket_); | 463 DCHECK(socket_); |
| 458 DCHECK(logger_); | 464 DCHECK(logger_); |
| 459 } | 465 } |
| 460 | 466 |
| 461 CastChannelOpenFunction::CastMessageHandler::~CastMessageHandler() { | 467 CastChannelOpenFunction::CastMessageHandler::~CastMessageHandler() { |
| 462 } | 468 } |
| 463 | 469 |
| 464 void CastChannelOpenFunction::CastMessageHandler::OnError( | 470 void CastChannelOpenFunction::CastMessageHandler::OnError( |
| 465 ChannelError error_state) { | 471 ChannelError error_state) { |
| 466 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 472 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 467 | 473 |
| 468 ChannelInfo channel_info; | 474 ChannelInfo channel_info; |
| 469 FillChannelInfo(*socket_, &channel_info); | 475 FillChannelInfo(*socket_, &channel_info); |
| 470 channel_info.error_state = cast_channel::ToChannelError(error_state); | 476 channel_info.error_state = api::cast_channel::ToChannelError(error_state); |
| 471 ErrorInfo error_info; | 477 ErrorInfo error_info; |
| 472 FillErrorInfo(channel_info.error_state, logger_->GetLastErrors(socket_->id()), | 478 FillErrorInfo(channel_info.error_state, logger_->GetLastErrors(socket_->id()), |
| 473 &error_info); | 479 &error_info); |
| 474 | 480 |
| 475 std::unique_ptr<base::ListValue> results = | 481 std::unique_ptr<base::ListValue> results = |
| 476 OnError::Create(channel_info, error_info); | 482 OnError::Create(channel_info, error_info); |
| 477 std::unique_ptr<Event> event(new Event( | 483 std::unique_ptr<Event> event(new Event( |
| 478 events::CAST_CHANNEL_ON_ERROR, OnError::kEventName, std::move(results))); | 484 events::CAST_CHANNEL_ON_ERROR, OnError::kEventName, std::move(results))); |
| 479 BrowserThread::PostTask( | 485 BrowserThread::PostTask( |
| 480 BrowserThread::UI, FROM_HERE, | 486 BrowserThread::UI, FROM_HERE, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 499 std::move(results))); | 505 std::move(results))); |
| 500 BrowserThread::PostTask( | 506 BrowserThread::PostTask( |
| 501 BrowserThread::UI, FROM_HERE, | 507 BrowserThread::UI, FROM_HERE, |
| 502 base::Bind(ui_dispatch_cb_, base::Passed(std::move(event)))); | 508 base::Bind(ui_dispatch_cb_, base::Passed(std::move(event)))); |
| 503 } | 509 } |
| 504 | 510 |
| 505 void CastChannelOpenFunction::CastMessageHandler::Start() { | 511 void CastChannelOpenFunction::CastMessageHandler::Start() { |
| 506 } | 512 } |
| 507 | 513 |
| 508 } // namespace extensions | 514 } // namespace extensions |
| OLD | NEW |