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

Side by Side Diff: chrome/browser/chromeos/signed_settings_migration_helper.cc

Issue 10832035: Switch from SignedSettings to DeviceSettingsService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More test fixing... 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/signed_settings_migration_helper.h" 5 #include "chrome/browser/chromeos/signed_settings_migration_helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/chromeos/cros_settings.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 10
13 namespace chromeos { 11 namespace chromeos {
14 12
15 SignedSettingsMigrationHelper::SignedSettingsMigrationHelper() 13 SignedSettingsMigrationHelper::SignedSettingsMigrationHelper()
16 : ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)) { 14 : ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)) {
17 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_CHECKED,
18 content::NotificationService::AllSources());
19 } 15 }
20 16
21 SignedSettingsMigrationHelper::~SignedSettingsMigrationHelper() { 17 SignedSettingsMigrationHelper::~SignedSettingsMigrationHelper() {
22 registrar_.RemoveAll();
23 migration_values_.Clear(); 18 migration_values_.Clear();
24 } 19 }
25 20
26 void SignedSettingsMigrationHelper::AddMigrationValue(const std::string& path, 21 void SignedSettingsMigrationHelper::AddMigrationValue(const std::string& path,
27 base::Value* value) { 22 base::Value* value) {
28 migration_values_.SetValue(path, value); 23 migration_values_.SetValue(path, value);
29 } 24 }
30 25
31 void SignedSettingsMigrationHelper::MigrateValues(void) { 26 void SignedSettingsMigrationHelper::MigrateValues(void) {
32 ptr_factory_.InvalidateWeakPtrs(); 27 ptr_factory_.InvalidateWeakPtrs();
33 OwnershipService::GetSharedInstance()->GetStatusAsync( 28 DeviceSettingsService::Get()->GetOwnershipStatusAsync(
34 base::Bind(&SignedSettingsMigrationHelper::DoMigrateValues, 29 base::Bind(&SignedSettingsMigrationHelper::DoMigrateValues,
35 ptr_factory_.GetWeakPtr())); 30 ptr_factory_.GetWeakPtr()));
36 } 31 }
37 32
38 // NotificationObserver overrides:
39 void SignedSettingsMigrationHelper::Observe(
40 int type,
41 const content::NotificationSource& source,
42 const content::NotificationDetails& details) {
43 if (type == chrome::NOTIFICATION_OWNERSHIP_CHECKED)
44 MigrateValues();
45 }
46
47 void SignedSettingsMigrationHelper::DoMigrateValues( 33 void SignedSettingsMigrationHelper::DoMigrateValues(
48 OwnershipService::Status status, 34 DeviceSettingsService::OwnershipStatus status,
49 bool current_user_is_owner) { 35 bool current_user_is_owner) {
50 // We can call StartStorePropertyOp in two cases - either if the owner is 36 // We can call CrosSettings::Set in two cases - either if the owner is
51 // currently logged in and the policy can be updated immediately or if there 37 // 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 38 // 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 39 // cache until the device is owned. If none of these cases is met then we will
54 // cases is met then we will wait for user change notification and retry. 40 // wait for the next opportunity.
55 if (current_user_is_owner || status != OwnershipService::OWNERSHIP_TAKEN) { 41 if (current_user_is_owner ||
42 status != DeviceSettingsService::OWNERSHIP_TAKEN) {
56 std::map<std::string, base::Value*>::const_iterator i; 43 std::map<std::string, base::Value*>::const_iterator i;
57 for (i = migration_values_.begin(); i != migration_values_.end(); ++i) { 44 for (i = migration_values_.begin(); i != migration_values_.end(); ++i) {
58 // Queue all values for storing. 45 // Queue all values for storing.
59 CrosSettings::Get()->Set(i->first, *i->second); 46 CrosSettings::Get()->Set(i->first, *i->second);
60 } 47 }
61 migration_values_.Clear(); 48 migration_values_.Clear();
62 } 49 }
63 } 50 }
64 51
65 } // namespace chromeos 52 } // namespace chromeos
66
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698