| 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 <utility> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/location.h" | 10 #include "base/location.h" |
| 9 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 10 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
| 11 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 12 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
| 13 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" | 15 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/signin/signin_manager_factory.h" | 17 #include "chrome/browser/signin/signin_manager_factory.h" |
| 16 #include "chrome/common/chrome_content_client.h" | 18 #include "chrome/common/chrome_content_client.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 device_management_service_, profile_request_context); | 59 device_management_service_, profile_request_context); |
| 58 client->SetupRegistration(dm_token, client_id); | 60 client->SetupRegistration(dm_token, client_id); |
| 59 DCHECK(client->is_registered()); | 61 DCHECK(client->is_registered()); |
| 60 // The user has just signed in, so the UserCloudPolicyManager should not yet | 62 // The user has just signed in, so the UserCloudPolicyManager should not yet |
| 61 // be initialized. This routine will initialize the UserCloudPolicyManager | 63 // be initialized. This routine will initialize the UserCloudPolicyManager |
| 62 // with the passed client and will proactively ask the client to fetch | 64 // with the passed client and will proactively ask the client to fetch |
| 63 // policy without waiting for the CloudPolicyService to finish initialization. | 65 // policy without waiting for the CloudPolicyService to finish initialization. |
| 64 UserCloudPolicyManager* manager = policy_manager(); | 66 UserCloudPolicyManager* manager = policy_manager(); |
| 65 DCHECK(manager); | 67 DCHECK(manager); |
| 66 DCHECK(!manager->core()->client()); | 68 DCHECK(!manager->core()->client()); |
| 67 InitializeUserCloudPolicyManager(username, client.Pass()); | 69 InitializeUserCloudPolicyManager(username, std::move(client)); |
| 68 DCHECK(manager->IsClientRegistered()); | 70 DCHECK(manager->IsClientRegistered()); |
| 69 | 71 |
| 70 // Now initiate a policy fetch. | 72 // Now initiate a policy fetch. |
| 71 manager->core()->service()->RefreshPolicy(callback); | 73 manager->core()->service()->RefreshPolicy(callback); |
| 72 } | 74 } |
| 73 | 75 |
| 74 void UserPolicySigninServiceBase::GoogleSignedOut(const std::string& account_id, | 76 void UserPolicySigninServiceBase::GoogleSignedOut(const std::string& account_id, |
| 75 const std::string& username) { | 77 const std::string& username) { |
| 76 ShutdownUserCloudPolicyManager(); | 78 ShutdownUserCloudPolicyManager(); |
| 77 } | 79 } |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 | 235 |
| 234 void UserPolicySigninServiceBase::InitializeUserCloudPolicyManager( | 236 void UserPolicySigninServiceBase::InitializeUserCloudPolicyManager( |
| 235 const std::string& username, | 237 const std::string& username, |
| 236 scoped_ptr<CloudPolicyClient> client) { | 238 scoped_ptr<CloudPolicyClient> client) { |
| 237 DCHECK(client); | 239 DCHECK(client); |
| 238 UserCloudPolicyManager* manager = policy_manager(); | 240 UserCloudPolicyManager* manager = policy_manager(); |
| 239 manager->SetSigninUsername(username); | 241 manager->SetSigninUsername(username); |
| 240 DCHECK(!manager->core()->client()); | 242 DCHECK(!manager->core()->client()); |
| 241 scoped_refptr<net::URLRequestContextGetter> context = | 243 scoped_refptr<net::URLRequestContextGetter> context = |
| 242 client->GetRequestContext(); | 244 client->GetRequestContext(); |
| 243 manager->Connect(local_state_, context, client.Pass()); | 245 manager->Connect(local_state_, context, std::move(client)); |
| 244 DCHECK(manager->core()->service()); | 246 DCHECK(manager->core()->service()); |
| 245 | 247 |
| 246 // Observe the client to detect errors fetching policy. | 248 // Observe the client to detect errors fetching policy. |
| 247 manager->core()->client()->AddObserver(this); | 249 manager->core()->client()->AddObserver(this); |
| 248 // Observe the service to determine when it's initialized. | 250 // Observe the service to determine when it's initialized. |
| 249 manager->core()->service()->AddObserver(this); | 251 manager->core()->service()->AddObserver(this); |
| 250 } | 252 } |
| 251 | 253 |
| 252 void UserPolicySigninServiceBase::ShutdownUserCloudPolicyManager() { | 254 void UserPolicySigninServiceBase::ShutdownUserCloudPolicyManager() { |
| 253 PrepareForUserCloudPolicyManagerShutdown(); | 255 PrepareForUserCloudPolicyManagerShutdown(); |
| 254 UserCloudPolicyManager* manager = policy_manager(); | 256 UserCloudPolicyManager* manager = policy_manager(); |
| 255 if (manager) | 257 if (manager) |
| 256 manager->DisconnectAndRemovePolicy(); | 258 manager->DisconnectAndRemovePolicy(); |
| 257 } | 259 } |
| 258 | 260 |
| 259 scoped_refptr<net::URLRequestContextGetter> | 261 scoped_refptr<net::URLRequestContextGetter> |
| 260 UserPolicySigninServiceBase::CreateSystemRequestContext() { | 262 UserPolicySigninServiceBase::CreateSystemRequestContext() { |
| 261 return new SystemPolicyRequestContext( | 263 return new SystemPolicyRequestContext( |
| 262 system_request_context(), GetUserAgent()); | 264 system_request_context(), GetUserAgent()); |
| 263 } | 265 } |
| 264 | 266 |
| 265 } // namespace policy | 267 } // namespace policy |
| OLD | NEW |