ProfileManager::RegisterTestingProfile() now takes a std::unique_ptr
This commit clarifies previously established ownership semantics of
Profiles within ProfileManager through the use of unique pointers.
Changes were made to the parameters of
ProfileManager::RegisterTestingProfile() and
ProfileManager::RegisterProfile() to take a std::unique_ptr instead of a
raw pointer. A further change was made to the return type of
ProfileManager::CreateProfileAsyncHelper() from a raw pointer to a
unique pointer. All callers to the aforementioned functions (including
unit tests) that made calls to the two functions are updated to pass in
unique pointers.
Bug: 968187
Change-Id: I05cab32d75fa8aad30359e8cc5b4a85efaaf9d12
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1639183
Reviewed-by: Lei Zhang <[email protected]>
Commit-Queue: Daniel Hosseinian <[email protected]>
Cr-Commit-Position: refs/heads/master@{#667232}
diff --git a/chrome/browser/profiles/profile_manager_unittest.cc b/chrome/browser/profiles/profile_manager_unittest.cc
index 36ff895..8d8578f9 100644
--- a/chrome/browser/profiles/profile_manager_unittest.cc
+++ b/chrome/browser/profiles/profile_manager_unittest.cc
@@ -5,6 +5,7 @@
#include <stddef.h>
#include <string>
+#include <utility>
#include "base/bind.h"
#include "base/bind_helpers.h"
@@ -98,15 +99,16 @@
return new TestingProfile(file_path, nullptr);
}
- Profile* CreateProfileAsyncHelper(const base::FilePath& path,
- Delegate* delegate) override {
+ std::unique_ptr<Profile> CreateProfileAsyncHelper(
+ const base::FilePath& path,
+ Delegate* delegate) override {
// ThreadTaskRunnerHandle::Get() is TestingProfile's "async" IOTaskRunner
// (ref. TestingProfile::GetIOTaskRunner()).
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(base::IgnoreResult(&base::CreateDirectory), path));
- return new TestingProfile(path, this);
+ return std::make_unique<TestingProfile>(path, this);
}
};
@@ -522,22 +524,24 @@
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
const base::FilePath supervised_path =
temp_dir_.GetPath().AppendASCII("Supervised");
- TestingProfile* supervised_profile =
- new TestingProfile(supervised_path, nullptr);
+ auto supervised_profile =
+ std::make_unique<TestingProfile>(supervised_path, nullptr);
supervised_profile->GetPrefs()->SetString(
prefs::kSupervisedUserId, supervised_users::kChildAccountSUID);
// RegisterTestingProfile adds the profile to the cache and takes ownership.
- profile_manager->RegisterTestingProfile(supervised_profile, true, false);
+ profile_manager->RegisterTestingProfile(std::move(supervised_profile), true,
+ false);
ASSERT_EQ(1u, storage.GetNumberOfProfiles());
EXPECT_TRUE(storage.GetAllProfilesAttributesSortedByName()[0]->IsOmitted());
#endif
const base::FilePath nonsupervised_path =
temp_dir_.GetPath().AppendASCII("Non-Supervised");
- TestingProfile* nonsupervised_profile =
- new TestingProfile(nonsupervised_path, nullptr);
- profile_manager->RegisterTestingProfile(nonsupervised_profile, true, false);
+ auto nonsupervised_profile =
+ std::make_unique<TestingProfile>(nonsupervised_path, nullptr);
+ profile_manager->RegisterTestingProfile(std::move(nonsupervised_profile),
+ true, false);
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
EXPECT_EQ(2u, storage.GetNumberOfProfiles());
@@ -1363,10 +1367,10 @@
TestingProfile::Builder builder;
builder.SetGuestSession();
builder.SetPath(ProfileManager::GetGuestProfilePath());
- TestingProfile* guest_profile = builder.Build().release();
+ std::unique_ptr<TestingProfile> guest_profile = builder.Build();
guest_profile->set_profile_name(guest_profile_name);
- // Registering the profile passes ownership to the ProfileManager.
- profile_manager->RegisterTestingProfile(guest_profile, false, false);
+ profile_manager->RegisterTestingProfile(std::move(guest_profile), false,
+ false);
// The Guest profile does not get added to the ProfileAttributesStorage.
EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size());