| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" | 5 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 if (!user->HasGaiaAccount() || | 142 if (!user->HasGaiaAccount() || |
| 143 user->IsSupervised() || | 143 user->IsSupervised() || |
| 144 BrowserPolicyConnector::IsNonEnterpriseUser(username)) { | 144 BrowserPolicyConnector::IsNonEnterpriseUser(username)) { |
| 145 return scoped_ptr<UserCloudPolicyManagerChromeOS>(); | 145 return scoped_ptr<UserCloudPolicyManagerChromeOS>(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 policy::BrowserPolicyConnectorChromeOS* connector = | 148 policy::BrowserPolicyConnectorChromeOS* connector = |
| 149 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 149 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 150 const bool is_browser_restart = | 150 const bool is_browser_restart = |
| 151 command_line->HasSwitch(chromeos::switches::kLoginUser); | 151 command_line->HasSwitch(chromeos::switches::kLoginUser); |
| 152 const user_manager::UserManager* const user_manager = | 152 const bool wait_for_initial_policy = !is_browser_restart; |
| 153 user_manager::UserManager::Get(); | |
| 154 | 153 |
| 155 // We want to block for policy in a few situations: if the user is new, or | 154 const base::TimeDelta initial_policy_fetch_timeout = |
| 156 // if we are forcing an online signin. An online signin will be forced if | 155 user_manager::UserManager::Get()->IsCurrentUserNew() |
| 157 // there has been a credential error, or if the initial session creation | 156 ? base::TimeDelta::Max() |
| 158 // was not completed (the oauth_token_status is not set to valid by | 157 : base::TimeDelta::FromSeconds(kInitialPolicyFetchTimeoutSeconds); |
| 159 // OAuth2LoginManager until profile creation/session restore is complete). | |
| 160 const bool block_forever_for_policy = | |
| 161 !user_manager->IsLoggedInAsStub() && | |
| 162 (user_manager->IsCurrentUserNew() || | |
| 163 user_manager->GetActiveUser()->force_online_signin() || | |
| 164 user_manager->GetActiveUser()->oauth_token_status() != | |
| 165 user_manager::User::OAUTH2_TOKEN_STATUS_VALID); | |
| 166 | |
| 167 const bool wait_for_policy_fetch = | |
| 168 block_forever_for_policy || !is_browser_restart; | |
| 169 | |
| 170 base::TimeDelta initial_policy_fetch_timeout; | |
| 171 if (block_forever_for_policy) { | |
| 172 initial_policy_fetch_timeout = base::TimeDelta::Max(); | |
| 173 } else if (wait_for_policy_fetch) { | |
| 174 initial_policy_fetch_timeout = | |
| 175 base::TimeDelta::FromSeconds(kInitialPolicyFetchTimeoutSeconds); | |
| 176 } | |
| 177 | 158 |
| 178 DeviceManagementService* device_management_service = | 159 DeviceManagementService* device_management_service = |
| 179 connector->device_management_service(); | 160 connector->device_management_service(); |
| 180 if (wait_for_policy_fetch) | 161 if (wait_for_initial_policy) |
| 181 device_management_service->ScheduleInitialization(0); | 162 device_management_service->ScheduleInitialization(0); |
| 182 | 163 |
| 183 base::FilePath profile_dir = profile->GetPath(); | 164 base::FilePath profile_dir = profile->GetPath(); |
| 184 const base::FilePath legacy_dir = profile_dir.Append(kDeviceManagementDir); | 165 const base::FilePath legacy_dir = profile_dir.Append(kDeviceManagementDir); |
| 185 const base::FilePath policy_cache_file = legacy_dir.Append(kPolicy); | 166 const base::FilePath policy_cache_file = legacy_dir.Append(kPolicy); |
| 186 const base::FilePath token_cache_file = legacy_dir.Append(kToken); | 167 const base::FilePath token_cache_file = legacy_dir.Append(kToken); |
| 187 const base::FilePath component_policy_cache_dir = | 168 const base::FilePath component_policy_cache_dir = |
| 188 profile_dir.Append(kPolicy).Append(kComponentsDir); | 169 profile_dir.Append(kPolicy).Append(kComponentsDir); |
| 189 const base::FilePath external_data_dir = | 170 const base::FilePath external_data_dir = |
| 190 profile_dir.Append(kPolicy).Append(kPolicyExternalDataDir); | 171 profile_dir.Append(kPolicy).Append(kPolicyExternalDataDir); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 213 if (force_immediate_load) | 194 if (force_immediate_load) |
| 214 store->LoadImmediately(); | 195 store->LoadImmediately(); |
| 215 | 196 |
| 216 scoped_refptr<base::SequencedTaskRunner> file_task_runner = | 197 scoped_refptr<base::SequencedTaskRunner> file_task_runner = |
| 217 content::BrowserThread::GetMessageLoopProxyForThread( | 198 content::BrowserThread::GetMessageLoopProxyForThread( |
| 218 content::BrowserThread::FILE); | 199 content::BrowserThread::FILE); |
| 219 | 200 |
| 220 scoped_ptr<UserCloudPolicyManagerChromeOS> manager( | 201 scoped_ptr<UserCloudPolicyManagerChromeOS> manager( |
| 221 new UserCloudPolicyManagerChromeOS( | 202 new UserCloudPolicyManagerChromeOS( |
| 222 std::move(store), std::move(external_data_manager), | 203 std::move(store), std::move(external_data_manager), |
| 223 component_policy_cache_dir, wait_for_policy_fetch, | 204 component_policy_cache_dir, wait_for_initial_policy, |
| 224 initial_policy_fetch_timeout, base::ThreadTaskRunnerHandle::Get(), | 205 initial_policy_fetch_timeout, base::ThreadTaskRunnerHandle::Get(), |
| 225 file_task_runner, io_task_runner)); | 206 file_task_runner, io_task_runner)); |
| 226 | 207 |
| 227 bool wildcard_match = false; | 208 bool wildcard_match = false; |
| 228 if (connector->IsEnterpriseManaged() && | 209 if (connector->IsEnterpriseManaged() && |
| 229 chromeos::CrosSettings::IsWhitelisted(username, &wildcard_match) && | 210 chromeos::CrosSettings::IsWhitelisted(username, &wildcard_match) && |
| 230 wildcard_match && !connector->IsNonEnterpriseUser(username)) { | 211 wildcard_match && !connector->IsNonEnterpriseUser(username)) { |
| 231 manager->EnableWildcardLoginCheck(username); | 212 manager->EnableWildcardLoginCheck(username); |
| 232 } | 213 } |
| 233 | 214 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 263 | 244 |
| 264 bool UserCloudPolicyManagerFactoryChromeOS::HasTestingFactory( | 245 bool UserCloudPolicyManagerFactoryChromeOS::HasTestingFactory( |
| 265 content::BrowserContext* context) { | 246 content::BrowserContext* context) { |
| 266 return false; | 247 return false; |
| 267 } | 248 } |
| 268 | 249 |
| 269 void UserCloudPolicyManagerFactoryChromeOS::CreateServiceNow( | 250 void UserCloudPolicyManagerFactoryChromeOS::CreateServiceNow( |
| 270 content::BrowserContext* context) {} | 251 content::BrowserContext* context) {} |
| 271 | 252 |
| 272 } // namespace policy | 253 } // namespace policy |
| OLD | NEW |