| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/installer/util/master_preferences.h" | 5 #include "chrome/installer/util/master_preferences.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "chrome/common/json_value_serializer.h" | 11 #include "chrome/common/json_value_serializer.h" |
| 12 #include "chrome/installer/util/util_constants.h" | 12 #include "chrome/installer/util/util_constants.h" |
| 13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 14 | 14 |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 const wchar_t* kDistroDict = L"distribution"; | 17 |
| 18 const char kDistroDict[] = "distribution"; |
| 18 | 19 |
| 19 bool GetGURLFromValue(const Value* in_value, GURL* out_value) { | 20 bool GetGURLFromValue(const Value* in_value, GURL* out_value) { |
| 20 if (!in_value || !out_value) | 21 if (!in_value || !out_value) |
| 21 return false; | 22 return false; |
| 22 std::string url; | 23 std::string url; |
| 23 in_value->GetAsString(&url); | 24 in_value->GetAsString(&url); |
| 24 GURL gurl(url); | 25 GURL gurl(url); |
| 25 *out_value = gurl; | 26 *out_value = gurl; |
| 26 return true; | 27 return true; |
| 27 } | 28 } |
| 28 | 29 |
| 29 std::vector<GURL> GetNamedList(const wchar_t* name, | 30 std::vector<GURL> GetNamedList(const char* name, |
| 30 const DictionaryValue* prefs) { | 31 const DictionaryValue* prefs) { |
| 31 std::vector<GURL> list; | 32 std::vector<GURL> list; |
| 32 if (!prefs) | 33 if (!prefs) |
| 33 return list; | 34 return list; |
| 34 ListValue* value_list = NULL; | 35 ListValue* value_list = NULL; |
| 35 if (!prefs->GetList(name, &value_list)) | 36 if (!prefs->GetList(name, &value_list)) |
| 36 return list; | 37 return list; |
| 37 for (size_t i = 0; i < value_list->GetSize(); ++i) { | 38 for (size_t i = 0; i < value_list->GetSize(); ++i) { |
| 38 Value* entry; | 39 Value* entry; |
| 39 GURL gurl_entry; | 40 GURL gurl_entry; |
| 40 if (!value_list->Get(i, &entry) || !GetGURLFromValue(entry, &gurl_entry)) { | 41 if (!value_list->Get(i, &entry) || !GetGURLFromValue(entry, &gurl_entry)) { |
| 41 NOTREACHED(); | 42 NOTREACHED(); |
| 42 break; | 43 break; |
| 43 } | 44 } |
| 44 list.push_back(gurl_entry); | 45 list.push_back(gurl_entry); |
| 45 } | 46 } |
| 46 return list; | 47 return list; |
| 47 } | 48 } |
| 48 | 49 |
| 49 } | 50 } // namespace |
| 50 | 51 |
| 51 namespace installer_util { | 52 namespace installer_util { |
| 52 | 53 |
| 53 bool GetDistroBooleanPreference(const DictionaryValue* prefs, | 54 bool GetDistroBooleanPreference(const DictionaryValue* prefs, |
| 54 const std::wstring& name, | 55 const std::string& name, |
| 55 bool* value) { | 56 bool* value) { |
| 56 if (!prefs || !value) | 57 if (!prefs || !value) |
| 57 return false; | 58 return false; |
| 58 | 59 |
| 59 DictionaryValue* distro = NULL; | 60 DictionaryValue* distro = NULL; |
| 60 if (!prefs->GetDictionary(kDistroDict, &distro) || !distro) | 61 if (!prefs->GetDictionary(kDistroDict, &distro) || !distro) |
| 61 return false; | 62 return false; |
| 62 | 63 |
| 63 if (!distro->GetBoolean(name, value)) | 64 if (!distro->GetBoolean(name, value)) |
| 64 return false; | 65 return false; |
| 65 | 66 |
| 66 return true; | 67 return true; |
| 67 } | 68 } |
| 68 | 69 |
| 69 bool GetDistroStringPreference(const DictionaryValue* prefs, | 70 bool GetDistroStringPreference(const DictionaryValue* prefs, |
| 70 const std::wstring& name, | 71 const std::string& name, |
| 71 std::wstring* value) { | 72 std::string* value) { |
| 72 if (!prefs || !value) | 73 if (!prefs || !value) |
| 73 return false; | 74 return false; |
| 74 | 75 |
| 75 DictionaryValue* distro = NULL; | 76 DictionaryValue* distro = NULL; |
| 76 if (!prefs->GetDictionary(kDistroDict, &distro) || !distro) | 77 if (!prefs->GetDictionary(kDistroDict, &distro) || !distro) |
| 77 return false; | 78 return false; |
| 78 | 79 |
| 79 std::wstring str_value; | 80 std::string str_value; |
| 80 if (!distro->GetString(name, &str_value)) | 81 if (!distro->GetString(name, &str_value)) |
| 81 return false; | 82 return false; |
| 82 | 83 |
| 83 if (str_value.empty()) | 84 if (str_value.empty()) |
| 84 return false; | 85 return false; |
| 85 | 86 |
| 86 *value = str_value; | 87 *value = str_value; |
| 87 return true; | 88 return true; |
| 88 } | 89 } |
| 89 | 90 |
| 90 bool GetDistroIntegerPreference(const DictionaryValue* prefs, | 91 bool GetDistroIntegerPreference(const DictionaryValue* prefs, |
| 91 const std::wstring& name, | 92 const std::string& name, |
| 92 int* value) { | 93 int* value) { |
| 93 if (!prefs || !value) | 94 if (!prefs || !value) |
| 94 return false; | 95 return false; |
| 95 | 96 |
| 96 DictionaryValue* distro = NULL; | 97 DictionaryValue* distro = NULL; |
| 97 if (!prefs->GetDictionary(kDistroDict, &distro) || !distro) | 98 if (!prefs->GetDictionary(kDistroDict, &distro) || !distro) |
| 98 return false; | 99 return false; |
| 99 | 100 |
| 100 if (!distro->GetInteger(name, value)) | 101 if (!distro->GetInteger(name, value)) |
| 101 return false; | 102 return false; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 if (!root.get()) | 180 if (!root.get()) |
| 180 return NULL; | 181 return NULL; |
| 181 | 182 |
| 182 if (!root->IsType(Value::TYPE_DICTIONARY)) | 183 if (!root->IsType(Value::TYPE_DICTIONARY)) |
| 183 return NULL; | 184 return NULL; |
| 184 | 185 |
| 185 return static_cast<DictionaryValue*>(root.release()); | 186 return static_cast<DictionaryValue*>(root.release()); |
| 186 } | 187 } |
| 187 | 188 |
| 188 std::vector<GURL> GetFirstRunTabs(const DictionaryValue* prefs) { | 189 std::vector<GURL> GetFirstRunTabs(const DictionaryValue* prefs) { |
| 189 return GetNamedList(L"first_run_tabs", prefs); | 190 return GetNamedList("first_run_tabs", prefs); |
| 190 } | 191 } |
| 191 | 192 |
| 192 bool SetDistroBooleanPreference(DictionaryValue* prefs, | 193 bool SetDistroBooleanPreference(DictionaryValue* prefs, |
| 193 const std::wstring& name, | 194 const std::string& name, |
| 194 bool value) { | 195 bool value) { |
| 195 if (!prefs || name.empty()) | 196 if (!prefs || name.empty()) |
| 196 return false; | 197 return false; |
| 197 prefs->SetBoolean(std::wstring(kDistroDict) + L"." + name, value); | 198 prefs->SetBoolean(std::string(kDistroDict) + "." + name, value); |
| 198 return true; | 199 return true; |
| 199 } | 200 } |
| 200 | 201 |
| 201 bool HasExtensionsBlock(const DictionaryValue* prefs, | 202 bool HasExtensionsBlock(const DictionaryValue* prefs, |
| 202 DictionaryValue** extensions) { | 203 DictionaryValue** extensions) { |
| 203 return (prefs->GetDictionary(master_preferences::kExtensionsBlock, | 204 return (prefs->GetDictionary(master_preferences::kExtensionsBlock, |
| 204 extensions)); | 205 extensions)); |
| 205 } | 206 } |
| 206 | 207 |
| 207 } // installer_util | 208 } // installer_util |
| OLD | NEW |