OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/signed_settings_migration_helper.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/values.h" |
| 9 #include "chrome/browser/chromeos/cros_settings.h" |
| 10 #include "chrome/common/chrome_notification_types.h" |
| 11 #include "content/public/browser/notification_service.h" |
| 12 |
| 13 namespace chromeos { |
| 14 |
| 15 SignedSettingsMigrationHelper::SignedSettingsMigrationHelper() { |
| 16 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_CHECKED, |
| 17 content::NotificationService::AllSources()); |
| 18 } |
| 19 |
| 20 SignedSettingsMigrationHelper::~SignedSettingsMigrationHelper() { |
| 21 registrar_.RemoveAll(); |
| 22 migration_values_.Clear(); |
| 23 } |
| 24 |
| 25 void SignedSettingsMigrationHelper::AddMigrationValue(const std::string& path, |
| 26 base::Value* value) { |
| 27 migration_values_.SetValue(path, value); |
| 28 } |
| 29 |
| 30 void SignedSettingsMigrationHelper::MigrateValues(void) { |
| 31 ownership_checker_.reset(new OwnershipStatusChecker( |
| 32 base::Bind(&SignedSettingsMigrationHelper::DoMigrateValues, |
| 33 base::Unretained(this)))); |
| 34 } |
| 35 |
| 36 // NotificationObserver overrides: |
| 37 void SignedSettingsMigrationHelper::Observe( |
| 38 int type, |
| 39 const content::NotificationSource& source, |
| 40 const content::NotificationDetails& details) { |
| 41 if (type == chrome::NOTIFICATION_OWNERSHIP_CHECKED) |
| 42 MigrateValues(); |
| 43 } |
| 44 |
| 45 void SignedSettingsMigrationHelper::DoMigrateValues( |
| 46 OwnershipService::Status status, |
| 47 bool current_user_is_owner) { |
| 48 ownership_checker_.reset(NULL); |
| 49 |
| 50 // We can call StartStorePropertyOp in two cases - either if the owner is |
| 51 // currently logged in and the policy can be updated immediately or if there |
| 52 // is no owner yet in which case the value will be temporarily stored in the |
| 53 // SignedSettingsCache until the device is owned. If none of these |
| 54 // cases is met then we will wait for user change notification and retry. |
| 55 if (current_user_is_owner || status != OwnershipService::OWNERSHIP_TAKEN) { |
| 56 std::map<std::string, base::Value*>::const_iterator i; |
| 57 for (i = migration_values_.begin(); i != migration_values_.end(); ++i) { |
| 58 // Queue all values for storing. |
| 59 CrosSettings::Get()->Set(i->first, *i->second); |
| 60 } |
| 61 migration_values_.Clear(); |
| 62 } |
| 63 } |
| 64 |
| 65 } // namespace chromeos |
| 66 |
OLD | NEW |