| 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 "base/prefs/pref_service.h" | |
| 11 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/policy/browser_policy_connector.h" | 11 #include "chrome/browser/policy/browser_policy_connector.h" |
| 13 #include "chrome/browser/policy/cloud/device_management_service.h" | 12 #include "chrome/browser/policy/cloud/device_management_service.h" |
| 14 #include "chrome/browser/policy/cloud/user_cloud_policy_manager.h" | 13 #include "chrome/browser/policy/cloud/user_cloud_policy_manager.h" |
| 15 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" | 14 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" |
| 16 #include "chrome/browser/profiles/profile.h" | |
| 17 #include "chrome/browser/signin/signin_manager.h" | 15 #include "chrome/browser/signin/signin_manager.h" |
| 18 #include "chrome/browser/signin/signin_manager_factory.h" | 16 #include "chrome/browser/signin/signin_manager_factory.h" |
| 19 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/pref_names.h" | |
| 21 #include "content/public/browser/notification_source.h" | 18 #include "content/public/browser/notification_source.h" |
| 22 #include "net/url_request/url_request_context_getter.h" | 19 #include "net/url_request/url_request_context_getter.h" |
| 23 | 20 |
| 24 namespace policy { | 21 namespace policy { |
| 25 | 22 |
| 26 UserPolicySigninServiceBase::UserPolicySigninServiceBase( | 23 UserPolicySigninServiceBase::UserPolicySigninServiceBase( |
| 27 Profile* profile, | 24 Profile* profile, |
| 28 PrefService* local_state, | 25 PrefService* local_state, |
| 29 scoped_refptr<net::URLRequestContextGetter> request_context, | 26 scoped_refptr<net::URLRequestContextGetter> request_context, |
| 30 DeviceManagementService* device_management_service) | 27 DeviceManagementService* device_management_service) |
| 31 : profile_(profile), | 28 : profile_(profile), |
| 32 local_state_(local_state), | 29 local_state_(local_state), |
| 33 request_context_(request_context), | 30 request_context_(request_context), |
| 34 device_management_service_(device_management_service), | 31 device_management_service_(device_management_service), |
| 35 weak_factory_(this) { | 32 weak_factory_(this) { |
| 36 if (profile_->GetPrefs()->GetBoolean(prefs::kDisableCloudPolicyOnSignin)) | |
| 37 return; | |
| 38 | |
| 39 // Initialize/shutdown the UserCloudPolicyManager when the user signs out. | 33 // Initialize/shutdown the UserCloudPolicyManager when the user signs out. |
| 40 registrar_.Add(this, | 34 registrar_.Add(this, |
| 41 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, | 35 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, |
| 42 content::Source<Profile>(profile)); | 36 content::Source<Profile>(profile)); |
| 43 | 37 |
| 44 // 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 |
| 45 // initializing, so we can startup the UserCloudPolicyManager. | 39 // initializing, so we can startup the UserCloudPolicyManager. |
| 46 registrar_.Add(this, | 40 registrar_.Add(this, |
| 47 chrome::NOTIFICATION_PROFILE_ADDED, | 41 chrome::NOTIFICATION_PROFILE_ADDED, |
| 48 content::Source<Profile>(profile)); | 42 content::Source<Profile>(profile)); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 // If the DeviceManagementService is not yet initialized, start it up now. | 162 // If the DeviceManagementService is not yet initialized, start it up now. |
| 169 device_management_service_->ScheduleInitialization(0); | 163 device_management_service_->ScheduleInitialization(0); |
| 170 | 164 |
| 171 // Create a new CloudPolicyClient for fetching the DMToken. | 165 // Create a new CloudPolicyClient for fetching the DMToken. |
| 172 return UserCloudPolicyManager::CreateCloudPolicyClient( | 166 return UserCloudPolicyManager::CreateCloudPolicyClient( |
| 173 device_management_service_); | 167 device_management_service_); |
| 174 } | 168 } |
| 175 | 169 |
| 176 bool UserPolicySigninServiceBase::ShouldLoadPolicyForUser( | 170 bool UserPolicySigninServiceBase::ShouldLoadPolicyForUser( |
| 177 const std::string& username) { | 171 const std::string& username) { |
| 178 if (profile_->GetPrefs()->GetBoolean(prefs::kDisableCloudPolicyOnSignin)) | |
| 179 return false; // Cloud policy is disabled. | |
| 180 | |
| 181 if (username.empty()) | 172 if (username.empty()) |
| 182 return false; // Not signed in. | 173 return false; // Not signed in. |
| 183 | 174 |
| 184 if (ShouldForceLoadPolicy()) | 175 if (ShouldForceLoadPolicy()) |
| 185 return true; | 176 return true; |
| 186 | 177 |
| 187 return !BrowserPolicyConnector::IsNonEnterpriseUser(username); | 178 return !BrowserPolicyConnector::IsNonEnterpriseUser(username); |
| 188 } | 179 } |
| 189 | 180 |
| 190 void UserPolicySigninServiceBase::InitializeOnProfileReady() { | 181 void UserPolicySigninServiceBase::InitializeOnProfileReady() { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 | 234 |
| 244 UserCloudPolicyManager* UserPolicySigninServiceBase::GetManager() { | 235 UserCloudPolicyManager* UserPolicySigninServiceBase::GetManager() { |
| 245 return UserCloudPolicyManagerFactory::GetForProfile(profile_); | 236 return UserCloudPolicyManagerFactory::GetForProfile(profile_); |
| 246 } | 237 } |
| 247 | 238 |
| 248 SigninManager* UserPolicySigninServiceBase::GetSigninManager() { | 239 SigninManager* UserPolicySigninServiceBase::GetSigninManager() { |
| 249 return SigninManagerFactory::GetForProfile(profile_); | 240 return SigninManagerFactory::GetForProfile(profile_); |
| 250 } | 241 } |
| 251 | 242 |
| 252 } // namespace policy | 243 } // namespace policy |
| OLD | NEW |