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

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

Issue 12088022: Enable cloud policy by default. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed tests. Tests do the craziest damn things. Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/user_policy_signin_service.h" 5 #include "chrome/browser/policy/user_policy_signin_service.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/policy/browser_policy_connector.h" 9 #include "chrome/browser/policy/browser_policy_connector.h"
10 #include "chrome/browser/policy/cloud_policy_service.h" 10 #include "chrome/browser/policy/cloud_policy_service.h"
(...skipping 30 matching lines...) Expand all
41 } // namespace 41 } // namespace
42 42
43 namespace policy { 43 namespace policy {
44 44
45 UserPolicySigninService::UserPolicySigninService( 45 UserPolicySigninService::UserPolicySigninService(
46 Profile* profile) 46 Profile* profile)
47 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), 47 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
48 profile_(profile), 48 profile_(profile),
49 pending_fetch_(false) { 49 pending_fetch_(false) {
50 50
51 if (!profile_->GetPrefs()->GetBoolean(prefs::kLoadCloudPolicyOnSignin)) 51 if (profile_->GetPrefs()->GetBoolean(prefs::kDisableCloudPolicyOnSignin))
52 return; 52 return;
53 53
54 // Initialize/shutdown the UserCloudPolicyManager when the user signs out. 54 // Initialize/shutdown the UserCloudPolicyManager when the user signs out.
55 registrar_.Add(this, 55 registrar_.Add(this,
56 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, 56 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT,
57 content::Source<Profile>(profile)); 57 content::Source<Profile>(profile));
58 58
59 // Listen for an OAuth token to become available so we can register a client 59 // Listen for an OAuth token to become available so we can register a client
60 // if for some reason the client is not already registered (for example, if 60 // if for some reason the client is not already registered (for example, if
61 // the policy load failed during initial signin). 61 // the policy load failed during initial signin).
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 DCHECK(manager->core()->service()); 131 DCHECK(manager->core()->service());
132 DCHECK(manager->core()->client()); 132 DCHECK(manager->core()->client());
133 manager->core()->service()->AddObserver(this); 133 manager->core()->service()->AddObserver(this);
134 manager->core()->client()->AddObserver(this); 134 manager->core()->client()->AddObserver(this);
135 } 135 }
136 136
137 void UserPolicySigninService::Observe( 137 void UserPolicySigninService::Observe(
138 int type, 138 int type,
139 const content::NotificationSource& source, 139 const content::NotificationSource& source,
140 const content::NotificationDetails& details) { 140 const content::NotificationDetails& details) {
141 // If using a TestingProfile with no SigninManager or UserCloudPolicyManager,
142 // skip initialization.
143 if (!GetManager() || !SigninManagerFactory::GetForProfile(profile_)) {
144 DVLOG(1) << "Skipping initialization for tests due to missing components.";
145 return;
146 }
147
141 switch (type) { 148 switch (type) {
142 case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT: 149 case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT:
143 ShutdownUserCloudPolicyManager(); 150 ShutdownUserCloudPolicyManager();
144 break; 151 break;
145 case chrome::NOTIFICATION_PROFILE_ADDED: { 152 case chrome::NOTIFICATION_PROFILE_ADDED: {
146 // A new profile has been loaded - if it's signed in, then initialize the 153 // A new profile has been loaded - if it's signed in, then initialize the
147 // UCPM, otherwise shut down the UCPM (which deletes any cached policy 154 // UCPM, otherwise shut down the UCPM (which deletes any cached policy
148 // data). This must be done here instead of at constructor time because 155 // data). This must be done here instead of at constructor time because
149 // the Profile is not fully initialized when this object is constructed 156 // the Profile is not fully initialized when this object is constructed
150 // (DoFinalInit() has not yet been called, so ProfileIOData and 157 // (DoFinalInit() has not yet been called, so ProfileIOData and
(...skipping 19 matching lines...) Expand all
170 InitializeUserCloudPolicyManager(); 177 InitializeUserCloudPolicyManager();
171 } 178 }
172 break; 179 break;
173 } 180 }
174 default: 181 default:
175 NOTREACHED(); 182 NOTREACHED();
176 } 183 }
177 } 184 }
178 185
179 bool UserPolicySigninService::ShouldLoadPolicyForSignedInUser() { 186 bool UserPolicySigninService::ShouldLoadPolicyForSignedInUser() {
180 if (!profile_->GetPrefs()->GetBoolean(prefs::kLoadCloudPolicyOnSignin)) 187 if (profile_->GetPrefs()->GetBoolean(prefs::kDisableCloudPolicyOnSignin))
181 return false; // Cloud policy is disabled. 188 return false; // Cloud policy is disabled.
182 189
183 const std::string& username = SigninManagerFactory::GetForProfile(profile_)-> 190 const std::string& username = SigninManagerFactory::GetForProfile(profile_)->
184 GetAuthenticatedUsername(); 191 GetAuthenticatedUsername();
185 192
186 if (username.empty()) 193 if (username.empty())
187 return false; // Not signed in. 194 return false; // Not signed in.
188 195
189 return !BrowserPolicyConnector::IsNonEnterpriseUser(username); 196 return !BrowserPolicyConnector::IsNonEnterpriseUser(username);
190 } 197 }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 367
361 void UserPolicySigninService::Shutdown() { 368 void UserPolicySigninService::Shutdown() {
362 StopObserving(); 369 StopObserving();
363 } 370 }
364 371
365 UserCloudPolicyManager* UserPolicySigninService::GetManager() { 372 UserCloudPolicyManager* UserPolicySigninService::GetManager() {
366 return UserCloudPolicyManagerFactory::GetForProfile(profile_); 373 return UserCloudPolicyManagerFactory::GetForProfile(profile_);
367 } 374 }
368 375
369 } // namespace policy 376 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698