Chromium Code Reviews| 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 void DoMigrateValues(OwnershipService::Status status, | |
|
Mattias Nissler (ping if slow)
2011/08/31 15:08:33
make this private
pastarmovj
2011/08/31 15:26:36
Done.
| |
| 88 bool current_user_is_owner) { | |
| 89 ownership_checker_.reset(NULL); | |
| 90 | |
| 91 if (current_user_is_owner || status != OwnershipService::OWNERSHIP_TAKEN) { | |
|
Mattias Nissler (ping if slow)
2011/08/31 15:08:33
Put a comment why we do this if ownership hasn't b
pastarmovj
2011/08/31 15:26:36
Done.
| |
| 92 std::map<std::string, std::string>::const_iterator i; | |
| 93 for (i = migration_values_.begin(); i != migration_values_.end(); ++i) { | |
| 94 // This is needed to avoid loosing the value after the clear below. | |
|
Mattias Nissler (ping if slow)
2011/08/31 15:08:33
Nope, this is not needed. A copy is created when c
pastarmovj
2011/08/31 15:26:36
Before I did need it because I was passing the res
| |
| 95 // Temp objects passed by const ref will have the life time of the ref. | |
| 96 const std::string name = i->first; | |
| 97 const std::string value = i->second; | |
| 98 // Queue all values for storing. | |
| 99 SignedSettingsHelper::Get()->StartStorePropertyOp(name, value, | |
| 100 callback_); | |
| 101 } | |
| 102 migration_values_.clear(); | |
| 103 } else { | |
| 104 // Either we are not yet logged in or the user currently logged in is not | |
| 105 // the owner. So we should wait for user change. (Actually only the first | |
| 106 // case is interesting for us.) | |
| 107 } | |
| 108 } | |
| 109 | |
| 110 // NotificationObserver overrides: | |
| 111 virtual void Observe(int type, | |
| 112 const NotificationSource& source, | |
| 113 const NotificationDetails& details) OVERRIDE { | |
| 114 if (type == chrome::NOTIFICATION_OWNERSHIP_CHECKED) | |
| 115 MigrateValues(); | |
| 116 } | |
| 117 | |
| 118 private: | |
| 119 NotificationRegistrar registrar_; | |
| 120 scoped_ptr<OwnershipStatusChecker> ownership_checker_; | |
| 121 SignedSettingsHelper::Callback* callback_; | |
| 122 | |
| 123 std::map<std::string, std::string> migration_values_; | |
| 124 | |
| 125 DISALLOW_COPY_AND_ASSIGN(MigrationHelper); | |
| 126 }; | |
| 76 | 127 |
| 77 bool IsControlledBooleanSetting(const std::string& pref_path) { | 128 bool IsControlledBooleanSetting(const std::string& pref_path) { |
| 78 // TODO(nkostylev): Using std::find for 4 value array generates this warning | 129 // 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. | 130 // in chroot stl_algo.h:231: error: array subscript is above array bounds. |
| 80 // GCC 4.4.3 | 131 // GCC 4.4.3 |
| 81 return (pref_path == kAccountsPrefAllowNewUser) || | 132 return (pref_path == kAccountsPrefAllowNewUser) || |
| 82 (pref_path == kAccountsPrefAllowGuest) || | 133 (pref_path == kAccountsPrefAllowGuest) || |
| 83 (pref_path == kAccountsPrefShowUserNamesOnSignIn) || | 134 (pref_path == kAccountsPrefShowUserNamesOnSignIn) || |
| 84 (pref_path == kSignedDataRoamingEnabled) || | 135 (pref_path == kSignedDataRoamingEnabled) || |
| 85 (pref_path == kStatsReportingPref); | 136 (pref_path == kStatsReportingPref); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 } | 333 } |
| 283 } | 334 } |
| 284 | 335 |
| 285 private: | 336 private: |
| 286 // upper bound for number of retries to fetch a signed setting. | 337 // upper bound for number of retries to fetch a signed setting. |
| 287 static const int kNumRetriesLimit = 9; | 338 static const int kNumRetriesLimit = 9; |
| 288 | 339 |
| 289 UserCrosSettingsTrust() | 340 UserCrosSettingsTrust() |
| 290 : ownership_service_(OwnershipService::GetSharedInstance()), | 341 : ownership_service_(OwnershipService::GetSharedInstance()), |
| 291 retries_left_(kNumRetriesLimit) { | 342 retries_left_(kNumRetriesLimit) { |
| 343 migration_helper_.set_callback(this); | |
| 292 // Start prefetching Boolean and String preferences. | 344 // Start prefetching Boolean and String preferences. |
| 293 Reload(); | 345 Reload(); |
| 294 } | 346 } |
| 295 | 347 |
| 296 virtual ~UserCrosSettingsTrust() { | 348 virtual ~UserCrosSettingsTrust() { |
| 297 if (BrowserThread::CurrentlyOn(BrowserThread::UI) && | 349 if (BrowserThread::CurrentlyOn(BrowserThread::UI) && |
| 298 CrosLibrary::Get()->EnsureLoaded()) { | 350 CrosLibrary::Get()->EnsureLoaded()) { |
| 299 // Cancels all pending callbacks from us. | 351 // Cancels all pending callbacks from us. |
| 300 SignedSettingsHelper::Get()->CancelCallback(this); | 352 SignedSettingsHelper::Get()->CancelCallback(this); |
| 301 } | 353 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 } | 397 } |
| 346 } else if (path == kStatsReportingPref) { | 398 } else if (path == kStatsReportingPref) { |
| 347 bool stats_consent = (use_value == USE_VALUE_SUPPLIED) ? value : false; | 399 bool stats_consent = (use_value == USE_VALUE_SUPPLIED) ? value : false; |
| 348 // TODO(pastarmovj): Remove this once migration is not needed anymore. | 400 // 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. | 401 // If the value is not set we should try to migrate legacy consent file. |
| 350 if (use_value == USE_VALUE_DEFAULT) { | 402 if (use_value == USE_VALUE_DEFAULT) { |
| 351 // Loading consent file state causes us to do blocking IO on UI thread. | 403 // Loading consent file state causes us to do blocking IO on UI thread. |
| 352 // Temporarily allow it until we fix http://crbug.com/62626 | 404 // Temporarily allow it until we fix http://crbug.com/62626 |
| 353 base::ThreadRestrictions::ScopedAllowIO allow_io; | 405 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 354 stats_consent = GoogleUpdateSettings::GetCollectStatsConsent(); | 406 stats_consent = GoogleUpdateSettings::GetCollectStatsConsent(); |
| 355 // Only store settings if the owner is logged on, otherwise the write | 407 // 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 | 408 migration_helper_.AddMigrationValue( |
| 357 // loop. Owner check needs to be done on the FILE thread. | 409 path, stats_consent ? "true" : "false"); |
| 358 BrowserThread::PostTask(BrowserThread::FILE, | 410 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); | 411 UpdateCacheBool(path, stats_consent, USE_VALUE_SUPPLIED); |
| 364 LOG(WARNING) << "No metrics policy set will revert to checking " | 412 LOG(WARNING) << "No metrics policy set will revert to checking " |
| 365 << "consent file which is " | 413 << "consent file which is " |
| 366 << (stats_consent ? "on." : "off."); | 414 << (stats_consent ? "on." : "off."); |
| 367 } | 415 } |
| 368 // TODO(pastarmovj): Remove this once we don't need to regenerate the | 416 // TODO(pastarmovj): Remove this once we don't need to regenerate the |
| 369 // consent file for the GUID anymore. | 417 // consent file for the GUID anymore. |
| 370 VLOG(1) << "Metrics policy is being set to : " << stats_consent | 418 VLOG(1) << "Metrics policy is being set to : " << stats_consent |
| 371 << "(reason : " << use_value << ")"; | 419 << "(reason : " << use_value << ")"; |
| 372 OptionsUtil::ResolveMetricsReportingEnabled(stats_consent); | 420 OptionsUtil::ResolveMetricsReportingEnabled(stats_consent); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 | 532 |
| 485 // Reload the whitelist on settings op failure. | 533 // Reload the whitelist on settings op failure. |
| 486 if (code != SignedSettings::SUCCESS) | 534 if (code != SignedSettings::SUCCESS) |
| 487 CrosSettings::Get()->FireObservers(kAccountsPrefUsers); | 535 CrosSettings::Get()->FireObservers(kAccountsPrefUsers); |
| 488 } | 536 } |
| 489 | 537 |
| 490 // Pending callbacks that need to be invoked after settings verification. | 538 // Pending callbacks that need to be invoked after settings verification. |
| 491 base::hash_map< std::string, std::vector< Task* > > callbacks_; | 539 base::hash_map< std::string, std::vector< Task* > > callbacks_; |
| 492 | 540 |
| 493 OwnershipService* ownership_service_; | 541 OwnershipService* ownership_service_; |
| 542 MigrationHelper migration_helper_; | |
| 494 | 543 |
| 495 // In order to guard against occasional failure to fetch a property | 544 // In order to guard against occasional failure to fetch a property |
| 496 // we allow for some number of retries. | 545 // we allow for some number of retries. |
| 497 int retries_left_; | 546 int retries_left_; |
| 498 | 547 |
| 499 friend class SignedSettingsHelper; | 548 friend class SignedSettingsHelper; |
| 500 friend struct DefaultSingletonTraits<UserCrosSettingsTrust>; | 549 friend struct DefaultSingletonTraits<UserCrosSettingsTrust>; |
| 501 | 550 |
| 502 DISALLOW_COPY_AND_ASSIGN(UserCrosSettingsTrust); | 551 DISALLOW_COPY_AND_ASSIGN(UserCrosSettingsTrust); |
| 503 }; | 552 }; |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 698 if (cached_whitelist_update->Remove(email_value, NULL)) | 747 if (cached_whitelist_update->Remove(email_value, NULL)) |
| 699 prefs->ScheduleSavePersistentPrefs(); | 748 prefs->ScheduleSavePersistentPrefs(); |
| 700 } | 749 } |
| 701 | 750 |
| 702 // static | 751 // static |
| 703 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) { | 752 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) { |
| 704 UpdateCacheString(kDeviceOwner, email, USE_VALUE_SUPPLIED); | 753 UpdateCacheString(kDeviceOwner, email, USE_VALUE_SUPPLIED); |
| 705 } | 754 } |
| 706 | 755 |
| 707 } // namespace chromeos | 756 } // namespace chromeos |
| OLD | NEW |