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

Side by Side Diff: chrome/browser/chromeos/policy/browser_policy_connector_chromeos.cc

Issue 247283007: Add ScopedStubEnterpriseInstallAttributes for tests to set test install attributes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 months 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/browser_policy_connector_chromeos.h" 5 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
6 6
7 #include <string> 7 #include <string>
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 77 }
78 return kDefaultConsumerDeviceManagementServerUrl; 78 return kDefaultConsumerDeviceManagementServerUrl;
79 }; 79 };
80 80
81 } // namespace 81 } // namespace
82 82
83 BrowserPolicyConnectorChromeOS::BrowserPolicyConnectorChromeOS() 83 BrowserPolicyConnectorChromeOS::BrowserPolicyConnectorChromeOS()
84 : device_cloud_policy_manager_(NULL), 84 : device_cloud_policy_manager_(NULL),
85 global_user_cloud_policy_provider_(NULL), 85 global_user_cloud_policy_provider_(NULL),
86 weak_ptr_factory_(this) { 86 weak_ptr_factory_(this) {
87 if (g_testing_install_attributes) 87 if (g_testing_install_attributes) {
88 install_attributes_.reset(g_testing_install_attributes); 88 install_attributes_.reset(g_testing_install_attributes);
89 g_testing_install_attributes = NULL;
90 }
89 91
90 // SystemSaltGetter or DBusThreadManager may be uninitialized on unit tests. 92 // SystemSaltGetter or DBusThreadManager may be uninitialized on unit tests.
91 93
92 // TODO(satorux): Remove SystemSaltGetter::IsInitialized() when it's ready 94 // TODO(satorux): Remove SystemSaltGetter::IsInitialized() when it's ready
93 // (removing it now breaks tests). crbug.com/141016. 95 // (removing it now breaks tests). crbug.com/141016.
94 if (chromeos::SystemSaltGetter::IsInitialized() && 96 if (chromeos::SystemSaltGetter::IsInitialized() &&
95 chromeos::DBusThreadManager::IsInitialized()) { 97 chromeos::DBusThreadManager::IsInitialized()) {
96 chromeos::CryptohomeClient* cryptohome_client = 98 chromeos::CryptohomeClient* cryptohome_client =
97 chromeos::DBusThreadManager::Get()->GetCryptohomeClient(); 99 chromeos::DBusThreadManager::Get()->GetCryptohomeClient();
98 if (!g_testing_install_attributes) { 100 if (!install_attributes_) {
99 install_attributes_.reset( 101 install_attributes_.reset(
100 new EnterpriseInstallAttributes(cryptohome_client)); 102 new EnterpriseInstallAttributes(cryptohome_client));
101 } 103 }
102 base::FilePath install_attrs_file; 104 base::FilePath install_attrs_file;
103 CHECK(PathService::Get(chromeos::FILE_INSTALL_ATTRIBUTES, 105 CHECK(PathService::Get(chromeos::FILE_INSTALL_ATTRIBUTES,
104 &install_attrs_file)); 106 &install_attrs_file));
105 install_attributes_->ReadCacheFile(install_attrs_file); 107 install_attributes_->ReadCacheFile(install_attrs_file);
106 108
107 scoped_ptr<DeviceCloudPolicyStoreChromeOS> device_cloud_policy_store( 109 scoped_ptr<DeviceCloudPolicyStoreChromeOS> device_cloud_policy_store(
108 new DeviceCloudPolicyStoreChromeOS( 110 new DeviceCloudPolicyStoreChromeOS(
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 ConfigurationPolicyProvider* user_policy_provider) { 238 ConfigurationPolicyProvider* user_policy_provider) {
237 global_user_cloud_policy_provider_->SetDelegate(user_policy_provider); 239 global_user_cloud_policy_provider_->SetDelegate(user_policy_provider);
238 } 240 }
239 241
240 void BrowserPolicyConnectorChromeOS::SetInstallAttributesForTesting( 242 void BrowserPolicyConnectorChromeOS::SetInstallAttributesForTesting(
241 EnterpriseInstallAttributes* attributes) { 243 EnterpriseInstallAttributes* attributes) {
242 DCHECK(!g_testing_install_attributes); 244 DCHECK(!g_testing_install_attributes);
243 g_testing_install_attributes = attributes; 245 g_testing_install_attributes = attributes;
244 } 246 }
245 247
248 void BrowserPolicyConnectorChromeOS::RemoveInstallAttributesForTesting() {
249 if (g_testing_install_attributes) {
250 delete g_testing_install_attributes;
251 g_testing_install_attributes = NULL;
252 }
253 }
254
246 // static 255 // static
247 void BrowserPolicyConnectorChromeOS::RegisterPrefs( 256 void BrowserPolicyConnectorChromeOS::RegisterPrefs(
248 PrefRegistrySimple* registry) { 257 PrefRegistrySimple* registry) {
249 registry->RegisterIntegerPref( 258 registry->RegisterIntegerPref(
250 prefs::kDevicePolicyRefreshRate, 259 prefs::kDevicePolicyRefreshRate,
251 CloudPolicyRefreshScheduler::kDefaultRefreshDelayMs); 260 CloudPolicyRefreshScheduler::kDefaultRefreshDelayMs);
252 } 261 }
253 262
254 void BrowserPolicyConnectorChromeOS::SetTimezoneIfPolicyAvailable() { 263 void BrowserPolicyConnectorChromeOS::SetTimezoneIfPolicyAvailable() {
255 typedef chromeos::CrosSettingsProvider Provider; 264 typedef chromeos::CrosSettingsProvider Provider;
256 Provider::TrustedStatus result = 265 Provider::TrustedStatus result =
257 chromeos::CrosSettings::Get()->PrepareTrustedValues(base::Bind( 266 chromeos::CrosSettings::Get()->PrepareTrustedValues(base::Bind(
258 &BrowserPolicyConnectorChromeOS::SetTimezoneIfPolicyAvailable, 267 &BrowserPolicyConnectorChromeOS::SetTimezoneIfPolicyAvailable,
259 weak_ptr_factory_.GetWeakPtr())); 268 weak_ptr_factory_.GetWeakPtr()));
260 269
261 if (result != Provider::TRUSTED) 270 if (result != Provider::TRUSTED)
262 return; 271 return;
263 272
264 std::string timezone; 273 std::string timezone;
265 if (chromeos::CrosSettings::Get()->GetString(chromeos::kSystemTimezonePolicy, 274 if (chromeos::CrosSettings::Get()->GetString(chromeos::kSystemTimezonePolicy,
266 &timezone) && 275 &timezone) &&
267 !timezone.empty()) { 276 !timezone.empty()) {
268 chromeos::system::TimezoneSettings::GetInstance()->SetTimezoneFromID( 277 chromeos::system::TimezoneSettings::GetInstance()->SetTimezoneFromID(
269 base::UTF8ToUTF16(timezone)); 278 base::UTF8ToUTF16(timezone));
270 } 279 }
271 } 280 }
272 281
273 } // namespace policy 282 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698