diff options
author | kmarshall <kmarshall@chromium.org> | 2015-04-02 22:32:37 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-03 05:33:10 +0000 |
commit | 2452c7ae6e233248252037511207448dfa5b6535 (patch) | |
tree | 06421caf8b83d743bc485ec7b78e84b795491072 /extensions | |
parent | 43f9c3f62cb9faef5cd89eee48fd5e58e29a921f (diff) | |
download | chromium_src-2452c7ae6e233248252037511207448dfa5b6535.zip chromium_src-2452c7ae6e233248252037511207448dfa5b6535.tar.gz chromium_src-2452c7ae6e233248252037511207448dfa5b6535.tar.bz2 |
Error reporting fixes and enhancements for the Cast Channel API.
Add Logger support to KeepAliveDelegate.
Modify Cast Channel error reporting paths to use the logger object as
the sole means of propagating LastErrors objects.
Remove LastErrors from OnError params and make CastChannelAPI responsible
for accessing it from the logger object directly.
Make OnError fire consistently for *all* errors.
Rename 'read_delegate' to 'delegate' everywhere, because error reporting is
useful for more than just reads.
Modify unit tests to verify that LastErrors fields are being set.
Various linter-driven cleanups.
BUG=471314
Review URL: https://codereview.chromium.org/1053433002
Cr-Commit-Position: refs/heads/master@{#323636}
Diffstat (limited to 'extensions')
15 files changed, 179 insertions, 132 deletions
diff --git a/extensions/browser/api/cast_channel/cast_channel_api.cc b/extensions/browser/api/cast_channel/cast_channel_api.cc index a55c688..e00646e 100644 --- a/extensions/browser/api/cast_channel/cast_channel_api.cc +++ b/extensions/browser/api/cast_channel/cast_channel_api.cc @@ -400,12 +400,14 @@ void CastChannelOpenFunction::AsyncWorkStart() { // Construct read delegates. scoped_ptr<core_api::cast_channel::CastTransport::Delegate> delegate( make_scoped_ptr(new CastMessageHandler( - base::Bind(&CastChannelAPI::SendEvent, api_->AsWeakPtr()), socket))); + base::Bind(&CastChannelAPI::SendEvent, api_->AsWeakPtr()), socket, + api_->GetLogger()))); if (socket->keep_alive()) { // Wrap read delegate in a KeepAliveDelegate for timeout handling. core_api::cast_channel::KeepAliveDelegate* keep_alive = new core_api::cast_channel::KeepAliveDelegate( - socket, delegate.Pass(), ping_interval_, liveness_timeout_); + socket, api_->GetLogger(), delegate.Pass(), ping_interval_, + liveness_timeout_); scoped_ptr<base::Timer> injected_timer = api_->GetInjectedTimeoutTimerForTest(); if (injected_timer) { @@ -565,24 +567,26 @@ void CastChannelGetLogsFunction::AsyncWorkStart() { CastChannelOpenFunction::CastMessageHandler::CastMessageHandler( const EventDispatchCallback& ui_dispatch_cb, - cast_channel::CastSocket* socket) - : ui_dispatch_cb_(ui_dispatch_cb), socket_(socket) { + cast_channel::CastSocket* socket, + scoped_refptr<Logger> logger) + : ui_dispatch_cb_(ui_dispatch_cb), socket_(socket), logger_(logger) { DCHECK(socket_); + DCHECK(logger_); } CastChannelOpenFunction::CastMessageHandler::~CastMessageHandler() { } void CastChannelOpenFunction::CastMessageHandler::OnError( - cast_channel::ChannelError error_state, - const cast_channel::LastErrors& last_errors) { + cast_channel::ChannelError error_state) { DCHECK_CURRENTLY_ON(BrowserThread::IO); ChannelInfo channel_info; FillChannelInfo(*socket_, &channel_info); channel_info.error_state = error_state; ErrorInfo error_info; - FillErrorInfo(error_state, last_errors, &error_info); + FillErrorInfo(error_state, logger_->GetLastErrors(socket_->id()), + &error_info); scoped_ptr<base::ListValue> results = OnError::Create(channel_info, error_info); diff --git a/extensions/browser/api/cast_channel/cast_channel_api.h b/extensions/browser/api/cast_channel/cast_channel_api.h index 50f5d98..2ddef3e 100644 --- a/extensions/browser/api/cast_channel/cast_channel_api.h +++ b/extensions/browser/api/cast_channel/cast_channel_api.h @@ -167,12 +167,12 @@ class CastChannelOpenFunction : public CastChannelAsyncApiFunction { class CastMessageHandler : public cast_channel::CastTransport::Delegate { public: CastMessageHandler(const EventDispatchCallback& ui_dispatch_cb, - cast_channel::CastSocket* socket); + cast_channel::CastSocket* socket, + scoped_refptr<core_api::cast_channel::Logger> logger); ~CastMessageHandler() override; // CastTransport::Delegate implementation. - void OnError(cast_channel::ChannelError error_state, - const cast_channel::LastErrors& last_errors) override; + void OnError(cast_channel::ChannelError error_state) override; void OnMessage(const cast_channel::CastMessage& message) override; void Start() override; @@ -182,6 +182,8 @@ class CastChannelOpenFunction : public CastChannelAsyncApiFunction { // conditions. EventDispatchCallback const ui_dispatch_cb_; cast_channel::CastSocket* const socket_; + // Logger object for reporting error details. + scoped_refptr<core_api::cast_channel::Logger> logger_; DISALLOW_COPY_AND_ASSIGN(CastMessageHandler); }; diff --git a/extensions/browser/api/cast_channel/cast_channel_apitest.cc b/extensions/browser/api/cast_channel/cast_channel_apitest.cc index 4452fcb..e118cd2 100644 --- a/extensions/browser/api/cast_channel/cast_channel_apitest.cc +++ b/extensions/browser/api/cast_channel/cast_channel_apitest.cc @@ -38,6 +38,7 @@ using cast_channel::ChannelAuthType; using cast_channel::ChannelError; using cast_channel::CreateIPEndPointForTest; using cast_channel::ErrorInfo; +using cast_channel::LastErrors; using cast_channel::Logger; using cast_channel::MessageInfo; using cast_channel::MockCastSocket; @@ -77,10 +78,6 @@ ACTION_TEMPLATE(InvokeCompletionCallback, ::std::tr1::get<k>(args).Run(result); } -ACTION_P2(InvokeDelegateOnError, api_test, api) { - api_test->CallOnError(api); -} - } // namespace class CastChannelAPITest : public ExtensionApiTest { @@ -164,13 +161,12 @@ class CastChannelAPITest : public ExtensionApiTest { return extensions::CastChannelAPI::Get(profile()); } - void CallOnError(extensions::CastChannelAPI* api) { - cast_channel::LastErrors last_errors; - last_errors.challenge_reply_error_type = - cast_channel::proto::CHALLENGE_REPLY_ERROR_CERT_PARSING_FAILED; - last_errors.nss_error_code = -8164; - message_delegate_->OnError(cast_channel::CHANNEL_ERROR_CONNECT_ERROR, - last_errors); + // Logs some bogus error details and calls the OnError handler. + void DoCallOnError(extensions::CastChannelAPI* api) { + api->GetLogger()->LogSocketEventWithRv(mock_cast_socket_->id(), + cast_channel::proto::SOCKET_WRITE, + net::ERR_FAILED); + message_delegate_->OnError(cast_channel::CHANNEL_ERROR_CONNECT_ERROR); } protected: @@ -234,11 +230,19 @@ class CastChannelAPITest : public ExtensionApiTest { MockCastSocket* mock_cast_socket_; base::MockTimer* timeout_timer_; net::IPEndPoint ip_endpoint_; + LastErrors last_errors_; CastTransport::Delegate* message_delegate_; net::CapturingNetLog capturing_net_log_; int channel_id_; }; +ACTION_P2(InvokeDelegateOnError, api_test, api) { + content::BrowserThread::PostTask( + content::BrowserThread::IO, FROM_HERE, + base::Bind(&CastChannelAPITest::DoCallOnError, base::Unretained(api_test), + base::Unretained(api))); +} + // TODO(kmarshall): Win Dbg has a workaround that makes RunExtensionSubtest // always return true without actually running the test. Remove when fixed. #if defined(OS_WIN) && !defined(NDEBUG) diff --git a/extensions/browser/api/cast_channel/cast_socket.cc b/extensions/browser/api/cast_channel/cast_socket.cc index b6348f4..bfb31d0 100644 --- a/extensions/browser/api/cast_channel/cast_socket.cc +++ b/extensions/browser/api/cast_channel/cast_socket.cc @@ -73,7 +73,6 @@ ApiResourceManager<core_api::cast_channel::CastSocket>::GetFactoryInstance() { namespace core_api { namespace cast_channel { - CastSocket::CastSocket(const std::string& owner_extension_id) : ApiResource(owner_extension_id) { } @@ -233,13 +232,13 @@ bool CastSocketImpl::VerifyChannelPolicy(const AuthResult& result) { bool CastSocketImpl::VerifyChallengeReply() { AuthResult result = AuthenticateChallengeReply(*challenge_reply_, peer_cert_); + logger_->LogSocketChallengeReplyEvent(channel_id_, result); if (result.success()) { VLOG(1) << result.error_message; if (!VerifyChannelPolicy(result)) { return false; } } - logger_->LogSocketChallengeReplyEvent(channel_id_, result); return result.success(); } @@ -253,7 +252,7 @@ void CastSocketImpl::Connect(scoped_ptr<CastTransport::Delegate> delegate, DCHECK(CalledOnValidThread()); VLOG_WITH_CONNECTION(1) << "Connect readyState = " << ready_state_; - read_delegate_ = delegate.Pass(); + delegate_ = delegate.Pass(); if (ready_state_ != READY_STATE_NONE) { logger_->LogSocketEventWithDetails( @@ -454,6 +453,8 @@ int CastSocketImpl::DoAuthChallengeSend() { int CastSocketImpl::DoAuthChallengeSendComplete(int result) { VLOG_WITH_CONNECTION(1) << "DoAuthChallengeSendComplete: " << result; if (result < 0) { + logger_->LogSocketEventWithRv(channel_id_, + proto::SEND_AUTH_CHALLENGE_FAILED, result); SetErrorState(CHANNEL_ERROR_SOCKET_ERROR); return result; } @@ -476,19 +477,17 @@ LastErrors CastSocketImpl::AuthTransportDelegate::last_errors() const { return last_errors_; } -void CastSocketImpl::AuthTransportDelegate::OnError( - ChannelError error_state, - const LastErrors& last_errors) { - socket_->SetErrorState(error_state); - socket_->PostTaskToStartConnectLoop(net::ERR_CONNECTION_FAILED); +void CastSocketImpl::AuthTransportDelegate::OnError(ChannelError error_state) { error_state_ = error_state; - last_errors_ = last_errors; + socket_->PostTaskToStartConnectLoop(net::ERR_CONNECTION_FAILED); } void CastSocketImpl::AuthTransportDelegate::OnMessage( const CastMessage& message) { if (!IsAuthMessage(message)) { - socket_->SetErrorState(CHANNEL_ERROR_TRANSPORT_ERROR); + error_state_ = CHANNEL_ERROR_TRANSPORT_ERROR; + socket_->logger_->LogSocketEvent(socket_->channel_id_, + proto::AUTH_CHALLENGE_REPLY_INVALID); socket_->PostTaskToStartConnectLoop(net::ERR_INVALID_RESPONSE); } else { socket_->challenge_reply_.reset(new CastMessage(message)); @@ -504,8 +503,8 @@ void CastSocketImpl::AuthTransportDelegate::Start() { int CastSocketImpl::DoAuthChallengeReplyComplete(int result) { VLOG_WITH_CONNECTION(1) << "DoAuthChallengeReplyComplete: " << result; if (auth_delegate_->error_state() != CHANNEL_ERROR_NONE) { - read_delegate_->OnError(auth_delegate_->error_state(), - auth_delegate_->last_errors()); + SetErrorState(auth_delegate_->error_state()); + return net::ERR_CONNECTION_FAILED; } auth_delegate_ = nullptr; if (result < 0) { @@ -523,7 +522,7 @@ void CastSocketImpl::DoConnectCallback() { VLOG(1) << "DoConnectCallback (error_state = " << error_state_ << ")"; if (error_state_ == CHANNEL_ERROR_NONE) { SetReadyState(READY_STATE_OPEN); - transport_->SetReadDelegate(read_delegate_.Pass()); + transport_->SetReadDelegate(delegate_.Pass()); } else { SetReadyState(READY_STATE_CLOSED); CloseInternal(); @@ -597,6 +596,7 @@ void CastSocketImpl::SetErrorState(ChannelError error_state) { DCHECK_EQ(CHANNEL_ERROR_NONE, error_state_); error_state_ = error_state; logger_->LogSocketErrorState(channel_id_, ErrorStateToProto(error_state_)); + delegate_->OnError(error_state_); } } // namespace cast_channel } // namespace core_api diff --git a/extensions/browser/api/cast_channel/cast_socket.h b/extensions/browser/api/cast_channel/cast_socket.h index 64d9589..55d7b94 100644 --- a/extensions/browser/api/cast_channel/cast_socket.h +++ b/extensions/browser/api/cast_channel/cast_socket.h @@ -18,6 +18,7 @@ #include "extensions/browser/api/api_resource_manager.h" #include "extensions/browser/api/cast_channel/cast_socket.h" #include "extensions/browser/api/cast_channel/cast_transport.h" +#include "extensions/browser/api/cast_channel/logger_util.h" #include "extensions/common/api/cast_channel.h" #include "extensions/common/api/cast_channel/logging.pb.h" #include "net/base/completion_callback.h" @@ -103,9 +104,10 @@ class CastSocket : public ApiResource { // True when keep-alive signaling is handled for this socket. virtual bool keep_alive() const = 0; - // Marks a socket as invalid due to an error. Errors close the socket - // and any further socket operations will return the error code - // net::SOCKET_NOT_CORRECTED. + // Marks a socket as invalid due to an error, and sends an OnError + // event to |delegate_|. + // The OnError event receipient is responsible for closing the socket in the + // event of an error. // Setting the error state does not close the socket if it is open. virtual void SetErrorState(ChannelError error_state) = 0; @@ -172,7 +174,7 @@ class CastSocketImpl : public CastSocket { // CastTransport::Delegate methods for receiving handshake messages. class AuthTransportDelegate : public CastTransport::Delegate { public: - AuthTransportDelegate(CastSocketImpl* socket); + explicit AuthTransportDelegate(CastSocketImpl* socket); // Gets the error state of the channel. // Returns CHANNEL_ERROR_NONE if no errors are present. @@ -182,8 +184,7 @@ class CastSocketImpl : public CastSocket { LastErrors last_errors() const; // CastTransport::Delegate interface. - void OnError(ChannelError error_state, - const LastErrors& last_errors) override; + void OnError(ChannelError error_state) override; void OnMessage(const CastMessage& message) override; void Start() override; @@ -360,7 +361,7 @@ class CastSocketImpl : public CastSocket { scoped_ptr<CastTransport> transport_; // Caller's message read and error handling delegate. - scoped_ptr<CastTransport::Delegate> read_delegate_; + scoped_ptr<CastTransport::Delegate> delegate_; // Raw pointer to the auth handshake delegate. Used to get detailed error // information. diff --git a/extensions/browser/api/cast_channel/cast_socket_unittest.cc b/extensions/browser/api/cast_channel/cast_socket_unittest.cc index b2d73e3..112a3b9 100644 --- a/extensions/browser/api/cast_channel/cast_socket_unittest.cc +++ b/extensions/browser/api/cast_channel/cast_socket_unittest.cc @@ -137,8 +137,7 @@ class MockDelegate : public CastTransport::Delegate { public: MockDelegate() {} virtual ~MockDelegate() {} - MOCK_METHOD2(OnError, - void(ChannelError error_state, const LastErrors& last_errors)); + MOCK_METHOD1(OnError, void(ChannelError error_state)); MOCK_METHOD1(OnMessage, void(const CastMessage& message)); MOCK_METHOD0(Start, void()); @@ -341,13 +340,10 @@ class CastSocketTest : public testing::Test { : logger_(new Logger( scoped_ptr<base::TickClock>(new base::SimpleTestTickClock), base::TimeTicks())), - read_delegate_(new MockDelegate) {} + delegate_(new MockDelegate) {} ~CastSocketTest() override {} - void SetUp() override { - EXPECT_CALL(*read_delegate_, OnMessage(_)).Times(0); - EXPECT_CALL(*read_delegate_, OnError(_, _)).Times(0); - } + void SetUp() override { EXPECT_CALL(*delegate_, OnMessage(_)).Times(0); } void TearDown() override { if (socket_.get()) { @@ -371,7 +367,7 @@ class CastSocketTest : public testing::Test { .WillOnce(RunCompletionCallback<1>(net::OK)); EXPECT_CALL(*socket_->GetMockTransport(), Start()); EXPECT_CALL(handler_, OnConnectComplete(CHANNEL_ERROR_NONE)); - socket_->Connect(read_delegate_.Pass(), + socket_->Connect(delegate_.Pass(), base::Bind(&CompleteHandler::OnConnectComplete, base::Unretained(&handler_))); RunPendingTasks(); @@ -391,7 +387,7 @@ class CastSocketTest : public testing::Test { Logger* logger_; scoped_ptr<TestCastSocket> socket_; CompleteHandler handler_; - scoped_ptr<MockDelegate> read_delegate_; + scoped_ptr<MockDelegate> delegate_; private: DISALLOW_COPY_AND_ASSIGN(CastSocketTest); @@ -405,7 +401,7 @@ TEST_F(CastSocketTest, TestConnectAndClose) { socket_->SetupSsl1Connect(net::SYNCHRONOUS, net::OK); EXPECT_CALL(handler_, OnConnectComplete(CHANNEL_ERROR_NONE)); - socket_->Connect(read_delegate_.Pass(), + socket_->Connect(delegate_.Pass(), base::Bind(&CompleteHandler::OnConnectComplete, base::Unretained(&handler_))); RunPendingTasks(); @@ -430,7 +426,7 @@ TEST_F(CastSocketTest, TestConnect) { socket_->AddReadResult(net::ASYNC, net::ERR_IO_PENDING); EXPECT_CALL(handler_, OnConnectComplete(CHANNEL_ERROR_NONE)); - socket_->Connect(read_delegate_.Pass(), + socket_->Connect(delegate_.Pass(), base::Bind(&CompleteHandler::OnConnectComplete, base::Unretained(&handler_))); RunPendingTasks(); @@ -446,13 +442,17 @@ TEST_F(CastSocketTest, TestConnectFails) { socket_->SetupTcp1Connect(net::ASYNC, net::ERR_FAILED); EXPECT_CALL(handler_, OnConnectComplete(CHANNEL_ERROR_CONNECT_ERROR)); - socket_->Connect(read_delegate_.Pass(), + socket_->Connect(delegate_.Pass(), base::Bind(&CompleteHandler::OnConnectComplete, base::Unretained(&handler_))); RunPendingTasks(); EXPECT_EQ(cast_channel::READY_STATE_CLOSED, socket_->ready_state()); EXPECT_EQ(cast_channel::CHANNEL_ERROR_CONNECT_ERROR, socket_->error_state()); + EXPECT_EQ(proto::TCP_SOCKET_CONNECT_COMPLETE, + logger_->GetLastErrors(socket_->id()).event_type); + EXPECT_EQ(net::ERR_FAILED, + logger_->GetLastErrors(socket_->id()).net_return_value); } // Test that the following connection flow works: @@ -470,7 +470,7 @@ TEST_F(CastSocketTest, TestConnectTwoStep) { socket_->SetupSsl2Connect(net::ASYNC, net::OK); EXPECT_CALL(handler_, OnConnectComplete(CHANNEL_ERROR_NONE)); - socket_->Connect(read_delegate_.Pass(), + socket_->Connect(delegate_.Pass(), base::Bind(&CompleteHandler::OnConnectComplete, base::Unretained(&handler_))); RunPendingTasks(); @@ -493,7 +493,7 @@ TEST_F(CastSocketTest, TestConnectMaxTwoAttempts) { socket_->SetupSsl2Connect(net::ASYNC, net::ERR_CERT_AUTHORITY_INVALID); EXPECT_CALL(handler_, OnConnectComplete(CHANNEL_ERROR_AUTHENTICATION_ERROR)); - socket_->Connect(read_delegate_.Pass(), + socket_->Connect(delegate_.Pass(), base::Bind(&CompleteHandler::OnConnectComplete, base::Unretained(&handler_))); RunPendingTasks(); @@ -564,7 +564,7 @@ TEST_F(CastSocketTest, TestConnectAuthMessageCorrupted) { .WillOnce(RunCompletionCallback<1>(net::OK)); EXPECT_CALL(*socket_->GetMockTransport(), Start()); EXPECT_CALL(handler_, OnConnectComplete(CHANNEL_ERROR_TRANSPORT_ERROR)); - socket_->Connect(read_delegate_.Pass(), + socket_->Connect(delegate_.Pass(), base::Bind(&CompleteHandler::OnConnectComplete, base::Unretained(&handler_))); RunPendingTasks(); @@ -587,7 +587,7 @@ TEST_F(CastSocketTest, TestConnectTcpConnectErrorAsync) { socket_->SetupTcp1Connect(net::ASYNC, net::ERR_FAILED); EXPECT_CALL(handler_, OnConnectComplete(CHANNEL_ERROR_CONNECT_ERROR)); - socket_->Connect(read_delegate_.Pass(), + socket_->Connect(delegate_.Pass(), base::Bind(&CompleteHandler::OnConnectComplete, base::Unretained(&handler_))); RunPendingTasks(); @@ -603,7 +603,7 @@ TEST_F(CastSocketTest, TestConnectTcpConnectErrorSync) { socket_->SetupTcp1Connect(net::SYNCHRONOUS, net::ERR_FAILED); EXPECT_CALL(handler_, OnConnectComplete(CHANNEL_ERROR_CONNECT_ERROR)); - socket_->Connect(read_delegate_.Pass(), + socket_->Connect(delegate_.Pass(), base::Bind(&CompleteHandler::OnConnectComplete, base::Unretained(&handler_))); RunPendingTasks(); @@ -617,7 +617,8 @@ TEST_F(CastSocketTest, TestConnectTcpTimeoutError) { CreateCastSocketSecure(); socket_->SetupTcp1ConnectUnresponsive(); EXPECT_CALL(handler_, OnConnectComplete(CHANNEL_ERROR_CONNECT_TIMEOUT)); - socket_->Connect(read_delegate_.Pass(), + EXPECT_CALL(*delegate_, OnError(CHANNEL_ERROR_CONNECT_TIMEOUT)); + socket_->Connect(delegate_.Pass(), base::Bind(&CompleteHandler::OnConnectComplete, base::Unretained(&handler_))); RunPendingTasks(); @@ -640,7 +641,7 @@ TEST_F(CastSocketTest, TestConnectSslConnectErrorAsync) { socket_->SetupSsl1Connect(net::SYNCHRONOUS, net::ERR_FAILED); EXPECT_CALL(handler_, OnConnectComplete(CHANNEL_ERROR_AUTHENTICATION_ERROR)); - socket_->Connect(read_delegate_.Pass(), + socket_->Connect(delegate_.Pass(), base::Bind(&CompleteHandler::OnConnectComplete, base::Unretained(&handler_))); RunPendingTasks(); @@ -658,7 +659,7 @@ TEST_F(CastSocketTest, TestConnectSslConnectErrorSync) { socket_->SetupSsl1Connect(net::ASYNC, net::ERR_FAILED); EXPECT_CALL(handler_, OnConnectComplete(CHANNEL_ERROR_AUTHENTICATION_ERROR)); - socket_->Connect(read_delegate_.Pass(), + socket_->Connect(delegate_.Pass(), base::Bind(&CompleteHandler::OnConnectComplete, base::Unretained(&handler_))); RunPendingTasks(); @@ -677,7 +678,7 @@ TEST_F(CastSocketTest, TestConnectCertExtractionErrorAsync) { socket_->SetExtractCertResult(false); EXPECT_CALL(handler_, OnConnectComplete(CHANNEL_ERROR_AUTHENTICATION_ERROR)); - socket_->Connect(read_delegate_.Pass(), + socket_->Connect(delegate_.Pass(), base::Bind(&CompleteHandler::OnConnectComplete, base::Unretained(&handler_))); RunPendingTasks(); @@ -696,7 +697,7 @@ TEST_F(CastSocketTest, TestConnectCertExtractionErrorSync) { socket_->SetExtractCertResult(false); EXPECT_CALL(handler_, OnConnectComplete(CHANNEL_ERROR_AUTHENTICATION_ERROR)); - socket_->Connect(read_delegate_.Pass(), + socket_->Connect(delegate_.Pass(), base::Bind(&CompleteHandler::OnConnectComplete, base::Unretained(&handler_))); RunPendingTasks(); @@ -718,7 +719,7 @@ TEST_F(CastSocketTest, TestConnectChallengeSendError) { .WillOnce(RunCompletionCallback<1>(net::ERR_CONNECTION_RESET)); EXPECT_CALL(handler_, OnConnectComplete(CHANNEL_ERROR_SOCKET_ERROR)); - socket_->Connect(read_delegate_.Pass(), + socket_->Connect(delegate_.Pass(), base::Bind(&CompleteHandler::OnConnectComplete, base::Unretained(&handler_))); RunPendingTasks(); @@ -738,27 +739,18 @@ TEST_F(CastSocketTest, TestConnectChallengeReplyReceiveError) { SendMessage(EqualsProto(CreateAuthChallenge()), _)) .WillOnce(RunCompletionCallback<1>(net::OK)); socket_->AddReadResult(net::SYNCHRONOUS, net::ERR_FAILED); - - LastErrors last_errors; - last_errors.net_return_value = 555; - LastErrors last_errors_captured; - last_errors_captured.net_return_value = 0; - - EXPECT_CALL(*read_delegate_, OnError(CHANNEL_ERROR_SOCKET_ERROR, _)) - .WillOnce(SaveArg<1>(&last_errors_captured)); - + EXPECT_CALL(*delegate_, OnError(CHANNEL_ERROR_SOCKET_ERROR)); EXPECT_CALL(handler_, OnConnectComplete(CHANNEL_ERROR_SOCKET_ERROR)); EXPECT_CALL(*socket_->GetMockTransport(), Start()); - socket_->Connect(read_delegate_.Pass(), + socket_->Connect(delegate_.Pass(), base::Bind(&CompleteHandler::OnConnectComplete, base::Unretained(&handler_))); socket_->GetMockTransport()->current_delegate()->OnError( - CHANNEL_ERROR_SOCKET_ERROR, last_errors); + CHANNEL_ERROR_SOCKET_ERROR); RunPendingTasks(); EXPECT_EQ(cast_channel::READY_STATE_CLOSED, socket_->ready_state()); EXPECT_EQ(cast_channel::CHANNEL_ERROR_SOCKET_ERROR, socket_->error_state()); - EXPECT_EQ(555, last_errors_captured.net_return_value); } TEST_F(CastSocketTest, TestConnectChallengeVerificationFails) { @@ -770,13 +762,14 @@ TEST_F(CastSocketTest, TestConnectChallengeVerificationFails) { socket_->SetupSsl2Connect(net::ASYNC, net::OK); socket_->SetVerifyChallengeResult(false); + EXPECT_CALL(*delegate_, OnError(CHANNEL_ERROR_AUTHENTICATION_ERROR)); CastMessage challenge_proto = CreateAuthChallenge(); EXPECT_CALL(*socket_->GetMockTransport(), SendMessage(EqualsProto(challenge_proto), _)) .WillOnce(RunCompletionCallback<1>(net::OK)); EXPECT_CALL(handler_, OnConnectComplete(CHANNEL_ERROR_AUTHENTICATION_ERROR)); EXPECT_CALL(*socket_->GetMockTransport(), Start()); - socket_->Connect(read_delegate_.Pass(), + socket_->Connect(delegate_.Pass(), base::Bind(&CompleteHandler::OnConnectComplete, base::Unretained(&handler_))); RunPendingTasks(); @@ -816,7 +809,7 @@ TEST_F(CastSocketTest, TestConnectEndToEndWithRealTransportAsync) { socket_->AddWriteResultForData(net::ASYNC, test_message_str); EXPECT_CALL(handler_, OnConnectComplete(CHANNEL_ERROR_NONE)); - socket_->Connect(read_delegate_.Pass(), + socket_->Connect(delegate_.Pass(), base::Bind(&CompleteHandler::OnConnectComplete, base::Unretained(&handler_))); RunPendingTasks(); @@ -861,7 +854,7 @@ TEST_F(CastSocketTest, TestConnectEndToEndWithRealTransportSync) { socket_->AddWriteResultForData(net::SYNCHRONOUS, test_message_str); EXPECT_CALL(handler_, OnConnectComplete(CHANNEL_ERROR_NONE)); - socket_->Connect(read_delegate_.Pass(), + socket_->Connect(delegate_.Pass(), base::Bind(&CompleteHandler::OnConnectComplete, base::Unretained(&handler_))); RunPendingTasks(); diff --git a/extensions/browser/api/cast_channel/cast_test_util.h b/extensions/browser/api/cast_channel/cast_test_util.h index defa627..2323e34 100644 --- a/extensions/browser/api/cast_channel/cast_test_util.h +++ b/extensions/browser/api/cast_channel/cast_test_util.h @@ -2,8 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef EXTENSIONS_BROWSER_API_CAST_CHANNEL_TEST_UTIL_H -#define EXTENSIONS_BROWSER_API_CAST_CHANNEL_TEST_UTIL_H +#ifndef EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_TEST_UTIL_H_ +#define EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_TEST_UTIL_H_ + +#include <string> #include "extensions/browser/api/cast_channel/cast_socket.h" #include "extensions/browser/api/cast_channel/cast_transport.h" @@ -46,8 +48,7 @@ class MockCastTransportDelegate : public CastTransport::Delegate { MockCastTransportDelegate(); ~MockCastTransportDelegate() override; - MOCK_METHOD2(OnError, - void(ChannelError error, const LastErrors& last_errors)); + MOCK_METHOD1(OnError, void(ChannelError error)); MOCK_METHOD1(OnMessage, void(const CastMessage& message)); MOCK_METHOD0(Start, void(void)); @@ -68,8 +69,8 @@ class MockCastSocket : public CastSocket { // Proxy for ConnectRawPtr. Unpacks scoped_ptr into a GMock-friendly bare // ptr. - virtual void Connect(scoped_ptr<CastTransport::Delegate> delegate, - base::Callback<void(ChannelError)> callback) override { + void Connect(scoped_ptr<CastTransport::Delegate> delegate, + base::Callback<void(ChannelError)> callback) override { delegate_ = delegate.Pass(); ConnectRawPtr(delegate_.get(), callback); } @@ -120,4 +121,4 @@ ACTION_TEMPLATE(RunCompletionCallback, } // namespace core_api } // namespace extensions -#endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_TEST_UTIL_H +#endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_TEST_UTIL_H_ diff --git a/extensions/browser/api/cast_channel/cast_transport.cc b/extensions/browser/api/cast_channel/cast_transport.cc index 1b35d6b..777b168 100644 --- a/extensions/browser/api/cast_channel/cast_transport.cc +++ b/extensions/browser/api/cast_channel/cast_transport.cc @@ -123,12 +123,12 @@ proto::ErrorState CastTransportImpl::ErrorStateToProto(ChannelError state) { } } -void CastTransportImpl::SetReadDelegate(scoped_ptr<Delegate> read_delegate) { +void CastTransportImpl::SetReadDelegate(scoped_ptr<Delegate> delegate) { DCHECK(CalledOnValidThread()); - DCHECK(read_delegate); - read_delegate_ = read_delegate.Pass(); + DCHECK(delegate); + delegate_ = delegate.Pass(); if (started_) { - read_delegate_->Start(); + delegate_->Start(); } } @@ -241,6 +241,12 @@ void CastTransportImpl::OnWriteResult(int result) { logger_->LogSocketWriteState(channel_id_, WriteStateToProto(write_state_)); } + if (rv == net::ERR_FAILED) { + VLOG_WITH_CONNECTION(2) << "Sending OnError()."; + DCHECK_NE(CHANNEL_ERROR_NONE, error_state_); + delegate_->OnError(error_state_); + } + // If write loop is done because the queue is empty then set write // state to NONE if (write_queue_.empty()) { @@ -275,6 +281,7 @@ int CastTransportImpl::DoWrite() { int CastTransportImpl::DoWriteComplete(int result) { VLOG_WITH_CONNECTION(2) << "DoWriteComplete result=" << result; DCHECK(!write_queue_.empty()); + logger_->LogSocketEventWithRv(channel_id_, proto::SOCKET_WRITE, result); if (result <= 0) { // NOTE that 0 also indicates an error SetErrorState(CHANNEL_ERROR_SOCKET_ERROR); SetWriteState(WRITE_STATE_ERROR); @@ -320,9 +327,8 @@ int CastTransportImpl::DoWriteError(int result) { void CastTransportImpl::Start() { DCHECK(CalledOnValidThread()); DCHECK(!started_); - DCHECK(read_delegate_) - << "Read delegate must be set prior to calling Start()"; - read_delegate_->Start(); + DCHECK(delegate_) << "Read delegate must be set prior to calling Start()"; + delegate_->Start(); if (read_state_ == READ_STATE_NONE) { // Initialize and run the read state machine. SetReadState(READ_STATE_READ); @@ -371,9 +377,9 @@ void CastTransportImpl::OnReadResult(int result) { } if (rv == net::ERR_FAILED) { - VLOG_WITH_CONNECTION(2) << "Sending OnError()."; DCHECK_NE(CHANNEL_ERROR_NONE, error_state_); - read_delegate_->OnError(error_state_, logger_->GetLastErrors(channel_id_)); + VLOG_WITH_CONNECTION(2) << "Sending OnError()."; + delegate_->OnError(error_state_); } } @@ -393,7 +399,7 @@ int CastTransportImpl::DoRead() { int CastTransportImpl::DoReadComplete(int result) { VLOG_WITH_CONNECTION(2) << "DoReadComplete result = " << result; - + logger_->LogSocketEventWithRv(channel_id_, proto::SOCKET_READ, result); if (result <= 0) { VLOG_WITH_CONNECTION(1) << "Read error, peer closed the socket."; SetErrorState(CHANNEL_ERROR_SOCKET_ERROR); @@ -431,11 +437,7 @@ int CastTransportImpl::DoReadCallback() { return net::ERR_INVALID_RESPONSE; } SetReadState(READ_STATE_READ); - logger_->LogSocketEventForMessage(channel_id_, proto::NOTIFY_ON_MESSAGE, - current_message_->namespace_(), - std::string()); - - read_delegate_->OnMessage(*current_message_); + delegate_->OnMessage(*current_message_); current_message_.reset(); return net::OK; } diff --git a/extensions/browser/api/cast_channel/cast_transport.h b/extensions/browser/api/cast_channel/cast_transport.h index 8a84a6d..5c1b942 100644 --- a/extensions/browser/api/cast_channel/cast_transport.h +++ b/extensions/browser/api/cast_channel/cast_transport.h @@ -45,11 +45,9 @@ class CastTransport { // Owned read delegates are Start()ed automatically. virtual void Start() = 0; - // An error occurred on the channel. |last_errors| contains the last errors - // logged for the channel from the implementation. + // An error occurred on the channel. // The caller is responsible for closing |socket| if an error occurred. - virtual void OnError(ChannelError error_state, - const LastErrors& last_errors) = 0; + virtual void OnError(ChannelError error_state) = 0; // A message was received on the channel. virtual void OnMessage(const CastMessage& message) = 0; @@ -188,7 +186,7 @@ class CastTransportImpl : public CastTransport, public base::NonThreadSafe { net::Socket* const socket_; // Methods for communicating message receipt and error status to client code. - scoped_ptr<Delegate> read_delegate_; + scoped_ptr<Delegate> delegate_; // Write flow state machine state. WriteState write_state_; diff --git a/extensions/browser/api/cast_channel/cast_transport_unittest.cc b/extensions/browser/api/cast_channel/cast_transport_unittest.cc index 6989446..6b6b1bc 100644 --- a/extensions/browser/api/cast_channel/cast_transport_unittest.cc +++ b/extensions/browser/api/cast_channel/cast_transport_unittest.cc @@ -33,6 +33,9 @@ namespace extensions { namespace core_api { namespace cast_channel { namespace { + +const int kChannelId = 0; + // Mockable placeholder for write completion events. class CompleteHandler { public: @@ -143,8 +146,9 @@ class CastTransportTest : public testing::Test { scoped_ptr<base::TickClock>(new base::SimpleTestTickClock), base::TimeTicks())) { delegate_ = new MockCastTransportDelegate; - transport_.reset(new CastTransportImpl( - &mock_socket_, 0, CreateIPEndPointForTest(), auth_type_, logger_)); + transport_.reset(new CastTransportImpl(&mock_socket_, kChannelId, + CreateIPEndPointForTest(), + auth_type_, logger_)); transport_->SetReadDelegate(make_scoped_ptr(delegate_)); } ~CastTransportTest() override {} @@ -227,6 +231,9 @@ TEST_F(CastTransportTest, TestWriteFailureAsync) { message, base::Bind(&CompleteHandler::Complete, base::Unretained(&write_handler))); socket_cbs.Pop(net::ERR_CONNECTION_RESET); + EXPECT_EQ(proto::SOCKET_WRITE, logger_->GetLastErrors(kChannelId).event_type); + EXPECT_EQ(net::ERR_CONNECTION_RESET, + logger_->GetLastErrors(kChannelId).net_return_value); } // ---------------------------------------------------------------------------- @@ -281,6 +288,9 @@ TEST_F(CastTransportTest, TestWriteFailureSync) { transport_->SendMessage( message, base::Bind(&CompleteHandler::Complete, base::Unretained(&write_handler))); + EXPECT_EQ(proto::SOCKET_WRITE, logger_->GetLastErrors(kChannelId).event_type); + EXPECT_EQ(net::ERR_CONNECTION_RESET, + logger_->GetLastErrors(kChannelId).net_return_value); } // ---------------------------------------------------------------------------- @@ -385,10 +395,13 @@ TEST_F(CastTransportTest, TestReadErrorInHeaderAsync) { Return(net::ERR_IO_PENDING))) .RetiresOnSaturation(); - EXPECT_CALL(*delegate_, OnError(CHANNEL_ERROR_SOCKET_ERROR, _)); + EXPECT_CALL(*delegate_, OnError(CHANNEL_ERROR_SOCKET_ERROR)); transport_->Start(); // Header read failure. socket_cbs.Pop(net::ERR_CONNECTION_RESET); + EXPECT_EQ(proto::SOCKET_READ, logger_->GetLastErrors(kChannelId).event_type); + EXPECT_EQ(net::ERR_CONNECTION_RESET, + logger_->GetLastErrors(kChannelId).net_return_value); } TEST_F(CastTransportTest, TestReadErrorInBodyAsync) { @@ -418,12 +431,15 @@ TEST_F(CastTransportTest, TestReadErrorInBodyAsync) { EnqueueCallback<2>(&socket_cbs), Return(net::ERR_IO_PENDING))) .RetiresOnSaturation(); - EXPECT_CALL(*delegate_, OnError(CHANNEL_ERROR_SOCKET_ERROR, _)); + EXPECT_CALL(*delegate_, OnError(CHANNEL_ERROR_SOCKET_ERROR)); transport_->Start(); // Header read is OK. socket_cbs.Pop(MessageFramer::MessageHeader::header_size()); // Body read fails. socket_cbs.Pop(net::ERR_CONNECTION_RESET); + EXPECT_EQ(proto::SOCKET_READ, logger_->GetLastErrors(kChannelId).event_type); + EXPECT_EQ(net::ERR_CONNECTION_RESET, + logger_->GetLastErrors(kChannelId).net_return_value); } TEST_F(CastTransportTest, TestReadCorruptedMessageAsync) { @@ -461,7 +477,7 @@ TEST_F(CastTransportTest, TestReadCorruptedMessageAsync) { Return(net::ERR_IO_PENDING))) .RetiresOnSaturation(); - EXPECT_CALL(*delegate_, OnError(CHANNEL_ERROR_INVALID_MESSAGE, _)); + EXPECT_CALL(*delegate_, OnError(CHANNEL_ERROR_INVALID_MESSAGE)); transport_->Start(); socket_cbs.Pop(MessageFramer::MessageHeader::header_size()); socket_cbs.Pop(serialized_message.size() - @@ -554,7 +570,7 @@ TEST_F(CastTransportTest, TestReadErrorInHeaderSync) { .WillOnce(DoAll(FillBufferFromString<0>(serialized_message), Return(net::ERR_CONNECTION_RESET))) .RetiresOnSaturation(); - EXPECT_CALL(*delegate_, OnError(CHANNEL_ERROR_SOCKET_ERROR, _)); + EXPECT_CALL(*delegate_, OnError(CHANNEL_ERROR_SOCKET_ERROR)); transport_->Start(); } @@ -581,8 +597,11 @@ TEST_F(CastTransportTest, TestReadErrorInBodySync) { MessageFramer::MessageHeader::header_size() - 1)), Return(net::ERR_CONNECTION_RESET))) .RetiresOnSaturation(); - EXPECT_CALL(*delegate_, OnError(CHANNEL_ERROR_SOCKET_ERROR, _)); + EXPECT_CALL(*delegate_, OnError(CHANNEL_ERROR_SOCKET_ERROR)); transport_->Start(); + EXPECT_EQ(proto::SOCKET_READ, logger_->GetLastErrors(kChannelId).event_type); + EXPECT_EQ(net::ERR_CONNECTION_RESET, + logger_->GetLastErrors(kChannelId).net_return_value); } TEST_F(CastTransportTest, TestReadCorruptedMessageSync) { @@ -617,7 +636,7 @@ TEST_F(CastTransportTest, TestReadCorruptedMessageSync) { Return(serialized_message.size() - MessageFramer::MessageHeader::header_size()))) .RetiresOnSaturation(); - EXPECT_CALL(*delegate_, OnError(CHANNEL_ERROR_INVALID_MESSAGE, _)); + EXPECT_CALL(*delegate_, OnError(CHANNEL_ERROR_INVALID_MESSAGE)); transport_->Start(); } } // namespace cast_channel diff --git a/extensions/browser/api/cast_channel/keep_alive_delegate.cc b/extensions/browser/api/cast_channel/keep_alive_delegate.cc index d8fd716..ac04030 100644 --- a/extensions/browser/api/cast_channel/keep_alive_delegate.cc +++ b/extensions/browser/api/cast_channel/keep_alive_delegate.cc @@ -2,11 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <string> + #include "base/json/json_reader.h" #include "base/json/json_writer.h" #include "extensions/browser/api/cast_channel/cast_message_util.h" #include "extensions/browser/api/cast_channel/cast_socket.h" #include "extensions/browser/api/cast_channel/keep_alive_delegate.h" +#include "extensions/browser/api/cast_channel/logger.h" #include "extensions/common/api/cast_channel/cast_channel.pb.h" #include "extensions/common/api/cast_channel/logging.pb.h" #include "net/base/net_errors.h" @@ -76,11 +79,13 @@ CastMessage KeepAliveDelegate::CreateKeepAliveMessage( KeepAliveDelegate::KeepAliveDelegate( CastSocket* socket, + scoped_refptr<Logger> logger, scoped_ptr<CastTransport::Delegate> inner_delegate, base::TimeDelta ping_interval, base::TimeDelta liveness_timeout) : started_(false), socket_(socket), + logger_(logger), inner_delegate_(inner_delegate.Pass()), liveness_timeout_(liveness_timeout), ping_interval_(ping_interval) { @@ -149,26 +154,23 @@ void KeepAliveDelegate::SendKeepAliveMessageComplete(const char* message_type, VLOG(2) << "Sending " << message_type << " complete, rv=" << rv; if (rv != net::OK) { // An error occurred while sending the ping response. - // Close the connection. VLOG(1) << "Error sending " << message_type; - inner_delegate_->OnError(cast_channel::CHANNEL_ERROR_SOCKET_ERROR, - LastErrors()); + logger_->LogSocketEventWithRv(socket_->id(), proto::PING_WRITE_ERROR, rv); + inner_delegate_->OnError(cast_channel::CHANNEL_ERROR_SOCKET_ERROR); } } void KeepAliveDelegate::LivenessTimeout() const { VLOG(1) << "Ping timeout"; - inner_delegate_->OnError(cast_channel::CHANNEL_ERROR_PING_TIMEOUT, - LastErrors()); + inner_delegate_->OnError(cast_channel::CHANNEL_ERROR_PING_TIMEOUT); } // CastTransport::Delegate interface. -void KeepAliveDelegate::OnError(ChannelError error_state, - const LastErrors& last_errors) { +void KeepAliveDelegate::OnError(ChannelError error_state) { DCHECK(started_); DCHECK(thread_checker_.CalledOnValidThread()); VLOG(2) << "KeepAlive::OnError"; - inner_delegate_->OnError(error_state, last_errors); + inner_delegate_->OnError(error_state); } void KeepAliveDelegate::OnMessage(const CastMessage& message) { diff --git a/extensions/browser/api/cast_channel/keep_alive_delegate.h b/extensions/browser/api/cast_channel/keep_alive_delegate.h index baf6a8c..2526ff5 100644 --- a/extensions/browser/api/cast_channel/keep_alive_delegate.h +++ b/extensions/browser/api/cast_channel/keep_alive_delegate.h @@ -15,6 +15,7 @@ namespace core_api { namespace cast_channel { class CastSocket; +class Logger; // Decorator delegate which provides keep-alive functionality. // Keep-alive messages are handled by this object; all other messages and @@ -22,6 +23,8 @@ class CastSocket; class KeepAliveDelegate : public CastTransport::Delegate { public: // |socket|: The socket to be kept alive. + // |logger|: The logging object which collects protocol events and error + // details. // |inner_delegate|: The delegate which processes all non-keep-alive // messages. This object assumes ownership of // |inner_delegate|. @@ -30,6 +33,7 @@ class KeepAliveDelegate : public CastTransport::Delegate { // |liveness_timeout|: The amount of idle time to wait before terminating the // connection. KeepAliveDelegate(CastSocket* socket, + scoped_refptr<Logger> logger, scoped_ptr<CastTransport::Delegate> inner_delegate, base::TimeDelta ping_interval, base::TimeDelta liveness_timeout); @@ -44,8 +48,7 @@ class KeepAliveDelegate : public CastTransport::Delegate { // CastTransport::Delegate implementation. void Start() override; - void OnError(ChannelError error_state, - const LastErrors& last_errors) override; + void OnError(ChannelError error_state) override; void OnMessage(const CastMessage& message) override; static const char kHeartbeatPingType[]; @@ -73,6 +76,9 @@ class KeepAliveDelegate : public CastTransport::Delegate { // Socket that is managed by the keep-alive object. CastSocket* socket_; + // Logging object. + scoped_refptr<Logger> logger_; + // Delegate object which receives all non-keep alive messages. scoped_ptr<CastTransport::Delegate> inner_delegate_; @@ -103,4 +109,4 @@ class KeepAliveDelegate : public CastTransport::Delegate { } // namespace core_api } // namespace extensions -#endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_SOCKET_H_ +#endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_KEEP_ALIVE_DELEGATE_H_ diff --git a/extensions/browser/api/cast_channel/keep_alive_delegate_unittest.cc b/extensions/browser/api/cast_channel/keep_alive_delegate_unittest.cc index 0fe3f53..f0ca605 100644 --- a/extensions/browser/api/cast_channel/keep_alive_delegate_unittest.cc +++ b/extensions/browser/api/cast_channel/keep_alive_delegate_unittest.cc @@ -4,6 +4,7 @@ #include "extensions/browser/api/cast_channel/keep_alive_delegate.h" +#include "base/test/simple_test_tick_clock.h" #include "base/timer/mock_timer.h" #include "extensions/browser/api/cast_channel/cast_test_util.h" #include "net/base/net_errors.h" @@ -47,8 +48,11 @@ class KeepAliveDelegateTest : public testing::Test { protected: void SetUp() override { inner_delegate_ = new MockCastTransportDelegate; + logger_ = + new Logger(scoped_ptr<base::TickClock>(new base::SimpleTestTickClock), + base::TimeTicks()); keep_alive_.reset(new KeepAliveDelegate( - &socket_, make_scoped_ptr(inner_delegate_), + &socket_, logger_, make_scoped_ptr(inner_delegate_), base::TimeDelta::FromMilliseconds(kTestPingTimeoutMillis), base::TimeDelta::FromMilliseconds(kTestLivenessTimeoutMillis))); liveness_timer_ = new MockTimerWithMonitoredReset(true, false); @@ -59,10 +63,12 @@ class KeepAliveDelegateTest : public testing::Test { MockCastSocket socket_; scoped_ptr<KeepAliveDelegate> keep_alive_; + scoped_refptr<Logger> logger_; MockCastTransportDelegate* inner_delegate_; MockTimerWithMonitoredReset* liveness_timer_; MockTimerWithMonitoredReset* ping_timer_; + private: DISALLOW_COPY_AND_ASSIGN(KeepAliveDelegateTest); }; @@ -88,12 +94,16 @@ TEST_F(KeepAliveDelegateTest, TestPingFailed) { _)) .WillOnce(RunCompletionCallback<1>(net::ERR_CONNECTION_RESET)); EXPECT_CALL(*inner_delegate_, Start()); - EXPECT_CALL(*inner_delegate_, OnError(CHANNEL_ERROR_SOCKET_ERROR, _)); + EXPECT_CALL(*inner_delegate_, OnError(CHANNEL_ERROR_SOCKET_ERROR)); EXPECT_CALL(*ping_timer_, ResetTriggered()).Times(1); EXPECT_CALL(*liveness_timer_, ResetTriggered()).Times(1); keep_alive_->Start(); ping_timer_->Fire(); + EXPECT_EQ(proto::PING_WRITE_ERROR, + logger_->GetLastErrors(socket_.id()).event_type); + EXPECT_EQ(net::ERR_CONNECTION_RESET, + logger_->GetLastErrors(socket_.id()).net_return_value); } TEST_F(KeepAliveDelegateTest, TestPingAndLivenessTimeout) { @@ -101,7 +111,7 @@ TEST_F(KeepAliveDelegateTest, TestPingAndLivenessTimeout) { SendMessage(EqualsProto(KeepAliveDelegate::CreateKeepAliveMessage( KeepAliveDelegate::kHeartbeatPingType)), _)).WillOnce(RunCompletionCallback<1>(net::OK)); - EXPECT_CALL(*inner_delegate_, OnError(CHANNEL_ERROR_PING_TIMEOUT, _)); + EXPECT_CALL(*inner_delegate_, OnError(CHANNEL_ERROR_PING_TIMEOUT)); EXPECT_CALL(*inner_delegate_, Start()); EXPECT_CALL(*ping_timer_, ResetTriggered()).Times(1); EXPECT_CALL(*liveness_timer_, ResetTriggered()).Times(1); diff --git a/extensions/common/api/cast_channel/OWNERS b/extensions/common/api/cast_channel/OWNERS new file mode 100644 index 0000000..94f5464 --- /dev/null +++ b/extensions/common/api/cast_channel/OWNERS @@ -0,0 +1,3 @@ +mfoltz@chromium.org +kmarshall@chromium.org +wez@chromium.org diff --git a/extensions/common/api/cast_channel/logging.proto b/extensions/common/api/cast_channel/logging.proto index bc0be5c..bf7204c 100644 --- a/extensions/common/api/cast_channel/logging.proto +++ b/extensions/common/api/cast_channel/logging.proto @@ -32,13 +32,15 @@ enum EventType { MESSAGE_WRITTEN = 20; // Message SOCKET_READ = 21; // Logged with RV. MESSAGE_READ = 22; // Message - NOTIFY_ON_MESSAGE = 23; // Message - NOTIFY_ON_ERROR = 24; SOCKET_CLOSED = 25; SSL_CERT_EXCESSIVE_LIFETIME = 26; CHANNEL_POLICY_ENFORCED = 27; - TCP_SOCKET_CONNECT_COMPLETE = 28; // Logged with RV. - SSL_SOCKET_CONNECT_COMPLETE = 29; // Logged with RV. + TCP_SOCKET_CONNECT_COMPLETE = 28; // Logged with RV. + SSL_SOCKET_CONNECT_COMPLETE = 29; // Logged with RV. + SSL_SOCKET_CONNECT_FAILED = 30; // Logged with RV. + SEND_AUTH_CHALLENGE_FAILED = 31; // Logged with RV. + AUTH_CHALLENGE_REPLY_INVALID = 32; + PING_WRITE_ERROR = 33; // Logged with RV. } enum ChannelAuth { |