Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4169)

Unified Diff: chrome/browser/chromeos/settings/device_settings_migration_helper.cc

Issue 10832035: Switch from SignedSettings to DeviceSettingsService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, remove blocking GetOwnershipStatus() Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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.
+// 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

Powered by Google App Engine
This is Rietveld 408576698