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

Side by Side Diff: chrome/browser/policy/cloud/user_policy_signin_service_base.cc

Issue 49783006: policy: Remove SigninManager from UserCloudPolicyStore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/cloud/user_policy_signin_service_base.h" 5 #include "chrome/browser/policy/cloud/user_policy_signin_service_base.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 27 matching lines...) Expand all
38 // Register a listener to be called back once the current profile has finished 38 // Register a listener to be called back once the current profile has finished
39 // initializing, so we can startup the UserCloudPolicyManager. 39 // initializing, so we can startup the UserCloudPolicyManager.
40 registrar_.Add(this, 40 registrar_.Add(this,
41 chrome::NOTIFICATION_PROFILE_ADDED, 41 chrome::NOTIFICATION_PROFILE_ADDED,
42 content::Source<Profile>(profile)); 42 content::Source<Profile>(profile));
43 } 43 }
44 44
45 UserPolicySigninServiceBase::~UserPolicySigninServiceBase() {} 45 UserPolicySigninServiceBase::~UserPolicySigninServiceBase() {}
46 46
47 void UserPolicySigninServiceBase::FetchPolicyForSignedInUser( 47 void UserPolicySigninServiceBase::FetchPolicyForSignedInUser(
48 const std::string& username,
48 scoped_ptr<CloudPolicyClient> client, 49 scoped_ptr<CloudPolicyClient> client,
49 const PolicyFetchCallback& callback) { 50 const PolicyFetchCallback& callback) {
50 DCHECK(client); 51 DCHECK(client);
51 DCHECK(client->is_registered()); 52 DCHECK(client->is_registered());
52 // The user has just signed in, so the UserCloudPolicyManager should not yet 53 // The user has just signed in, so the UserCloudPolicyManager should not yet
53 // be initialized. This routine will initialize the UserCloudPolicyManager 54 // be initialized. This routine will initialize the UserCloudPolicyManager
54 // with the passed client and will proactively ask the client to fetch 55 // with the passed client and will proactively ask the client to fetch
55 // policy without waiting for the CloudPolicyService to finish initialization. 56 // policy without waiting for the CloudPolicyService to finish initialization.
56 UserCloudPolicyManager* manager = GetManager(); 57 UserCloudPolicyManager* manager = GetManager();
57 DCHECK(manager); 58 DCHECK(manager);
58 DCHECK(!manager->core()->client()); 59 DCHECK(!manager->core()->client());
59 InitializeUserCloudPolicyManager(client.Pass()); 60 InitializeUserCloudPolicyManager(username, client.Pass());
60 DCHECK(manager->IsClientRegistered()); 61 DCHECK(manager->IsClientRegistered());
61 62
62 // Now initiate a policy fetch. 63 // Now initiate a policy fetch.
63 manager->core()->service()->RefreshPolicy(callback); 64 manager->core()->service()->RefreshPolicy(callback);
64 } 65 }
65 66
66 void UserPolicySigninServiceBase::Observe( 67 void UserPolicySigninServiceBase::Observe(
67 int type, 68 int type,
68 const content::NotificationSource& source, 69 const content::NotificationSource& source,
69 const content::NotificationDetails& details) { 70 const content::NotificationDetails& details) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 DCHECK(!username.empty()); 153 DCHECK(!username.empty());
153 // We should not be called with a client already initialized. 154 // We should not be called with a client already initialized.
154 DCHECK(!GetManager() || !GetManager()->core()->client()); 155 DCHECK(!GetManager() || !GetManager()->core()->client());
155 156
156 // If the user should not get policy, just bail out. 157 // If the user should not get policy, just bail out.
157 if (!GetManager() || !ShouldLoadPolicyForUser(username)) { 158 if (!GetManager() || !ShouldLoadPolicyForUser(username)) {
158 DVLOG(1) << "Signed in user is not in the whitelist"; 159 DVLOG(1) << "Signed in user is not in the whitelist";
159 return scoped_ptr<CloudPolicyClient>(); 160 return scoped_ptr<CloudPolicyClient>();
160 } 161 }
161 162
163 GetManager()->SetSigninUsername(username);
164
162 // If the DeviceManagementService is not yet initialized, start it up now. 165 // If the DeviceManagementService is not yet initialized, start it up now.
163 device_management_service_->ScheduleInitialization(0); 166 device_management_service_->ScheduleInitialization(0);
164 167
165 // Create a new CloudPolicyClient for fetching the DMToken. 168 // Create a new CloudPolicyClient for fetching the DMToken.
166 return UserCloudPolicyManager::CreateCloudPolicyClient( 169 return UserCloudPolicyManager::CreateCloudPolicyClient(
167 device_management_service_); 170 device_management_service_);
168 } 171 }
169 172
170 bool UserPolicySigninServiceBase::ShouldLoadPolicyForUser( 173 bool UserPolicySigninServiceBase::ShouldLoadPolicyForUser(
171 const std::string& username) { 174 const std::string& username) {
(...skipping 22 matching lines...) Expand all
194 return; 197 return;
195 } 198 }
196 199
197 UserCloudPolicyManager* manager = GetManager(); 200 UserCloudPolicyManager* manager = GetManager();
198 // Initialize the UCPM if it is not already initialized. 201 // Initialize the UCPM if it is not already initialized.
199 if (!manager->core()->service()) { 202 if (!manager->core()->service()) {
200 // If there is no cached DMToken then we can detect this when the 203 // If there is no cached DMToken then we can detect this when the
201 // OnInitializationCompleted() callback is invoked and this will 204 // OnInitializationCompleted() callback is invoked and this will
202 // initiate a policy fetch. 205 // initiate a policy fetch.
203 InitializeUserCloudPolicyManager( 206 InitializeUserCloudPolicyManager(
207 username,
204 UserCloudPolicyManager::CreateCloudPolicyClient( 208 UserCloudPolicyManager::CreateCloudPolicyClient(
205 device_management_service_).Pass()); 209 device_management_service_).Pass());
210 } else {
211 manager->SetSigninUsername(username);
206 } 212 }
207 213
208 // If the CloudPolicyService is initialized, kick off registration. 214 // If the CloudPolicyService is initialized, kick off registration.
209 // Otherwise OnInitializationCompleted is invoked as soon as the service 215 // Otherwise OnInitializationCompleted is invoked as soon as the service
210 // finishes its initialization. 216 // finishes its initialization.
211 if (manager->core()->service()->IsInitializationComplete()) 217 if (manager->core()->service()->IsInitializationComplete())
212 OnInitializationCompleted(manager->core()->service()); 218 OnInitializationCompleted(manager->core()->service());
213 } 219 }
214 220
215 void UserPolicySigninServiceBase::InitializeUserCloudPolicyManager( 221 void UserPolicySigninServiceBase::InitializeUserCloudPolicyManager(
222 const std::string& username,
216 scoped_ptr<CloudPolicyClient> client) { 223 scoped_ptr<CloudPolicyClient> client) {
217 UserCloudPolicyManager* manager = GetManager(); 224 UserCloudPolicyManager* manager = GetManager();
225 manager->SetSigninUsername(username);
218 DCHECK(!manager->core()->client()); 226 DCHECK(!manager->core()->client());
219 manager->Connect(local_state_, request_context_, client.Pass()); 227 manager->Connect(local_state_, request_context_, client.Pass());
220 DCHECK(manager->core()->service()); 228 DCHECK(manager->core()->service());
221 229
222 // Observe the client to detect errors fetching policy. 230 // Observe the client to detect errors fetching policy.
223 manager->core()->client()->AddObserver(this); 231 manager->core()->client()->AddObserver(this);
224 // Observe the service to determine when it's initialized. 232 // Observe the service to determine when it's initialized.
225 manager->core()->service()->AddObserver(this); 233 manager->core()->service()->AddObserver(this);
226 } 234 }
227 235
228 void UserPolicySigninServiceBase::ShutdownUserCloudPolicyManager() { 236 void UserPolicySigninServiceBase::ShutdownUserCloudPolicyManager() {
229 PrepareForUserCloudPolicyManagerShutdown(); 237 PrepareForUserCloudPolicyManagerShutdown();
230 UserCloudPolicyManager* manager = GetManager(); 238 UserCloudPolicyManager* manager = GetManager();
231 if (manager) 239 if (manager)
232 manager->DisconnectAndRemovePolicy(); 240 manager->DisconnectAndRemovePolicy();
233 } 241 }
234 242
235 UserCloudPolicyManager* UserPolicySigninServiceBase::GetManager() { 243 UserCloudPolicyManager* UserPolicySigninServiceBase::GetManager() {
236 return UserCloudPolicyManagerFactory::GetForProfile(profile_); 244 return UserCloudPolicyManagerFactory::GetForProfile(profile_);
237 } 245 }
238 246
239 SigninManager* UserPolicySigninServiceBase::GetSigninManager() { 247 SigninManager* UserPolicySigninServiceBase::GetSigninManager() {
240 return SigninManagerFactory::GetForProfile(profile_); 248 return SigninManagerFactory::GetForProfile(profile_);
241 } 249 }
242 250
243 } // namespace policy 251 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698