Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/browser/policy/profile_policy_connector_factory.h" | 5 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/policy/profile_policy_connector.h" | 8 #include "chrome/browser/policy/profile_policy_connector.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
| 11 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" | 11 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" |
| 12 #include "components/user_prefs/pref_registry_syncable.h" | 12 #include "components/user_prefs/pref_registry_syncable.h" |
| 13 | 13 |
| 14 #if defined(ENABLE_CONFIGURATION_POLICY) | 14 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 15 #if defined(OS_CHROMEOS) | 15 #if defined(OS_CHROMEOS) |
| 16 #include "chrome/browser/chromeos/login/user.h" | |
| 16 #include "chrome/browser/chromeos/login/user_manager.h" | 17 #include "chrome/browser/chromeos/login/user_manager.h" |
| 18 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" | |
| 17 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom eos.h" | 19 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom eos.h" |
| 18 #else | 20 #else |
| 21 #include "chrome/browser/policy/cloud/user_cloud_policy_manager.h" | |
| 19 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" | 22 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" |
| 20 #endif | 23 #endif |
| 21 #endif | 24 #endif |
| 22 | 25 |
| 23 namespace policy { | 26 namespace policy { |
| 24 | 27 |
| 25 // static | 28 // static |
| 26 ProfilePolicyConnectorFactory* ProfilePolicyConnectorFactory::GetInstance() { | 29 ProfilePolicyConnectorFactory* ProfilePolicyConnectorFactory::GetInstance() { |
| 27 return Singleton<ProfilePolicyConnectorFactory>::get(); | 30 return Singleton<ProfilePolicyConnectorFactory>::get(); |
| 28 } | 31 } |
| 29 | 32 |
| 30 // static | 33 // static |
| 31 ProfilePolicyConnector* ProfilePolicyConnectorFactory::GetForProfile( | 34 ProfilePolicyConnector* ProfilePolicyConnectorFactory::GetForProfile( |
| 32 Profile* profile) { | 35 Profile* profile) { |
| 33 return GetInstance()->GetForProfileInternal(profile); | 36 return GetInstance()->GetForProfileInternal(profile); |
| 34 } | 37 } |
| 35 | 38 |
| 36 // static | 39 // static |
| 37 scoped_ptr<ProfilePolicyConnector> | 40 scoped_ptr<ProfilePolicyConnector> |
| 38 ProfilePolicyConnectorFactory::CreateForProfile( | 41 ProfilePolicyConnectorFactory::CreateForProfile( |
| 39 Profile* profile, | 42 Profile* profile, |
| 40 bool force_immediate_load, | 43 bool force_immediate_load, |
| 41 base::SequencedTaskRunner* sequenced_task_runner) { | 44 base::SequencedTaskRunner* sequenced_task_runner) { |
| 42 return GetInstance()->CreateForProfileInternal( | 45 return GetInstance()->CreateForProfileInternal(profile, |
| 43 profile, force_immediate_load, sequenced_task_runner); | 46 force_immediate_load, |
| 47 sequenced_task_runner); | |
| 44 } | 48 } |
| 45 | 49 |
| 46 void ProfilePolicyConnectorFactory::SetServiceForTesting( | 50 void ProfilePolicyConnectorFactory::SetServiceForTesting( |
| 47 Profile* profile, | 51 Profile* profile, |
| 48 ProfilePolicyConnector* connector) { | 52 ProfilePolicyConnector* connector) { |
| 49 ProfilePolicyConnector*& map_entry = connectors_[profile]; | 53 ProfilePolicyConnector*& map_entry = connectors_[profile]; |
| 50 CHECK(!map_entry); | 54 CHECK(!map_entry); |
| 51 map_entry = connector; | 55 map_entry = connector; |
| 52 } | 56 } |
| 53 | 57 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 77 CHECK(it != connectors_.end()); | 81 CHECK(it != connectors_.end()); |
| 78 return it->second; | 82 return it->second; |
| 79 } | 83 } |
| 80 | 84 |
| 81 scoped_ptr<ProfilePolicyConnector> | 85 scoped_ptr<ProfilePolicyConnector> |
| 82 ProfilePolicyConnectorFactory::CreateForProfileInternal( | 86 ProfilePolicyConnectorFactory::CreateForProfileInternal( |
| 83 Profile* profile, | 87 Profile* profile, |
| 84 bool force_immediate_load, | 88 bool force_immediate_load, |
| 85 base::SequencedTaskRunner* sequenced_task_runner) { | 89 base::SequencedTaskRunner* sequenced_task_runner) { |
| 86 DCHECK(connectors_.find(profile) == connectors_.end()); | 90 DCHECK(connectors_.find(profile) == connectors_.end()); |
| 87 ProfilePolicyConnector* connector = new ProfilePolicyConnector(profile); | 91 #if defined(ENABLE_CONFIGURATION_POLICY) && defined(OS_CHROMEOS) |
| 88 connector->Init(force_immediate_load, sequenced_task_runner); | 92 chromeos::User* user = NULL; |
| 93 if (!profile->IsLoginProfile()) { | |
| 94 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); | |
| 95 user = user_manager->GetUserByProfile(profile); | |
| 96 CHECK(user); | |
| 97 } | |
| 98 CloudPolicyManager* user_cloud_policy_manager = | |
| 99 UserCloudPolicyManagerFactoryChromeOS::GetForProfile(profile); | |
| 100 #else | |
| 101 CloudPolicyManager* user_cloud_policy_manager = | |
| 102 UserCloudPolicyManagerFactory::GetForProfile(profile); | |
| 103 #endif | |
| 104 ProfilePolicyConnector* connector = new ProfilePolicyConnector(); | |
| 105 connector->Init(force_immediate_load, | |
| 106 #if defined(ENABLE_CONFIGURATION_POLICY) && defined(OS_CHROMEOS) | |
| 107 user, | |
| 108 #endif | |
| 109 user_cloud_policy_manager, | |
| 110 sequenced_task_runner); | |
| 89 connectors_[profile] = connector; | 111 connectors_[profile] = connector; |
| 90 return scoped_ptr<ProfilePolicyConnector>(connector); | 112 return make_scoped_ptr(connector); |
| 91 } | 113 } |
| 92 | 114 |
| 93 void ProfilePolicyConnectorFactory::BrowserContextShutdown( | 115 void ProfilePolicyConnectorFactory::BrowserContextShutdown( |
| 94 content::BrowserContext* context) { | 116 content::BrowserContext* context) { |
| 95 Profile* profile = static_cast<Profile*>(context); | 117 Profile* profile = static_cast<Profile*>(context); |
| 96 if (profile->IsOffTheRecord()) | 118 if (profile->IsOffTheRecord()) |
| 97 return; | 119 return; |
| 98 ConnectorMap::iterator it = connectors_.find(profile); | 120 ConnectorMap::iterator it = connectors_.find(profile); |
| 99 if (it != connectors_.end()) | 121 if (it != connectors_.end()) |
| 100 it->second->Shutdown(); | 122 it->second->Shutdown(); |
| 101 } | 123 } |
| 102 | 124 |
| 103 void ProfilePolicyConnectorFactory::BrowserContextDestroyed( | 125 void ProfilePolicyConnectorFactory::BrowserContextDestroyed( |
| 104 content::BrowserContext* context) { | 126 content::BrowserContext* context) { |
| 105 ConnectorMap::iterator it = connectors_.find(static_cast<Profile*>(context)); | 127 ConnectorMap::iterator it = connectors_.find(static_cast<Profile*>(context)); |
| 106 if (it != connectors_.end()) | 128 if (it != connectors_.end()) |
| 107 connectors_.erase(it); | 129 connectors_.erase(it); |
| 108 BrowserContextKeyedBaseFactory::BrowserContextDestroyed(context); | 130 BrowserContextKeyedBaseFactory::BrowserContextDestroyed(context); |
| 109 } | 131 } |
| 110 | 132 |
| 111 void ProfilePolicyConnectorFactory::RegisterProfilePrefs( | 133 void ProfilePolicyConnectorFactory::RegisterProfilePrefs( |
| 112 user_prefs::PrefRegistrySyncable* registry) { | 134 user_prefs::PrefRegistrySyncable* registry) { |
| 113 #if defined(OS_CHROMEOS) | 135 #if defined(OS_CHROMEOS) |
| 114 registry->RegisterBooleanPref( | 136 registry->RegisterBooleanPref( |
| 115 prefs::kUsedPolicyCertificatesOnce, | 137 prefs::kUsedPolicyCertificatesOnce, |
| 116 false, | 138 false, |
| 117 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 139 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
|
Joao da Silva
2013/10/16 12:44:58
This registration should move to network_policy_se
pneubeck (no reviews)
2013/10/22 18:47:41
Done.
| |
| 118 #endif | 140 #endif |
| 119 #if defined(OS_ANDROID) | 141 #if defined(OS_ANDROID) |
| 120 registry->RegisterListPref( | 142 registry->RegisterListPref( |
| 121 prefs::kManagedBookmarks, | 143 prefs::kManagedBookmarks, |
| 122 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 144 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 123 #endif | 145 #endif |
| 124 } | 146 } |
| 125 | 147 |
| 126 void ProfilePolicyConnectorFactory::SetEmptyTestingFactory( | 148 void ProfilePolicyConnectorFactory::SetEmptyTestingFactory( |
| 127 content::BrowserContext* context) {} | 149 content::BrowserContext* context) {} |
| 128 | 150 |
| 129 void ProfilePolicyConnectorFactory::CreateServiceNow( | 151 void ProfilePolicyConnectorFactory::CreateServiceNow( |
| 130 content::BrowserContext* context) {} | 152 content::BrowserContext* context) {} |
| 131 | 153 |
| 132 } // namespace policy | 154 } // namespace policy |
| OLD | NEW |