| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/bind.h" | |
| 11 #include "base/callback.h" | |
| 12 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
| 13 #include "base/logging.h" | 11 #include "base/logging.h" |
| 14 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 15 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 16 #include "base/task.h" | 14 #include "base/task.h" |
| 17 #include "base/values.h" | 15 #include "base/values.h" |
| 18 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/chromeos/cros/cros_library.h" | 17 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 20 #include "chrome/browser/chromeos/cros/login_library.h" | 18 #include "chrome/browser/chromeos/cros/login_library.h" |
| 21 #include "chrome/browser/chromeos/cros/network_library.h" | 19 #include "chrome/browser/chromeos/cros/network_library.h" |
| 22 #include "chrome/browser/chromeos/cros_settings.h" | 20 #include "chrome/browser/chromeos/cros_settings.h" |
| 23 #include "chrome/browser/chromeos/cros_settings_names.h" | 21 #include "chrome/browser/chromeos/cros_settings_names.h" |
| 24 #include "chrome/browser/chromeos/login/ownership_service.h" | 22 #include "chrome/browser/chromeos/login/ownership_service.h" |
| 23 #include "chrome/browser/chromeos/login/ownership_status_checker.h" |
| 25 #include "chrome/browser/chromeos/login/user_manager.h" | 24 #include "chrome/browser/chromeos/login/user_manager.h" |
| 26 #include "chrome/browser/policy/browser_policy_connector.h" | 25 #include "chrome/browser/policy/browser_policy_connector.h" |
| 27 #include "chrome/browser/prefs/pref_service.h" | 26 #include "chrome/browser/prefs/pref_service.h" |
| 28 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 27 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 29 #include "chrome/browser/ui/options/options_util.h" | 28 #include "chrome/browser/ui/options/options_util.h" |
| 29 #include "chrome/common/chrome_notification_types.h" |
| 30 #include "chrome/installer/util/google_update_settings.h" | 30 #include "chrome/installer/util/google_update_settings.h" |
| 31 #include "content/browser/browser_thread.h" | 31 #include "content/browser/browser_thread.h" |
| 32 | 32 |
| 33 namespace chromeos { | 33 namespace chromeos { |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 const char kTrueIncantation[] = "true"; | 37 const char kTrueIncantation[] = "true"; |
| 38 const char kFalseIncantation[] = "false"; | 38 const char kFalseIncantation[] = "false"; |
| 39 const char kTrustedSuffix[] = "/trusted"; | 39 const char kTrustedSuffix[] = "/trusted"; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 51 | 51 |
| 52 const char* kStringSettings[] = { | 52 const char* kStringSettings[] = { |
| 53 kDeviceOwner, | 53 kDeviceOwner, |
| 54 kReleaseChannel | 54 kReleaseChannel |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 const char* kListSettings[] = { | 57 const char* kListSettings[] = { |
| 58 kAccountsPrefUsers | 58 kAccountsPrefUsers |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 // Only write the property if the owner is the current logged on user. | 61 // This class provides the means to migrate settings to the signed settings |
| 62 void StartStorePropertyOpIfOwner(const std::string& name, | 62 // store. It does one of three things - store the settings in the policy blob |
| 63 const std::string& value, | 63 // immediately if the current user is the owner. Uses the |
| 64 SignedSettingsHelper::Callback* callback) { | 64 // SignedSettingsTempStorage if there is no owner yet, or waits for an |
| 65 if (OwnershipService::GetSharedInstance()->CurrentUserIsOwner()) { | 65 // OWNERSHIP_CHECKED notification to delay the storing until the owner has |
| 66 BrowserThread::PostTask(BrowserThread::UI, | 66 // logged in. |
| 67 FROM_HERE, | 67 class MigrationHelper : public NotificationObserver { |
| 68 base::Bind( | 68 public: |
| 69 &SignedSettingsHelper::StartStorePropertyOp, | 69 explicit MigrationHelper() : callback_(NULL) { |
| 70 base::Unretained(SignedSettingsHelper::Get()), | 70 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_CHECKED, |
| 71 name, | 71 NotificationService::AllSources()); |
| 72 value, | |
| 73 callback)); | |
| 74 } | 72 } |
| 75 } | 73 |
| 74 void set_callback(SignedSettingsHelper::Callback* callback) { |
| 75 callback_ = callback; |
| 76 } |
| 77 |
| 78 void AddMigrationValue(const std::string& path, const std::string& value) { |
| 79 migration_values_[path] = value; |
| 80 } |
| 81 |
| 82 void MigrateValues(void) { |
| 83 ownership_checker_.reset(new OwnershipStatusChecker(NewCallback( |
| 84 this, &MigrationHelper::DoMigrateValues))); |
| 85 } |
| 86 |
| 87 // NotificationObserver overrides: |
| 88 virtual void Observe(int type, |
| 89 const NotificationSource& source, |
| 90 const NotificationDetails& details) OVERRIDE { |
| 91 if (type == chrome::NOTIFICATION_OWNERSHIP_CHECKED) |
| 92 MigrateValues(); |
| 93 } |
| 94 |
| 95 private: |
| 96 void DoMigrateValues(OwnershipService::Status status, |
| 97 bool current_user_is_owner) { |
| 98 ownership_checker_.reset(NULL); |
| 99 |
| 100 // We can call StartStorePropertyOp in two cases - either if the owner is |
| 101 // currently logged in and the policy can be updated immediately or if there |
| 102 // is no owner yet in which case the value will be temporarily stored in the |
| 103 // SignedSettingsTempStorage until the device is owned. If none of these |
| 104 // cases is met then we will wait for user change notification and retry. |
| 105 if (current_user_is_owner || status != OwnershipService::OWNERSHIP_TAKEN) { |
| 106 std::map<std::string, std::string>::const_iterator i; |
| 107 for (i = migration_values_.begin(); i != migration_values_.end(); ++i) { |
| 108 // Queue all values for storing. |
| 109 SignedSettingsHelper::Get()->StartStorePropertyOp(i->first, i->second, |
| 110 callback_); |
| 111 } |
| 112 migration_values_.clear(); |
| 113 } |
| 114 } |
| 115 |
| 116 NotificationRegistrar registrar_; |
| 117 scoped_ptr<OwnershipStatusChecker> ownership_checker_; |
| 118 SignedSettingsHelper::Callback* callback_; |
| 119 |
| 120 std::map<std::string, std::string> migration_values_; |
| 121 |
| 122 DISALLOW_COPY_AND_ASSIGN(MigrationHelper); |
| 123 }; |
| 76 | 124 |
| 77 bool IsControlledBooleanSetting(const std::string& pref_path) { | 125 bool IsControlledBooleanSetting(const std::string& pref_path) { |
| 78 // TODO(nkostylev): Using std::find for 4 value array generates this warning | 126 // TODO(nkostylev): Using std::find for 4 value array generates this warning |
| 79 // in chroot stl_algo.h:231: error: array subscript is above array bounds. | 127 // in chroot stl_algo.h:231: error: array subscript is above array bounds. |
| 80 // GCC 4.4.3 | 128 // GCC 4.4.3 |
| 81 return (pref_path == kAccountsPrefAllowNewUser) || | 129 return (pref_path == kAccountsPrefAllowNewUser) || |
| 82 (pref_path == kAccountsPrefAllowGuest) || | 130 (pref_path == kAccountsPrefAllowGuest) || |
| 83 (pref_path == kAccountsPrefShowUserNamesOnSignIn) || | 131 (pref_path == kAccountsPrefShowUserNamesOnSignIn) || |
| 84 (pref_path == kSignedDataRoamingEnabled) || | 132 (pref_path == kSignedDataRoamingEnabled) || |
| 85 (pref_path == kStatsReportingPref); | 133 (pref_path == kStatsReportingPref); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 } | 330 } |
| 283 } | 331 } |
| 284 | 332 |
| 285 private: | 333 private: |
| 286 // upper bound for number of retries to fetch a signed setting. | 334 // upper bound for number of retries to fetch a signed setting. |
| 287 static const int kNumRetriesLimit = 9; | 335 static const int kNumRetriesLimit = 9; |
| 288 | 336 |
| 289 UserCrosSettingsTrust() | 337 UserCrosSettingsTrust() |
| 290 : ownership_service_(OwnershipService::GetSharedInstance()), | 338 : ownership_service_(OwnershipService::GetSharedInstance()), |
| 291 retries_left_(kNumRetriesLimit) { | 339 retries_left_(kNumRetriesLimit) { |
| 340 migration_helper_.set_callback(this); |
| 292 // Start prefetching Boolean and String preferences. | 341 // Start prefetching Boolean and String preferences. |
| 293 Reload(); | 342 Reload(); |
| 294 } | 343 } |
| 295 | 344 |
| 296 virtual ~UserCrosSettingsTrust() { | 345 virtual ~UserCrosSettingsTrust() { |
| 297 if (BrowserThread::CurrentlyOn(BrowserThread::UI) && | 346 if (BrowserThread::CurrentlyOn(BrowserThread::UI) && |
| 298 CrosLibrary::Get()->EnsureLoaded()) { | 347 CrosLibrary::Get()->EnsureLoaded()) { |
| 299 // Cancels all pending callbacks from us. | 348 // Cancels all pending callbacks from us. |
| 300 SignedSettingsHelper::Get()->CancelCallback(this); | 349 SignedSettingsHelper::Get()->CancelCallback(this); |
| 301 } | 350 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 } | 394 } |
| 346 } else if (path == kStatsReportingPref) { | 395 } else if (path == kStatsReportingPref) { |
| 347 bool stats_consent = (use_value == USE_VALUE_SUPPLIED) ? value : false; | 396 bool stats_consent = (use_value == USE_VALUE_SUPPLIED) ? value : false; |
| 348 // TODO(pastarmovj): Remove this once migration is not needed anymore. | 397 // TODO(pastarmovj): Remove this once migration is not needed anymore. |
| 349 // If the value is not set we should try to migrate legacy consent file. | 398 // If the value is not set we should try to migrate legacy consent file. |
| 350 if (use_value == USE_VALUE_DEFAULT) { | 399 if (use_value == USE_VALUE_DEFAULT) { |
| 351 // Loading consent file state causes us to do blocking IO on UI thread. | 400 // Loading consent file state causes us to do blocking IO on UI thread. |
| 352 // Temporarily allow it until we fix http://crbug.com/62626 | 401 // Temporarily allow it until we fix http://crbug.com/62626 |
| 353 base::ThreadRestrictions::ScopedAllowIO allow_io; | 402 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 354 stats_consent = GoogleUpdateSettings::GetCollectStatsConsent(); | 403 stats_consent = GoogleUpdateSettings::GetCollectStatsConsent(); |
| 355 // Only store settings if the owner is logged on, otherwise the write | 404 // Make sure the values will get eventually written to the policy file. |
| 356 // will fail, triggering another read and we'll end up in an infinite | 405 migration_helper_.AddMigrationValue( |
| 357 // loop. Owner check needs to be done on the FILE thread. | 406 path, stats_consent ? "true" : "false"); |
| 358 BrowserThread::PostTask(BrowserThread::FILE, | 407 migration_helper_.MigrateValues(); |
| 359 FROM_HERE, | |
| 360 base::Bind(&StartStorePropertyOpIfOwner, path, | |
| 361 stats_consent ? "true" : "false", | |
| 362 this)); | |
| 363 UpdateCacheBool(path, stats_consent, USE_VALUE_SUPPLIED); | 408 UpdateCacheBool(path, stats_consent, USE_VALUE_SUPPLIED); |
| 364 LOG(WARNING) << "No metrics policy set will revert to checking " | 409 LOG(WARNING) << "No metrics policy set will revert to checking " |
| 365 << "consent file which is " | 410 << "consent file which is " |
| 366 << (stats_consent ? "on." : "off."); | 411 << (stats_consent ? "on." : "off."); |
| 367 } | 412 } |
| 368 // TODO(pastarmovj): Remove this once we don't need to regenerate the | 413 // TODO(pastarmovj): Remove this once we don't need to regenerate the |
| 369 // consent file for the GUID anymore. | 414 // consent file for the GUID anymore. |
| 370 VLOG(1) << "Metrics policy is being set to : " << stats_consent | 415 VLOG(1) << "Metrics policy is being set to : " << stats_consent |
| 371 << "(reason : " << use_value << ")"; | 416 << "(reason : " << use_value << ")"; |
| 372 OptionsUtil::ResolveMetricsReportingEnabled(stats_consent); | 417 OptionsUtil::ResolveMetricsReportingEnabled(stats_consent); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 | 529 |
| 485 // Reload the whitelist on settings op failure. | 530 // Reload the whitelist on settings op failure. |
| 486 if (code != SignedSettings::SUCCESS) | 531 if (code != SignedSettings::SUCCESS) |
| 487 CrosSettings::Get()->FireObservers(kAccountsPrefUsers); | 532 CrosSettings::Get()->FireObservers(kAccountsPrefUsers); |
| 488 } | 533 } |
| 489 | 534 |
| 490 // Pending callbacks that need to be invoked after settings verification. | 535 // Pending callbacks that need to be invoked after settings verification. |
| 491 base::hash_map< std::string, std::vector< Task* > > callbacks_; | 536 base::hash_map< std::string, std::vector< Task* > > callbacks_; |
| 492 | 537 |
| 493 OwnershipService* ownership_service_; | 538 OwnershipService* ownership_service_; |
| 539 MigrationHelper migration_helper_; |
| 494 | 540 |
| 495 // In order to guard against occasional failure to fetch a property | 541 // In order to guard against occasional failure to fetch a property |
| 496 // we allow for some number of retries. | 542 // we allow for some number of retries. |
| 497 int retries_left_; | 543 int retries_left_; |
| 498 | 544 |
| 499 friend class SignedSettingsHelper; | 545 friend class SignedSettingsHelper; |
| 500 friend struct DefaultSingletonTraits<UserCrosSettingsTrust>; | 546 friend struct DefaultSingletonTraits<UserCrosSettingsTrust>; |
| 501 | 547 |
| 502 DISALLOW_COPY_AND_ASSIGN(UserCrosSettingsTrust); | 548 DISALLOW_COPY_AND_ASSIGN(UserCrosSettingsTrust); |
| 503 }; | 549 }; |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 if (cached_whitelist_update->Remove(email_value, NULL)) | 744 if (cached_whitelist_update->Remove(email_value, NULL)) |
| 699 prefs->ScheduleSavePersistentPrefs(); | 745 prefs->ScheduleSavePersistentPrefs(); |
| 700 } | 746 } |
| 701 | 747 |
| 702 // static | 748 // static |
| 703 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) { | 749 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) { |
| 704 UpdateCacheString(kDeviceOwner, email, USE_VALUE_SUPPLIED); | 750 UpdateCacheString(kDeviceOwner, email, USE_VALUE_SUPPLIED); |
| 705 } | 751 } |
| 706 | 752 |
| 707 } // namespace chromeos | 753 } // namespace chromeos |
| OLD | NEW |