Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // 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
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/settings/device_settings_migration_helper.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/values.h" | |
| 9 #include "chrome/browser/chromeos/settings/cros_settings.h" | |
| 10 | |
| 11 namespace chromeos { | |
| 12 | |
| 13 DeviceSettingsMigrationHelper::DeviceSettingsMigrationHelper() | |
| 14 : ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)) { | |
| 15 } | |
| 16 | |
| 17 DeviceSettingsMigrationHelper::~DeviceSettingsMigrationHelper() { | |
| 18 migration_values_.Clear(); | |
| 19 } | |
| 20 | |
| 21 void DeviceSettingsMigrationHelper::AddMigrationValue(const std::string& path, | |
| 22 base::Value* value) { | |
| 23 migration_values_.SetValue(path, value); | |
| 24 } | |
| 25 | |
| 26 void DeviceSettingsMigrationHelper::MigrateValues(void) { | |
| 27 ptr_factory_.InvalidateWeakPtrs(); | |
| 28 DeviceSettingsService::Get()->GetOwnershipStatusAsync( | |
| 29 base::Bind(&DeviceSettingsMigrationHelper::DoMigrateValues, | |
| 30 ptr_factory_.GetWeakPtr())); | |
| 31 } | |
| 32 | |
| 33 void DeviceSettingsMigrationHelper::DoMigrateValues( | |
| 34 DeviceSettingsService::OwnershipStatus status, | |
| 35 bool current_user_is_owner) { | |
| 36 // We can call CrosSettings::Set in two cases - either if the owner is | |
| 37 // currently logged in and the policy can be updated immediately or if there | |
| 38 // is no owner yet in which case the value will be temporarily stored in the | |
| 39 // cache until the device is owned. If none of these cases is met then we will | |
| 40 // wait for the next opportunity. | |
| 41 if (current_user_is_owner || | |
| 42 status != DeviceSettingsService::OWNERSHIP_TAKEN) { | |
| 43 std::map<std::string, base::Value*>::const_iterator i; | |
| 44 for (i = migration_values_.begin(); i != migration_values_.end(); ++i) { | |
| 45 // Queue all values for storing. | |
| 46 CrosSettings::Get()->Set(i->first, *i->second); | |
| 47 } | |
| 48 migration_values_.Clear(); | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 } // namespace chromeos | |
| OLD | NEW |