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

Side by Side Diff: chrome/browser/policy/profile_policy_connector_factory.cc

Issue 24153012: Fix cyclic dependency between ProfilePolicyConnector and PrefService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed another bug for OTRProfile. Created 7 years, 1 month 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 | Annotate | Revision Log
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/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(Profile* profile,
39 Profile* profile, 42 bool force_immediate_load) {
40 bool force_immediate_load) {
41 return GetInstance()->CreateForProfileInternal(profile, force_immediate_load); 43 return GetInstance()->CreateForProfileInternal(profile, force_immediate_load);
42 } 44 }
43 45
44 void ProfilePolicyConnectorFactory::SetServiceForTesting( 46 void ProfilePolicyConnectorFactory::SetServiceForTesting(
45 Profile* profile, 47 Profile* profile,
46 ProfilePolicyConnector* connector) { 48 ProfilePolicyConnector* connector) {
47 ProfilePolicyConnector*& map_entry = connectors_[profile]; 49 ProfilePolicyConnector*& map_entry = connectors_[profile];
48 CHECK(!map_entry); 50 CHECK(!map_entry);
49 map_entry = connector; 51 map_entry = connector;
50 } 52 }
(...skipping 19 matching lines...) Expand all
70 ProfilePolicyConnectorFactory::GetForProfileInternal(Profile* profile) { 72 ProfilePolicyConnectorFactory::GetForProfileInternal(Profile* profile) {
71 // Get the connector for the original Profile, so that the incognito Profile 73 // Get the connector for the original Profile, so that the incognito Profile
72 // gets managed settings from the same PolicyService. 74 // gets managed settings from the same PolicyService.
73 ConnectorMap::const_iterator it = 75 ConnectorMap::const_iterator it =
74 connectors_.find(profile->GetOriginalProfile()); 76 connectors_.find(profile->GetOriginalProfile());
75 CHECK(it != connectors_.end()); 77 CHECK(it != connectors_.end());
76 return it->second; 78 return it->second;
77 } 79 }
78 80
79 scoped_ptr<ProfilePolicyConnector> 81 scoped_ptr<ProfilePolicyConnector>
80 ProfilePolicyConnectorFactory::CreateForProfileInternal( 82 ProfilePolicyConnectorFactory::CreateForProfileInternal(
81 Profile* profile, 83 Profile* profile,
82 bool force_immediate_load) { 84 bool force_immediate_load) {
83 DCHECK(connectors_.find(profile) == connectors_.end()); 85 DCHECK(connectors_.find(profile) == connectors_.end());
84 ProfilePolicyConnector* connector = new ProfilePolicyConnector(profile); 86 #if defined(ENABLE_CONFIGURATION_POLICY) && defined(OS_CHROMEOS)
85 connector->Init(force_immediate_load); 87 chromeos::User* user = NULL;
88 if (!profile->IsLoginProfile()) {
89 chromeos::UserManager* user_manager = chromeos::UserManager::Get();
90 user = user_manager->GetUserByProfile(profile);
91 CHECK(user);
92 }
93 CloudPolicyManager* user_cloud_policy_manager =
94 UserCloudPolicyManagerFactoryChromeOS::GetForProfile(profile);
95 #else
96 CloudPolicyManager* user_cloud_policy_manager =
97 UserCloudPolicyManagerFactory::GetForProfile(profile);
98 #endif
99 ProfilePolicyConnector* connector = new ProfilePolicyConnector();
100 connector->Init(force_immediate_load,
101 #if defined(ENABLE_CONFIGURATION_POLICY) && defined(OS_CHROMEOS)
102 user,
103 #endif
104 user_cloud_policy_manager);
86 connectors_[profile] = connector; 105 connectors_[profile] = connector;
87 return scoped_ptr<ProfilePolicyConnector>(connector); 106 return make_scoped_ptr(connector);
88 } 107 }
89 108
90 void ProfilePolicyConnectorFactory::BrowserContextShutdown( 109 void ProfilePolicyConnectorFactory::BrowserContextShutdown(
91 content::BrowserContext* context) { 110 content::BrowserContext* context) {
92 Profile* profile = static_cast<Profile*>(context); 111 Profile* profile = static_cast<Profile*>(context);
93 if (profile->IsOffTheRecord()) 112 if (profile->IsOffTheRecord())
94 return; 113 return;
95 ConnectorMap::iterator it = connectors_.find(profile); 114 ConnectorMap::iterator it = connectors_.find(profile);
96 if (it != connectors_.end()) 115 if (it != connectors_.end())
97 it->second->Shutdown(); 116 it->second->Shutdown();
98 } 117 }
99 118
100 void ProfilePolicyConnectorFactory::BrowserContextDestroyed( 119 void ProfilePolicyConnectorFactory::BrowserContextDestroyed(
101 content::BrowserContext* context) { 120 content::BrowserContext* context) {
102 ConnectorMap::iterator it = connectors_.find(static_cast<Profile*>(context)); 121 ConnectorMap::iterator it = connectors_.find(static_cast<Profile*>(context));
103 if (it != connectors_.end()) 122 if (it != connectors_.end())
104 connectors_.erase(it); 123 connectors_.erase(it);
105 BrowserContextKeyedBaseFactory::BrowserContextDestroyed(context); 124 BrowserContextKeyedBaseFactory::BrowserContextDestroyed(context);
106 } 125 }
107 126
108 void ProfilePolicyConnectorFactory::RegisterProfilePrefs( 127 void ProfilePolicyConnectorFactory::RegisterProfilePrefs(
109 user_prefs::PrefRegistrySyncable* registry) { 128 user_prefs::PrefRegistrySyncable* registry) {
110 #if defined(OS_CHROMEOS)
111 registry->RegisterBooleanPref(
112 prefs::kUsedPolicyCertificatesOnce,
113 false,
114 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
115 #endif
116 #if defined(OS_ANDROID) 129 #if defined(OS_ANDROID)
117 registry->RegisterListPref( 130 registry->RegisterListPref(
118 prefs::kManagedBookmarks, 131 prefs::kManagedBookmarks,
119 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 132 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
120 #endif 133 #endif
121 } 134 }
122 135
123 void ProfilePolicyConnectorFactory::SetEmptyTestingFactory( 136 void ProfilePolicyConnectorFactory::SetEmptyTestingFactory(
124 content::BrowserContext* context) {} 137 content::BrowserContext* context) {}
125 138
126 void ProfilePolicyConnectorFactory::CreateServiceNow( 139 void ProfilePolicyConnectorFactory::CreateServiceNow(
127 content::BrowserContext* context) {} 140 content::BrowserContext* context) {}
128 141
129 } // namespace policy 142 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698