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

Side by Side Diff: remoting/host/security_key/gnubby_auth_handler_win.cc

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU Created 4 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "remoting/host/security_key/gnubby_auth_handler.h" 5 #include "remoting/host/security_key/gnubby_auth_handler.h"
6 6
7 #include <map> 7 #include <map>
8 #include <memory>
8 #include <string> 9 #include <string>
9 10
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/threading/thread_checker.h" 13 #include "base/threading/thread_checker.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "base/timer/timer.h" 15 #include "base/timer/timer.h"
16 #include "ipc/ipc_channel.h" 16 #include "ipc/ipc_channel.h"
17 #include "ipc/ipc_listener.h" 17 #include "ipc/ipc_listener.h"
18 #include "ipc/ipc_message.h" 18 #include "ipc/ipc_message.h"
19 #include "ipc/ipc_message_macros.h" 19 #include "ipc/ipc_message_macros.h"
20 #include "remoting/base/logging.h" 20 #include "remoting/base/logging.h"
21 #include "remoting/host/chromoting_messages.h" 21 #include "remoting/host/chromoting_messages.h"
22 #include "remoting/host/security_key/remote_security_key_ipc_constants.h" 22 #include "remoting/host/security_key/remote_security_key_ipc_constants.h"
(...skipping 25 matching lines...) Expand all
48 // can service the next client/request. This system allows multiple security 48 // can service the next client/request. This system allows multiple security
49 // key forwarding sessions to occur concurrently. 49 // key forwarding sessions to occur concurrently.
50 // TODO(joedow): Update GnubbyAuthHandler impls to run on a separate IO thread 50 // TODO(joedow): Update GnubbyAuthHandler impls to run on a separate IO thread
51 // instead of the thread it was created on: crbug.com/591739 51 // instead of the thread it was created on: crbug.com/591739
52 class GnubbyAuthHandlerWin : public GnubbyAuthHandler, public IPC::Listener { 52 class GnubbyAuthHandlerWin : public GnubbyAuthHandler, public IPC::Listener {
53 public: 53 public:
54 GnubbyAuthHandlerWin(); 54 GnubbyAuthHandlerWin();
55 ~GnubbyAuthHandlerWin() override; 55 ~GnubbyAuthHandlerWin() override;
56 56
57 private: 57 private:
58 typedef std::map<int, scoped_ptr<RemoteSecurityKeyIpcServer>> ActiveChannels; 58 typedef std::map<int, std::unique_ptr<RemoteSecurityKeyIpcServer>>
59 ActiveChannels;
59 60
60 // GnubbyAuthHandler interface. 61 // GnubbyAuthHandler interface.
61 void CreateGnubbyConnection() override; 62 void CreateGnubbyConnection() override;
62 bool IsValidConnectionId(int gnubby_connection_id) const override; 63 bool IsValidConnectionId(int gnubby_connection_id) const override;
63 void SendClientResponse(int gnubby_connection_id, 64 void SendClientResponse(int gnubby_connection_id,
64 const std::string& response) override; 65 const std::string& response) override;
65 void SendErrorAndCloseConnection(int gnubby_connection_id) override; 66 void SendErrorAndCloseConnection(int gnubby_connection_id) override;
66 void SetSendMessageCallback(const SendMessageCallback& callback) override; 67 void SetSendMessageCallback(const SendMessageCallback& callback) override;
67 size_t GetActiveConnectionCountForTest() const override; 68 size_t GetActiveConnectionCountForTest() const override;
68 void SetRequestTimeoutForTest(base::TimeDelta timeout) override; 69 void SetRequestTimeoutForTest(base::TimeDelta timeout) override;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 101
101 // The amount of time to wait for a client to process the connection details 102 // The amount of time to wait for a client to process the connection details
102 // message and disconnect from the IPC server channel before disconnecting it. 103 // message and disconnect from the IPC server channel before disconnecting it.
103 base::TimeDelta disconnect_timeout_; 104 base::TimeDelta disconnect_timeout_;
104 105
105 // Used to recreate the IPC server channel if a client forgets to disconnect. 106 // Used to recreate the IPC server channel if a client forgets to disconnect.
106 base::OneShotTimer timer_; 107 base::OneShotTimer timer_;
107 108
108 // IPC Clients connect to this channel first to receive their own IPC 109 // IPC Clients connect to this channel first to receive their own IPC
109 // channel to start a security key forwarding session on. 110 // channel to start a security key forwarding session on.
110 scoped_ptr<IPC::Channel> ipc_server_channel_; 111 std::unique_ptr<IPC::Channel> ipc_server_channel_;
111 112
112 // Ensures GnubbyAuthHandlerWin methods are called on the same thread. 113 // Ensures GnubbyAuthHandlerWin methods are called on the same thread.
113 base::ThreadChecker thread_checker_; 114 base::ThreadChecker thread_checker_;
114 115
115 DISALLOW_COPY_AND_ASSIGN(GnubbyAuthHandlerWin); 116 DISALLOW_COPY_AND_ASSIGN(GnubbyAuthHandlerWin);
116 }; 117 };
117 118
118 scoped_ptr<GnubbyAuthHandler> GnubbyAuthHandler::Create( 119 std::unique_ptr<GnubbyAuthHandler> GnubbyAuthHandler::Create(
119 const SendMessageCallback& callback) { 120 const SendMessageCallback& callback) {
120 scoped_ptr<GnubbyAuthHandler> auth_handler(new GnubbyAuthHandlerWin()); 121 std::unique_ptr<GnubbyAuthHandler> auth_handler(new GnubbyAuthHandlerWin());
121 auth_handler->SetSendMessageCallback(callback); 122 auth_handler->SetSendMessageCallback(callback);
122 return auth_handler; 123 return auth_handler;
123 } 124 }
124 125
125 GnubbyAuthHandlerWin::GnubbyAuthHandlerWin() 126 GnubbyAuthHandlerWin::GnubbyAuthHandlerWin()
126 : disconnect_timeout_( 127 : disconnect_timeout_(
127 base::TimeDelta::FromSeconds(kInitialRequestTimeoutSeconds)) {} 128 base::TimeDelta::FromSeconds(kInitialRequestTimeoutSeconds)) {}
128 129
129 GnubbyAuthHandlerWin::~GnubbyAuthHandlerWin() {} 130 GnubbyAuthHandlerWin::~GnubbyAuthHandlerWin() {}
130 131
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 220
220 timer_.Start(FROM_HERE, disconnect_timeout_, 221 timer_.Start(FROM_HERE, disconnect_timeout_,
221 base::Bind(&GnubbyAuthHandlerWin::OnChannelError, 222 base::Bind(&GnubbyAuthHandlerWin::OnChannelError,
222 base::Unretained(this))); 223 base::Unretained(this)));
223 224
224 // TODO(joedow): Use |peer_pid| to determine the originating session 225 // TODO(joedow): Use |peer_pid| to determine the originating session
225 // using ProcessIdToSessionId() and verify it is the one we created. 226 // using ProcessIdToSessionId() and verify it is the one we created.
226 // Tracked via crbug.com/591746 227 // Tracked via crbug.com/591746
227 228
228 int new_connection_id = ++last_connection_id_; 229 int new_connection_id = ++last_connection_id_;
229 scoped_ptr<RemoteSecurityKeyIpcServer> ipc_server( 230 std::unique_ptr<RemoteSecurityKeyIpcServer> ipc_server(
230 RemoteSecurityKeyIpcServer::Create( 231 RemoteSecurityKeyIpcServer::Create(
231 new_connection_id, disconnect_timeout_, send_message_callback_, 232 new_connection_id, disconnect_timeout_, send_message_callback_,
232 base::Bind(&GnubbyAuthHandlerWin::CloseSecurityKeyRequestIpcChannel, 233 base::Bind(&GnubbyAuthHandlerWin::CloseSecurityKeyRequestIpcChannel,
233 base::Unretained(this), new_connection_id))); 234 base::Unretained(this), new_connection_id)));
234 235
235 std::string unique_channel_name = GenerateUniqueChannelName(); 236 std::string unique_channel_name = GenerateUniqueChannelName();
236 if (ipc_server->CreateChannel( 237 if (ipc_server->CreateChannel(
237 unique_channel_name, 238 unique_channel_name,
238 base::TimeDelta::FromSeconds(kGnubbyRequestTimeoutSeconds))) { 239 base::TimeDelta::FromSeconds(kGnubbyRequestTimeoutSeconds))) {
239 active_channels_[new_connection_id] = std::move(ipc_server); 240 active_channels_[new_connection_id] = std::move(ipc_server);
240 ipc_server_channel_->Send( 241 ipc_server_channel_->Send(
241 new ChromotingNetworkToRemoteSecurityKeyMsg_ConnectionDetails( 242 new ChromotingNetworkToRemoteSecurityKeyMsg_ConnectionDetails(
242 unique_channel_name)); 243 unique_channel_name));
243 } 244 }
244 } 245 }
245 246
246 void GnubbyAuthHandlerWin::OnChannelError() { 247 void GnubbyAuthHandlerWin::OnChannelError() {
247 DCHECK(thread_checker_.CalledOnValidThread()); 248 DCHECK(thread_checker_.CalledOnValidThread());
248 249
249 // Could be an error, most likely the client disconnected though. Either way 250 // Could be an error, most likely the client disconnected though. Either way
250 // we should restart the server to prepare for the next connection. 251 // we should restart the server to prepare for the next connection.
251 RecreateIpcServerChannel(); 252 RecreateIpcServerChannel();
252 } 253 }
253 254
254 } // namespace remoting 255 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/security_key/gnubby_auth_handler_mac.cc ('k') | remoting/host/security_key/gnubby_auth_handler_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698