| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/common/json_value_serializer.h" | 10 #include "chrome/common/json_value_serializer.h" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | |
| 14 const wchar_t* kDistroDict = L"distribution"; | 13 const wchar_t* kDistroDict = L"distribution"; |
| 15 | 14 |
| 16 DictionaryValue* GetPrefsFromFile(const FilePath& master_prefs_path) { | |
| 17 std::string json_data; | |
| 18 if (!file_util::ReadFileToString(master_prefs_path, &json_data)) | |
| 19 return NULL; | |
| 20 | 15 |
| 21 JSONStringValueSerializer json(json_data); | |
| 22 scoped_ptr<Value> root(json.Deserialize(NULL)); | |
| 23 | |
| 24 if (!root.get()) | |
| 25 return NULL; | |
| 26 | |
| 27 if (!root->IsType(Value::TYPE_DICTIONARY)) | |
| 28 return NULL; | |
| 29 | |
| 30 return static_cast<DictionaryValue*>(root.release()); | |
| 31 } | |
| 32 } // namespace | 16 } // namespace |
| 33 | 17 |
| 34 namespace installer_util { | 18 namespace installer_util { |
| 35 namespace master_preferences { | 19 namespace master_preferences { |
| 36 const wchar_t kAltFirstRunBubble[] = L"oem_bubble"; | 20 const wchar_t kAltFirstRunBubble[] = L"oem_bubble"; |
| 37 const wchar_t kAltShortcutText[] = L"alternate_shortcut_text"; | 21 const wchar_t kAltShortcutText[] = L"alternate_shortcut_text"; |
| 22 const wchar_t kChromeShortcutIconIndex[] = L"chrome_shortcut_icon_index"; |
| 38 const wchar_t kCreateAllShortcuts[] = L"create_all_shortcuts"; | 23 const wchar_t kCreateAllShortcuts[] = L"create_all_shortcuts"; |
| 39 const wchar_t kDistroImportBookmarksPref[] = L"import_bookmarks"; | 24 const wchar_t kDistroImportBookmarksPref[] = L"import_bookmarks"; |
| 40 const wchar_t kDistroImportHistoryPref[] = L"import_history"; | 25 const wchar_t kDistroImportHistoryPref[] = L"import_history"; |
| 41 const wchar_t kDistroImportHomePagePref[] = L"import_home_page"; | 26 const wchar_t kDistroImportHomePagePref[] = L"import_home_page"; |
| 42 const wchar_t kDistroImportSearchPref[] = L"import_search_engine"; | 27 const wchar_t kDistroImportSearchPref[] = L"import_search_engine"; |
| 43 const wchar_t kDistroPingDelay[] = L"ping_delay"; | 28 const wchar_t kDistroPingDelay[] = L"ping_delay"; |
| 44 const wchar_t kDistroShowWelcomePage[] = L"show_welcome_page"; | 29 const wchar_t kDistroShowWelcomePage[] = L"show_welcome_page"; |
| 45 const wchar_t kDistroSkipFirstRunPref[] = L"skip_first_run_ui"; | 30 const wchar_t kDistroSkipFirstRunPref[] = L"skip_first_run_ui"; |
| 46 const wchar_t kDoNotLaunchChrome[] = L"do_not_launch_chrome"; | 31 const wchar_t kDoNotLaunchChrome[] = L"do_not_launch_chrome"; |
| 47 const wchar_t kMakeChromeDefault[] = L"make_chrome_default"; | 32 const wchar_t kMakeChromeDefault[] = L"make_chrome_default"; |
| 48 const wchar_t kMakeChromeDefaultForUser[] = L"make_chrome_default_for_user"; | 33 const wchar_t kMakeChromeDefaultForUser[] = L"make_chrome_default_for_user"; |
| 49 const wchar_t kRequireEula[] = L"require_eula"; | 34 const wchar_t kRequireEula[] = L"require_eula"; |
| 50 const wchar_t kSystemLevel[] = L"system_level"; | 35 const wchar_t kSystemLevel[] = L"system_level"; |
| 51 const wchar_t kVerboseLogging[] = L"verbose_logging"; | 36 const wchar_t kVerboseLogging[] = L"verbose_logging"; |
| 52 } | 37 } |
| 53 | 38 |
| 54 bool GetDistroBooleanPreference(const DictionaryValue* prefs, | 39 bool GetDistroBooleanPreference(const DictionaryValue* prefs, |
| 55 const std::wstring& name) { | 40 const std::wstring& name) { |
| 56 | 41 |
| 57 bool value = false; | 42 bool value = false; |
| 58 DictionaryValue* distro = NULL; | 43 DictionaryValue* distro = NULL; |
| 59 if (prefs && prefs->GetDictionary(kDistroDict, &distro) && distro) | 44 if (prefs && prefs->GetDictionary(kDistroDict, &distro) && distro) |
| 60 distro->GetBoolean(name, &value); | 45 distro->GetBoolean(name, &value); |
| 61 return value; | 46 return value; |
| 62 } | 47 } |
| 63 | 48 |
| 64 bool GetDistributionPingDelay(const DictionaryValue* prefs, | 49 bool GetDistroIntegerPreference(const DictionaryValue* prefs, |
| 65 int* ping_delay) { | 50 const std::wstring& name, |
| 66 if (!ping_delay) | 51 int* value) { |
| 52 if (!value) |
| 67 return false; | 53 return false; |
| 68 | 54 |
| 69 // 90 seconds is the default that we want to use in case master preferences | |
| 70 // is missing or corrupt. | |
| 71 *ping_delay = 90; | |
| 72 | |
| 73 DictionaryValue* distro = NULL; | 55 DictionaryValue* distro = NULL; |
| 74 if (!prefs || !prefs->GetDictionary(kDistroDict, &distro) || !distro) | 56 if (!prefs || !prefs->GetDictionary(kDistroDict, &distro) || !distro) |
| 75 return false; | 57 return false; |
| 76 | 58 |
| 77 if (!distro->GetInteger(master_preferences::kDistroPingDelay, ping_delay)) | 59 if (!distro->GetInteger(name, value)) |
| 78 return false; | 60 return false; |
| 79 | 61 |
| 80 return true; | 62 return true; |
| 81 } | 63 } |
| 82 | 64 |
| 83 DictionaryValue* ParseDistributionPreferences( | 65 DictionaryValue* ParseDistributionPreferences( |
| 84 const FilePath& master_prefs_path) { | 66 const FilePath& master_prefs_path) { |
| 85 if (!file_util::PathExists(master_prefs_path)) { | 67 if (!file_util::PathExists(master_prefs_path)) { |
| 86 LOG(WARNING) << "Master preferences file not found: " | 68 LOG(WARNING) << "Master preferences file not found: " |
| 87 << master_prefs_path.value(); | 69 << master_prefs_path.value(); |
| 88 return NULL; | 70 return NULL; |
| 89 } | 71 } |
| 72 std::string json_data; |
| 73 if (!file_util::ReadFileToString(master_prefs_path, &json_data)) |
| 74 return NULL; |
| 75 JSONStringValueSerializer json(json_data); |
| 76 scoped_ptr<Value> root(json.Deserialize(NULL)); |
| 90 | 77 |
| 91 return GetPrefsFromFile(master_prefs_path); | 78 if (!root.get()) |
| 79 return NULL; |
| 80 |
| 81 if (!root->IsType(Value::TYPE_DICTIONARY)) |
| 82 return NULL; |
| 83 |
| 84 return static_cast<DictionaryValue*>(root.release()); |
| 92 } | 85 } |
| 93 | 86 |
| 94 std::vector<std::wstring> GetFirstRunTabs(const DictionaryValue* prefs) { | 87 std::vector<std::wstring> GetFirstRunTabs(const DictionaryValue* prefs) { |
| 95 std::vector<std::wstring> launch_tabs; | 88 std::vector<std::wstring> launch_tabs; |
| 96 if (!prefs) | 89 if (!prefs) |
| 97 return launch_tabs; | 90 return launch_tabs; |
| 98 ListValue* tabs_list = NULL; | 91 ListValue* tabs_list = NULL; |
| 99 if (!prefs->GetList(L"first_run_tabs", &tabs_list)) | 92 if (!prefs->GetList(L"first_run_tabs", &tabs_list)) |
| 100 return launch_tabs; | 93 return launch_tabs; |
| 101 for (size_t i = 0; i < tabs_list->GetSize(); ++i) { | 94 for (size_t i = 0; i < tabs_list->GetSize(); ++i) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 118 if (prefs && !name.empty()) { | 111 if (prefs && !name.empty()) { |
| 119 std::wstring key(kDistroDict); | 112 std::wstring key(kDistroDict); |
| 120 key.append(L"." + name); | 113 key.append(L"." + name); |
| 121 if (prefs->SetBoolean(key, value)) | 114 if (prefs->SetBoolean(key, value)) |
| 122 ret = true; | 115 ret = true; |
| 123 } | 116 } |
| 124 return ret; | 117 return ret; |
| 125 } | 118 } |
| 126 | 119 |
| 127 } // installer_util | 120 } // installer_util |
| OLD | NEW |