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

Side by Side Diff: chrome/browser/chromeos/ownership/owner_settings_service_chromeos.cc

Issue 654263003: Implemented OwnerSettingsService::Set() method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed crashes under asan. Created 6 years, 1 month 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/ownership/owner_settings_service_chromeos.h" 5 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
14 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
15 #include "chrome/browser/chrome_notification_types.h" 15 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/chromeos/profiles/profile_helper.h" 16 #include "chrome/browser/chromeos/profiles/profile_helper.h"
17 #include "chrome/browser/chromeos/settings/cros_settings.h" 17 #include "chrome/browser/chromeos/settings/cros_settings.h"
18 #include "chrome/browser/chromeos/settings/device_settings_provider.h"
18 #include "chrome/browser/chromeos/settings/session_manager_operation.h" 19 #include "chrome/browser/chromeos/settings/session_manager_operation.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
20 #include "chromeos/dbus/dbus_thread_manager.h" 21 #include "chromeos/dbus/dbus_thread_manager.h"
21 #include "chromeos/tpm_token_loader.h" 22 #include "chromeos/tpm_token_loader.h"
22 #include "components/ownership/owner_key_util.h" 23 #include "components/ownership/owner_key_util.h"
23 #include "components/policy/core/common/cloud/cloud_policy_constants.h" 24 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
24 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
25 #include "content/public/browser/notification_details.h" 26 #include "content/public/browser/notification_details.h"
26 #include "content/public/browser/notification_service.h" 27 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/notification_source.h" 28 #include "content/public/browser/notification_source.h"
28 #include "content/public/common/content_switches.h" 29 #include "content/public/common/content_switches.h"
29 #include "crypto/nss_util.h" 30 #include "crypto/nss_util.h"
30 #include "crypto/nss_util_internal.h" 31 #include "crypto/nss_util_internal.h"
31 #include "crypto/rsa_private_key.h" 32 #include "crypto/rsa_private_key.h"
32 #include "crypto/scoped_nss_types.h" 33 #include "crypto/scoped_nss_types.h"
33 #include "crypto/signature_creator.h" 34 #include "crypto/signature_creator.h"
34 35
35 namespace em = enterprise_management; 36 namespace em = enterprise_management;
36 37
37 using content::BrowserThread; 38 using content::BrowserThread;
38 using ownership::OwnerKeyUtil; 39 using ownership::OwnerKeyUtil;
39 using ownership::PrivateKey; 40 using ownership::PrivateKey;
40 using ownership::PublicKey; 41 using ownership::PublicKey;
41 42
42 namespace chromeos { 43 namespace chromeos {
43 44
44 namespace { 45 namespace {
45 46
46 DeviceSettingsService* g_device_settings_service_for_testing = NULL;
47
48 bool IsOwnerInTests(const std::string& user_id) { 47 bool IsOwnerInTests(const std::string& user_id) {
49 if (user_id.empty() || 48 if (user_id.empty() ||
50 !CommandLine::ForCurrentProcess()->HasSwitch(::switches::kTestType) || 49 !CommandLine::ForCurrentProcess()->HasSwitch(::switches::kTestType) ||
51 !CrosSettings::IsInitialized()) { 50 !CrosSettings::IsInitialized()) {
52 return false; 51 return false;
53 } 52 }
54 const base::Value* value = CrosSettings::Get()->GetPref(kDeviceOwner); 53 const base::Value* value = CrosSettings::Get()->GetPref(kDeviceOwner);
55 if (!value || value->GetType() != base::Value::TYPE_STRING) 54 if (!value || value->GetType() != base::Value::TYPE_STRING)
56 return false; 55 return false;
57 return static_cast<const base::StringValue*>(value)->GetString() == user_id; 56 return static_cast<const base::StringValue*>(value)->GetString() == user_id;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 scoped_refptr<base::TaskRunner> task_runner = 139 scoped_refptr<base::TaskRunner> task_runner =
141 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( 140 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
142 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 141 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
143 base::PostTaskAndReplyWithResult( 142 base::PostTaskAndReplyWithResult(
144 task_runner.get(), 143 task_runner.get(),
145 FROM_HERE, 144 FROM_HERE,
146 base::Bind(&DoesPrivateKeyExistAsyncHelper, owner_key_util), 145 base::Bind(&DoesPrivateKeyExistAsyncHelper, owner_key_util),
147 callback); 146 callback);
148 } 147 }
149 148
150 DeviceSettingsService* GetDeviceSettingsService() {
151 if (g_device_settings_service_for_testing)
152 return g_device_settings_service_for_testing;
153 return DeviceSettingsService::IsInitialized() ? DeviceSettingsService::Get()
154 : NULL;
155 }
156
157 } // namespace 149 } // namespace
158 150
159 OwnerSettingsServiceChromeOS::OwnerSettingsServiceChromeOS( 151 OwnerSettingsServiceChromeOS::OwnerSettingsServiceChromeOS(
152 DeviceSettingsService* device_settings_service,
160 Profile* profile, 153 Profile* profile,
161 const scoped_refptr<OwnerKeyUtil>& owner_key_util) 154 const scoped_refptr<OwnerKeyUtil>& owner_key_util)
162 : ownership::OwnerSettingsService(owner_key_util), 155 : ownership::OwnerSettingsService(owner_key_util),
156 device_settings_service_(device_settings_service),
163 profile_(profile), 157 profile_(profile),
164 waiting_for_profile_creation_(true), 158 waiting_for_profile_creation_(true),
165 waiting_for_tpm_token_(true), 159 waiting_for_tpm_token_(true),
166 weak_factory_(this) { 160 has_pending_changes_(false),
161 weak_factory_(this),
162 store_settings_factory_(this) {
167 if (TPMTokenLoader::IsInitialized()) { 163 if (TPMTokenLoader::IsInitialized()) {
168 TPMTokenLoader::TPMTokenStatus tpm_token_status = 164 TPMTokenLoader::TPMTokenStatus tpm_token_status =
169 TPMTokenLoader::Get()->IsTPMTokenEnabled( 165 TPMTokenLoader::Get()->IsTPMTokenEnabled(
170 base::Bind(&OwnerSettingsServiceChromeOS::OnTPMTokenReady, 166 base::Bind(&OwnerSettingsServiceChromeOS::OnTPMTokenReady,
171 weak_factory_.GetWeakPtr())); 167 weak_factory_.GetWeakPtr()));
172 waiting_for_tpm_token_ = 168 waiting_for_tpm_token_ =
173 tpm_token_status == TPMTokenLoader::TPM_TOKEN_STATUS_UNDETERMINED; 169 tpm_token_status == TPMTokenLoader::TPM_TOKEN_STATUS_UNDETERMINED;
174 } 170 }
175 171
176 if (DBusThreadManager::IsInitialized() && 172 if (DBusThreadManager::IsInitialized() &&
177 DBusThreadManager::Get()->GetSessionManagerClient()) { 173 DBusThreadManager::Get()->GetSessionManagerClient()) {
178 DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this); 174 DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this);
179 } 175 }
180 176
177 if (device_settings_service_)
178 device_settings_service_->AddObserver(this);
179
181 registrar_.Add(this, 180 registrar_.Add(this,
182 chrome::NOTIFICATION_PROFILE_CREATED, 181 chrome::NOTIFICATION_PROFILE_CREATED,
183 content::Source<Profile>(profile_)); 182 content::Source<Profile>(profile_));
183
184 UpdateFromService();
184 } 185 }
185 186
186 OwnerSettingsServiceChromeOS::~OwnerSettingsServiceChromeOS() { 187 OwnerSettingsServiceChromeOS::~OwnerSettingsServiceChromeOS() {
187 DCHECK(thread_checker_.CalledOnValidThread()); 188 DCHECK(thread_checker_.CalledOnValidThread());
189
190 if (device_settings_service_)
191 device_settings_service_->RemoveObserver(this);
192
188 if (DBusThreadManager::IsInitialized() && 193 if (DBusThreadManager::IsInitialized() &&
189 DBusThreadManager::Get()->GetSessionManagerClient()) { 194 DBusThreadManager::Get()->GetSessionManagerClient()) {
190 DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this); 195 DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this);
191 } 196 }
192 } 197 }
193 198
194 void OwnerSettingsServiceChromeOS::OnTPMTokenReady( 199 void OwnerSettingsServiceChromeOS::OnTPMTokenReady(
195 bool /* tpm_token_enabled */) { 200 bool /* tpm_token_enabled */) {
196 DCHECK(thread_checker_.CalledOnValidThread()); 201 DCHECK(thread_checker_.CalledOnValidThread());
197 waiting_for_tpm_token_ = false; 202 waiting_for_tpm_token_ = false;
198 203
199 // TPMTokenLoader initializes the TPM and NSS database which is necessary to 204 // TPMTokenLoader initializes the TPM and NSS database which is necessary to
200 // determine ownership. Force a reload once we know these are initialized. 205 // determine ownership. Force a reload once we know these are initialized.
201 ReloadKeypair(); 206 ReloadKeypair();
202 } 207 }
203 208
204 void OwnerSettingsServiceChromeOS::SignAndStorePolicyAsync( 209 bool OwnerSettingsServiceChromeOS::HandlesSetting(const std::string& setting) {
205 scoped_ptr<em::PolicyData> policy, 210 return DeviceSettingsProvider::IsDeviceSetting(setting);
206 const base::Closure& callback) { 211 }
207 DCHECK(thread_checker_.CalledOnValidThread()); 212
208 SignAndStoreSettingsOperation* operation = new SignAndStoreSettingsOperation( 213 bool OwnerSettingsServiceChromeOS::Set(const std::string& setting,
209 base::Bind(&OwnerSettingsServiceChromeOS::HandleCompletedOperation, 214 const base::Value& value) {
210 weak_factory_.GetWeakPtr(), 215 if (!IsOwner() && !IsOwnerInTests(user_id_))
211 callback), 216 return false;
212 policy.Pass()); 217
213 operation->set_owner_settings_service(weak_factory_.GetWeakPtr()); 218 UpdateDeviceSettings(setting, value, device_settings_);
214 pending_operations_.push_back(operation); 219 em::PolicyData policy_data;
215 if (pending_operations_.front() == operation) 220 policy_data.set_username(user_id_);
216 StartNextOperation(); 221 CHECK(device_settings_.SerializeToString(policy_data.mutable_policy_value()));
222 FOR_EACH_OBSERVER(OwnerSettingsService::Observer,
223 observers_,
224 OnTentativeChangesInPolicy(policy_data));
225 has_pending_changes_ = true;
226 StoreDeviceSettings();
227 return true;
228 }
229
230 bool OwnerSettingsServiceChromeOS::CommitTentativeDeviceSettings(
231 scoped_ptr<enterprise_management::PolicyData> policy) {
232 if (!IsOwner() && !IsOwnerInTests(user_id_))
233 return false;
234 if (policy->username() != user_id_) {
235 LOG(ERROR) << "Username mismatch: " << policy->username() << " vs. "
236 << user_id_;
237 return false;
238 }
239 CHECK(device_settings_.ParseFromString(policy->policy_value()));
240 FOR_EACH_OBSERVER(OwnerSettingsService::Observer,
241 observers_,
242 OnTentativeChangesInPolicy(*policy));
243 has_pending_changes_ = true;
244 StoreDeviceSettings();
245 return true;
217 } 246 }
218 247
219 void OwnerSettingsServiceChromeOS::Observe( 248 void OwnerSettingsServiceChromeOS::Observe(
220 int type, 249 int type,
221 const content::NotificationSource& source, 250 const content::NotificationSource& source,
222 const content::NotificationDetails& details) { 251 const content::NotificationDetails& details) {
223 DCHECK(thread_checker_.CalledOnValidThread()); 252 DCHECK(thread_checker_.CalledOnValidThread());
224 if (type != chrome::NOTIFICATION_PROFILE_CREATED) { 253 if (type != chrome::NOTIFICATION_PROFILE_CREATED) {
225 NOTREACHED(); 254 NOTREACHED();
226 return; 255 return;
227 } 256 }
228 257
229 Profile* profile = content::Source<Profile>(source).ptr(); 258 Profile* profile = content::Source<Profile>(source).ptr();
230 if (profile != profile_) { 259 if (profile != profile_) {
231 NOTREACHED(); 260 NOTREACHED();
232 return; 261 return;
233 } 262 }
234 263
235 waiting_for_profile_creation_ = false; 264 waiting_for_profile_creation_ = false;
236 ReloadKeypair(); 265 ReloadKeypair();
237 } 266 }
238 267
239 void OwnerSettingsServiceChromeOS::OwnerKeySet(bool success) { 268 void OwnerSettingsServiceChromeOS::OwnerKeySet(bool success) {
240 DCHECK(thread_checker_.CalledOnValidThread()); 269 DCHECK(thread_checker_.CalledOnValidThread());
241 if (success) 270 if (success)
242 ReloadKeypair(); 271 ReloadKeypair();
243 } 272 }
244 273
274 void OwnerSettingsServiceChromeOS::OwnershipStatusChanged() {
275 DCHECK(thread_checker_.CalledOnValidThread());
276 StoreDeviceSettings();
277 }
278
279 void OwnerSettingsServiceChromeOS::DeviceSettingsUpdated() {
280 DCHECK(thread_checker_.CalledOnValidThread());
281 StoreDeviceSettings();
282 }
283
284 void OwnerSettingsServiceChromeOS::OnDeviceSettingsServiceShutdown() {
285 device_settings_service_ = nullptr;
286 }
287
245 // static 288 // static
246 void OwnerSettingsServiceChromeOS::IsOwnerForSafeModeAsync( 289 void OwnerSettingsServiceChromeOS::IsOwnerForSafeModeAsync(
247 const std::string& user_hash, 290 const std::string& user_hash,
248 const scoped_refptr<OwnerKeyUtil>& owner_key_util, 291 const scoped_refptr<OwnerKeyUtil>& owner_key_util,
249 const IsOwnerCallback& callback) { 292 const IsOwnerCallback& callback) {
250 CHECK(chromeos::LoginState::Get()->IsInSafeMode()); 293 CHECK(chromeos::LoginState::Get()->IsInSafeMode());
251 294
252 // Make sure NSS is initialized and NSS DB is loaded for the user before 295 // Make sure NSS is initialized and NSS DB is loaded for the user before
253 // searching for the owner key. 296 // searching for the owner key.
254 BrowserThread::PostTaskAndReply( 297 BrowserThread::PostTaskAndReply(
255 BrowserThread::IO, 298 BrowserThread::IO,
256 FROM_HERE, 299 FROM_HERE,
257 base::Bind(base::IgnoreResult(&crypto::InitializeNSSForChromeOSUser), 300 base::Bind(base::IgnoreResult(&crypto::InitializeNSSForChromeOSUser),
258 user_hash, 301 user_hash,
259 ProfileHelper::GetProfilePathByUserIdHash(user_hash)), 302 ProfileHelper::GetProfilePathByUserIdHash(user_hash)),
260 base::Bind(&DoesPrivateKeyExistAsync, owner_key_util, callback)); 303 base::Bind(&DoesPrivateKeyExistAsync, owner_key_util, callback));
261 } 304 }
262 305
263 // static 306 // static
264 void OwnerSettingsServiceChromeOS::SetDeviceSettingsServiceForTesting( 307 scoped_ptr<em::PolicyData> OwnerSettingsServiceChromeOS::AssemblePolicy(
265 DeviceSettingsService* device_settings_service) { 308 const std::string& user_id,
266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 309 const em::PolicyData* policy_data,
267 g_device_settings_service_for_testing = device_settings_service; 310 const em::ChromeDeviceSettingsProto* settings) {
311 scoped_ptr<em::PolicyData> policy(new em::PolicyData());
312 if (policy_data) {
313 // Preserve management settings.
314 if (policy_data->has_management_mode())
315 policy->set_management_mode(policy_data->management_mode());
316 if (policy_data->has_request_token())
317 policy->set_request_token(policy_data->request_token());
318 if (policy_data->has_device_id())
319 policy->set_device_id(policy_data->device_id());
320 } else {
321 // If there's no previous policy data, this is the first time the device
322 // setting is set. We set the management mode to NOT_MANAGED initially.
323 policy->set_management_mode(em::PolicyData::NOT_MANAGED);
324 }
325 policy->set_policy_type(policy::dm_protocol::kChromeDevicePolicyType);
326 policy->set_timestamp(
327 (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds());
328 policy->set_username(user_id);
329 if (!settings->SerializeToString(policy->mutable_policy_value()))
330 return scoped_ptr<em::PolicyData>();
331
332 return policy.Pass();
268 } 333 }
269 334
335 // static
336 void OwnerSettingsServiceChromeOS::UpdateDeviceSettings(
337 const std::string& path,
338 const base::Value& value,
339 enterprise_management::ChromeDeviceSettingsProto& settings) {
340 if (path == kAccountsPrefAllowNewUser) {
341 em::AllowNewUsersProto* allow = settings.mutable_allow_new_users();
342 bool allow_value;
343 if (value.GetAsBoolean(&allow_value)) {
344 allow->set_allow_new_users(allow_value);
345 } else {
346 NOTREACHED();
347 }
348 } else if (path == kAccountsPrefAllowGuest) {
349 em::GuestModeEnabledProto* guest = settings.mutable_guest_mode_enabled();
350 bool guest_value;
351 if (value.GetAsBoolean(&guest_value))
352 guest->set_guest_mode_enabled(guest_value);
353 else
354 NOTREACHED();
355 } else if (path == kAccountsPrefSupervisedUsersEnabled) {
356 em::SupervisedUsersSettingsProto* supervised =
357 settings.mutable_supervised_users_settings();
358 bool supervised_value;
359 if (value.GetAsBoolean(&supervised_value))
360 supervised->set_supervised_users_enabled(supervised_value);
361 else
362 NOTREACHED();
363 } else if (path == kAccountsPrefShowUserNamesOnSignIn) {
364 em::ShowUserNamesOnSigninProto* show = settings.mutable_show_user_names();
365 bool show_value;
366 if (value.GetAsBoolean(&show_value))
367 show->set_show_user_names(show_value);
368 else
369 NOTREACHED();
370 } else if (path == kAccountsPrefDeviceLocalAccounts) {
371 em::DeviceLocalAccountsProto* device_local_accounts =
372 settings.mutable_device_local_accounts();
373 device_local_accounts->clear_account();
374 const base::ListValue* accounts_list = NULL;
375 if (value.GetAsList(&accounts_list)) {
376 for (base::ListValue::const_iterator entry(accounts_list->begin());
377 entry != accounts_list->end();
378 ++entry) {
379 const base::DictionaryValue* entry_dict = NULL;
380 if ((*entry)->GetAsDictionary(&entry_dict)) {
381 em::DeviceLocalAccountInfoProto* account =
382 device_local_accounts->add_account();
383 std::string account_id;
384 if (entry_dict->GetStringWithoutPathExpansion(
385 kAccountsPrefDeviceLocalAccountsKeyId, &account_id)) {
386 account->set_account_id(account_id);
387 }
388 int type;
389 if (entry_dict->GetIntegerWithoutPathExpansion(
390 kAccountsPrefDeviceLocalAccountsKeyType, &type)) {
391 account->set_type(
392 static_cast<em::DeviceLocalAccountInfoProto::AccountType>(
393 type));
394 }
395 std::string kiosk_app_id;
396 if (entry_dict->GetStringWithoutPathExpansion(
397 kAccountsPrefDeviceLocalAccountsKeyKioskAppId,
398 &kiosk_app_id)) {
399 account->mutable_kiosk_app()->set_app_id(kiosk_app_id);
400 }
401 } else {
402 NOTREACHED();
403 }
404 }
405 } else {
406 NOTREACHED();
407 }
408 } else if (path == kAccountsPrefDeviceLocalAccountAutoLoginId) {
409 em::DeviceLocalAccountsProto* device_local_accounts =
410 settings.mutable_device_local_accounts();
411 std::string id;
412 if (value.GetAsString(&id))
413 device_local_accounts->set_auto_login_id(id);
414 else
415 NOTREACHED();
416 } else if (path == kAccountsPrefDeviceLocalAccountAutoLoginDelay) {
417 em::DeviceLocalAccountsProto* device_local_accounts =
418 settings.mutable_device_local_accounts();
419 int delay;
420 if (value.GetAsInteger(&delay))
421 device_local_accounts->set_auto_login_delay(delay);
422 else
423 NOTREACHED();
424 } else if (path == kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled) {
425 em::DeviceLocalAccountsProto* device_local_accounts =
426 settings.mutable_device_local_accounts();
427 bool enabled;
428 if (value.GetAsBoolean(&enabled))
429 device_local_accounts->set_enable_auto_login_bailout(enabled);
430 else
431 NOTREACHED();
432 } else if (path ==
433 kAccountsPrefDeviceLocalAccountPromptForNetworkWhenOffline) {
434 em::DeviceLocalAccountsProto* device_local_accounts =
435 settings.mutable_device_local_accounts();
436 bool should_prompt;
437 if (value.GetAsBoolean(&should_prompt))
438 device_local_accounts->set_prompt_for_network_when_offline(should_prompt);
439 else
440 NOTREACHED();
441 } else if (path == kSignedDataRoamingEnabled) {
442 em::DataRoamingEnabledProto* roam = settings.mutable_data_roaming_enabled();
443 bool roaming_value = false;
444 if (value.GetAsBoolean(&roaming_value))
445 roam->set_data_roaming_enabled(roaming_value);
446 else
447 NOTREACHED();
448 } else if (path == kReleaseChannel) {
449 em::ReleaseChannelProto* release_channel =
450 settings.mutable_release_channel();
451 std::string channel_value;
452 if (value.GetAsString(&channel_value))
453 release_channel->set_release_channel(channel_value);
454 else
455 NOTREACHED();
456 } else if (path == kStatsReportingPref) {
457 em::MetricsEnabledProto* metrics = settings.mutable_metrics_enabled();
458 bool metrics_value = false;
459 if (value.GetAsBoolean(&metrics_value))
460 metrics->set_metrics_enabled(metrics_value);
461 else
462 NOTREACHED();
463 } else if (path == kAccountsPrefUsers) {
464 em::UserWhitelistProto* whitelist_proto = settings.mutable_user_whitelist();
465 whitelist_proto->clear_user_whitelist();
466 const base::ListValue* users;
467 if (value.GetAsList(&users)) {
468 for (base::ListValue::const_iterator i = users->begin();
469 i != users->end();
470 ++i) {
471 std::string email;
472 if ((*i)->GetAsString(&email))
473 whitelist_proto->add_user_whitelist(email);
474 }
475 }
476 } else if (path == kAccountsPrefEphemeralUsersEnabled) {
477 em::EphemeralUsersEnabledProto* ephemeral_users_enabled =
478 settings.mutable_ephemeral_users_enabled();
479 bool ephemeral_users_enabled_value = false;
480 if (value.GetAsBoolean(&ephemeral_users_enabled_value)) {
481 ephemeral_users_enabled->set_ephemeral_users_enabled(
482 ephemeral_users_enabled_value);
483 } else {
484 NOTREACHED();
485 }
486 } else if (path == kAllowRedeemChromeOsRegistrationOffers) {
487 em::AllowRedeemChromeOsRegistrationOffersProto* allow_redeem_offers =
488 settings.mutable_allow_redeem_offers();
489 bool allow_redeem_offers_value;
490 if (value.GetAsBoolean(&allow_redeem_offers_value)) {
491 allow_redeem_offers->set_allow_redeem_offers(allow_redeem_offers_value);
492 } else {
493 NOTREACHED();
494 }
495 } else if (path == kStartUpFlags) {
496 em::StartUpFlagsProto* flags_proto = settings.mutable_start_up_flags();
497 flags_proto->Clear();
498 const base::ListValue* flags;
499 if (value.GetAsList(&flags)) {
500 for (base::ListValue::const_iterator i = flags->begin();
501 i != flags->end();
502 ++i) {
503 std::string flag;
504 if ((*i)->GetAsString(&flag))
505 flags_proto->add_flags(flag);
506 }
507 }
508 } else if (path == kSystemUse24HourClock) {
509 em::SystemUse24HourClockProto* use_24hour_clock_proto =
510 settings.mutable_use_24hour_clock();
511 use_24hour_clock_proto->Clear();
512 bool use_24hour_clock_value;
513 if (value.GetAsBoolean(&use_24hour_clock_value)) {
514 use_24hour_clock_proto->set_use_24hour_clock(use_24hour_clock_value);
515 } else {
516 NOTREACHED();
517 }
518 } else if (path == kAttestationForContentProtectionEnabled) {
519 em::AttestationSettingsProto* attestation_settings =
520 settings.mutable_attestation_settings();
521 bool setting_enabled;
522 if (value.GetAsBoolean(&setting_enabled)) {
523 attestation_settings->set_content_protection_enabled(setting_enabled);
524 } else {
525 NOTREACHED();
526 }
527 } else {
528 // The remaining settings don't support Set(), since they are not
529 // intended to be customizable by the user:
530 // kAccountsPrefTransferSAMLCookies
531 // kAppPack
532 // kDeviceAttestationEnabled
533 // kDeviceOwner
534 // kIdleLogoutTimeout
535 // kIdleLogoutWarningDuration
536 // kReleaseChannelDelegated
537 // kReportDeviceActivityTimes
538 // kReportDeviceBootMode
539 // kReportDeviceLocation
540 // kReportDeviceVersionInfo
541 // kReportDeviceNetworkInterfaces
542 // kReportDeviceUsers
543 // kScreenSaverExtensionId
544 // kScreenSaverTimeout
545 // kServiceAccountIdentity
546 // kStartUpUrls
547 // kSystemTimezonePolicy
548 // kVariationsRestrictParameter
549
550 LOG(FATAL) << "Device setting " << path << " is read-only.";
551 }
552 }
553
270 void OwnerSettingsServiceChromeOS::OnPostKeypairLoadedActions() { 554 void OwnerSettingsServiceChromeOS::OnPostKeypairLoadedActions() {
271 DCHECK(thread_checker_.CalledOnValidThread()); 555 DCHECK(thread_checker_.CalledOnValidThread());
272 556
273 user_id_ = profile_->GetProfileName(); 557 user_id_ = profile_->GetProfileName();
274 const bool is_owner = IsOwner() || IsOwnerInTests(user_id_); 558 const bool is_owner = IsOwner() || IsOwnerInTests(user_id_);
275 if (is_owner && GetDeviceSettingsService()) 559 if (is_owner && device_settings_service_)
276 GetDeviceSettingsService()->InitOwner(user_id_, weak_factory_.GetWeakPtr()); 560 device_settings_service_->InitOwner(user_id_, weak_factory_.GetWeakPtr());
277 } 561 }
278 562
279 void OwnerSettingsServiceChromeOS::ReloadKeypairImpl(const base::Callback< 563 void OwnerSettingsServiceChromeOS::ReloadKeypairImpl(const base::Callback<
280 void(const scoped_refptr<PublicKey>& public_key, 564 void(const scoped_refptr<PublicKey>& public_key,
281 const scoped_refptr<PrivateKey>& private_key)>& callback) { 565 const scoped_refptr<PrivateKey>& private_key)>& callback) {
282 DCHECK(thread_checker_.CalledOnValidThread()); 566 DCHECK(thread_checker_.CalledOnValidThread());
283 567
284 if (waiting_for_profile_creation_ || waiting_for_tpm_token_) 568 if (waiting_for_profile_creation_ || waiting_for_tpm_token_)
285 return; 569 return;
286 scoped_refptr<base::TaskRunner> task_runner = 570 scoped_refptr<base::TaskRunner> task_runner =
287 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( 571 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
288 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 572 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
289 task_runner->PostTask( 573 task_runner->PostTask(
290 FROM_HERE, 574 FROM_HERE,
291 base::Bind(&LoadPrivateKey, 575 base::Bind(&LoadPrivateKey,
292 owner_key_util_, 576 owner_key_util_,
293 ProfileHelper::GetUserIdHashFromProfile(profile_), 577 ProfileHelper::GetUserIdHashFromProfile(profile_),
294 callback)); 578 callback));
295 } 579 }
296 580
297 void OwnerSettingsServiceChromeOS::StartNextOperation() { 581 void OwnerSettingsServiceChromeOS::StoreDeviceSettings() {
298 DeviceSettingsService* service = GetDeviceSettingsService(); 582 if (!has_pending_changes_ || store_settings_factory_.HasWeakPtrs())
299 if (!pending_operations_.empty() && service && 583 return;
300 service->session_manager_client()) { 584 if (!UpdateFromService())
301 pending_operations_.front()->Start( 585 return;
302 service->session_manager_client(), owner_key_util_, public_key_); 586 scoped_ptr<em::PolicyData> policy = AssemblePolicy(
303 } 587 user_id_, device_settings_service_->policy_data(), &device_settings_);
588 has_pending_changes_ = false;
589 bool rv = AssembleAndSignPolicyAsync(
590 content::BrowserThread::GetBlockingPool(),
591 policy.Pass(),
592 base::Bind(&OwnerSettingsServiceChromeOS::OnPolicyAssembledAndSigned,
593 store_settings_factory_.GetWeakPtr()));
594 if (!rv)
595 OnSignedPolicyStored(false /* success */);
304 } 596 }
305 597
306 void OwnerSettingsServiceChromeOS::HandleCompletedOperation( 598 void OwnerSettingsServiceChromeOS::OnPolicyAssembledAndSigned(
307 const base::Closure& callback, 599 scoped_ptr<em::PolicyFetchResponse> policy_response) {
308 SessionManagerOperation* operation, 600 if (!policy_response.get() || !device_settings_service_) {
309 DeviceSettingsService::Status status) { 601 OnSignedPolicyStored(false /* success */);
310 DCHECK_EQ(operation, pending_operations_.front()); 602 return;
603 }
604 device_settings_service_->Store(
605 policy_response.Pass(),
606 base::Bind(&OwnerSettingsServiceChromeOS::OnSignedPolicyStored,
607 store_settings_factory_.GetWeakPtr(),
608 true /* success */));
609 }
311 610
312 DeviceSettingsService* service = GetDeviceSettingsService(); 611 void OwnerSettingsServiceChromeOS::OnSignedPolicyStored(bool success) {
313 if (status == DeviceSettingsService::STORE_SUCCESS) { 612 store_settings_factory_.InvalidateWeakPtrs();
314 service->set_policy_data(operation->policy_data().Pass()); 613 FOR_EACH_OBSERVER(OwnerSettingsService::Observer,
315 service->set_device_settings(operation->device_settings().Pass()); 614 observers_,
615 OnSignedPolicyStored(success));
616 StoreDeviceSettings();
617 if (!success)
618 has_pending_changes_ = true;
619 }
620
621 bool OwnerSettingsServiceChromeOS::UpdateFromService() {
622 if (!device_settings_service_ ||
623 device_settings_service_->status() !=
624 DeviceSettingsService::STORE_SUCCESS ||
625 !device_settings_service_->device_settings()) {
626 return false;
316 } 627 }
317 628 enterprise_management::ChromeDeviceSettingsProto settings =
318 if ((operation->public_key().get() && !public_key_.get()) || 629 *device_settings_service_->device_settings();
319 (operation->public_key().get() && public_key_.get() && 630 settings.MergeFrom(device_settings_);
320 operation->public_key()->data() != public_key_->data())) { 631 device_settings_.Swap(&settings);
321 // Public part changed so we need to reload private part too. 632 return true;
322 ReloadKeypair();
323 content::NotificationService::current()->Notify(
324 chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED,
325 content::Source<OwnerSettingsServiceChromeOS>(this),
326 content::NotificationService::NoDetails());
327 }
328 service->OnSignAndStoreOperationCompleted(status);
329 if (!callback.is_null())
330 callback.Run();
331
332 pending_operations_.pop_front();
333 delete operation;
334 StartNextOperation();
335 } 633 }
336 634
337 } // namespace chromeos 635 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698