OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/user_cros_settings_provider.h" | 5 #include "chrome/browser/chromeos/user_cros_settings_provider.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 return; | 298 return; |
299 // Do not trust before fetching complete. | 299 // Do not trust before fetching complete. |
300 prefs->ClearPref((name + kTrustedSuffix).c_str()); | 300 prefs->ClearPref((name + kTrustedSuffix).c_str()); |
301 prefs->ScheduleSavePersistentPrefs(); | 301 prefs->ScheduleSavePersistentPrefs(); |
302 if (CrosLibrary::Get()->EnsureLoaded()) { | 302 if (CrosLibrary::Get()->EnsureLoaded()) { |
303 SignedSettingsHelper::Get()->StartRetrieveProperty(name, this); | 303 SignedSettingsHelper::Get()->StartRetrieveProperty(name, this); |
304 } | 304 } |
305 } | 305 } |
306 | 306 |
307 // Implementation of SignedSettingsHelper::Callback. | 307 // Implementation of SignedSettingsHelper::Callback. |
308 virtual void OnRetrievePropertyCompleted(bool success, | 308 virtual void OnRetrievePropertyCompleted(SignedSettings::ReturnCode code, |
309 const std::string& name, | 309 const std::string& name, |
310 const std::string& value) { | 310 const std::string& value) { |
311 if (!IsControlledBooleanSetting(name) && !IsControlledStringSetting(name)) { | 311 if (!IsControlledBooleanSetting(name) && !IsControlledStringSetting(name)) { |
312 NOTREACHED(); | 312 NOTREACHED(); |
313 return; | 313 return; |
314 } | 314 } |
315 DCHECK(GetOwnershipStatus() != OWNERSHIP_UNKNOWN); | 315 DCHECK(GetOwnershipStatus() != OWNERSHIP_UNKNOWN); |
316 | 316 |
| 317 bool success = code == SignedSettings::SUCCESS; |
317 PrefService* prefs = g_browser_process->local_state(); | 318 PrefService* prefs = g_browser_process->local_state(); |
318 if (!success && GetOwnershipStatus() == OWNERSHIP_TAKEN) { | 319 if (!success && GetOwnershipStatus() == OWNERSHIP_TAKEN) { |
319 LOG(ERROR) << "On owned device: failed to retrieve cros " | 320 LOG(ERROR) << "On owned device: failed to retrieve cros " |
320 "setting, name=" << name; | 321 "setting, name=" << name; |
321 if (retries_left_ > 0) { | 322 if (retries_left_ > 0) { |
322 retries_left_ -= 1; | 323 retries_left_ -= 1; |
323 StartFetchingSetting(name); | 324 StartFetchingSetting(name); |
324 return; | 325 return; |
325 } | 326 } |
326 LOG(ERROR) << "No retries left"; | 327 LOG(ERROR) << "No retries left"; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 std::vector<Task*>& callbacks_vector = callbacks_[name]; | 360 std::vector<Task*>& callbacks_vector = callbacks_[name]; |
360 for (size_t i = 0; i < callbacks_vector.size(); ++i) | 361 for (size_t i = 0; i < callbacks_vector.size(); ++i) |
361 MessageLoop::current()->PostTask(FROM_HERE, callbacks_vector[i]); | 362 MessageLoop::current()->PostTask(FROM_HERE, callbacks_vector[i]); |
362 callbacks_vector.clear(); | 363 callbacks_vector.clear(); |
363 } | 364 } |
364 if (success) | 365 if (success) |
365 CrosSettings::Get()->FireObservers(name.c_str()); | 366 CrosSettings::Get()->FireObservers(name.c_str()); |
366 } | 367 } |
367 | 368 |
368 // Implementation of SignedSettingsHelper::Callback. | 369 // Implementation of SignedSettingsHelper::Callback. |
369 virtual void OnStorePropertyCompleted(bool success, | 370 virtual void OnStorePropertyCompleted(SignedSettings::ReturnCode code, |
370 const std::string& name, | 371 const std::string& name, |
371 const std::string& value) { | 372 const std::string& value) { |
372 VLOG(1) << "Store cros setting " << name << "=" << value << ", success=" | 373 VLOG(1) << "Store cros setting " << name << "=" << value << ", code=" |
373 << success; | 374 << code; |
374 | 375 |
375 // Reload the setting if store op fails. | 376 // Reload the setting if store op fails. |
376 if (!success) | 377 if (code != SignedSettings::SUCCESS) |
377 SignedSettingsHelper::Get()->StartRetrieveProperty(name, this); | 378 SignedSettingsHelper::Get()->StartRetrieveProperty(name, this); |
378 } | 379 } |
379 | 380 |
380 // Implementation of SignedSettingsHelper::Callback. | 381 // Implementation of SignedSettingsHelper::Callback. |
381 virtual void OnWhitelistCompleted(bool success, const std::string& email) { | 382 virtual void OnWhitelistCompleted(SignedSettings::ReturnCode code, |
382 VLOG(1) << "Add " << email << " to whitelist, success=" << success; | 383 const std::string& email) { |
| 384 VLOG(1) << "Add " << email << " to whitelist, code=" << code; |
383 | 385 |
384 // Reload the whitelist on settings op failure. | 386 // Reload the whitelist on settings op failure. |
385 if (!success) | 387 if (code != SignedSettings::SUCCESS) |
386 CrosSettings::Get()->FireObservers(kAccountsPrefUsers); | 388 CrosSettings::Get()->FireObservers(kAccountsPrefUsers); |
387 } | 389 } |
388 | 390 |
389 // Implementation of SignedSettingsHelper::Callback. | 391 // Implementation of SignedSettingsHelper::Callback. |
390 virtual void OnUnwhitelistCompleted(bool success, const std::string& email) { | 392 virtual void OnUnwhitelistCompleted(SignedSettings::ReturnCode code, |
391 VLOG(1) << "Remove " << email << " from whitelist, success=" << success; | 393 const std::string& email) { |
| 394 VLOG(1) << "Remove " << email << " from whitelist, code=" << code; |
392 | 395 |
393 // Reload the whitelist on settings op failure. | 396 // Reload the whitelist on settings op failure. |
394 if (!success) | 397 if (code != SignedSettings::SUCCESS) |
395 CrosSettings::Get()->FireObservers(kAccountsPrefUsers); | 398 CrosSettings::Get()->FireObservers(kAccountsPrefUsers); |
396 } | 399 } |
397 | 400 |
398 // NotificationObserver implementation. | 401 // NotificationObserver implementation. |
399 virtual void Observe(NotificationType type, | 402 virtual void Observe(NotificationType type, |
400 const NotificationSource& source, | 403 const NotificationSource& source, |
401 const NotificationDetails& details) { | 404 const NotificationDetails& details) { |
402 if (type.value == NotificationType::OWNERSHIP_TAKEN) { | 405 if (type.value == NotificationType::OWNERSHIP_TAKEN) { |
403 SetOwnershipStatus(OWNERSHIP_TAKEN, SOURCE_OBSERVE); | 406 SetOwnershipStatus(OWNERSHIP_TAKEN, SOURCE_OBSERVE); |
404 notification_registrar_.RemoveAll(); | 407 notification_registrar_.RemoveAll(); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 return false; | 555 return false; |
553 } | 556 } |
554 | 557 |
555 bool UserCrosSettingsProvider::HandlesSetting(const std::string& path) { | 558 bool UserCrosSettingsProvider::HandlesSetting(const std::string& path) { |
556 return ::StartsWithASCII(path, "cros.accounts.", true); | 559 return ::StartsWithASCII(path, "cros.accounts.", true); |
557 } | 560 } |
558 | 561 |
559 void UserCrosSettingsProvider::WhitelistUser(const std::string& email) { | 562 void UserCrosSettingsProvider::WhitelistUser(const std::string& email) { |
560 SignedSettingsHelper::Get()->StartWhitelistOp( | 563 SignedSettingsHelper::Get()->StartWhitelistOp( |
561 email, true, UserCrosSettingsTrust::GetSharedInstance()); | 564 email, true, UserCrosSettingsTrust::GetSharedInstance()); |
562 | |
563 PrefService* prefs = g_browser_process->local_state(); | 565 PrefService* prefs = g_browser_process->local_state(); |
564 ListValue* cached_whitelist = prefs->GetMutableList(kAccountsPrefUsers); | 566 ListValue* cached_whitelist = prefs->GetMutableList(kAccountsPrefUsers); |
565 cached_whitelist->Append(Value::CreateStringValue(email)); | 567 cached_whitelist->Append(Value::CreateStringValue(email)); |
566 prefs->ScheduleSavePersistentPrefs(); | 568 prefs->ScheduleSavePersistentPrefs(); |
567 } | 569 } |
568 | 570 |
569 void UserCrosSettingsProvider::UnwhitelistUser(const std::string& email) { | 571 void UserCrosSettingsProvider::UnwhitelistUser(const std::string& email) { |
570 SignedSettingsHelper::Get()->StartWhitelistOp( | 572 SignedSettingsHelper::Get()->StartWhitelistOp( |
571 email, false, UserCrosSettingsTrust::GetSharedInstance()); | 573 email, false, UserCrosSettingsTrust::GetSharedInstance()); |
572 | 574 |
573 PrefService* prefs = g_browser_process->local_state(); | 575 PrefService* prefs = g_browser_process->local_state(); |
574 ListValue* cached_whitelist = prefs->GetMutableList(kAccountsPrefUsers); | 576 ListValue* cached_whitelist = prefs->GetMutableList(kAccountsPrefUsers); |
575 StringValue email_value(email); | 577 StringValue email_value(email); |
576 if (cached_whitelist->Remove(email_value) != -1) | 578 if (cached_whitelist->Remove(email_value) != -1) |
577 prefs->ScheduleSavePersistentPrefs(); | 579 prefs->ScheduleSavePersistentPrefs(); |
578 } | 580 } |
579 | 581 |
580 // static | 582 // static |
581 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) { | 583 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) { |
582 UpdateCacheString(kDeviceOwner, email, USE_VALUE_SUPPLIED); | 584 UpdateCacheString(kDeviceOwner, email, USE_VALUE_SUPPLIED); |
583 } | 585 } |
584 | 586 |
585 } // namespace chromeos | 587 } // namespace chromeos |
OLD | NEW |