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

Side by Side Diff: sandbox/win/src/broker_services.cc

Issue 1752233002: Convert Pass()→std::move() on Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 9 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
« no previous file with comments | « printing/emf_win.cc ('k') | sandbox/win/src/job.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "sandbox/win/src/broker_services.h" 5 #include "sandbox/win/src/broker_services.h"
6 6
7 #include <AclAPI.h> 7 #include <AclAPI.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <utility>
9 10
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
13 #include "base/stl_util.h" 14 #include "base/stl_util.h"
14 #include "base/threading/platform_thread.h" 15 #include "base/threading/platform_thread.h"
15 #include "base/win/scoped_handle.h" 16 #include "base/win/scoped_handle.h"
16 #include "base/win/scoped_process_information.h" 17 #include "base/win/scoped_process_information.h"
17 #include "base/win/startup_information.h" 18 #include "base/win/startup_information.h"
18 #include "base/win/windows_version.h" 19 #include "base/win/windows_version.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 THREAD_CTRL_NONE, 53 THREAD_CTRL_NONE,
53 THREAD_CTRL_REMOVE_PEER, 54 THREAD_CTRL_REMOVE_PEER,
54 THREAD_CTRL_QUIT, 55 THREAD_CTRL_QUIT,
55 THREAD_CTRL_LAST, 56 THREAD_CTRL_LAST,
56 }; 57 };
57 58
58 // Helper structure that allows the Broker to associate a job notification 59 // Helper structure that allows the Broker to associate a job notification
59 // with a job object and with a policy. 60 // with a job object and with a policy.
60 struct JobTracker { 61 struct JobTracker {
61 JobTracker(base::win::ScopedHandle job, sandbox::PolicyBase* policy) 62 JobTracker(base::win::ScopedHandle job, sandbox::PolicyBase* policy)
62 : job(job.Pass()), policy(policy) { 63 : job(std::move(job)), policy(policy) {}
63 }
64 ~JobTracker() { 64 ~JobTracker() {
65 FreeResources(); 65 FreeResources();
66 } 66 }
67 67
68 // Releases the Job and notifies the associated Policy object to release its 68 // Releases the Job and notifies the associated Policy object to release its
69 // resources as well. 69 // resources as well.
70 void FreeResources(); 70 void FreeResources();
71 71
72 base::win::ScopedHandle job; 72 base::win::ScopedHandle job;
73 sandbox::PolicyBase* policy; 73 sandbox::PolicyBase* policy;
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 430
431 // Construct the thread pool here in case it is expensive. 431 // Construct the thread pool here in case it is expensive.
432 // The thread pool is shared by all the targets 432 // The thread pool is shared by all the targets
433 if (NULL == thread_pool_) 433 if (NULL == thread_pool_)
434 thread_pool_ = new Win2kThreadPool(); 434 thread_pool_ = new Win2kThreadPool();
435 435
436 // Create the TargetProcess object and spawn the target suspended. Note that 436 // Create the TargetProcess object and spawn the target suspended. Note that
437 // Brokerservices does not own the target object. It is owned by the Policy. 437 // Brokerservices does not own the target object. It is owned by the Policy.
438 base::win::ScopedProcessInformation process_info; 438 base::win::ScopedProcessInformation process_info;
439 TargetProcess* target = 439 TargetProcess* target =
440 new TargetProcess(initial_token.Pass(), lockdown_token.Pass(), 440 new TargetProcess(std::move(initial_token), std::move(lockdown_token),
441 lowbox_token.Pass(), job.Get(), thread_pool_); 441 std::move(lowbox_token), job.Get(), thread_pool_);
442 442
443 DWORD win_result = target->Create(exe_path, command_line, inherit_handles, 443 DWORD win_result = target->Create(exe_path, command_line, inherit_handles,
444 startup_info, &process_info); 444 startup_info, &process_info);
445 445
446 if (ERROR_SUCCESS != win_result) { 446 if (ERROR_SUCCESS != win_result) {
447 SpawnCleanup(target, win_result); 447 SpawnCleanup(target, win_result);
448 return SBOX_ERROR_CREATE_PROCESS; 448 return SBOX_ERROR_CREATE_PROCESS;
449 } 449 }
450 450
451 // Now the policy is the owner of the target. 451 // Now the policy is the owner of the target.
452 if (!policy_base->AddTarget(target)) { 452 if (!policy_base->AddTarget(target)) {
453 return SpawnCleanup(target, 0); 453 return SpawnCleanup(target, 0);
454 } 454 }
455 455
456 // We are going to keep a pointer to the policy because we'll call it when 456 // We are going to keep a pointer to the policy because we'll call it when
457 // the job object generates notifications using the completion port. 457 // the job object generates notifications using the completion port.
458 policy_base->AddRef(); 458 policy_base->AddRef();
459 if (job.IsValid()) { 459 if (job.IsValid()) {
460 scoped_ptr<JobTracker> tracker(new JobTracker(job.Pass(), policy_base)); 460 scoped_ptr<JobTracker> tracker(new JobTracker(std::move(job), policy_base));
461 461
462 // There is no obvious recovery after failure here. Previous version with 462 // There is no obvious recovery after failure here. Previous version with
463 // SpawnCleanup() caused deletion of TargetProcess twice. crbug.com/480639 463 // SpawnCleanup() caused deletion of TargetProcess twice. crbug.com/480639
464 CHECK(AssociateCompletionPort(tracker->job.Get(), job_port_.Get(), 464 CHECK(AssociateCompletionPort(tracker->job.Get(), job_port_.Get(),
465 tracker.get())); 465 tracker.get()));
466 466
467 // Save the tracker because in cleanup we might need to force closing 467 // Save the tracker because in cleanup we might need to force closing
468 // the Jobs. 468 // the Jobs.
469 tracker_list_.push_back(tracker.release()); 469 tracker_list_.push_back(tracker.release());
470 child_process_ids_.insert(process_info.process_id()); 470 child_process_ids_.insert(process_info.process_id());
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 return SBOX_ERROR_UNSUPPORTED; 556 return SBOX_ERROR_UNSUPPORTED;
557 557
558 base::string16 name = LookupAppContainer(sid); 558 base::string16 name = LookupAppContainer(sid);
559 if (name.empty()) 559 if (name.empty())
560 return SBOX_ERROR_INVALID_APP_CONTAINER; 560 return SBOX_ERROR_INVALID_APP_CONTAINER;
561 561
562 return DeleteAppContainer(sid); 562 return DeleteAppContainer(sid);
563 } 563 }
564 564
565 } // namespace sandbox 565 } // namespace sandbox
OLDNEW
« no previous file with comments | « printing/emf_win.cc ('k') | sandbox/win/src/job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698