Commit 7136c986 authored by Xi Han's avatar Xi Han Committed by Commit Bot

Create ProfileKey early

We remove the parameter of PrefService* from ProfileKey's constructor. This is
because some KeyedService are created using ProfileKey* before the PrefService
is created in the Profile. For example, SuperviseUserSettingService and
InProcessPrefServiceFactoryFactory.

Bug: 937469
Change-Id: I45c4b849e229a34ec6f465e428a7a514e9f77118
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1568793Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarHenrique Nakashima <hnakashima@chromium.org>
Reviewed-by: default avatarMohamed Heikal <mheikal@chromium.org>
Commit-Queue: Xi Han <hanxi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652220}
parent d3659a52
......@@ -139,7 +139,10 @@ void NotifyOTRProfileDestroyedOnIOThread(void* original_profile,
} // namespace
OffTheRecordProfileImpl::OffTheRecordProfileImpl(Profile* real_profile)
: profile_(real_profile), start_time_(base::Time::Now()) {
: profile_(real_profile),
start_time_(base::Time::Now()),
key_(std::make_unique<ProfileKey>(profile_->GetPath(),
profile_->GetProfileKey())) {
// Must happen before we ask for prefs as prefs needs the connection to the
// service manager, which is set up in Initialize.
BrowserContext::Initialize(this, profile_->GetPath());
......@@ -149,8 +152,7 @@ OffTheRecordProfileImpl::OffTheRecordProfileImpl(Profile* real_profile)
InProcessPrefServiceFactoryFactory::GetInstanceForContext(this)
->CreateDelegate());
key_ = std::make_unique<ProfileKey>(profile_->GetPath(), prefs_.get(),
profile_->GetProfileKey());
key_->SetPrefs(prefs_.get());
SimpleKeyMap::GetInstance()->Associate(this, key_.get());
// Register on BrowserContext.
......
......@@ -468,6 +468,7 @@ ProfileImpl::ProfileImpl(
io_data_(this),
last_session_exit_type_(EXIT_NORMAL),
start_time_(base::Time::Now()),
key_(std::make_unique<ProfileKey>(GetPath())),
delegate_(delegate),
reporting_permissions_checker_factory_(this),
shared_cors_origin_access_list_(
......@@ -583,7 +584,7 @@ ProfileImpl::ProfileImpl(
user_prefs::UserPrefs::Set(this, prefs_.get());
}
key_ = std::make_unique<ProfileKey>(GetPath(), prefs_.get());
key_->SetPrefs(prefs_.get());
SimpleKeyMap::GetInstance()->Associate(this, key_.get());
#if defined(OS_CHROMEOS)
......
......@@ -4,13 +4,23 @@
#include "chrome/browser/profiles/profile_key.h"
ProfileKey::ProfileKey(const base::FilePath& path,
PrefService* prefs,
ProfileKey* original_key)
: SimpleFactoryKey(path), prefs_(prefs), original_key_(original_key) {}
#include "base/logging.h"
ProfileKey::ProfileKey(const base::FilePath& path, ProfileKey* original_key)
: SimpleFactoryKey(path), prefs_(nullptr), original_key_(original_key) {}
ProfileKey::~ProfileKey() = default;
PrefService* ProfileKey::GetPrefs() {
DCHECK(prefs_);
return prefs_;
}
void ProfileKey::SetPrefs(PrefService* prefs) {
DCHECK(!prefs_);
prefs_ = prefs;
}
bool ProfileKey::IsOffTheRecord() const {
return original_key_ != nullptr;
}
......
......@@ -16,13 +16,13 @@ class PrefService;
class ProfileKey : public SimpleFactoryKey {
public:
ProfileKey(const base::FilePath& path,
PrefService* prefs,
ProfileKey* original_key = nullptr);
~ProfileKey() override;
// Profile-specific APIs needed in reduced mode:
ProfileKey* GetOriginalKey() { return original_key_; }
PrefService* GetPrefs() { return prefs_; }
PrefService* GetPrefs();
void SetPrefs(PrefService* prefs);
static ProfileKey* FromSimpleFactoryKey(SimpleFactoryKey* key);
......
......@@ -388,6 +388,13 @@ void TestingProfile::Init() {
profile_manager->GetSystemProfilePath());
}
if (IsOffTheRecord()) {
key_ = std::make_unique<ProfileKey>(original_profile_->GetPath(),
original_profile_->GetProfileKey());
} else {
key_ = std::make_unique<ProfileKey>(profile_path_);
}
BrowserContext::Initialize(this, profile_path_);
#if defined(OS_ANDROID)
......@@ -425,13 +432,7 @@ void TestingProfile::Init() {
else
CreateTestingPrefService();
if (IsOffTheRecord()) {
key_ =
std::make_unique<ProfileKey>(original_profile_->GetPath(), prefs_.get(),
original_profile_->GetProfileKey());
} else {
key_ = std::make_unique<ProfileKey>(profile_path_, prefs_.get());
}
key_->SetPrefs(prefs_.get());
SimpleKeyMap::GetInstance()->Associate(this, key_.get());
if (!base::PathExists(profile_path_))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment