We can use C++11 constructs for cleaning up the following cases: 1. Use of raw pointers when there's an ownership passing semantics in some places. 2. StartValidation() gathers ownership on the object (while RunValidation() not).
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/18f3a62dabe898a03ad69569feb0ce37c53fc001 commit 18f3a62dabe898a03ad69569feb0ce37c53fc001 Author: emaxx <emaxx@chromium.org> Date: Wed Apr 19 13:37:09 2017 Make CloudPolicyValidator memory management clearer 1. Create() becomes returning a unique_ptr instead of a raw pointer. 2. StartValidation() becomes accepting the validator as a unique_ptr argument instead of taking ownership over "this". This should prevent from making bugs leading to memory leaks or double freeing, which were hard to notice with the old interface. 3. Minor cleanup related to C++11 features. No change of behavior is expected to be introduced. BUG= 710679 TEST=existing tests Review-Url: https://codereview.chromium.org/2817643002 Cr-Commit-Position: refs/heads/master@{#465579} [modify] https://crrev.com/18f3a62dabe898a03ad69569feb0ce37c53fc001/chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.cc [modify] https://crrev.com/18f3a62dabe898a03ad69569feb0ce37c53fc001/chrome/browser/chromeos/policy/device_local_account_policy_store.cc [modify] https://crrev.com/18f3a62dabe898a03ad69569feb0ce37c53fc001/chrome/browser/chromeos/policy/enrollment_handler_chromeos.cc [modify] https://crrev.com/18f3a62dabe898a03ad69569feb0ce37c53fc001/chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos.cc [modify] https://crrev.com/18f3a62dabe898a03ad69569feb0ce37c53fc001/chrome/browser/chromeos/settings/session_manager_operation.cc [modify] https://crrev.com/18f3a62dabe898a03ad69569feb0ce37c53fc001/components/policy/core/common/cloud/cloud_policy_validator.cc [modify] https://crrev.com/18f3a62dabe898a03ad69569feb0ce37c53fc001/components/policy/core/common/cloud/cloud_policy_validator.h [modify] https://crrev.com/18f3a62dabe898a03ad69569feb0ce37c53fc001/components/policy/core/common/cloud/cloud_policy_validator_unittest.cc [modify] https://crrev.com/18f3a62dabe898a03ad69569feb0ce37c53fc001/components/policy/core/common/cloud/user_cloud_policy_store.cc [modify] https://crrev.com/18f3a62dabe898a03ad69569feb0ce37c53fc001/components/policy/core/common/cloud/user_cloud_policy_store_base.cc
as per #2
Comment 1 by emaxx@chromium.org
, Apr 18 2017