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/login/signed_settings_temp_storage.h" | |
6 | |
7 #include "base/values.h" | |
8 #include "chrome/browser/chromeos/login/ownership_service.h" | |
9 #include "chrome/browser/chromeos/login/signed_settings_helper.h" | |
10 #include "chrome/browser/prefs/pref_service.h" | |
11 #include "chrome/browser/prefs/scoped_user_pref_update.h" | |
12 #include "chrome/common/pref_names.h" | |
13 | |
14 using content::BrowserThread; | |
15 | |
16 namespace chromeos { | |
17 | |
18 // static | |
19 void SignedSettingsTempStorage::RegisterPrefs(PrefService* local_state) { | |
20 local_state->RegisterDictionaryPref(prefs::kSignedSettingsTempStorage); | |
21 } | |
22 | |
23 // static | |
24 bool SignedSettingsTempStorage::Store(const std::string& name, | |
25 const base::Value& value, | |
26 PrefService* local_state) { | |
27 if (local_state) { | |
28 DictionaryPrefUpdate temp_storage_update( | |
29 local_state, prefs::kSignedSettingsTempStorage); | |
30 temp_storage_update->SetWithoutPathExpansion( | |
31 name, value.DeepCopy()); | |
32 return true; | |
33 } | |
34 return false; | |
35 } | |
36 | |
37 // static | |
38 bool SignedSettingsTempStorage::Retrieve(const std::string& name, | |
39 base::Value** value, | |
40 PrefService* local_state) { | |
41 if (local_state) { | |
42 const DictionaryValue* temp_storage = | |
43 local_state->GetDictionary(prefs::kSignedSettingsTempStorage); | |
44 if (temp_storage && temp_storage->HasKey(name)) { | |
45 temp_storage->GetWithoutPathExpansion(name, value); | |
46 return true; | |
47 } | |
48 } | |
49 return false; | |
50 } | |
51 | |
52 // static | |
53 void SignedSettingsTempStorage::Finalize(PrefService* local_state) { | |
54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
55 if (local_state) { | |
56 const DictionaryValue* temp_storage = | |
57 local_state->GetDictionary(prefs::kSignedSettingsTempStorage); | |
58 if (temp_storage) { | |
59 // We've stored some settings in transient storage | |
60 // before owner has been assigned. | |
61 // Now owner is assigned and key is generated and we should persist | |
62 // those settings into signed storage. | |
63 for (DictionaryValue::key_iterator it = temp_storage->begin_keys(); | |
64 it != temp_storage->end_keys(); | |
65 ++it) { | |
66 base::Value* value = NULL; | |
67 bool get_result = temp_storage->GetWithoutPathExpansion(*it, &value); | |
68 DCHECK(value && get_result); | |
69 if (value) | |
70 SignedSettingsHelper::Get()->StartStorePropertyOp(*it, *value, NULL); | |
71 } | |
72 local_state->ClearPref(prefs::kSignedSettingsTempStorage); | |
73 } | |
74 } | |
75 } | |
76 | |
77 } // namespace chromeos | |
OLD | NEW |