Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Side by Side Diff: chrome/browser/chromeos/policy/user_policy_manager_factory_chromeos.cc

Issue 2638623006: Merge {Device,User}ActiveDirectoryPolicyManager into a single class (Closed)
Patch Set: Have factories return unique_ptr Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/chromeos/policy/user_policy_manager_factory_chromeos.h" 5 #include "chrome/browser/chromeos/policy/user_policy_manager_factory_chromeos.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/sequenced_task_runner.h" 16 #include "base/sequenced_task_runner.h"
17 #include "base/threading/sequenced_worker_pool.h" 17 #include "base/threading/sequenced_worker_pool.h"
18 #include "base/threading/thread_task_runner_handle.h" 18 #include "base/threading/thread_task_runner_handle.h"
19 #include "base/time/time.h" 19 #include "base/time/time.h"
20 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/chromeos/policy/active_directory_policy_manager.h"
21 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 22 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
22 #include "chrome/browser/chromeos/policy/user_active_directory_policy_manager.h"
23 #include "chrome/browser/chromeos/policy/user_cloud_external_data_manager.h" 23 #include "chrome/browser/chromeos/policy/user_cloud_external_data_manager.h"
24 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" 24 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h"
25 #include "chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos.h" 25 #include "chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos.h"
26 #include "chrome/browser/chromeos/profiles/profile_helper.h" 26 #include "chrome/browser/chromeos/profiles/profile_helper.h"
27 #include "chrome/browser/chromeos/settings/cros_settings.h" 27 #include "chrome/browser/chromeos/settings/cros_settings.h"
28 #include "chrome/browser/chromeos/settings/install_attributes.h" 28 #include "chrome/browser/chromeos/settings/install_attributes.h"
29 #include "chrome/browser/policy/schema_registry_service.h" 29 #include "chrome/browser/policy/schema_registry_service.h"
30 #include "chrome/browser/policy/schema_registry_service_factory.h" 30 #include "chrome/browser/policy/schema_registry_service_factory.h"
31 #include "chrome/browser/profiles/profile.h" 31 #include "chrome/browser/profiles/profile.h"
32 #include "chromeos/chromeos_paths.h" 32 #include "chromeos/chromeos_paths.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 } 85 }
86 86
87 // static 87 // static
88 UserCloudPolicyManagerChromeOS* 88 UserCloudPolicyManagerChromeOS*
89 UserPolicyManagerFactoryChromeOS::GetCloudPolicyManagerForProfile( 89 UserPolicyManagerFactoryChromeOS::GetCloudPolicyManagerForProfile(
90 Profile* profile) { 90 Profile* profile) {
91 return GetInstance()->GetCloudPolicyManager(profile); 91 return GetInstance()->GetCloudPolicyManager(profile);
92 } 92 }
93 93
94 // static 94 // static
95 UserActiveDirectoryPolicyManager* 95 ActiveDirectoryPolicyManager*
96 UserPolicyManagerFactoryChromeOS::GetActiveDirectoryPolicyManagerForProfile( 96 UserPolicyManagerFactoryChromeOS::GetActiveDirectoryPolicyManagerForProfile(
97 Profile* profile) { 97 Profile* profile) {
98 return GetInstance()->GetActiveDirectoryPolicyManager(profile); 98 return GetInstance()->GetActiveDirectoryPolicyManager(profile);
99 } 99 }
100 100
101 // static 101 // static
102 std::unique_ptr<ConfigurationPolicyProvider> 102 std::unique_ptr<ConfigurationPolicyProvider>
103 UserPolicyManagerFactoryChromeOS::CreateForProfile( 103 UserPolicyManagerFactoryChromeOS::CreateForProfile(
104 Profile* profile, 104 Profile* profile,
105 bool force_immediate_load, 105 bool force_immediate_load,
(...skipping 12 matching lines...) Expand all
118 UserPolicyManagerFactoryChromeOS::~UserPolicyManagerFactoryChromeOS() {} 118 UserPolicyManagerFactoryChromeOS::~UserPolicyManagerFactoryChromeOS() {}
119 119
120 UserCloudPolicyManagerChromeOS* 120 UserCloudPolicyManagerChromeOS*
121 UserPolicyManagerFactoryChromeOS::GetCloudPolicyManager(Profile* profile) { 121 UserPolicyManagerFactoryChromeOS::GetCloudPolicyManager(Profile* profile) {
122 // Get the manager for the original profile, since the PolicyService is 122 // Get the manager for the original profile, since the PolicyService is
123 // also shared between the incognito Profile and the original Profile. 123 // also shared between the incognito Profile and the original Profile.
124 const auto it = cloud_managers_.find(profile->GetOriginalProfile()); 124 const auto it = cloud_managers_.find(profile->GetOriginalProfile());
125 return it != cloud_managers_.end() ? it->second : nullptr; 125 return it != cloud_managers_.end() ? it->second : nullptr;
126 } 126 }
127 127
128 UserActiveDirectoryPolicyManager* 128 ActiveDirectoryPolicyManager*
129 UserPolicyManagerFactoryChromeOS::GetActiveDirectoryPolicyManager( 129 UserPolicyManagerFactoryChromeOS::GetActiveDirectoryPolicyManager(
130 Profile* profile) { 130 Profile* profile) {
131 // Get the manager for the original profile, since the PolicyService is 131 // Get the manager for the original profile, since the PolicyService is
132 // also shared between the incognito Profile and the original Profile. 132 // also shared between the incognito Profile and the original Profile.
133 const auto it = 133 const auto it =
134 active_directory_managers_.find(profile->GetOriginalProfile()); 134 active_directory_managers_.find(profile->GetOriginalProfile());
135 return it != active_directory_managers_.end() ? it->second : nullptr; 135 return it != active_directory_managers_.end() ? it->second : nullptr;
136 } 136 }
137 137
138 std::unique_ptr<ConfigurationPolicyProvider> 138 std::unique_ptr<ConfigurationPolicyProvider>
(...skipping 14 matching lines...) Expand all
153 // |user| should never be nullptr except for the signin profile. This object 153 // |user| should never be nullptr except for the signin profile. This object
154 // is created as part of the Profile creation, which happens right after 154 // is created as part of the Profile creation, which happens right after
155 // sign-in. The just-signed-in User is the active user during that time. 155 // sign-in. The just-signed-in User is the active user during that time.
156 const user_manager::User* user = 156 const user_manager::User* user =
157 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); 157 chromeos::ProfileHelper::Get()->GetUserByProfile(profile);
158 CHECK(user); 158 CHECK(user);
159 159
160 // User policy exists for enterprise accounts only: 160 // User policy exists for enterprise accounts only:
161 // - For regular cloud-managed users (those who have a GAIA account), a 161 // - For regular cloud-managed users (those who have a GAIA account), a
162 // |UserCloudPolicyManagerChromeOS| is created here. 162 // |UserCloudPolicyManagerChromeOS| is created here.
163 // - For Active Directory managed users, a |UserActiveDirectoryPolicyManager| 163 // - For Active Directory managed users, an |ActiveDirectoryPolicyManager|
164 // is created. 164 // is created.
165 // - For device-local accounts, policy is provided by 165 // - For device-local accounts, policy is provided by
166 // |DeviceLocalAccountPolicyService|. 166 // |DeviceLocalAccountPolicyService|.
167 // All other user types do not have user policy. 167 // All other user types do not have user policy.
168 const AccountId& account_id = user->GetAccountId(); 168 const AccountId& account_id = user->GetAccountId();
169 if (user->IsSupervised() || 169 if (user->IsSupervised() ||
170 BrowserPolicyConnector::IsNonEnterpriseUser(account_id.GetUserEmail())) { 170 BrowserPolicyConnector::IsNonEnterpriseUser(account_id.GetUserEmail())) {
171 return {}; 171 return {};
172 } 172 }
173 173
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 backend_task_runner, io_task_runner, 253 backend_task_runner, io_task_runner,
254 external_data_dir, store.get())); 254 external_data_dir, store.get()));
255 if (force_immediate_load) 255 if (force_immediate_load)
256 store->LoadImmediately(); 256 store->LoadImmediately();
257 257
258 scoped_refptr<base::SequencedTaskRunner> file_task_runner = 258 scoped_refptr<base::SequencedTaskRunner> file_task_runner =
259 content::BrowserThread::GetTaskRunnerForThread( 259 content::BrowserThread::GetTaskRunnerForThread(
260 content::BrowserThread::FILE); 260 content::BrowserThread::FILE);
261 261
262 if (is_active_directory) { 262 if (is_active_directory) {
263 std::unique_ptr<UserActiveDirectoryPolicyManager> manager = 263 std::unique_ptr<ActiveDirectoryPolicyManager> manager =
264 base::MakeUnique<UserActiveDirectoryPolicyManager>(account_id, 264 ActiveDirectoryPolicyManager::CreateForUserPolicy(account_id,
265 std::move(store)); 265 std::move(store));
266 manager->Init( 266 manager->Init(
267 SchemaRegistryServiceFactory::GetForContext(profile)->registry()); 267 SchemaRegistryServiceFactory::GetForContext(profile)->registry());
268 268
269 active_directory_managers_[profile] = manager.get(); 269 active_directory_managers_[profile] = manager.get();
270 return std::move(manager); 270 return std::move(manager);
271 } else { 271 } else {
272 std::unique_ptr<UserCloudPolicyManagerChromeOS> manager = 272 std::unique_ptr<UserCloudPolicyManagerChromeOS> manager =
273 base::MakeUnique<UserCloudPolicyManagerChromeOS>( 273 base::MakeUnique<UserCloudPolicyManagerChromeOS>(
274 std::move(store), std::move(external_data_manager), 274 std::move(store), std::move(external_data_manager),
275 component_policy_cache_dir, wait_for_policy_fetch, 275 component_policy_cache_dir, wait_for_policy_fetch,
(...skipping 23 matching lines...) Expand all
299 299
300 void UserPolicyManagerFactoryChromeOS::BrowserContextShutdown( 300 void UserPolicyManagerFactoryChromeOS::BrowserContextShutdown(
301 content::BrowserContext* context) { 301 content::BrowserContext* context) {
302 Profile* profile = static_cast<Profile*>(context); 302 Profile* profile = static_cast<Profile*>(context);
303 if (profile->IsOffTheRecord()) 303 if (profile->IsOffTheRecord())
304 return; 304 return;
305 UserCloudPolicyManagerChromeOS* cloud_manager = 305 UserCloudPolicyManagerChromeOS* cloud_manager =
306 GetCloudPolicyManager(profile); 306 GetCloudPolicyManager(profile);
307 if (cloud_manager) 307 if (cloud_manager)
308 cloud_manager->Shutdown(); 308 cloud_manager->Shutdown();
309 UserActiveDirectoryPolicyManager* active_directory_manager = 309 ActiveDirectoryPolicyManager* active_directory_manager =
310 GetActiveDirectoryPolicyManager(profile); 310 GetActiveDirectoryPolicyManager(profile);
311 if (active_directory_manager) 311 if (active_directory_manager)
312 active_directory_manager->Shutdown(); 312 active_directory_manager->Shutdown();
313 } 313 }
314 314
315 void UserPolicyManagerFactoryChromeOS::BrowserContextDestroyed( 315 void UserPolicyManagerFactoryChromeOS::BrowserContextDestroyed(
316 content::BrowserContext* context) { 316 content::BrowserContext* context) {
317 Profile* profile = static_cast<Profile*>(context); 317 Profile* profile = static_cast<Profile*>(context);
318 cloud_managers_.erase(profile); 318 cloud_managers_.erase(profile);
319 active_directory_managers_.erase(profile); 319 active_directory_managers_.erase(profile);
320 BrowserContextKeyedBaseFactory::BrowserContextDestroyed(context); 320 BrowserContextKeyedBaseFactory::BrowserContextDestroyed(context);
321 } 321 }
322 322
323 void UserPolicyManagerFactoryChromeOS::SetEmptyTestingFactory( 323 void UserPolicyManagerFactoryChromeOS::SetEmptyTestingFactory(
324 content::BrowserContext* context) {} 324 content::BrowserContext* context) {}
325 325
326 bool UserPolicyManagerFactoryChromeOS::HasTestingFactory( 326 bool UserPolicyManagerFactoryChromeOS::HasTestingFactory(
327 content::BrowserContext* context) { 327 content::BrowserContext* context) {
328 return false; 328 return false;
329 } 329 }
330 330
331 void UserPolicyManagerFactoryChromeOS::CreateServiceNow( 331 void UserPolicyManagerFactoryChromeOS::CreateServiceNow(
332 content::BrowserContext* context) {} 332 content::BrowserContext* context) {}
333 333
334 } // namespace policy 334 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698