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

Side by Side Diff: chrome/browser/chromeos/login/signed_settings_temp_storage.cc

Issue 8091002: PART2: Make SignedSettings use proper Value types instead of string all around the place. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed the nits and rebased on ToT (which now has PART1 in). Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 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 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/login/signed_settings_temp_storage.h" 5 #include "chrome/browser/chromeos/login/signed_settings_temp_storage.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "chrome/browser/chromeos/login/ownership_service.h" 8 #include "chrome/browser/chromeos/login/ownership_service.h"
9 #include "chrome/browser/chromeos/login/signed_settings_helper.h" 9 #include "chrome/browser/chromeos/login/signed_settings_helper.h"
10 #include "chrome/browser/prefs/pref_service.h" 10 #include "chrome/browser/prefs/pref_service.h"
11 #include "chrome/browser/prefs/scoped_user_pref_update.h" 11 #include "chrome/browser/prefs/scoped_user_pref_update.h"
12 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
13 13
14 using content::BrowserThread; 14 using content::BrowserThread;
15 15
16 namespace chromeos { 16 namespace chromeos {
17 17
18 // static 18 // static
19 void SignedSettingsTempStorage::RegisterPrefs(PrefService* local_state) { 19 void SignedSettingsTempStorage::RegisterPrefs(PrefService* local_state) {
20 local_state->RegisterDictionaryPref(prefs::kSignedSettingsTempStorage); 20 local_state->RegisterDictionaryPref(prefs::kSignedSettingsTempStorage);
21 } 21 }
22 22
23 // static 23 // static
24 bool SignedSettingsTempStorage::Store(const std::string& name, 24 bool SignedSettingsTempStorage::Store(const std::string& name,
25 const std::string& value, 25 const base::Value& value,
26 PrefService* local_state) { 26 PrefService* local_state) {
27 if (local_state) { 27 if (local_state) {
28 DictionaryPrefUpdate temp_storage_update( 28 DictionaryPrefUpdate temp_storage_update(
29 local_state, prefs::kSignedSettingsTempStorage); 29 local_state, prefs::kSignedSettingsTempStorage);
30 temp_storage_update->SetWithoutPathExpansion( 30 temp_storage_update->SetWithoutPathExpansion(
31 name, Value::CreateStringValue(value)); 31 name, value.DeepCopy());
32 return true; 32 return true;
33 } 33 }
34 return false; 34 return false;
35 } 35 }
36 36
37 // static 37 // static
38 bool SignedSettingsTempStorage::Retrieve(const std::string& name, 38 bool SignedSettingsTempStorage::Retrieve(const std::string& name,
39 std::string* value, 39 base::Value** value,
40 PrefService* local_state) { 40 PrefService* local_state) {
41 if (local_state) { 41 if (local_state) {
42 const DictionaryValue* temp_storage = 42 const DictionaryValue* temp_storage =
43 local_state->GetDictionary(prefs::kSignedSettingsTempStorage); 43 local_state->GetDictionary(prefs::kSignedSettingsTempStorage);
44 if (temp_storage && temp_storage->HasKey(name)) { 44 if (temp_storage && temp_storage->HasKey(name)) {
45 temp_storage->GetStringWithoutPathExpansion(name, value); 45 temp_storage->GetWithoutPathExpansion(name, value);
46 return true; 46 return true;
47 } 47 }
48 } 48 }
49 return false; 49 return false;
50 } 50 }
51 51
52 // static 52 // static
53 void SignedSettingsTempStorage::Finalize(PrefService* local_state) { 53 void SignedSettingsTempStorage::Finalize(PrefService* local_state) {
54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
55 if (local_state) { 55 if (local_state) {
56 const DictionaryValue* temp_storage = 56 const DictionaryValue* temp_storage =
57 local_state->GetDictionary(prefs::kSignedSettingsTempStorage); 57 local_state->GetDictionary(prefs::kSignedSettingsTempStorage);
58 if (temp_storage) { 58 if (temp_storage) {
59 // We've stored some settings in transient storage 59 // We've stored some settings in transient storage
60 // before owner has been assigned. 60 // before owner has been assigned.
61 // Now owner is assigned and key is generated and we should persist 61 // Now owner is assigned and key is generated and we should persist
62 // those settings into signed storage. 62 // those settings into signed storage.
63 for (DictionaryValue::key_iterator it = temp_storage->begin_keys(); 63 for (DictionaryValue::key_iterator it = temp_storage->begin_keys();
64 it != temp_storage->end_keys(); 64 it != temp_storage->end_keys();
65 ++it) { 65 ++it) {
66 std::string value; 66 base::Value* value = NULL;
67 temp_storage->GetStringWithoutPathExpansion(*it, &value); 67 bool get_result = temp_storage->GetWithoutPathExpansion(*it, &value);
68 SignedSettingsHelper::Get()->StartStorePropertyOp(*it, value, NULL); 68 DCHECK(value && get_result);
69 if (value)
70 SignedSettingsHelper::Get()->StartStorePropertyOp(*it, *value, NULL);
69 } 71 }
70 local_state->ClearPref(prefs::kSignedSettingsTempStorage); 72 local_state->ClearPref(prefs::kSignedSettingsTempStorage);
71 } 73 }
72 } 74 }
73 } 75 }
74 76
75 } // namespace chromeos 77 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698