summaryrefslogtreecommitdiffstats
path: root/remoting/host
diff options
context:
space:
mode:
authorjoedow <joedow@chromium.org>2016-02-23 17:15:30 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-24 01:16:28 +0000
commitaceaf12ce102d2551169a6a6265269d33f8462a8 (patch)
tree61e7745a20b1a082fba69c8783996eb2a92dadf6 /remoting/host
parent17acb78d1b36d7ff5ba7dcc4f04c853241f54aa3 (diff)
downloadchromium_src-aceaf12ce102d2551169a6a6265269d33f8462a8.zip
chromium_src-aceaf12ce102d2551169a6a6265269d33f8462a8.tar.gz
chromium_src-aceaf12ce102d2551169a6a6265269d33f8462a8.tar.bz2
Removing Linux specific GnubbyAuthHandler header file.
This change is a result of feedback from the GnubbyAuthHandler refactoring. Since we will have platform specific implementations of the GnubbyAuthHandler, we should try to have a single header defining the interface and platform specific cc files for the impl. The Linux impl had a header which was used by its unit tests, however I think the test methods could be generic enough that the ForTest() methods make sense to have on the interface as the unittests for each impl will use them. This simplifies the code in the unittests and allows us to hide the platform specific impls in the cc file and remove the platform specific headers. BUG=587298 Review URL: https://codereview.chromium.org/1720243002 Cr-Commit-Position: refs/heads/master@{#377167}
Diffstat (limited to 'remoting/host')
-rw-r--r--remoting/host/host_mock_objects.h3
-rw-r--r--remoting/host/security_key/gnubby_auth_handler.h7
-rw-r--r--remoting/host/security_key/gnubby_auth_handler_linux.cc71
-rw-r--r--remoting/host/security_key/gnubby_auth_handler_linux.h93
-rw-r--r--remoting/host/security_key/gnubby_auth_handler_linux_unittest.cc33
5 files changed, 91 insertions, 116 deletions
diff --git a/remoting/host/host_mock_objects.h b/remoting/host/host_mock_objects.h
index 9c374af..2df17fc 100644
--- a/remoting/host/host_mock_objects.h
+++ b/remoting/host/host_mock_objects.h
@@ -25,6 +25,7 @@
#include "third_party/webrtc/modules/desktop_capture/mouse_cursor_monitor.h"
namespace base {
+class TimeDelta;
class SingleThreadTaskRunner;
} // namespace base
@@ -148,6 +149,8 @@ class MockGnubbyAuthHandler : public GnubbyAuthHandler {
MOCK_METHOD2(SendClientResponse,
void(int connection_id, const std::string& response));
MOCK_METHOD1(SendErrorAndCloseConnection, void(int connection_id));
+ MOCK_CONST_METHOD0(GetActiveConnectionCountForTest, size_t());
+ MOCK_METHOD1(SetRequestTimeoutForTest, void(const base::TimeDelta& timeout));
void SetSendMessageCallback(
const GnubbyAuthHandler::SendMessageCallback& callback) override;
diff --git a/remoting/host/security_key/gnubby_auth_handler.h b/remoting/host/security_key/gnubby_auth_handler.h
index 1c2f564..4c7ed25 100644
--- a/remoting/host/security_key/gnubby_auth_handler.h
+++ b/remoting/host/security_key/gnubby_auth_handler.h
@@ -12,6 +12,7 @@
namespace base {
class FilePath;
+class TimeDelta;
} // namespace base
namespace remoting {
@@ -53,6 +54,12 @@ class GnubbyAuthHandler {
// Closes the gnubby connection represented by |gnubby_connection_id|.
virtual void SendErrorAndCloseConnection(int gnubby_connection_id) = 0;
+
+ // Returns the number of active gnubby connections.
+ virtual size_t GetActiveConnectionCountForTest() const = 0;
+
+ // Sets the timeout used when waiting for a gnubby response.
+ virtual void SetRequestTimeoutForTest(const base::TimeDelta& timeout) = 0;
};
} // namespace remoting
diff --git a/remoting/host/security_key/gnubby_auth_handler_linux.cc b/remoting/host/security_key/gnubby_auth_handler_linux.cc
index 8a50686..f036434 100644
--- a/remoting/host/security_key/gnubby_auth_handler_linux.cc
+++ b/remoting/host/security_key/gnubby_auth_handler_linux.cc
@@ -1,9 +1,6 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
-#include "remoting/host/security_key/gnubby_auth_handler_linux.h"
-
#include <stdint.h>
#include <unistd.h>
@@ -11,12 +8,17 @@
#include "base/files/file_util.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
#include "base/stl_util.h"
+#include "base/threading/thread_checker.h"
#include "base/threading/thread_restrictions.h"
#include "base/values.h"
+#include "net/base/completion_callback.h"
#include "net/base/net_errors.h"
+#include "net/socket/stream_socket.h"
#include "net/socket/unix_domain_server_socket_posix.h"
#include "remoting/base/logging.h"
+#include "remoting/host/security_key/gnubby_auth_handler.h"
#include "remoting/host/security_key/gnubby_socket.h"
namespace {
@@ -46,6 +48,67 @@ unsigned int GetCommandCode(const std::string& data) {
namespace remoting {
+class GnubbyAuthHandlerLinux : public GnubbyAuthHandler {
+ public:
+ GnubbyAuthHandlerLinux();
+ ~GnubbyAuthHandlerLinux() override;
+
+ private:
+ typedef std::map<int, GnubbySocket*> ActiveSockets;
+
+ // GnubbyAuthHandler interface.
+ void CreateGnubbyConnection() override;
+ bool IsValidConnectionId(int gnubby_connection_id) const override;
+ void SendClientResponse(int gnubby_connection_id,
+ const std::string& response) override;
+ void SendErrorAndCloseConnection(int gnubby_connection_id) override;
+ void SetSendMessageCallback(const SendMessageCallback& callback) override;
+ size_t GetActiveConnectionCountForTest() const override;
+ void SetRequestTimeoutForTest(const base::TimeDelta& timeout) override;
+
+ // Starts listening for connection.
+ void DoAccept();
+
+ // Called when a connection is accepted.
+ void OnAccepted(int result);
+
+ // Called when a GnubbySocket has done reading.
+ void OnReadComplete(int gnubby_connection_id);
+
+ // Gets an active socket iterator for |gnubby_connection_id|.
+ ActiveSockets::const_iterator GetSocketForConnectionId(
+ int gnubby_connection_id) const;
+
+ // Send an error and closes an active socket.
+ void SendErrorAndCloseActiveSocket(const ActiveSockets::const_iterator& iter);
+
+ // A request timed out.
+ void RequestTimedOut(int gnubby_connection_id);
+
+ // Ensures GnubbyAuthHandlerLinux methods are called on the same thread.
+ base::ThreadChecker thread_checker_;
+
+ // Socket used to listen for authorization requests.
+ scoped_ptr<net::UnixDomainServerSocket> auth_socket_;
+
+ // A temporary holder for an accepted connection.
+ scoped_ptr<net::StreamSocket> accept_socket_;
+
+ // Used to pass gnubby extension messages to the client.
+ SendMessageCallback send_message_callback_;
+
+ // The last assigned gnubby connection id.
+ int last_connection_id_;
+
+ // Sockets by connection id used to process gnubbyd requests.
+ ActiveSockets active_sockets_;
+
+ // Timeout used for a request.
+ base::TimeDelta request_timeout_;
+
+ DISALLOW_COPY_AND_ASSIGN(GnubbyAuthHandlerLinux);
+};
+
scoped_ptr<GnubbyAuthHandler> GnubbyAuthHandler::Create(
const SendMessageCallback& callback) {
scoped_ptr<GnubbyAuthHandler> auth_handler(new GnubbyAuthHandlerLinux());
@@ -133,7 +196,7 @@ void GnubbyAuthHandlerLinux::SetSendMessageCallback(
send_message_callback_ = callback;
}
-size_t GnubbyAuthHandlerLinux::GetActiveSocketsMapSizeForTest() const {
+size_t GnubbyAuthHandlerLinux::GetActiveConnectionCountForTest() const {
return active_sockets_.size();
}
diff --git a/remoting/host/security_key/gnubby_auth_handler_linux.h b/remoting/host/security_key/gnubby_auth_handler_linux.h
deleted file mode 100644
index ff27c20..0000000
--- a/remoting/host/security_key/gnubby_auth_handler_linux.h
+++ /dev/null
@@ -1,93 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef REMOTING_HOST_SECURITY_KEY_GNUBBY_AUTH_HANDLER_LINUX_H_
-#define REMOTING_HOST_SECURITY_KEY_GNUBBY_AUTH_HANDLER_LINUX_H_
-
-#include <stddef.h>
-
-#include <map>
-#include <string>
-
-#include "base/macros.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/threading/thread_checker.h"
-#include "net/base/completion_callback.h"
-#include "net/socket/stream_socket.h"
-#include "remoting/host/security_key/gnubby_auth_handler.h"
-
-namespace net {
-class UnixDomainServerSocket;
-} // namespace net
-
-namespace remoting {
-
-class GnubbySocket;
-
-class GnubbyAuthHandlerLinux : public GnubbyAuthHandler {
- public:
- GnubbyAuthHandlerLinux();
- ~GnubbyAuthHandlerLinux() override;
-
- size_t GetActiveSocketsMapSizeForTest() const;
-
- void SetRequestTimeoutForTest(const base::TimeDelta& timeout);
-
- private:
- typedef std::map<int, GnubbySocket*> ActiveSockets;
-
- // GnubbyAuthHandler interface.
- void CreateGnubbyConnection() override;
- bool IsValidConnectionId(int gnubby_connection_id) const override;
- void SendClientResponse(int gnubby_connection_id,
- const std::string& response) override;
- void SendErrorAndCloseConnection(int gnubby_connection_id) override;
- void SetSendMessageCallback(const SendMessageCallback& callback) override;
-
- // Starts listening for connection.
- void DoAccept();
-
- // Called when a connection is accepted.
- void OnAccepted(int result);
-
- // Called when a GnubbySocket has done reading.
- void OnReadComplete(int gnubby_connection_id);
-
- // Gets an active socket iterator for |gnubby_connection_id|.
- ActiveSockets::const_iterator GetSocketForConnectionId(
- int gnubby_connection_id) const;
-
- // Send an error and closes an active socket.
- void SendErrorAndCloseActiveSocket(const ActiveSockets::const_iterator& iter);
-
- // A request timed out.
- void RequestTimedOut(int gnubby_connection_id);
-
- // Ensures GnubbyAuthHandlerLinux methods are called on the same thread.
- base::ThreadChecker thread_checker_;
-
- // Socket used to listen for authorization requests.
- scoped_ptr<net::UnixDomainServerSocket> auth_socket_;
-
- // A temporary holder for an accepted connection.
- scoped_ptr<net::StreamSocket> accept_socket_;
-
- // Used to pass gnubby extension messages to the client.
- SendMessageCallback send_message_callback_;
-
- // The last assigned gnubby connection id.
- int last_connection_id_;
-
- // Sockets by connection id used to process gnubbyd requests.
- ActiveSockets active_sockets_;
-
- // Timeout used for a request.
- base::TimeDelta request_timeout_;
-
- DISALLOW_COPY_AND_ASSIGN(GnubbyAuthHandlerLinux);
-};
-
-} // namespace remoting
-
-#endif // REMOTING_HOST_SECURITY_KEY_GNUBBY_AUTH_HANDLER_LINUX_H_
diff --git a/remoting/host/security_key/gnubby_auth_handler_linux_unittest.cc b/remoting/host/security_key/gnubby_auth_handler_linux_unittest.cc
index 5fd43cc..354ecc4 100644
--- a/remoting/host/security_key/gnubby_auth_handler_linux_unittest.cc
+++ b/remoting/host/security_key/gnubby_auth_handler_linux_unittest.cc
@@ -16,7 +16,7 @@
#include "net/base/net_errors.h"
#include "net/base/test_completion_callback.h"
#include "net/socket/unix_domain_client_socket_posix.h"
-#include "remoting/host/security_key/gnubby_auth_handler_linux.h"
+#include "remoting/host/security_key/gnubby_auth_handler.h"
#include "remoting/host/security_key/gnubby_socket.h"
#include "remoting/proto/internal.pb.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -57,9 +57,7 @@ class GnubbyAuthHandlerLinuxTest : public testing::Test {
send_message_callback_ =
base::Bind(&GnubbyAuthHandlerLinuxTest::SendMessageToClient,
base::Unretained(this));
- auth_handler_linux_.reset(new GnubbyAuthHandlerLinux());
- auth_handler_ = auth_handler_linux_.get();
- auth_handler_->SetSendMessageCallback(send_message_callback_);
+ auth_handler_ = remoting::GnubbyAuthHandler::Create(send_message_callback_);
}
void WaitForSendMessageToClient() {
@@ -119,10 +117,7 @@ class GnubbyAuthHandlerLinuxTest : public testing::Test {
scoped_ptr<base::RunLoop> run_loop_;
// Object under test.
- scoped_ptr<GnubbyAuthHandlerLinux> auth_handler_linux_;
-
- // GnubbyAuthHandler interface for |auth_handler_linux_|.
- GnubbyAuthHandler* auth_handler_;
+ scoped_ptr<GnubbyAuthHandler> auth_handler_;
GnubbyAuthHandler::SendMessageCallback send_message_callback_;
@@ -138,7 +133,7 @@ class GnubbyAuthHandlerLinuxTest : public testing::Test {
};
TEST_F(GnubbyAuthHandlerLinuxTest, NotClosedAfterRequest) {
- ASSERT_EQ(0u, auth_handler_linux_->GetActiveSocketsMapSizeForTest());
+ ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest());
auth_handler_->CreateGnubbyConnection();
@@ -156,11 +151,11 @@ TEST_F(GnubbyAuthHandlerLinuxTest, NotClosedAfterRequest) {
ASSERT_TRUE(auth_handler_->IsValidConnectionId(1));
// Verify that completing a request/response cycle didn't close the socket.
- ASSERT_EQ(1u, auth_handler_linux_->GetActiveSocketsMapSizeForTest());
+ ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest());
}
TEST_F(GnubbyAuthHandlerLinuxTest, HandleTwoRequests) {
- ASSERT_EQ(0u, auth_handler_linux_->GetActiveSocketsMapSizeForTest());
+ ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest());
auth_handler_->CreateGnubbyConnection();
@@ -186,11 +181,11 @@ TEST_F(GnubbyAuthHandlerLinuxTest, HandleTwoRequests) {
// Verify that completing two request/response cycles didn't close the
// socket.
- ASSERT_EQ(1u, auth_handler_linux_->GetActiveSocketsMapSizeForTest());
+ ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest());
}
TEST_F(GnubbyAuthHandlerLinuxTest, HandleTwoIndependentRequests) {
- ASSERT_EQ(0u, auth_handler_linux_->GetActiveSocketsMapSizeForTest());
+ ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest());
auth_handler_->CreateGnubbyConnection();
@@ -221,23 +216,23 @@ TEST_F(GnubbyAuthHandlerLinuxTest, HandleTwoIndependentRequests) {
ASSERT_FALSE(auth_handler_->IsValidConnectionId(1));
// Verify that the initial socket was released properly.
- ASSERT_EQ(1u, auth_handler_linux_->GetActiveSocketsMapSizeForTest());
+ ASSERT_EQ(1u, auth_handler_->GetActiveConnectionCountForTest());
}
TEST_F(GnubbyAuthHandlerLinuxTest, DidReadTimeout) {
- ASSERT_EQ(0u, auth_handler_linux_->GetActiveSocketsMapSizeForTest());
+ ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest());
auth_handler_->CreateGnubbyConnection();
net::UnixDomainClientSocket client_socket(socket_path_.value(), false);
net::TestCompletionCallback connect_callback;
int rv = client_socket.Connect(connect_callback.callback());
ASSERT_EQ(net::OK, connect_callback.GetResult(rv));
- auth_handler_linux_->SetRequestTimeoutForTest(base::TimeDelta());
- ASSERT_EQ(0u, auth_handler_linux_->GetActiveSocketsMapSizeForTest());
+ auth_handler_->SetRequestTimeoutForTest(base::TimeDelta());
+ ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest());
}
TEST_F(GnubbyAuthHandlerLinuxTest, ClientErrorMessageDelivered) {
- ASSERT_EQ(0u, auth_handler_linux_->GetActiveSocketsMapSizeForTest());
+ ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest());
auth_handler_->CreateGnubbyConnection();
net::UnixDomainClientSocket client_socket(socket_path_.value(), false);
@@ -246,7 +241,7 @@ TEST_F(GnubbyAuthHandlerLinuxTest, ClientErrorMessageDelivered) {
ASSERT_EQ(net::OK, connect_callback.GetResult(rv));
auth_handler_->SendErrorAndCloseConnection(1);
- ASSERT_EQ(0u, auth_handler_linux_->GetActiveSocketsMapSizeForTest());
+ ASSERT_EQ(0u, auth_handler_->GetActiveConnectionCountForTest());
}
} // namespace remoting