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

Unified Diff: components/cast_channel/cast_socket.cc

Issue 2942993003: [cast_channel] Make CastMessageHandler a CastSocket::Observer instead of CastTransport::Delegate (Closed)
Patch Set: resolve code review comments from Derek Created 3 years, 6 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
« no previous file with comments | « components/cast_channel/cast_socket.h ('k') | components/cast_channel/cast_socket_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/cast_channel/cast_socket.cc
diff --git a/components/cast_channel/cast_socket.cc b/components/cast_channel/cast_socket.cc
index e60004ed228f1e5c1a2f6ce9ebd0e2150cc12fbe..c4b2def9c626aec1cc70ab3a55d157a48effa71b 100644
--- a/components/cast_channel/cast_socket.cc
+++ b/components/cast_channel/cast_socket.cc
@@ -240,14 +240,13 @@ void CastSocketImpl::SetTransportForTesting(
transport_ = std::move(transport);
}
-void CastSocketImpl::Connect(std::unique_ptr<CastTransport::Delegate> delegate,
- base::Callback<void(ChannelError)> callback) {
+void CastSocketImpl::Connect(base::Callback<void(ChannelError)> callback) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
VLOG_WITH_CONNECTION(1) << "Connect readyState = "
- << ::cast_channel::ReadyStateToString(ready_state_);
+ << ReadyStateToString(ready_state_);
DCHECK_EQ(ConnectionState::START_CONNECT, connect_state_);
- delegate_ = std::move(delegate);
+ delegate_ = base::MakeUnique<CastSocketMessageDelegate>(this);
if (ready_state_ != ReadyState::NONE) {
callback.Run(ChannelError::CONNECT_ERROR);
@@ -274,6 +273,12 @@ CastTransport* CastSocketImpl::transport() const {
return transport_.get();
}
+void CastSocketImpl::AddObserver(Observer* observer) {
+ DCHECK(observer);
+ if (!observers_.HasObserver(observer))
+ observers_.AddObserver(observer);
+}
+
void CastSocketImpl::OnConnectTimeout() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
// Stop all pending connection setup tasks and report back to the client.
@@ -526,7 +531,7 @@ int CastSocketImpl::DoAuthChallengeReplyComplete(int result) {
void CastSocketImpl::DoConnectCallback() {
VLOG(1) << "DoConnectCallback (error_state = "
- << ::cast_channel::ChannelErrorToString(error_state_) << ")";
+ << ChannelErrorToString(error_state_) << ")";
if (connect_callback_.is_null()) {
DLOG(FATAL) << "Connection callback invoked multiple times.";
return;
@@ -564,7 +569,7 @@ void CastSocketImpl::CloseInternal() {
}
VLOG_WITH_CONNECTION(1) << "Close ReadyState = "
- << ::cast_channel::ReadyStateToString(ready_state_);
+ << ReadyStateToString(ready_state_);
transport_.reset();
tcp_socket_.reset();
socket_.reset();
@@ -597,11 +602,34 @@ void CastSocketImpl::SetReadyState(ReadyState ready_state) {
void CastSocketImpl::SetErrorState(ChannelError error_state) {
VLOG_WITH_CONNECTION(1) << "SetErrorState "
- << ::cast_channel::ChannelErrorToString(error_state);
+ << ChannelErrorToString(error_state);
DCHECK_EQ(ChannelError::NONE, error_state_);
error_state_ = error_state;
delegate_->OnError(error_state_);
}
+CastSocketImpl::CastSocketMessageDelegate::CastSocketMessageDelegate(
+ CastSocketImpl* socket)
+ : socket_(socket) {
+ DCHECK(socket_);
+}
+
+CastSocketImpl::CastSocketMessageDelegate::~CastSocketMessageDelegate() {}
+
+// CastTransport::Delegate implementation.
+void CastSocketImpl::CastSocketMessageDelegate::OnError(
+ ChannelError error_state) {
+ for (auto& observer : socket_->observers_)
+ observer.OnError(*socket_, error_state);
+}
+
+void CastSocketImpl::CastSocketMessageDelegate::OnMessage(
+ const CastMessage& message) {
+ for (auto& observer : socket_->observers_)
+ observer.OnMessage(*socket_, message);
+}
+
+void CastSocketImpl::CastSocketMessageDelegate::Start() {}
+
} // namespace cast_channel
#undef VLOG_WITH_CONNECTION
« no previous file with comments | « components/cast_channel/cast_socket.h ('k') | components/cast_channel/cast_socket_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698