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 <limits> | 7 #include <limits> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 static base::LazyInstance<BrowserContextKeyedAPIFactory<CastChannelAPI> > | 125 static base::LazyInstance<BrowserContextKeyedAPIFactory<CastChannelAPI> > |
126 g_factory = LAZY_INSTANCE_INITIALIZER; | 126 g_factory = LAZY_INSTANCE_INITIALIZER; |
127 | 127 |
128 // static | 128 // static |
129 BrowserContextKeyedAPIFactory<CastChannelAPI>* | 129 BrowserContextKeyedAPIFactory<CastChannelAPI>* |
130 CastChannelAPI::GetFactoryInstance() { | 130 CastChannelAPI::GetFactoryInstance() { |
131 return g_factory.Pointer(); | 131 return g_factory.Pointer(); |
132 } | 132 } |
133 | 133 |
134 scoped_ptr<CastSocket> CastChannelAPI::CreateCastSocket( | 134 scoped_ptr<CastSocket> CastChannelAPI::CreateCastSocket( |
135 const std::string& extension_id, const net::IPEndPoint& ip_endpoint, | 135 const std::string& extension_id, |
136 ChannelAuthType channel_auth, const base::TimeDelta& timeout) { | 136 const net::IPEndPoint& ip_endpoint, |
137 ChannelAuthType channel_auth, | |
138 const base::TimeDelta& timeout) { | |
Wez
2014/09/25 02:09:15
nit: These can be un-wrapped.
Kevin M
2014/09/25 17:53:04
Done.
| |
137 if (socket_for_test_.get()) { | 139 if (socket_for_test_.get()) { |
138 return socket_for_test_.Pass(); | 140 return socket_for_test_.Pass(); |
139 } else { | 141 } else { |
140 return scoped_ptr<CastSocket>( | 142 return scoped_ptr<CastSocket>( |
141 new CastSocket(extension_id, | 143 new CastSocket(extension_id, |
142 ip_endpoint, | 144 ip_endpoint, |
143 channel_auth, | 145 channel_auth, |
144 this, | 146 this, |
145 ExtensionsBrowserClient::Get()->GetNetLog(), | 147 ExtensionsBrowserClient::Get()->GetNetLog(), |
146 timeout, | 148 timeout, |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 case base::Value::TYPE_BINARY: | 419 case base::Value::TYPE_BINARY: |
418 break; | 420 break; |
419 default: | 421 default: |
420 SetError("Invalid type of message_info.data"); | 422 SetError("Invalid type of message_info.data"); |
421 return false; | 423 return false; |
422 } | 424 } |
423 return true; | 425 return true; |
424 } | 426 } |
425 | 427 |
426 void CastChannelSendFunction::AsyncWorkStart() { | 428 void CastChannelSendFunction::AsyncWorkStart() { |
427 CastSocket* socket = GetSocketOrCompleteWithError( | 429 CastSocket* socket = |
428 params_->channel.channel_id); | 430 GetSocketOrCompleteWithError(params_->channel.channel_id); |
Wez
2014/09/25 02:09:15
nit: And these.
Kevin M
2014/09/25 17:53:04
Done.
| |
429 if (socket) | 431 if (socket) |
430 socket->SendMessage(params_->message, | 432 socket->SendMessage(params_->message, |
431 base::Bind(&CastChannelSendFunction::OnSend, this)); | 433 base::Bind(&CastChannelSendFunction::OnSend, this)); |
432 } | 434 } |
433 | 435 |
434 void CastChannelSendFunction::OnSend(int result) { | 436 void CastChannelSendFunction::OnSend(int result) { |
435 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 437 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
436 int channel_id = params_->channel.channel_id; | 438 int channel_id = params_->channel.channel_id; |
437 CastSocket* socket = GetSocket(channel_id); | 439 CastSocket* socket = GetSocket(channel_id); |
438 if (result < 0 || !socket) { | 440 if (result < 0 || !socket) { |
439 SetResultFromError(channel_id, | 441 SetResultFromError(channel_id, |
440 cast_channel::CHANNEL_ERROR_SOCKET_ERROR); | 442 cast_channel::CHANNEL_ERROR_SOCKET_ERROR); |
441 } else { | 443 } else { |
442 SetResultFromSocket(*socket); | 444 SetResultFromSocket(*socket); |
443 } | 445 } |
444 AsyncWorkCompleted(); | 446 AsyncWorkCompleted(); |
445 } | 447 } |
446 | 448 |
447 CastChannelCloseFunction::CastChannelCloseFunction() { } | 449 CastChannelCloseFunction::CastChannelCloseFunction() { } |
448 | 450 |
449 CastChannelCloseFunction::~CastChannelCloseFunction() { } | 451 CastChannelCloseFunction::~CastChannelCloseFunction() { } |
450 | 452 |
451 bool CastChannelCloseFunction::Prepare() { | 453 bool CastChannelCloseFunction::Prepare() { |
452 params_ = Close::Params::Create(*args_); | 454 params_ = Close::Params::Create(*args_); |
453 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 455 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
454 return true; | 456 return true; |
455 } | 457 } |
456 | 458 |
457 void CastChannelCloseFunction::AsyncWorkStart() { | 459 void CastChannelCloseFunction::AsyncWorkStart() { |
458 CastSocket* socket = GetSocketOrCompleteWithError( | 460 CastSocket* socket = |
459 params_->channel.channel_id); | 461 GetSocketOrCompleteWithError(params_->channel.channel_id); |
Wez
2014/09/25 02:09:15
nit: And this!
Kevin M
2014/09/25 17:53:04
Done.
| |
460 if (socket) | 462 if (socket) |
461 socket->Close(base::Bind(&CastChannelCloseFunction::OnClose, this)); | 463 socket->Close(base::Bind(&CastChannelCloseFunction::OnClose, this)); |
462 } | 464 } |
463 | 465 |
464 void CastChannelCloseFunction::OnClose(int result) { | 466 void CastChannelCloseFunction::OnClose(int result) { |
465 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 467 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
466 VLOG(1) << "CastChannelCloseFunction::OnClose result = " << result; | 468 VLOG(1) << "CastChannelCloseFunction::OnClose result = " << result; |
467 int channel_id = params_->channel.channel_id; | 469 int channel_id = params_->channel.channel_id; |
468 CastSocket* socket = GetSocket(channel_id); | 470 CastSocket* socket = GetSocket(channel_id); |
469 if (result < 0 || !socket) { | 471 if (result < 0 || !socket) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
503 } else { | 505 } else { |
504 SetError("Unable to get logs."); | 506 SetError("Unable to get logs."); |
505 } | 507 } |
506 | 508 |
507 api_->GetLogger()->Reset(); | 509 api_->GetLogger()->Reset(); |
508 | 510 |
509 AsyncWorkCompleted(); | 511 AsyncWorkCompleted(); |
510 } | 512 } |
511 | 513 |
512 } // namespace extensions | 514 } // namespace extensions |
OLD | NEW |