diff options
author | sergeyu <sergeyu@chromium.org> | 2015-12-23 11:01:22 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-23 19:02:20 +0000 |
commit | 1417e013d741b99685fee8f3d3c166f597655eda (patch) | |
tree | 6a2ab7f1547bd187cb4eb8e037f8ed69ca36eed1 /remoting/host/win | |
parent | 090488ff3ff55782b02a1b2965bdbe2acd0b8f53 (diff) | |
download | chromium_src-1417e013d741b99685fee8f3d3c166f597655eda.zip chromium_src-1417e013d741b99685fee8f3d3c166f597655eda.tar.gz chromium_src-1417e013d741b99685fee8f3d3c166f597655eda.tar.bz2 |
Use std::move() instead of .Pass() in remoting/host
Now there is a presubmit check that doesn't allow Pass() anymore.
See https://www.chromium.org/rvalue-references for information
about std::move in chromium.
Review URL: https://codereview.chromium.org/1549493004
Cr-Commit-Position: refs/heads/master@{#366759}
Diffstat (limited to 'remoting/host/win')
-rw-r--r-- | remoting/host/win/launch_process_with_token.cc | 7 | ||||
-rw-r--r-- | remoting/host/win/security_descriptor.cc | 4 | ||||
-rw-r--r-- | remoting/host/win/session_desktop_environment.cc | 24 | ||||
-rw-r--r-- | remoting/host/win/session_input_injector.cc | 12 | ||||
-rw-r--r-- | remoting/host/win/unprivileged_process_delegate.cc | 39 | ||||
-rw-r--r-- | remoting/host/win/worker_process_launcher.cc | 9 | ||||
-rw-r--r-- | remoting/host/win/worker_process_launcher_unittest.cc | 22 | ||||
-rw-r--r-- | remoting/host/win/wts_session_process_delegate.cc | 51 |
8 files changed, 70 insertions, 98 deletions
diff --git a/remoting/host/win/launch_process_with_token.cc b/remoting/host/win/launch_process_with_token.cc index 27689ad..a274b33 100644 --- a/remoting/host/win/launch_process_with_token.cc +++ b/remoting/host/win/launch_process_with_token.cc @@ -9,6 +9,7 @@ #include <winternl.h> #include <limits> +#include <utility> #include "base/logging.h" #include "base/memory/scoped_ptr.h" @@ -117,7 +118,7 @@ bool ConnectToExecutionServer(uint32_t session_id, return false; } - *pipe_out = pipe.Pass(); + *pipe_out = std::move(pipe); return true; } @@ -172,7 +173,7 @@ bool CreatePrivilegedToken(ScopedHandle* token_out) { return false; } - *token_out = privileged_token.Pass(); + *token_out = std::move(privileged_token); return true; } @@ -444,7 +445,7 @@ bool CreateSessionToken(uint32_t session_id, ScopedHandle* token_out) { // Revert to the default token. CHECK(RevertToSelf()); - *token_out = session_token.Pass(); + *token_out = std::move(session_token); return true; } diff --git a/remoting/host/win/security_descriptor.cc b/remoting/host/win/security_descriptor.cc index fffefe5..c316ff7 100644 --- a/remoting/host/win/security_descriptor.cc +++ b/remoting/host/win/security_descriptor.cc @@ -24,7 +24,7 @@ ScopedSd ConvertSddlToSd(const std::string& sddl) { memcpy(sd.get(), raw_sd, length); LocalFree(raw_sd); - return sd.Pass(); + return sd; } // Converts a SID into a text string. @@ -59,7 +59,7 @@ ScopedSid GetLogonSid(HANDLE token) { if (!CopySid(length, logon_sid.get(), groups->Groups[i].Sid)) return ScopedSid(); - return logon_sid.Pass(); + return logon_sid; } } diff --git a/remoting/host/win/session_desktop_environment.cc b/remoting/host/win/session_desktop_environment.cc index b903fa0..045562f 100644 --- a/remoting/host/win/session_desktop_environment.cc +++ b/remoting/host/win/session_desktop_environment.cc @@ -4,6 +4,8 @@ #include "remoting/host/win/session_desktop_environment.h" +#include <utility> + #include "base/logging.h" #include "base/single_thread_task_runner.h" #include "remoting/host/audio_capturer.h" @@ -14,19 +16,15 @@ namespace remoting { -SessionDesktopEnvironment::~SessionDesktopEnvironment() { -} +SessionDesktopEnvironment::~SessionDesktopEnvironment() {} scoped_ptr<InputInjector> SessionDesktopEnvironment::CreateInputInjector() { DCHECK(caller_task_runner()->BelongsToCurrentThread()); - scoped_ptr<InputInjector> input_injector = InputInjector::Create( - input_task_runner(), ui_task_runner()); - input_injector.reset(new SessionInputInjectorWin(input_task_runner(), - input_injector.Pass(), - ui_task_runner(), - inject_sas_)); - return input_injector.Pass(); + return make_scoped_ptr(new SessionInputInjectorWin( + input_task_runner(), + InputInjector::Create(input_task_runner(), ui_task_runner()), + ui_task_runner(), inject_sas_)); } SessionDesktopEnvironment::SessionDesktopEnvironment( @@ -62,17 +60,15 @@ scoped_ptr<DesktopEnvironment> SessionDesktopEnvironmentFactory::Create( DCHECK(caller_task_runner()->BelongsToCurrentThread()); scoped_ptr<SessionDesktopEnvironment> desktop_environment( - new SessionDesktopEnvironment(caller_task_runner(), - input_task_runner(), - ui_task_runner(), - inject_sas_, + new SessionDesktopEnvironment(caller_task_runner(), input_task_runner(), + ui_task_runner(), inject_sas_, supports_touch_events())); if (!desktop_environment->InitializeSecurity(client_session_control, curtain_enabled())) { return nullptr; } - return desktop_environment.Pass(); + return std::move(desktop_environment); } } // namespace remoting diff --git a/remoting/host/win/session_input_injector.cc b/remoting/host/win/session_input_injector.cc index 22c88b9..ce0ec31 100644 --- a/remoting/host/win/session_input_injector.cc +++ b/remoting/host/win/session_input_injector.cc @@ -8,6 +8,7 @@ #include <set> #include <string> +#include <utility> #include "base/bind.h" #include "base/callback.h" @@ -100,10 +101,9 @@ SessionInputInjectorWin::Core::Core( scoped_refptr<base::SingleThreadTaskRunner> inject_sas_task_runner, const base::Closure& inject_sas) : input_task_runner_(input_task_runner), - nested_executor_(nested_executor.Pass()), + nested_executor_(std::move(nested_executor)), inject_sas_task_runner_(inject_sas_task_runner), - inject_sas_(inject_sas) { -} + inject_sas_(inject_sas) {} void SessionInputInjectorWin::Core::Start( scoped_ptr<protocol::ClipboardStub> client_clipboard) { @@ -114,7 +114,7 @@ void SessionInputInjectorWin::Core::Start( return; } - nested_executor_->Start(client_clipboard.Pass()); + nested_executor_->Start(std::move(client_clipboard)); } void SessionInputInjectorWin::Core::InjectClipboardEvent( @@ -219,7 +219,7 @@ SessionInputInjectorWin::SessionInputInjectorWin( scoped_ptr<InputInjector> nested_executor, scoped_refptr<base::SingleThreadTaskRunner> inject_sas_task_runner, const base::Closure& inject_sas) { - core_ = new Core(input_task_runner, nested_executor.Pass(), + core_ = new Core(input_task_runner, std::move(nested_executor), inject_sas_task_runner, inject_sas); } @@ -228,7 +228,7 @@ SessionInputInjectorWin::~SessionInputInjectorWin() { void SessionInputInjectorWin::Start( scoped_ptr<protocol::ClipboardStub> client_clipboard) { - core_->Start(client_clipboard.Pass()); + core_->Start(std::move(client_clipboard)); } void SessionInputInjectorWin::InjectClipboardEvent( diff --git a/remoting/host/win/unprivileged_process_delegate.cc b/remoting/host/win/unprivileged_process_delegate.cc index 3290d9d..b7fb879 100644 --- a/remoting/host/win/unprivileged_process_delegate.cc +++ b/remoting/host/win/unprivileged_process_delegate.cc @@ -10,6 +10,8 @@ #include <sddl.h> +#include <utility> + #include "base/command_line.h" #include "base/files/file.h" #include "base/logging.h" @@ -237,9 +239,8 @@ UnprivilegedProcessDelegate::UnprivilegedProcessDelegate( scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, scoped_ptr<base::CommandLine> target_command) : io_task_runner_(io_task_runner), - target_command_(target_command.Pass()), - event_handler_(nullptr) { -} + target_command_(std::move(target_command)), + event_handler_(nullptr) {} UnprivilegedProcessDelegate::~UnprivilegedProcessDelegate() { DCHECK(CalledOnValidThread()); @@ -316,7 +317,7 @@ void UnprivilegedProcessDelegate::LaunchProcess( // Create our own window station and desktop accessible by |logon_sid|. WindowStationAndDesktop handles; - if (!CreateWindowStationAndDesktop(logon_sid.Pass(), &handles)) { + if (!CreateWindowStationAndDesktop(std::move(logon_sid), &handles)) { PLOG(ERROR) << "Failed to create a window station and desktop"; ReportFatalError(); return; @@ -325,23 +326,17 @@ void UnprivilegedProcessDelegate::LaunchProcess( // Try to launch the worker process. The launched process inherits // the window station, desktop and pipe handles, created above. ScopedHandle worker_thread; - if (!LaunchProcessWithToken(command_line.GetProgram(), - command_line.GetCommandLineString(), - token.Get(), - &process_attributes, - &thread_attributes, - true, - 0, - nullptr, - &worker_process, - &worker_thread)) { + if (!LaunchProcessWithToken( + command_line.GetProgram(), command_line.GetCommandLineString(), + token.Get(), &process_attributes, &thread_attributes, true, 0, + nullptr, &worker_process, &worker_thread)) { ReportFatalError(); return; } } - channel_ = server.Pass(); - ReportProcessLaunched(worker_process.Pass()); + channel_ = std::move(server); + ReportProcessLaunched(std::move(worker_process)); } void UnprivilegedProcessDelegate::Send(IPC::Message* message) { @@ -415,19 +410,15 @@ void UnprivilegedProcessDelegate::ReportProcessLaunched( DCHECK(CalledOnValidThread()); DCHECK(!worker_process_.IsValid()); - worker_process_ = worker_process.Pass(); + worker_process_ = std::move(worker_process); // Report a handle that can be used to wait for the worker process completion, // query information about the process and duplicate handles. DWORD desired_access = SYNCHRONIZE | PROCESS_DUP_HANDLE | PROCESS_QUERY_INFORMATION; HANDLE temp_handle; - if (!DuplicateHandle(GetCurrentProcess(), - worker_process_.Get(), - GetCurrentProcess(), - &temp_handle, - desired_access, - FALSE, + if (!DuplicateHandle(GetCurrentProcess(), worker_process_.Get(), + GetCurrentProcess(), &temp_handle, desired_access, FALSE, 0)) { PLOG(ERROR) << "Failed to duplicate a handle"; ReportFatalError(); @@ -435,7 +426,7 @@ void UnprivilegedProcessDelegate::ReportProcessLaunched( } ScopedHandle limited_handle(temp_handle); - event_handler_->OnProcessLaunched(limited_handle.Pass()); + event_handler_->OnProcessLaunched(std::move(limited_handle)); } } // namespace remoting diff --git a/remoting/host/win/worker_process_launcher.cc b/remoting/host/win/worker_process_launcher.cc index ebb69dd..941fefb 100644 --- a/remoting/host/win/worker_process_launcher.cc +++ b/remoting/host/win/worker_process_launcher.cc @@ -4,6 +4,8 @@ #include "remoting/host/win/worker_process_launcher.h" +#include <utility> + #include "base/location.h" #include "base/logging.h" #include "base/single_thread_task_runner.h" @@ -48,14 +50,13 @@ const int kLaunchResultTimeoutSeconds = 5; namespace remoting { -WorkerProcessLauncher::Delegate::~Delegate() { -} +WorkerProcessLauncher::Delegate::~Delegate() {} WorkerProcessLauncher::WorkerProcessLauncher( scoped_ptr<WorkerProcessLauncher::Delegate> launcher_delegate, WorkerProcessIpcDelegate* ipc_handler) : ipc_handler_(ipc_handler), - launcher_delegate_(launcher_delegate.Pass()), + launcher_delegate_(std::move(launcher_delegate)), exit_code_(CONTROL_C_EXIT), ipc_enabled_(false), kill_process_timeout_( @@ -119,7 +120,7 @@ void WorkerProcessLauncher::OnProcessLaunched( } ipc_enabled_ = true; - worker_process_ = worker_process.Pass(); + worker_process_ = std::move(worker_process); } void WorkerProcessLauncher::OnFatalError() { diff --git a/remoting/host/win/worker_process_launcher_unittest.cc b/remoting/host/win/worker_process_launcher_unittest.cc index 47496be..840c2d5 100644 --- a/remoting/host/win/worker_process_launcher_unittest.cc +++ b/remoting/host/win/worker_process_launcher_unittest.cc @@ -2,8 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "remoting/host/win/worker_process_launcher.h" + #include <stdint.h> +#include <utility> + #include "base/bind.h" #include "base/macros.h" #include "base/memory/ref_counted.h" @@ -19,7 +23,6 @@ #include "remoting/host/host_exit_codes.h" #include "remoting/host/ipc_util.h" #include "remoting/host/win/launch_process_with_token.h" -#include "remoting/host/win/worker_process_launcher.h" #include "remoting/host/worker_process_ipc_delegate.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock_mutant.h" @@ -316,9 +319,8 @@ void WorkerProcessLauncherTest::CrashWorker() { } void WorkerProcessLauncherTest::StartWorker() { - launcher_.reset(new WorkerProcessLauncher( - launcher_delegate_.Pass(), - &server_listener_)); + launcher_.reset(new WorkerProcessLauncher(std::move(launcher_delegate_), + &server_listener_)); launcher_->SetKillProcessTimeoutForTest(base::TimeDelta::FromMilliseconds(0)); } @@ -371,16 +373,10 @@ void WorkerProcessLauncherTest::DoLaunchProcess() { task_runner_); HANDLE temp_handle; - ASSERT_TRUE(DuplicateHandle(GetCurrentProcess(), - worker_process_.Get(), - GetCurrentProcess(), - &temp_handle, - 0, - FALSE, + ASSERT_TRUE(DuplicateHandle(GetCurrentProcess(), worker_process_.Get(), + GetCurrentProcess(), &temp_handle, 0, FALSE, DUPLICATE_SAME_ACCESS)); - ScopedHandle copy(temp_handle); - - event_handler_->OnProcessLaunched(copy.Pass()); + event_handler_->OnProcessLaunched(ScopedHandle(temp_handle)); } TEST_F(WorkerProcessLauncherTest, Start) { diff --git a/remoting/host/win/wts_session_process_delegate.cc b/remoting/host/win/wts_session_process_delegate.cc index 4a2a30d..c2ba5d6 100644 --- a/remoting/host/win/wts_session_process_delegate.cc +++ b/remoting/host/win/wts_session_process_delegate.cc @@ -7,6 +7,8 @@ #include "remoting/host/win/wts_session_process_delegate.h" +#include <utility> + #include "base/bind.h" #include "base/command_line.h" #include "base/files/file_path.h" @@ -89,10 +91,10 @@ class WtsSessionProcessDelegate::Core // Creates and initializes the job object that will sandbox the launched child // processes. - void InitializeJob(scoped_ptr<base::win::ScopedHandle> job); + void InitializeJob(ScopedHandle job); // Notified that the job object initialization is complete. - void InitializeJobCompleted(scoped_ptr<base::win::ScopedHandle> job); + void InitializeJobCompleted(ScopedHandle job); // Called when the number of processes running in the job reaches zero. void OnActiveProcessZero(); @@ -155,8 +157,7 @@ WtsSessionProcessDelegate::Core::Core( get_named_pipe_client_pid_(nullptr), launch_elevated_(launch_elevated), launch_pending_(false), - target_command_(target_command.Pass()) { -} + target_command_(std::move(target_command)) {} bool WtsSessionProcessDelegate::Core::Initialize(uint32_t session_id) { DCHECK(caller_task_runner_->BelongsToCurrentThread()); @@ -198,19 +199,13 @@ bool WtsSessionProcessDelegate::Core::Initialize(uint32_t session_id) { return false; } - // ScopedHandle is not compatible with base::Passed, so we wrap it to - // a scoped pointer. - scoped_ptr<ScopedHandle> job_wrapper(new ScopedHandle()); - *job_wrapper = job.Pass(); - // To receive job object notifications the job object is registered with // the completion port represented by |io_task_runner|. The registration has // to be done on the I/O thread because // MessageLoopForIO::RegisterJobObject() can only be called via // MessageLoopForIO::current(). io_task_runner_->PostTask( - FROM_HERE, - base::Bind(&Core::InitializeJob, this, base::Passed(&job_wrapper))); + FROM_HERE, base::Bind(&Core::InitializeJob, this, base::Passed(&job))); } // Create a session token for the launched process. @@ -331,7 +326,7 @@ void WtsSessionProcessDelegate::Core::OnChannelConnected(int32_t peer_pid) { return; } - ReportProcessLaunched(worker_process.Pass()); + ReportProcessLaunched(std::move(worker_process)); } if (event_handler_) @@ -422,14 +417,14 @@ void WtsSessionProcessDelegate::Core::DoLaunchProcess() { return; } - channel_ = channel.Pass(); - pipe_ = pipe.Pass(); + channel_ = std::move(channel); + pipe_ = std::move(pipe); // Report success if the worker process is lauched directly. Otherwise, PID of // the client connected to the pipe will be used later. See // OnChannelConnected(). if (!launch_elevated_) - ReportProcessLaunched(worker_process.Pass()); + ReportProcessLaunched(std::move(worker_process)); } void WtsSessionProcessDelegate::Core::DrainJobNotifications() { @@ -455,12 +450,11 @@ void WtsSessionProcessDelegate::Core::DrainJobNotificationsCompleted() { } } -void WtsSessionProcessDelegate::Core::InitializeJob( - scoped_ptr<base::win::ScopedHandle> job) { +void WtsSessionProcessDelegate::Core::InitializeJob(ScopedHandle job) { DCHECK(io_task_runner_->BelongsToCurrentThread()); // Register to receive job notifications via the I/O thread's completion port. - if (!base::MessageLoopForIO::current()->RegisterJobObject(job->Get(), this)) { + if (!base::MessageLoopForIO::current()->RegisterJobObject(job.Get(), this)) { PLOG(ERROR) << "Failed to associate the job object with a completion port"; return; } @@ -470,12 +464,11 @@ void WtsSessionProcessDelegate::Core::InitializeJob( &Core::InitializeJobCompleted, this, base::Passed(&job))); } -void WtsSessionProcessDelegate::Core::InitializeJobCompleted( - scoped_ptr<ScopedHandle> job) { +void WtsSessionProcessDelegate::Core::InitializeJobCompleted(ScopedHandle job) { DCHECK(caller_task_runner_->BelongsToCurrentThread()); DCHECK(!job_.IsValid()); - job_ = job->Pass(); + job_ = std::move(job); if (launch_pending_) DoLaunchProcess(); @@ -507,19 +500,15 @@ void WtsSessionProcessDelegate::Core::ReportProcessLaunched( DCHECK(caller_task_runner_->BelongsToCurrentThread()); DCHECK(!worker_process_.IsValid()); - worker_process_ = worker_process.Pass(); + worker_process_ = std::move(worker_process); // Report a handle that can be used to wait for the worker process completion, // query information about the process and duplicate handles. DWORD desired_access = SYNCHRONIZE | PROCESS_DUP_HANDLE | PROCESS_QUERY_INFORMATION; HANDLE temp_handle; - if (!DuplicateHandle(GetCurrentProcess(), - worker_process_.Get(), - GetCurrentProcess(), - &temp_handle, - desired_access, - FALSE, + if (!DuplicateHandle(GetCurrentProcess(), worker_process_.Get(), + GetCurrentProcess(), &temp_handle, desired_access, FALSE, 0)) { PLOG(ERROR) << "Failed to duplicate a handle"; ReportFatalError(); @@ -527,7 +516,7 @@ void WtsSessionProcessDelegate::Core::ReportProcessLaunched( } ScopedHandle limited_handle(temp_handle); - event_handler_->OnProcessLaunched(limited_handle.Pass()); + event_handler_->OnProcessLaunched(std::move(limited_handle)); } WtsSessionProcessDelegate::WtsSessionProcessDelegate( @@ -535,9 +524,7 @@ WtsSessionProcessDelegate::WtsSessionProcessDelegate( scoped_ptr<base::CommandLine> target_command, bool launch_elevated, const std::string& channel_security) { - core_ = new Core(io_task_runner, - target_command.Pass(), - launch_elevated, + core_ = new Core(io_task_runner, std::move(target_command), launch_elevated, channel_security); } |