OLD | NEW |
1 // Copyright (c) 2010 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/browser/first_run/first_run.h" | 5 #include "chrome/browser/first_run/first_run.h" |
6 | 6 |
7 #include "app/app_switches.h" | 7 #include "app/app_switches.h" |
| 8 #include "base/command_line.h" |
8 #include "base/file_path.h" | 9 #include "base/file_path.h" |
9 #include "base/file_util.h" | 10 #include "base/file_util.h" |
10 #include "base/path_service.h" | 11 #include "base/path_service.h" |
11 #include "base/process_util.h" | 12 #include "base/process_util.h" |
12 #include "base/string_piece.h" | 13 #include "base/string_piece.h" |
13 #include "base/string_util.h" | 14 #include "base/string_util.h" |
14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
15 #include "base/values.h" | 16 #include "base/values.h" |
16 #include "chrome/browser/gtk/first_run_dialog.h" | 17 #include "chrome/browser/gtk/first_run_dialog.h" |
17 #include "chrome/browser/profile_manager.h" | |
18 #include "chrome/browser/shell_integration.h" | 18 #include "chrome/browser/shell_integration.h" |
19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
21 #include "chrome/common/result_codes.h" | 21 #include "chrome/common/result_codes.h" |
22 #include "chrome/installer/util/google_update_settings.h" | 22 #include "chrome/installer/util/google_update_settings.h" |
23 #include "chrome/installer/util/master_preferences.h" | |
24 #include "chrome/installer/util/util_constants.h" | |
25 #include "googleurl/src/gurl.h" | 23 #include "googleurl/src/gurl.h" |
26 | 24 |
27 // TODO(estade): pay attention to the args between |profile| and | 25 // TODO(estade): pay attention to the args between |profile| and |
28 // |process_singleton|. | 26 // |process_singleton|. |
29 bool OpenFirstRunDialog(Profile* profile, | 27 bool OpenFirstRunDialog(Profile* profile, |
30 bool homepage_defined, | 28 bool homepage_defined, |
31 int import_items, | 29 int import_items, |
32 int dont_import_items, | 30 int dont_import_items, |
33 bool search_engine_experiment, | 31 bool search_engine_experiment, |
34 bool randomize_search_engine_experiment, | 32 bool randomize_search_engine_experiment, |
35 ProcessSingleton* process_singleton) { | 33 ProcessSingleton* process_singleton) { |
36 return FirstRunDialog::Show(profile, process_singleton); | 34 return FirstRunDialog::Show(profile, process_singleton); |
37 } | 35 } |
38 | 36 |
39 FilePath GetDefaultPrefFilePath(bool create_profile_dir, | |
40 const FilePath& user_data_dir) { | |
41 FilePath default_pref_dir = | |
42 ProfileManager::GetDefaultProfileDir(user_data_dir); | |
43 if (create_profile_dir) { | |
44 if (!file_util::PathExists(default_pref_dir)) { | |
45 if (!file_util::CreateDirectory(default_pref_dir)) | |
46 return FilePath(); | |
47 } | |
48 } | |
49 return ProfileManager::GetProfilePrefsPath(default_pref_dir); | |
50 } | |
51 | |
52 bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, | |
53 MasterPrefs* out_prefs) { | |
54 DCHECK(!user_data_dir.empty()); | |
55 | |
56 // The standard location of the master prefs is next to the chrome binary. | |
57 FilePath master_prefs; | |
58 if (!PathService::Get(base::DIR_EXE, &master_prefs)) | |
59 return true; | |
60 master_prefs = master_prefs.AppendASCII(installer_util::kDefaultMasterPrefs); | |
61 | |
62 scoped_ptr<DictionaryValue> prefs( | |
63 installer_util::ParseDistributionPreferences(master_prefs)); | |
64 if (!prefs.get()) | |
65 return true; | |
66 | |
67 out_prefs->new_tabs = installer_util::GetFirstRunTabs(prefs.get()); | |
68 | |
69 std::string not_used; | |
70 out_prefs->homepage_defined = prefs->GetString(prefs::kHomePage, ¬_used); | |
71 | |
72 bool value = false; | |
73 if (installer_util::GetDistroBooleanPreference(prefs.get(), | |
74 installer_util::master_preferences::kAltFirstRunBubble, &value) && value) | |
75 FirstRun::SetOEMFirstRunBubblePref(); | |
76 | |
77 FilePath user_prefs = GetDefaultPrefFilePath(true, user_data_dir); | |
78 if (user_prefs.empty()) | |
79 return true; | |
80 | |
81 // The master prefs are regular prefs so we can just copy the file | |
82 // to the default place and they just work. | |
83 if (!file_util::CopyFile(master_prefs, user_prefs)) | |
84 return true; | |
85 | |
86 // Note we are skipping all other master preferences if skip-first-run-ui | |
87 // is *not* specified. | |
88 if (!installer_util::GetDistroBooleanPreference(prefs.get(), | |
89 installer_util::master_preferences::kDistroSkipFirstRunPref, &value) || | |
90 !value) | |
91 return true; | |
92 | |
93 // From here on we won't show first run so we need to do the work to set the | |
94 // required state given that FirstRunView is not going to be called. | |
95 FirstRun::SetShowFirstRunBubblePref(true); | |
96 | |
97 if (installer_util::GetDistroBooleanPreference(prefs.get(), | |
98 installer_util::master_preferences::kDistroShowWelcomePage, &value) && | |
99 value) | |
100 FirstRun::SetShowWelcomePagePref(); | |
101 | |
102 // We need to be able to create the first run sentinel or else we cannot | |
103 // proceed because ImportSettings will launch the importer process which | |
104 // would end up here if the sentinel is not present. | |
105 if (!FirstRun::CreateSentinel()) | |
106 return false; | |
107 | |
108 std::string import_bookmarks_path; | |
109 installer_util::GetDistroStringPreference(prefs.get(), | |
110 installer_util::master_preferences::kDistroImportBookmarksFromFilePref, | |
111 &import_bookmarks_path); | |
112 | |
113 if (!import_bookmarks_path.empty()) { | |
114 // There are bookmarks to import from a file. | |
115 FilePath path = FilePath::FromWStringHack( | |
116 UTF8ToWide(import_bookmarks_path)); | |
117 if (!FirstRun::ImportBookmarks(path)) { | |
118 LOG(WARNING) << "silent bookmark import failed"; | |
119 } | |
120 } | |
121 return false; | |
122 } | |
123 | |
124 // TODO(port): This is just a piece of the silent import functionality from | 37 // TODO(port): This is just a piece of the silent import functionality from |
125 // ImportSettings for Windows. It would be nice to get the rest of it ported. | 38 // ImportSettings for Windows. It would be nice to get the rest of it ported. |
126 bool FirstRun::ImportBookmarks(const FilePath& import_bookmarks_path) { | 39 bool FirstRun::ImportBookmarks(const FilePath& import_bookmarks_path) { |
127 const CommandLine& cmdline = *CommandLine::ForCurrentProcess(); | 40 const CommandLine& cmdline = *CommandLine::ForCurrentProcess(); |
128 CommandLine import_cmd(cmdline.GetProgram()); | 41 CommandLine import_cmd(cmdline.GetProgram()); |
129 | 42 |
130 // Propagate user data directory switch. | 43 // Propagate user data directory switch. |
131 if (cmdline.HasSwitch(switches::kUserDataDir)) { | 44 if (cmdline.HasSwitch(switches::kUserDataDir)) { |
132 import_cmd.AppendSwitchPath(switches::kUserDataDir, | 45 import_cmd.AppendSwitchPath(switches::kUserDataDir, |
133 cmdline.GetSwitchValuePath(switches::kUserDataDir)); | 46 cmdline.GetSwitchValuePath(switches::kUserDataDir)); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 } | 87 } |
175 file_util::FileInfo exe_file_info; | 88 file_util::FileInfo exe_file_info; |
176 if (!file_util::GetFileInfo(exe_file_path, &exe_file_info)) { | 89 if (!file_util::GetFileInfo(exe_file_path, &exe_file_info)) { |
177 LOG(WARNING) << "Failed to get FileInfo object for FILE_EXE - " | 90 LOG(WARNING) << "Failed to get FileInfo object for FILE_EXE - " |
178 << exe_file_path.value(); | 91 << exe_file_path.value(); |
179 return saved_last_modified_time_of_exe_; | 92 return saved_last_modified_time_of_exe_; |
180 } | 93 } |
181 return exe_file_info.last_modified.ToDoubleT(); | 94 return exe_file_info.last_modified.ToDoubleT(); |
182 } | 95 } |
183 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) | 96 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) |
OLD | NEW |