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