Chromium Code Reviews| Index: remoting/host/desktop_session_agent_win.cc |
| diff --git a/remoting/host/desktop_session_agent_win.cc b/remoting/host/desktop_session_agent_win.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..540b8be2e6de2dfe4a4640da91df6ccf0a8c53f7 |
| --- /dev/null |
| +++ b/remoting/host/desktop_session_agent_win.cc |
| @@ -0,0 +1,91 @@ |
| +// Copyright (c) 2012 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/desktop_session_agent.h" |
| + |
| +#include "base/logging.h" |
| +#include "base/single_thread_task_runner.h" |
| +#include "base/stringprintf.h" |
| +#include "base/utf_string_conversions.h" |
| +#include "base/win/scoped_handle.h" |
| +#include "base/win/win_util.h" |
| +#include "ipc/ipc_channel.h" |
| +#include "ipc/ipc_channel_proxy.h" |
| +#include "remoting/host/win/launch_process_with_token.h" |
| + |
| +using base::win::ScopedHandle; |
| + |
| +const char kSelfSecurityDescriptorFormat[] = "O:%1$sG:%1$sD:(A;;GA;;;%1$s)"; |
|
Sergey Ulanov
2012/10/24 20:12:01
static or anonymous namespace. Or maybe move it in
alexeypa (please no reviews)
2012/10/24 21:41:51
It is a constant. It is limited to the file scope
|
| + |
| +namespace remoting { |
| + |
| +// Provides screen/audio capturing and input injection services for |
| +// the network process. |
| +class DesktopSessionAgentWin : public DesktopSessionAgent { |
| + public: |
| + DesktopSessionAgentWin( |
| + scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
| + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner); |
| + virtual ~DesktopSessionAgentWin(); |
| + |
| + protected: |
| + virtual bool DoCreateNetworkChannel( |
| + IPC::PlatformFileForTransit* client_out, |
| + scoped_ptr<IPC::ChannelProxy>* server_out) OVERRIDE; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(DesktopSessionAgentWin); |
| +}; |
| + |
| +DesktopSessionAgentWin::DesktopSessionAgentWin( |
| + scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
| + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) |
| + : DesktopSessionAgent(caller_task_runner, io_task_runner) { |
| +} |
| + |
| +DesktopSessionAgentWin::~DesktopSessionAgentWin() { |
| +} |
| + |
| +bool DesktopSessionAgentWin::DoCreateNetworkChannel( |
| + IPC::PlatformFileForTransit* client_out, |
| + scoped_ptr<IPC::ChannelProxy>* server_out) { |
| + // Generate a unique name for the channel. |
| + std::string channel_name = IPC::Channel::GenerateUniqueRandomChannelID(); |
| + |
| + // presubmit: allow wstring |
|
Sergey Ulanov
2012/10/24 20:12:01
remove this comment?
alexeypa (please no reviews)
2012/10/24 21:41:51
It is necessary to suppress the presubmit warning.
|
| + std::wstring user_sid; |
| + if (!base::win::GetUserSidString(&user_sid)) { |
| + LOG(ERROR) << "Failed to query the current user SID."; |
| + return false; |
| + } |
| + |
| + // Create a security descriptor that will be used to protect the named pipe in |
| + // between CreateNamedPipe() and CreateFile() calls before it will be passed |
| + // to the network process. It gives full access to the account that |
| + // the calling code is running under and denies access by anyone else. |
| + std::string security_descriptor = base::StringPrintf( |
| + kSelfSecurityDescriptorFormat, WideToUTF8(user_sid).c_str()); |
| + |
| + // Create a connected IPC channel. |
| + ScopedHandle client; |
| + scoped_ptr<IPC::ChannelProxy> server; |
| + if (!CreateConnectedIpcChannel(channel_name, security_descriptor, |
| + io_task_runner(), this, &client, &server)) { |
| + return false; |
| + } |
| + |
| + *client_out = client.Take(); |
| + *server_out = server.Pass(); |
| + return true; |
| +} |
| + |
| +// static |
| +scoped_ptr<DesktopSessionAgent> DesktopSessionAgent::Create( |
| + scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
| + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) { |
| + return scoped_ptr<DesktopSessionAgent>(new DesktopSessionAgentWin( |
| + caller_task_runner, io_task_runner)); |
| +} |
| + |
| +} // namespace remoting |