Chromium Code Reviews| Index: chrome/browser/chromeos/settings/device_settings_migration_helper.cc |
| diff --git a/chrome/browser/chromeos/settings/device_settings_migration_helper.cc b/chrome/browser/chromeos/settings/device_settings_migration_helper.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6dc63d8b50df9d854215ed0e2861b6d0e2bd17f2 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/settings/device_settings_migration_helper.cc |
| @@ -0,0 +1,52 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
|
pastarmovj
2012/08/03 13:35:58
Shouldn't this file be A+? Maybe it has diverged t
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/chromeos/settings/device_settings_migration_helper.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/values.h" |
| +#include "chrome/browser/chromeos/settings/cros_settings.h" |
| + |
| +namespace chromeos { |
| + |
| +DeviceSettingsMigrationHelper::DeviceSettingsMigrationHelper() |
| + : ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)) { |
| +} |
| + |
| +DeviceSettingsMigrationHelper::~DeviceSettingsMigrationHelper() { |
| + migration_values_.Clear(); |
| +} |
| + |
| +void DeviceSettingsMigrationHelper::AddMigrationValue(const std::string& path, |
| + base::Value* value) { |
| + migration_values_.SetValue(path, value); |
| +} |
| + |
| +void DeviceSettingsMigrationHelper::MigrateValues(void) { |
| + ptr_factory_.InvalidateWeakPtrs(); |
| + DeviceSettingsService::Get()->GetOwnershipStatusAsync( |
| + base::Bind(&DeviceSettingsMigrationHelper::DoMigrateValues, |
| + ptr_factory_.GetWeakPtr())); |
| +} |
| + |
| +void DeviceSettingsMigrationHelper::DoMigrateValues( |
| + DeviceSettingsService::OwnershipStatus status, |
| + bool current_user_is_owner) { |
| + // We can call CrosSettings::Set in two cases - either if the owner is |
| + // currently logged in and the policy can be updated immediately or if there |
| + // is no owner yet in which case the value will be temporarily stored in the |
| + // cache until the device is owned. If none of these cases is met then we will |
| + // wait for the next opportunity. |
| + if (current_user_is_owner || |
| + status != DeviceSettingsService::OWNERSHIP_TAKEN) { |
| + std::map<std::string, base::Value*>::const_iterator i; |
| + for (i = migration_values_.begin(); i != migration_values_.end(); ++i) { |
| + // Queue all values for storing. |
| + CrosSettings::Get()->Set(i->first, *i->second); |
| + } |
| + migration_values_.Clear(); |
| + } |
| +} |
| + |
| +} // namespace chromeos |