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

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

Issue 555283002: Create new class "CastTransport", which encapsulates the message read and write event loops. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed wez's feedback. Created 6 years, 3 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: extensions/browser/api/cast_channel/cast_channel_api.cc
diff --git a/extensions/browser/api/cast_channel/cast_channel_api.cc b/extensions/browser/api/cast_channel/cast_channel_api.cc
index 94a94af34d05b8665009ce750948d4974ddd6a9d..4d6f84666194cf82483b35ab4a6764cc6e462bbf 100644
--- a/extensions/browser/api/cast_channel/cast_channel_api.cc
+++ b/extensions/browser/api/cast_channel/cast_channel_api.cc
@@ -33,7 +33,7 @@ namespace OnError = cast_channel::OnError;
namespace OnMessage = cast_channel::OnMessage;
namespace Open = cast_channel::Open;
namespace Send = cast_channel::Send;
-using cast_channel::CastSocket;
+using cast_channel::CastSocketImpl;
using cast_channel::ChannelAuthType;
using cast_channel::ChannelError;
using cast_channel::ChannelInfo;
@@ -57,7 +57,7 @@ std::string ParamToString(const T& info) {
}
// Fills |channel_info| from the destination and state of |socket|.
-void FillChannelInfo(const CastSocket& socket, ChannelInfo* channel_info) {
+void FillChannelInfo(const CastSocketImpl& socket, ChannelInfo* channel_info) {
DCHECK(channel_info);
channel_info->channel_id = socket.id();
channel_info->url = socket.CastUrl();
@@ -130,28 +130,31 @@ CastChannelAPI::GetFactoryInstance() {
return g_factory.Pointer();
}
-scoped_ptr<CastSocket> CastChannelAPI::CreateCastSocket(
- const std::string& extension_id, const net::IPEndPoint& ip_endpoint,
- ChannelAuthType channel_auth, const base::TimeDelta& timeout) {
+scoped_ptr<CastSocketImpl> CastChannelAPI::CreateCastSocketImpl(
+ const std::string& extension_id,
+ const net::IPEndPoint& ip_endpoint,
+ 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,
- ExtensionsBrowserClient::Get()->GetNetLog(),
- timeout,
- logger_));
+ return scoped_ptr<CastSocketImpl>(
+ new CastSocketImpl(extension_id,
+ ip_endpoint,
+ channel_auth,
+ this,
+ ExtensionsBrowserClient::Get()->GetNetLog(),
+ timeout,
+ logger_));
}
}
-void CastChannelAPI::SetSocketForTest(scoped_ptr<CastSocket> socket_for_test) {
+void CastChannelAPI::SetSocketForTest(
+ scoped_ptr<CastSocketImpl> socket_for_test) {
socket_for_test_ = socket_for_test.Pass();
}
-void CastChannelAPI::OnError(const CastSocket* socket,
+void CastChannelAPI::OnError(const CastSocketImpl* socket,
cast_channel::ChannelError error_state,
const cast_channel::LastErrors& last_errors) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -167,7 +170,7 @@ void CastChannelAPI::OnError(const CastSocket* socket,
->DispatchEventToExtension(socket->owner_extension_id(), event.Pass());
}
-void CastChannelAPI::OnMessage(const CastSocket* socket,
+void CastChannelAPI::OnMessage(const CastSocketImpl* socket,
const MessageInfo& message_info) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
ChannelInfo channel_info;
@@ -189,7 +192,7 @@ CastChannelAsyncApiFunction::CastChannelAsyncApiFunction()
CastChannelAsyncApiFunction::~CastChannelAsyncApiFunction() { }
bool CastChannelAsyncApiFunction::PrePrepare() {
- manager_ = ApiResourceManager<CastSocket>::Get(browser_context());
+ manager_ = ApiResourceManager<CastSocketImpl>::Get(browser_context());
return true;
}
@@ -197,9 +200,9 @@ bool CastChannelAsyncApiFunction::Respond() {
return error_ == cast_channel::CHANNEL_ERROR_NONE;
}
-CastSocket* CastChannelAsyncApiFunction::GetSocketOrCompleteWithError(
+CastSocketImpl* CastChannelAsyncApiFunction::GetSocketOrCompleteWithError(
int channel_id) {
- CastSocket* socket = GetSocket(channel_id);
+ CastSocketImpl* socket = GetSocket(channel_id);
if (!socket) {
SetResultFromError(channel_id,
cast_channel::CHANNEL_ERROR_INVALID_CHANNEL_ID);
@@ -208,7 +211,7 @@ CastSocket* CastChannelAsyncApiFunction::GetSocketOrCompleteWithError(
return socket;
}
-int CastChannelAsyncApiFunction::AddSocket(CastSocket* socket) {
+int CastChannelAsyncApiFunction::AddSocket(CastSocketImpl* socket) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(socket);
DCHECK(manager_);
@@ -224,7 +227,7 @@ void CastChannelAsyncApiFunction::RemoveSocket(int channel_id) {
}
void CastChannelAsyncApiFunction::SetResultFromSocket(
- const CastSocket& socket) {
+ const CastSocketImpl& socket) {
ChannelInfo channel_info;
FillChannelInfo(socket, &channel_info);
error_ = socket.error_state();
@@ -245,7 +248,7 @@ void CastChannelAsyncApiFunction::SetResultFromError(int channel_id,
error_ = error;
}
-CastSocket* CastChannelAsyncApiFunction::GetSocket(int channel_id) {
+CastSocketImpl* CastChannelAsyncApiFunction::GetSocket(int channel_id) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(manager_);
return manager_->Get(extension_->id(), channel_id);
@@ -366,7 +369,7 @@ bool CastChannelOpenFunction::Prepare() {
void CastChannelOpenFunction::AsyncWorkStart() {
DCHECK(api_);
DCHECK(ip_endpoint_.get());
- scoped_ptr<CastSocket> socket = api_->CreateCastSocket(
+ scoped_ptr<CastSocketImpl> socket = api_->CreateCastSocketImpl(
extension_->id(),
*ip_endpoint_,
channel_auth_,
@@ -374,7 +377,7 @@ void CastChannelOpenFunction::AsyncWorkStart() {
? *connect_info_->timeout
: kDefaultConnectTimeoutMillis));
new_channel_id_ = AddSocket(socket.release());
- CastSocket* new_socket = GetSocket(new_channel_id_);
+ CastSocketImpl* new_socket = GetSocket(new_channel_id_);
api_->GetLogger()->LogNewSocketEvent(*new_socket);
new_socket->Connect(base::Bind(&CastChannelOpenFunction::OnOpen, this));
}
@@ -382,7 +385,7 @@ void CastChannelOpenFunction::AsyncWorkStart() {
void CastChannelOpenFunction::OnOpen(int result) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
VLOG(1) << "Connect finished, OnOpen invoked.";
- CastSocket* socket = GetSocket(new_channel_id_);
+ CastSocketImpl* socket = GetSocket(new_channel_id_);
if (!socket) {
SetResultFromError(new_channel_id_,
cast_channel::CHANNEL_ERROR_CONNECT_ERROR);
@@ -423,8 +426,8 @@ bool CastChannelSendFunction::Prepare() {
}
void CastChannelSendFunction::AsyncWorkStart() {
- CastSocket* socket = GetSocketOrCompleteWithError(
- params_->channel.channel_id);
+ CastSocketImpl* socket =
+ GetSocketOrCompleteWithError(params_->channel.channel_id);
if (socket)
socket->SendMessage(params_->message,
base::Bind(&CastChannelSendFunction::OnSend, this));
@@ -433,7 +436,7 @@ void CastChannelSendFunction::AsyncWorkStart() {
void CastChannelSendFunction::OnSend(int result) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
int channel_id = params_->channel.channel_id;
- CastSocket* socket = GetSocket(channel_id);
+ CastSocketImpl* socket = GetSocket(channel_id);
if (result < 0 || !socket) {
SetResultFromError(channel_id,
cast_channel::CHANNEL_ERROR_SOCKET_ERROR);
@@ -454,8 +457,8 @@ bool CastChannelCloseFunction::Prepare() {
}
void CastChannelCloseFunction::AsyncWorkStart() {
- CastSocket* socket = GetSocketOrCompleteWithError(
- params_->channel.channel_id);
+ CastSocketImpl* socket =
+ GetSocketOrCompleteWithError(params_->channel.channel_id);
if (socket)
socket->Close(base::Bind(&CastChannelCloseFunction::OnClose, this));
}
@@ -464,7 +467,7 @@ void CastChannelCloseFunction::OnClose(int result) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
VLOG(1) << "CastChannelCloseFunction::OnClose result = " << result;
int channel_id = params_->channel.channel_id;
- CastSocket* socket = GetSocket(channel_id);
+ CastSocketImpl* socket = GetSocket(channel_id);
if (result < 0 || !socket) {
SetResultFromError(channel_id,
cast_channel::CHANNEL_ERROR_SOCKET_ERROR);

Powered by Google App Engine
This is Rietveld 408576698