Commit dab54417 authored by Henrique Nakashima's avatar Henrique Nakashima Committed by Commit Bot

Make |configuration_policy_provider_| a raw pointer in ProfileImpl.

ProfileImpl curently has a unique_ptr<ConfigurationPolicyProvider> and a
UserCloudPolicyManager* that is points to the same object - when not in
Chrome OS.

This CL changes the ownership to be the most specific object type:
- unique_ptr<ConfigurationPolicyProvider> in Chrome OS
- unique_ptr<policy::UserCloudPolicyManager> in other platforms

This change is a precursor of
https://chromium-review.googlesource.com/c/chromium/src/+/1579768
which will break the Chrome OS options further.

Bug: 937770
Change-Id: I9aea3b2f40afbbd0801cca61cd1a64a3e63cc57c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1606576
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659658}
parent 63a7dac8
......@@ -551,10 +551,7 @@ void ProfileImpl::TakePrefsFromStartupData() {
key_ = startup_data->TakeProfileKey();
prefs_ = startup_data->TakeProfilePrefService();
schema_registry_service_ = startup_data->TakeSchemaRegistryService();
configuration_policy_provider_ =
startup_data->TakeConfigurationPolicyProvider();
user_cloud_policy_manager_ = static_cast<policy::UserCloudPolicyManager*>(
configuration_policy_provider_.get());
user_cloud_policy_manager_ = startup_data->TakeUserCloudPolicyManager();
profile_policy_connector_ = startup_data->TakeProfilePolicyConnector();
pref_registry_ = startup_data->TakePrefRegistrySyncable();
......@@ -575,25 +572,23 @@ void ProfileImpl::LoadPrefsForNormalStartup(bool async_prefs) {
// policy data immediately.
bool force_immediate_policy_load = !async_prefs;
policy::UserCloudPolicyManager* user_cloud_policy_manager;
#if defined(OS_CHROMEOS)
if (force_immediate_policy_load)
chromeos::DeviceSettingsService::Get()->LoadImmediately();
configuration_policy_provider_ =
configuration_policy_provider_chromeos_ =
policy::UserPolicyManagerFactoryChromeOS::CreateForProfile(
this, force_immediate_policy_load, io_task_runner_);
user_cloud_policy_manager_ = nullptr;
user_cloud_policy_manager = nullptr;
#else
std::unique_ptr<policy::UserCloudPolicyManager> user_cloud_policy_manager =
CreateUserCloudPolicyManager(
GetPath(), GetPolicySchemaRegistryService()->registry(),
force_immediate_policy_load, io_task_runner_);
user_cloud_policy_manager_ = user_cloud_policy_manager.get();
configuration_policy_provider_ = std::move(user_cloud_policy_manager);
user_cloud_policy_manager_ = CreateUserCloudPolicyManager(
GetPath(), GetPolicySchemaRegistryService()->registry(),
force_immediate_policy_load, io_task_runner_);
user_cloud_policy_manager = user_cloud_policy_manager_.get();
#endif
profile_policy_connector_ =
policy::CreateProfilePolicyConnectorForBrowserContext(
schema_registry_service_->registry(), user_cloud_policy_manager_,
schema_registry_service_->registry(), user_cloud_policy_manager,
g_browser_process->browser_policy_connector(),
force_immediate_policy_load, this);
......@@ -833,7 +828,7 @@ ProfileImpl::~ProfileImpl() {
// condition.
#if !defined(OS_CHROMEOS)
profile_policy_connector_->Shutdown();
configuration_policy_provider_->Shutdown();
configuration_policy_provider()->Shutdown();
#endif
// This causes the Preferences file to be written to disk.
......@@ -1125,10 +1120,19 @@ policy::SchemaRegistryService* ProfileImpl::GetPolicySchemaRegistryService() {
#if !defined(OS_CHROMEOS)
policy::UserCloudPolicyManager* ProfileImpl::GetUserCloudPolicyManager() {
return user_cloud_policy_manager_;
return user_cloud_policy_manager_.get();
}
#endif
policy::ConfigurationPolicyProvider*
ProfileImpl::configuration_policy_provider() {
#if defined(OS_CHROMEOS)
return configuration_policy_provider_chromeos_.get();
#else
return user_cloud_policy_manager_.get();
#endif
}
policy::ProfilePolicyConnector* ProfileImpl::GetProfilePolicyConnector() {
return profile_policy_connector_.get();
}
......
......@@ -225,6 +225,8 @@ class ProfileImpl : public Profile {
void GetMediaCacheParameters(base::FilePath* cache_path, int* max_size);
policy::ConfigurationPolicyProvider* configuration_policy_provider();
PrefChangeRegistrar pref_change_registrar_;
base::FilePath path_;
......@@ -242,12 +244,17 @@ class ProfileImpl : public Profile {
// PolicyService that the |prefs_| depend on, and must outlive |prefs_|. This
// can be removed once |prefs_| becomes a KeyedService too.
// |profile_policy_connector_| in turn depends on
// |configuration_policy_provider_|, which depends on
// |schema_registry_service_|.
// |user_cloud_policy_manager_| or |configuration_policy_provider_chromeos_|,
// which depend on |schema_registry_service_|.
std::unique_ptr<policy::SchemaRegistryService> schema_registry_service_;
#if defined(OS_CHROMEOS)
std::unique_ptr<policy::ConfigurationPolicyProvider>
configuration_policy_provider_;
policy::UserCloudPolicyManager* user_cloud_policy_manager_;
configuration_policy_provider_chromeos_;
#else
std::unique_ptr<policy::UserCloudPolicyManager> user_cloud_policy_manager_;
#endif
std::unique_ptr<policy::ProfilePolicyConnector> profile_policy_connector_;
// Keep |prefs_| on top for destruction order because |extension_prefs_|,
......
......@@ -86,9 +86,9 @@ StartupData::TakeSchemaRegistryService() {
return std::move(schema_registry_service_);
}
std::unique_ptr<policy::ConfigurationPolicyProvider>
StartupData::TakeConfigurationPolicyProvider() {
return std::move(configuration_policy_provider_);
std::unique_ptr<policy::UserCloudPolicyManager>
StartupData::TakeUserCloudPolicyManager() {
return std::move(user_cloud_policy_manager_);
}
std::unique_ptr<policy::ProfilePolicyConnector>
......@@ -136,17 +136,16 @@ void StartupData::CreateProfilePrefServiceInternal() {
std::move(schema_registry), browser_policy_connector->GetChromeSchema(),
browser_policy_connector->GetSchemaRegistry());
configuration_policy_provider_ = CreateUserCloudPolicyManager(
user_cloud_policy_manager_ = CreateUserCloudPolicyManager(
path, schema_registry_service_->registry(),
true /* force_immediate_policy_load */, io_task_runner);
auto* user_cloud_policy_manager = static_cast<policy::CloudPolicyManager*>(
configuration_policy_provider_.get());
profile_policy_connector_ = policy::CreateAndInitProfilePolicyConnector(
schema_registry_service_->registry(),
static_cast<policy::ChromeBrowserPolicyConnector*>(
browser_policy_connector),
user_cloud_policy_manager, user_cloud_policy_manager->core()->store(),
user_cloud_policy_manager_.get(),
user_cloud_policy_manager_->core()->store(),
true /* force_immediate_policy_load*/, nullptr /* user */);
RegisterProfilePrefs(false /* is_signin_profile */,
......
......@@ -16,9 +16,9 @@ class PrefRegistrySyncable;
}
namespace policy {
class ConfigurationPolicyProvider;
class ProfilePolicyConnector;
class SchemaRegistryService;
class UserCloudPolicyManager;
} // namespace policy
namespace sync_preferences {
......@@ -53,9 +53,8 @@ class StartupData {
// Passes ownership of the |schema_registry_service_| to the caller.
std::unique_ptr<policy::SchemaRegistryService> TakeSchemaRegistryService();
// Passes ownership of the |configuration_policy_provider_| to the caller.
std::unique_ptr<policy::ConfigurationPolicyProvider>
TakeConfigurationPolicyProvider();
// Passes ownership of the |user_cloud_policy_manager_| to the caller.
std::unique_ptr<policy::UserCloudPolicyManager> TakeUserCloudPolicyManager();
// Passes ownership of the |profile_policy_connector_| to the caller.
std::unique_ptr<policy::ProfilePolicyConnector> TakeProfilePolicyConnector();
......@@ -80,8 +79,7 @@ class StartupData {
std::unique_ptr<ProfileKey> key_;
std::unique_ptr<policy::SchemaRegistryService> schema_registry_service_;
std::unique_ptr<policy::ConfigurationPolicyProvider>
configuration_policy_provider_;
std::unique_ptr<policy::UserCloudPolicyManager> user_cloud_policy_manager_;
std::unique_ptr<policy::ProfilePolicyConnector> profile_policy_connector_;
scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_;
......
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