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

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: Review feedback 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).
62 registrar_.Add(this, 62 registrar_.Add(this,
63 chrome::NOTIFICATION_TOKEN_AVAILABLE, 63 chrome::NOTIFICATION_TOKEN_AVAILABLE,
64 content::Source<TokenService>( 64 content::Source<TokenService>(
65 TokenServiceFactory::GetForProfile(profile))); 65 TokenServiceFactory::GetForProfile(profile)));
66 66
67 // TokenService should not yet have loaded its tokens since this happens in 67 // TokenService should not yet have loaded its tokens since this happens in
68 // the background after PKS initialization - so this service should always be 68 // the background after PKS initialization - so this service should always be
69 // created before the oauth token is available. 69 // created before the oauth token is available.
70 DCHECK(!TokenServiceFactory::GetForProfile(profile_)->HasOAuthLoginToken()); 70 DCHECK(!TokenServiceFactory::GetForProfile(profile_)->HasOAuthLoginToken());
71 71
72 // Register a listener to be called back once the current profile has finished 72 // Register a listener to be called back once the current profile has finished
73 // initializing, so we can startup the UserCloudPolicyManager. 73 // initializing, so we can startup the UserCloudPolicyManager.
74 registrar_.Add(this, 74 registrar_.Add(this,
75 chrome::NOTIFICATION_PROFILE_ADDED, 75 chrome::NOTIFICATION_PROFILE_ADDED,
76 content::Source<Profile>(profile)); 76 content::Source<Profile>(profile));
77 77
78 // Make sure we've initialized the DeviceManagementService. It's OK to 78 // Make sure we've initialized the DeviceManagementService. It's OK to
79 // call this multiple times so we do it every time we create an instance of 79 // call this multiple times so we do it every time we create an instance of
80 // this class (every time a new profile is loaded). 80 // this class (every time a new profile is loaded).
81 // TODO(atwilson): Move this to BrowserPolicyConnector::Init()
82 // (http://crbug.com/165468).
81 g_browser_process->browser_policy_connector()-> 83 g_browser_process->browser_policy_connector()->
82 ScheduleServiceInitialization( 84 ScheduleServiceInitialization(
83 kPolicyServiceInitializationDelayMilliseconds); 85 kPolicyServiceInitializationDelayMilliseconds);
84 } 86 }
85 87
86 UserPolicySigninService::~UserPolicySigninService() {} 88 UserPolicySigninService::~UserPolicySigninService() {}
87 89
88 void UserPolicySigninService::FetchPolicyForSignedInUser( 90 void UserPolicySigninService::FetchPolicyForSignedInUser(
89 const std::string& oauth2_access_token, 91 const std::string& oauth2_access_token,
90 const PolicyFetchCallback& callback) { 92 const PolicyFetchCallback& callback) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 DCHECK(manager->core()->service()); 133 DCHECK(manager->core()->service());
132 DCHECK(manager->core()->client()); 134 DCHECK(manager->core()->client());
133 manager->core()->service()->AddObserver(this); 135 manager->core()->service()->AddObserver(this);
134 manager->core()->client()->AddObserver(this); 136 manager->core()->client()->AddObserver(this);
135 } 137 }
136 138
137 void UserPolicySigninService::Observe( 139 void UserPolicySigninService::Observe(
138 int type, 140 int type,
139 const content::NotificationSource& source, 141 const content::NotificationSource& source,
140 const content::NotificationDetails& details) { 142 const content::NotificationDetails& details) {
143 // If using a TestingProfile with no SigninManager or UserCloudPolicyManager,
144 // skip initialization.
145 if (!GetManager() || !SigninManagerFactory::GetForProfile(profile_)) {
146 DVLOG(1) << "Skipping initialization for tests due to missing components.";
147 return;
148 }
149
141 switch (type) { 150 switch (type) {
142 case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT: 151 case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT:
143 ShutdownUserCloudPolicyManager(); 152 ShutdownUserCloudPolicyManager();
144 break; 153 break;
145 case chrome::NOTIFICATION_PROFILE_ADDED: { 154 case chrome::NOTIFICATION_PROFILE_ADDED: {
146 // A new profile has been loaded - if it's signed in, then initialize the 155 // 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 156 // UCPM, otherwise shut down the UCPM (which deletes any cached policy
148 // data). This must be done here instead of at constructor time because 157 // data). This must be done here instead of at constructor time because
149 // the Profile is not fully initialized when this object is constructed 158 // the Profile is not fully initialized when this object is constructed
150 // (DoFinalInit() has not yet been called, so ProfileIOData and 159 // (DoFinalInit() has not yet been called, so ProfileIOData and
(...skipping 19 matching lines...) Expand all
170 InitializeUserCloudPolicyManager(); 179 InitializeUserCloudPolicyManager();
171 } 180 }
172 break; 181 break;
173 } 182 }
174 default: 183 default:
175 NOTREACHED(); 184 NOTREACHED();
176 } 185 }
177 } 186 }
178 187
179 bool UserPolicySigninService::ShouldLoadPolicyForSignedInUser() { 188 bool UserPolicySigninService::ShouldLoadPolicyForSignedInUser() {
180 if (!profile_->GetPrefs()->GetBoolean(prefs::kLoadCloudPolicyOnSignin)) 189 if (profile_->GetPrefs()->GetBoolean(prefs::kDisableCloudPolicyOnSignin))
181 return false; // Cloud policy is disabled. 190 return false; // Cloud policy is disabled.
182 191
183 const std::string& username = SigninManagerFactory::GetForProfile(profile_)-> 192 const std::string& username = SigninManagerFactory::GetForProfile(profile_)->
184 GetAuthenticatedUsername(); 193 GetAuthenticatedUsername();
185 194
186 if (username.empty()) 195 if (username.empty())
187 return false; // Not signed in. 196 return false; // Not signed in.
188 197
189 return !BrowserPolicyConnector::IsNonEnterpriseUser(username); 198 return !BrowserPolicyConnector::IsNonEnterpriseUser(username);
190 } 199 }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 369
361 void UserPolicySigninService::Shutdown() { 370 void UserPolicySigninService::Shutdown() {
362 StopObserving(); 371 StopObserving();
363 } 372 }
364 373
365 UserCloudPolicyManager* UserPolicySigninService::GetManager() { 374 UserCloudPolicyManager* UserPolicySigninService::GetManager() {
366 return UserCloudPolicyManagerFactory::GetForProfile(profile_); 375 return UserCloudPolicyManagerFactory::GetForProfile(profile_);
367 } 376 }
368 377
369 } // namespace policy 378 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/cloud_policy_browsertest.cc ('k') | chrome/browser/policy/user_policy_signin_service_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698