OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
16 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
17 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
18 #include "base/time.h" | 18 #include "base/time.h" |
19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
21 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
22 #include "chrome/browser/extensions/extension_service.h" | 22 #include "chrome/browser/extensions/extension_service.h" |
23 #include "chrome/browser/extensions/updater/extension_updater.h" | 23 #include "chrome/browser/extensions/updater/extension_updater.h" |
24 #include "chrome/browser/first_run/first_run_dialog.h" | 24 #include "chrome/browser/first_run/first_run_dialog.h" |
25 #include "chrome/browser/first_run/first_run_import_observer.h" | |
26 #include "chrome/browser/first_run/first_run_internal.h" | 25 #include "chrome/browser/first_run/first_run_internal.h" |
27 #include "chrome/browser/google/google_util.h" | 26 #include "chrome/browser/google/google_util.h" |
28 #include "chrome/browser/importer/external_process_importer_host.h" | 27 #include "chrome/browser/importer/external_process_importer_host.h" |
29 #include "chrome/browser/importer/importer_host.h" | 28 #include "chrome/browser/importer/importer_host.h" |
30 #include "chrome/browser/importer/importer_list.h" | 29 #include "chrome/browser/importer/importer_list.h" |
31 #include "chrome/browser/importer/importer_progress_dialog.h" | |
32 #include "chrome/browser/importer/importer_progress_observer.h" | 30 #include "chrome/browser/importer/importer_progress_observer.h" |
33 #include "chrome/browser/process_singleton.h" | 31 #include "chrome/browser/process_singleton.h" |
34 #include "chrome/browser/profiles/profile_manager.h" | 32 #include "chrome/browser/profiles/profile_manager.h" |
35 #include "chrome/browser/search_engines/template_url_service.h" | 33 #include "chrome/browser/search_engines/template_url_service.h" |
36 #include "chrome/browser/search_engines/template_url_service_factory.h" | 34 #include "chrome/browser/search_engines/template_url_service_factory.h" |
37 #include "chrome/browser/shell_integration.h" | 35 #include "chrome/browser/shell_integration.h" |
38 #include "chrome/browser/signin/signin_manager.h" | 36 #include "chrome/browser/signin/signin_manager.h" |
39 #include "chrome/browser/signin/signin_manager_factory.h" | 37 #include "chrome/browser/signin/signin_manager_factory.h" |
40 #include "chrome/browser/signin/signin_tracker.h" | 38 #include "chrome/browser/signin/signin_tracker.h" |
41 #include "chrome/browser/ui/browser.h" | 39 #include "chrome/browser/ui/browser.h" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 } else { // no policy (recommended or managed) is set | 194 } else { // no policy (recommended or managed) is set |
197 if (should_import) | 195 if (should_import) |
198 items |= import_type; | 196 items |= import_type; |
199 } | 197 } |
200 | 198 |
201 user_prefs->ClearPref(pref_path); | 199 user_prefs->ClearPref(pref_path); |
202 } | 200 } |
203 | 201 |
204 // Imports bookmarks from an html file. The path to the file is provided in | 202 // Imports bookmarks from an html file. The path to the file is provided in |
205 // the command line. | 203 // the command line. |
206 int ImportFromFile(Profile* profile, const CommandLine& cmdline) { | 204 void ImportFromFile(Profile* profile, const CommandLine& cmdline) { |
207 base::FilePath file_path = | 205 base::FilePath file_path = |
208 cmdline.GetSwitchValuePath(switches::kImportFromFile); | 206 cmdline.GetSwitchValuePath(switches::kImportFromFile); |
209 if (file_path.empty()) { | 207 if (file_path.empty()) { |
210 NOTREACHED(); | 208 NOTREACHED(); |
211 return false; | 209 return; |
212 } | 210 } |
213 scoped_refptr<ImporterHost> importer_host(new ImporterHost); | 211 scoped_refptr<ImporterHost> importer_host(new ImporterHost); |
214 importer_host->set_headless(); | 212 importer_host->set_headless(); |
215 | 213 |
216 importer::SourceProfile source_profile; | 214 importer::SourceProfile source_profile; |
217 source_profile.importer_type = importer::TYPE_BOOKMARKS_FILE; | 215 source_profile.importer_type = importer::TYPE_BOOKMARKS_FILE; |
218 source_profile.source_path = file_path; | 216 source_profile.source_path = file_path; |
219 | 217 |
220 FirstRunImportObserver importer_observer; | 218 first_run::internal::ImportEndedObserver observer; |
221 importer::ShowImportProgressDialog(importer::FAVORITES, | 219 importer_host->SetObserver(&observer); |
222 importer_host, | 220 importer_host->StartImportSettings( |
223 &importer_observer, | 221 source_profile, profile, importer::FAVORITES, new ProfileWriter(profile), |
224 source_profile, | 222 true); |
225 profile, | 223 // If the import process has not errored out, block on it. |
226 true); | 224 if (!observer.ended()) { |
227 | 225 observer.set_should_quit_message_loop(); |
228 importer_observer.RunLoop(); | 226 MessageLoop::current()->Run(); |
229 return importer_observer.import_result(); | 227 } |
230 } | 228 } |
231 | 229 |
232 GURL UrlFromString(const std::string& in) { | 230 GURL UrlFromString(const std::string& in) { |
233 return GURL(in); | 231 return GURL(in); |
234 } | 232 } |
235 | 233 |
236 void ConvertStringVectorToGURLVector( | 234 void ConvertStringVectorToGURLVector( |
237 const std::vector<std::string>& src, | 235 const std::vector<std::string>& src, |
238 std::vector<GURL>* ret) { | 236 std::vector<GURL>* ret) { |
239 ret->resize(src.size()); | 237 ret->resize(src.size()); |
240 std::transform(src.begin(), src.end(), ret->begin(), &UrlFromString); | 238 std::transform(src.begin(), src.end(), ret->begin(), &UrlFromString); |
241 } | 239 } |
242 | 240 |
243 } // namespace | 241 } // namespace |
244 | 242 |
245 namespace first_run { | 243 namespace first_run { |
246 namespace internal { | 244 namespace internal { |
247 | 245 |
248 FirstRunState first_run_ = FIRST_RUN_UNKNOWN; | 246 FirstRunState first_run_ = FIRST_RUN_UNKNOWN; |
249 | 247 |
250 static base::LazyInstance<base::FilePath> master_prefs_path_for_testing | 248 static base::LazyInstance<base::FilePath> master_prefs_path_for_testing |
251 = LAZY_INSTANCE_INITIALIZER; | 249 = LAZY_INSTANCE_INITIALIZER; |
252 | 250 |
| 251 // TODO(gab): This will go back inline above when it is moved to first_run.cc |
| 252 // (see TODO above), but needs to be separate for now to satisfy clang error: |
| 253 // "[chromium-style] virtual methods with non-empty bodies shouldn't be declared |
| 254 // inline". |
| 255 void ImportEndedObserver::ImportEnded() { |
| 256 ended_ = true; |
| 257 if (should_quit_message_loop_) |
| 258 MessageLoop::current()->Quit(); |
| 259 } |
| 260 |
253 installer::MasterPreferences* | 261 installer::MasterPreferences* |
254 LoadMasterPrefs(base::FilePath* master_prefs_path) { | 262 LoadMasterPrefs(base::FilePath* master_prefs_path) { |
255 if (!master_prefs_path_for_testing.Get().empty()) | 263 if (!master_prefs_path_for_testing.Get().empty()) |
256 *master_prefs_path = master_prefs_path_for_testing.Get(); | 264 *master_prefs_path = master_prefs_path_for_testing.Get(); |
257 else | 265 else |
258 *master_prefs_path = base::FilePath(MasterPrefsPath()); | 266 *master_prefs_path = base::FilePath(MasterPrefsPath()); |
259 if (master_prefs_path->empty()) | 267 if (master_prefs_path->empty()) |
260 return NULL; | 268 return NULL; |
261 installer::MasterPreferences* install_prefs = | 269 installer::MasterPreferences* install_prefs = |
262 new installer::MasterPreferences(*master_prefs_path); | 270 new installer::MasterPreferences(*master_prefs_path); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 #if !defined(OS_LINUX) && !defined(OS_BSD) | 396 #if !defined(OS_LINUX) && !defined(OS_BSD) |
389 bool IsOrganicFirstRun() { | 397 bool IsOrganicFirstRun() { |
390 std::string brand; | 398 std::string brand; |
391 google_util::GetBrand(&brand); | 399 google_util::GetBrand(&brand); |
392 return google_util::IsOrganicFirstRun(brand); | 400 return google_util::IsOrganicFirstRun(brand); |
393 } | 401 } |
394 #endif | 402 #endif |
395 | 403 |
396 int ImportBookmarkFromFileIfNeeded(Profile* profile, | 404 int ImportBookmarkFromFileIfNeeded(Profile* profile, |
397 const CommandLine& cmdline) { | 405 const CommandLine& cmdline) { |
398 int return_code = true; | |
399 if (cmdline.HasSwitch(switches::kImportFromFile)) { | 406 if (cmdline.HasSwitch(switches::kImportFromFile)) { |
400 // Silently import preset bookmarks from file. | 407 // Silently import preset bookmarks from file. |
401 // This is an OEM scenario. | 408 // This is an OEM scenario. |
402 return_code = ImportFromFile(profile, cmdline); | 409 ImportFromFile(profile, cmdline); |
403 } | 410 } |
404 return return_code; | 411 // ImportBookmarkFromFileIfNeeded() will go away as part of |
| 412 // http://crbug.com/219419, so it is fine to hardcode |true| for now. |
| 413 return true; |
405 } | 414 } |
406 | 415 |
407 } // namespace internal | 416 } // namespace internal |
408 } // namespace first_run | 417 } // namespace first_run |
409 | 418 |
410 namespace first_run { | 419 namespace first_run { |
411 | 420 |
412 MasterPrefs::MasterPrefs() | 421 MasterPrefs::MasterPrefs() |
413 : ping_delay(0), | 422 : ping_delay(0), |
414 homepage_defined(false), | 423 homepage_defined(false), |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 internal::DoPostImportPlatformSpecificTasks(); | 807 internal::DoPostImportPlatformSpecificTasks(); |
799 } | 808 } |
800 | 809 |
801 bool DidPerformProfileImport(bool* exited_successfully) { | 810 bool DidPerformProfileImport(bool* exited_successfully) { |
802 if (exited_successfully) | 811 if (exited_successfully) |
803 *exited_successfully = profile_import_exited_successfully; | 812 *exited_successfully = profile_import_exited_successfully; |
804 return did_perform_profile_import; | 813 return did_perform_profile_import; |
805 } | 814 } |
806 | 815 |
807 } // namespace first_run | 816 } // namespace first_run |
OLD | NEW |