OLD | NEW |
---|---|
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 } | 44 } |
45 | 45 |
46 UserPolicySigninServiceBase::~UserPolicySigninServiceBase() {} | 46 UserPolicySigninServiceBase::~UserPolicySigninServiceBase() {} |
47 | 47 |
48 void UserPolicySigninServiceBase::FetchPolicyForSignedInUser( | 48 void UserPolicySigninServiceBase::FetchPolicyForSignedInUser( |
49 const std::string& username, | 49 const std::string& username, |
50 const std::string& dm_token, | 50 const std::string& dm_token, |
51 const std::string& client_id, | 51 const std::string& client_id, |
52 scoped_refptr<net::URLRequestContextGetter> profile_request_context, | 52 scoped_refptr<net::URLRequestContextGetter> profile_request_context, |
53 const PolicyFetchCallback& callback) { | 53 const PolicyFetchCallback& callback) { |
54 UserCloudPolicyManager* manager = policy_manager(); | |
55 DCHECK(manager); | |
Mattias Nissler (ping if slow)
2014/01/27 13:52:13
remove, we'll crash anyways.
Andrew T Wilson (Slow)
2014/01/30 17:10:31
Reverted this change entirely.
| |
54 scoped_ptr<CloudPolicyClient> client( | 56 scoped_ptr<CloudPolicyClient> client( |
55 UserCloudPolicyManager::CreateCloudPolicyClient( | 57 manager->CreateCloudPolicyClient( |
56 device_management_service_, | 58 device_management_service_, |
57 CreateUserRequestContext(profile_request_context)).Pass()); | 59 CreateUserRequestContext(profile_request_context)).Pass()); |
58 client->SetupRegistration(dm_token, client_id); | 60 client->SetupRegistration(dm_token, client_id); |
61 DCHECK(!manager->core()->client()); | |
59 DCHECK(client->is_registered()); | 62 DCHECK(client->is_registered()); |
60 // The user has just signed in, so the UserCloudPolicyManager should not yet | 63 // The user has just signed in, so the UserCloudPolicyManager should not yet |
61 // be initialized. This routine will initialize the UserCloudPolicyManager | 64 // be initialized. This routine will initialize the UserCloudPolicyManager |
62 // with the passed client and will proactively ask the client to fetch | 65 // with the passed client and will proactively ask the client to fetch |
63 // policy without waiting for the CloudPolicyService to finish initialization. | 66 // policy without waiting for the CloudPolicyService to finish initialization. |
64 UserCloudPolicyManager* manager = policy_manager(); | |
65 DCHECK(manager); | |
66 DCHECK(!manager->core()->client()); | |
67 InitializeUserCloudPolicyManager(username, client.Pass()); | 67 InitializeUserCloudPolicyManager(username, client.Pass()); |
68 DCHECK(manager->IsClientRegistered()); | 68 DCHECK(manager->IsClientRegistered()); |
69 | 69 |
70 // Now initiate a policy fetch. | 70 // Now initiate a policy fetch. |
71 manager->core()->service()->RefreshPolicy(callback); | 71 manager->core()->service()->RefreshPolicy(callback); |
72 } | 72 } |
73 | 73 |
74 void UserPolicySigninServiceBase::Observe( | 74 void UserPolicySigninServiceBase::Observe( |
75 int type, | 75 int type, |
76 const content::NotificationSource& source, | 76 const content::NotificationSource& source, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 // If the user should not get policy, just bail out. | 158 // If the user should not get policy, just bail out. |
159 if (!policy_manager() || !ShouldLoadPolicyForUser(username)) { | 159 if (!policy_manager() || !ShouldLoadPolicyForUser(username)) { |
160 DVLOG(1) << "Signed in user is not in the whitelist"; | 160 DVLOG(1) << "Signed in user is not in the whitelist"; |
161 return scoped_ptr<CloudPolicyClient>(); | 161 return scoped_ptr<CloudPolicyClient>(); |
162 } | 162 } |
163 | 163 |
164 // If the DeviceManagementService is not yet initialized, start it up now. | 164 // If the DeviceManagementService is not yet initialized, start it up now. |
165 device_management_service_->ScheduleInitialization(0); | 165 device_management_service_->ScheduleInitialization(0); |
166 | 166 |
167 // Create a new CloudPolicyClient for fetching the DMToken. | 167 // Create a new CloudPolicyClient for fetching the DMToken. |
168 return UserCloudPolicyManager::CreateCloudPolicyClient( | 168 return policy_manager()->CreateCloudPolicyClient( |
169 device_management_service_, CreateSystemRequestContext()); | 169 device_management_service_, CreateSystemRequestContext()); |
170 } | 170 } |
171 | 171 |
172 bool UserPolicySigninServiceBase::ShouldLoadPolicyForUser( | 172 bool UserPolicySigninServiceBase::ShouldLoadPolicyForUser( |
173 const std::string& username) { | 173 const std::string& username) { |
174 if (username.empty()) | 174 if (username.empty()) |
175 return false; // Not signed in. | 175 return false; // Not signed in. |
176 | 176 |
177 if (ShouldForceLoadPolicy()) | 177 if (ShouldForceLoadPolicy()) |
178 return true; | 178 return true; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 } | 212 } |
213 | 213 |
214 UserCloudPolicyManager* manager = policy_manager(); | 214 UserCloudPolicyManager* manager = policy_manager(); |
215 // Initialize the UCPM if it is not already initialized. | 215 // Initialize the UCPM if it is not already initialized. |
216 if (!manager->core()->service()) { | 216 if (!manager->core()->service()) { |
217 // If there is no cached DMToken then we can detect this when the | 217 // If there is no cached DMToken then we can detect this when the |
218 // OnInitializationCompleted() callback is invoked and this will | 218 // OnInitializationCompleted() callback is invoked and this will |
219 // initiate a policy fetch. | 219 // initiate a policy fetch. |
220 InitializeUserCloudPolicyManager( | 220 InitializeUserCloudPolicyManager( |
221 username, | 221 username, |
222 UserCloudPolicyManager::CreateCloudPolicyClient( | 222 manager->CreateCloudPolicyClient( |
223 device_management_service_, | 223 device_management_service_, |
224 CreateUserRequestContext(profile_request_context)).Pass()); | 224 CreateUserRequestContext(profile_request_context)).Pass()); |
225 } else { | 225 } else { |
226 manager->SetSigninUsername(username); | 226 manager->SetSigninUsername(username); |
227 } | 227 } |
228 | 228 |
229 // If the CloudPolicyService is initialized, kick off registration. | 229 // If the CloudPolicyService is initialized, kick off registration. |
230 // Otherwise OnInitializationCompleted is invoked as soon as the service | 230 // Otherwise OnInitializationCompleted is invoked as soon as the service |
231 // finishes its initialization. | 231 // finishes its initialization. |
232 if (manager->core()->service()->IsInitializationComplete()) | 232 if (manager->core()->service()->IsInitializationComplete()) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 scoped_refptr<net::URLRequestContextGetter> | 268 scoped_refptr<net::URLRequestContextGetter> |
269 UserPolicySigninServiceBase::CreateUserRequestContext( | 269 UserPolicySigninServiceBase::CreateUserRequestContext( |
270 scoped_refptr<net::URLRequestContextGetter> profile_request_context) { | 270 scoped_refptr<net::URLRequestContextGetter> profile_request_context) { |
271 return new UserPolicyRequestContext( | 271 return new UserPolicyRequestContext( |
272 profile_request_context, | 272 profile_request_context, |
273 system_request_context(), | 273 system_request_context(), |
274 content::GetUserAgent(GURL(device_management_service_->GetServerUrl()))); | 274 content::GetUserAgent(GURL(device_management_service_->GetServerUrl()))); |
275 } | 275 } |
276 | 276 |
277 } // namespace policy | 277 } // namespace policy |
OLD | NEW |