OLD | NEW |
| (Empty) |
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 | |
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 : ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)) { | |
17 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_CHECKED, | |
18 content::NotificationService::AllSources()); | |
19 } | |
20 | |
21 SignedSettingsMigrationHelper::~SignedSettingsMigrationHelper() { | |
22 registrar_.RemoveAll(); | |
23 migration_values_.Clear(); | |
24 } | |
25 | |
26 void SignedSettingsMigrationHelper::AddMigrationValue(const std::string& path, | |
27 base::Value* value) { | |
28 migration_values_.SetValue(path, value); | |
29 } | |
30 | |
31 void SignedSettingsMigrationHelper::MigrateValues(void) { | |
32 ptr_factory_.InvalidateWeakPtrs(); | |
33 OwnershipService::GetSharedInstance()->GetStatusAsync( | |
34 base::Bind(&SignedSettingsMigrationHelper::DoMigrateValues, | |
35 ptr_factory_.GetWeakPtr())); | |
36 } | |
37 | |
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( | |
48 OwnershipService::Status status, | |
49 bool current_user_is_owner) { | |
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 |