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" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/hash_tables.h" | 12 #include "base/hash_tables.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "base/task.h" | 16 #include "base/task.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/chromeos/cros/cros_library.h" | 19 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 20 #include "chrome/browser/chromeos/cros/login_library.h" | 20 #include "chrome/browser/chromeos/cros/login_library.h" |
| 21 #include "chrome/browser/chromeos/cros/network_library.h" | 21 #include "chrome/browser/chromeos/cros/network_library.h" |
| 22 #include "chrome/browser/chromeos/cros_settings.h" | 22 #include "chrome/browser/chromeos/cros_settings.h" |
| 23 #include "chrome/browser/chromeos/cros_settings_names.h" | 23 #include "chrome/browser/chromeos/cros_settings_names.h" |
| 24 #include "chrome/browser/chromeos/login/ownership_service.h" | 24 #include "chrome/browser/chromeos/login/ownership_service.h" |
| 25 #include "chrome/browser/chromeos/login/user_manager.h" | 25 #include "chrome/browser/chromeos/login/user_manager.h" |
| 26 #include "chrome/browser/policy/browser_policy_connector.h" | 26 #include "chrome/browser/policy/browser_policy_connector.h" |
| 27 #include "chrome/browser/prefs/pref_service.h" | 27 #include "chrome/browser/prefs/pref_service.h" |
| 28 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 28 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 29 #include "chrome/browser/ui/options/options_util.h" | 29 #include "chrome/browser/ui/options/options_util.h" |
| 30 #include "chrome/common/chrome_notification_types.h" | |
| 30 #include "chrome/installer/util/google_update_settings.h" | 31 #include "chrome/installer/util/google_update_settings.h" |
| 31 #include "content/browser/browser_thread.h" | 32 #include "content/browser/browser_thread.h" |
| 32 | 33 |
| 33 namespace chromeos { | 34 namespace chromeos { |
| 34 | 35 |
| 35 namespace { | 36 namespace { |
| 36 | 37 |
| 37 const char kTrueIncantation[] = "true"; | 38 const char kTrueIncantation[] = "true"; |
| 38 const char kFalseIncantation[] = "false"; | 39 const char kFalseIncantation[] = "false"; |
| 39 const char kTrustedSuffix[] = "/trusted"; | 40 const char kTrustedSuffix[] = "/trusted"; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 51 | 52 |
| 52 const char* kStringSettings[] = { | 53 const char* kStringSettings[] = { |
| 53 kDeviceOwner, | 54 kDeviceOwner, |
| 54 kReleaseChannel | 55 kReleaseChannel |
| 55 }; | 56 }; |
| 56 | 57 |
| 57 const char* kListSettings[] = { | 58 const char* kListSettings[] = { |
| 58 kAccountsPrefUsers | 59 kAccountsPrefUsers |
| 59 }; | 60 }; |
| 60 | 61 |
| 61 // Only write the property if the owner is the current logged on user. | 62 // This class provides the means to migrate settings to the signed settings |
| 62 void StartStorePropertyOpIfOwner(const std::string& name, | 63 // store. It does one of three things - stored the settings in the policy blob |
| 63 const std::string& value, | 64 // immediately if the current user is the owner. Uses the |
| 64 SignedSettingsHelper::Callback* callback) { | 65 // SignedSettingsTempStorage if there is no owner yet. Or |
|
rkc
2011/08/31 11:18:11
Nit: Incomplete comment?
pastarmovj
2011/08/31 11:50:58
Ooops true.
| |
| 65 if (OwnershipService::GetSharedInstance()->CurrentUserIsOwner()) { | 66 class MigrationHelper : public NotificationObserver { |
| 66 BrowserThread::PostTask(BrowserThread::UI, | 67 public: |
| 67 FROM_HERE, | 68 explicit MigrationHelper() : callback_(NULL) { |
| 68 base::Bind( | 69 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_CHECKED, |
| 69 &SignedSettingsHelper::StartStorePropertyOp, | 70 NotificationService::AllSources()); |
| 70 base::Unretained(SignedSettingsHelper::Get()), | |
| 71 name, | |
| 72 value, | |
| 73 callback)); | |
| 74 } | 71 } |
| 75 } | 72 |
| 73 void set_callback(SignedSettingsHelper::Callback* callback) { | |
| 74 callback_ = callback; | |
| 75 } | |
| 76 | |
| 77 void AddMigrationValue(const std::string& path, const std::string& value) { | |
| 78 // Migration value is not thread safe so take care if you call this function | |
| 79 // while MigrateValues is running. You can make sure this is not the case if | |
| 80 // You only call this function on the FILE thread. | |
| 81 migration_values_[path] = value; | |
| 82 } | |
| 83 | |
| 84 void MigrateValues(void) { | |
| 85 // The check we do below should be done on the file thread so if we are not | |
| 86 // there jump on the right thread. | |
| 87 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { | |
| 88 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
| 89 base::Bind(&MigrationHelper::MigrateValues, | |
| 90 base::Unretained(this))); | |
| 91 return; | |
| 92 } | |
| 93 | |
| 94 OwnershipService* service = OwnershipService::GetSharedInstance(); | |
| 95 if (service->CurrentUserIsOwner() || | |
| 96 service->GetStatus(true) != OwnershipService::OWNERSHIP_TAKEN) { | |
| 97 std::map<std::string, std::string>::const_iterator i = | |
| 98 migration_values_.begin(); | |
| 99 for (; i != migration_values_.end(); ++i) { | |
| 100 // This is needed to avoid loosing the value after the clear below. | |
| 101 const std::string value = i->second; | |
| 102 // Queue all values for storing. | |
| 103 BrowserThread::PostTask( | |
| 104 BrowserThread::UI, FROM_HERE, | |
| 105 base::Bind( | |
| 106 &SignedSettingsHelper::StartStorePropertyOp, | |
| 107 base::Unretained(SignedSettingsHelper::Get()), | |
| 108 i->first.c_str(), value, | |
|
rkc
2011/08/31 11:18:11
Why the difference between the passing of these tw
pastarmovj
2011/08/31 11:50:58
Underneath they are not the same because the key(f
| |
| 109 callback_)); | |
| 110 } | |
| 111 migration_values_.clear(); | |
| 112 } else { | |
| 113 // Either we are not yet logged in or the user currently logged in is not | |
| 114 // the owner. So we should wait for user change. (Actually only the first | |
| 115 // case is interesting for us.) | |
| 116 } | |
| 117 } | |
| 118 | |
| 119 // NotificationObserver overrides: | |
| 120 virtual void Observe(int type, | |
| 121 const NotificationSource& source, | |
| 122 const NotificationDetails& details) OVERRIDE { | |
| 123 if (type == chrome::NOTIFICATION_OWNERSHIP_CHECKED) { | |
| 124 if (!migration_values_.empty()) | |
| 125 MigrateValues(); | |
| 126 } | |
| 127 } | |
| 128 | |
| 129 private: | |
| 130 NotificationRegistrar registrar_; | |
| 131 std::map<std::string, std::string> migration_values_; | |
| 132 SignedSettingsHelper::Callback* callback_; | |
| 133 | |
| 134 DISALLOW_COPY_AND_ASSIGN(MigrationHelper); | |
| 135 }; | |
| 76 | 136 |
| 77 bool IsControlledBooleanSetting(const std::string& pref_path) { | 137 bool IsControlledBooleanSetting(const std::string& pref_path) { |
| 78 // TODO(nkostylev): Using std::find for 4 value array generates this warning | 138 // 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. | 139 // in chroot stl_algo.h:231: error: array subscript is above array bounds. |
| 80 // GCC 4.4.3 | 140 // GCC 4.4.3 |
| 81 return (pref_path == kAccountsPrefAllowNewUser) || | 141 return (pref_path == kAccountsPrefAllowNewUser) || |
| 82 (pref_path == kAccountsPrefAllowGuest) || | 142 (pref_path == kAccountsPrefAllowGuest) || |
| 83 (pref_path == kAccountsPrefShowUserNamesOnSignIn) || | 143 (pref_path == kAccountsPrefShowUserNamesOnSignIn) || |
| 84 (pref_path == kSignedDataRoamingEnabled) || | 144 (pref_path == kSignedDataRoamingEnabled) || |
| 85 (pref_path == kStatsReportingPref); | 145 (pref_path == kStatsReportingPref); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 } | 342 } |
| 283 } | 343 } |
| 284 | 344 |
| 285 private: | 345 private: |
| 286 // upper bound for number of retries to fetch a signed setting. | 346 // upper bound for number of retries to fetch a signed setting. |
| 287 static const int kNumRetriesLimit = 9; | 347 static const int kNumRetriesLimit = 9; |
| 288 | 348 |
| 289 UserCrosSettingsTrust() | 349 UserCrosSettingsTrust() |
| 290 : ownership_service_(OwnershipService::GetSharedInstance()), | 350 : ownership_service_(OwnershipService::GetSharedInstance()), |
| 291 retries_left_(kNumRetriesLimit) { | 351 retries_left_(kNumRetriesLimit) { |
| 352 migration_helper_.set_callback(this); | |
| 292 // Start prefetching Boolean and String preferences. | 353 // Start prefetching Boolean and String preferences. |
| 293 Reload(); | 354 Reload(); |
| 294 } | 355 } |
| 295 | 356 |
| 296 virtual ~UserCrosSettingsTrust() { | 357 virtual ~UserCrosSettingsTrust() { |
| 297 if (BrowserThread::CurrentlyOn(BrowserThread::UI) && | 358 if (BrowserThread::CurrentlyOn(BrowserThread::UI) && |
| 298 CrosLibrary::Get()->EnsureLoaded()) { | 359 CrosLibrary::Get()->EnsureLoaded()) { |
| 299 // Cancels all pending callbacks from us. | 360 // Cancels all pending callbacks from us. |
| 300 SignedSettingsHelper::Get()->CancelCallback(this); | 361 SignedSettingsHelper::Get()->CancelCallback(this); |
| 301 } | 362 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 } | 406 } |
| 346 } else if (path == kStatsReportingPref) { | 407 } else if (path == kStatsReportingPref) { |
| 347 bool stats_consent = (use_value == USE_VALUE_SUPPLIED) ? value : false; | 408 bool stats_consent = (use_value == USE_VALUE_SUPPLIED) ? value : false; |
| 348 // TODO(pastarmovj): Remove this once migration is not needed anymore. | 409 // 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. | 410 // If the value is not set we should try to migrate legacy consent file. |
| 350 if (use_value == USE_VALUE_DEFAULT) { | 411 if (use_value == USE_VALUE_DEFAULT) { |
| 351 // Loading consent file state causes us to do blocking IO on UI thread. | 412 // Loading consent file state causes us to do blocking IO on UI thread. |
| 352 // Temporarily allow it until we fix http://crbug.com/62626 | 413 // Temporarily allow it until we fix http://crbug.com/62626 |
| 353 base::ThreadRestrictions::ScopedAllowIO allow_io; | 414 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 354 stats_consent = GoogleUpdateSettings::GetCollectStatsConsent(); | 415 stats_consent = GoogleUpdateSettings::GetCollectStatsConsent(); |
| 355 // Only store settings if the owner is logged on, otherwise the write | 416 // 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 | 417 migration_helper_.AddMigrationValue( |
| 357 // loop. Owner check needs to be done on the FILE thread. | 418 path, stats_consent ? "true" : "false"); |
| 358 BrowserThread::PostTask(BrowserThread::FILE, | 419 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); | 420 UpdateCacheBool(path, stats_consent, USE_VALUE_SUPPLIED); |
| 364 LOG(WARNING) << "No metrics policy set will revert to checking " | 421 LOG(WARNING) << "No metrics policy set will revert to checking " |
| 365 << "consent file which is " | 422 << "consent file which is " |
| 366 << (stats_consent ? "on." : "off."); | 423 << (stats_consent ? "on." : "off."); |
| 367 } | 424 } |
| 368 // TODO(pastarmovj): Remove this once we don't need to regenerate the | 425 // TODO(pastarmovj): Remove this once we don't need to regenerate the |
| 369 // consent file for the GUID anymore. | 426 // consent file for the GUID anymore. |
| 370 VLOG(1) << "Metrics policy is being set to : " << stats_consent | 427 VLOG(1) << "Metrics policy is being set to : " << stats_consent |
| 371 << "(reason : " << use_value << ")"; | 428 << "(reason : " << use_value << ")"; |
| 372 OptionsUtil::ResolveMetricsReportingEnabled(stats_consent); | 429 OptionsUtil::ResolveMetricsReportingEnabled(stats_consent); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 | 541 |
| 485 // Reload the whitelist on settings op failure. | 542 // Reload the whitelist on settings op failure. |
| 486 if (code != SignedSettings::SUCCESS) | 543 if (code != SignedSettings::SUCCESS) |
| 487 CrosSettings::Get()->FireObservers(kAccountsPrefUsers); | 544 CrosSettings::Get()->FireObservers(kAccountsPrefUsers); |
| 488 } | 545 } |
| 489 | 546 |
| 490 // Pending callbacks that need to be invoked after settings verification. | 547 // Pending callbacks that need to be invoked after settings verification. |
| 491 base::hash_map< std::string, std::vector< Task* > > callbacks_; | 548 base::hash_map< std::string, std::vector< Task* > > callbacks_; |
| 492 | 549 |
| 493 OwnershipService* ownership_service_; | 550 OwnershipService* ownership_service_; |
| 551 MigrationHelper migration_helper_; | |
| 494 | 552 |
| 495 // In order to guard against occasional failure to fetch a property | 553 // In order to guard against occasional failure to fetch a property |
| 496 // we allow for some number of retries. | 554 // we allow for some number of retries. |
| 497 int retries_left_; | 555 int retries_left_; |
| 498 | 556 |
| 499 friend class SignedSettingsHelper; | 557 friend class SignedSettingsHelper; |
| 500 friend struct DefaultSingletonTraits<UserCrosSettingsTrust>; | 558 friend struct DefaultSingletonTraits<UserCrosSettingsTrust>; |
| 501 | 559 |
| 502 DISALLOW_COPY_AND_ASSIGN(UserCrosSettingsTrust); | 560 DISALLOW_COPY_AND_ASSIGN(UserCrosSettingsTrust); |
| 503 }; | 561 }; |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 698 if (cached_whitelist_update->Remove(email_value, NULL)) | 756 if (cached_whitelist_update->Remove(email_value, NULL)) |
| 699 prefs->ScheduleSavePersistentPrefs(); | 757 prefs->ScheduleSavePersistentPrefs(); |
| 700 } | 758 } |
| 701 | 759 |
| 702 // static | 760 // static |
| 703 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) { | 761 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) { |
| 704 UpdateCacheString(kDeviceOwner, email, USE_VALUE_SUPPLIED); | 762 UpdateCacheString(kDeviceOwner, email, USE_VALUE_SUPPLIED); |
| 705 } | 763 } |
| 706 | 764 |
| 707 } // namespace chromeos | 765 } // namespace chromeos |
| OLD | NEW |