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/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.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/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
21 #include "chrome/browser/extensions/extension_service.h" | 21 #include "chrome/browser/extensions/extension_service.h" |
22 #include "chrome/browser/extensions/updater/extension_updater.h" | 22 #include "chrome/browser/extensions/updater/extension_updater.h" |
23 #include "chrome/browser/first_run/first_run_internal.h" | 23 #include "chrome/browser/first_run/first_run_internal.h" |
24 #include "chrome/browser/google/google_util.h" | 24 #include "chrome/browser/google/google_util.h" |
25 #include "chrome/browser/importer/external_process_importer_host.h" | 25 #include "chrome/browser/importer/external_process_importer_host.h" |
26 #include "chrome/browser/importer/importer_host.h" | 26 #include "chrome/browser/importer/importer_host.h" |
27 #include "chrome/browser/importer/importer_list.h" | 27 #include "chrome/browser/importer/importer_list.h" |
28 #include "chrome/browser/importer/importer_progress_observer.h" | 28 #include "chrome/browser/importer/importer_progress_observer.h" |
29 #include "chrome/browser/importer/importer_type.h" | 29 #include "chrome/browser/importer/importer_type.h" |
| 30 #include "chrome/browser/importer/profile_writer.h" |
30 #include "chrome/browser/profiles/profile_manager.h" | 31 #include "chrome/browser/profiles/profile_manager.h" |
31 #include "chrome/browser/search_engines/template_url_service.h" | 32 #include "chrome/browser/search_engines/template_url_service.h" |
32 #include "chrome/browser/search_engines/template_url_service_factory.h" | 33 #include "chrome/browser/search_engines/template_url_service_factory.h" |
33 #include "chrome/browser/shell_integration.h" | 34 #include "chrome/browser/shell_integration.h" |
34 #include "chrome/browser/signin/signin_manager.h" | 35 #include "chrome/browser/signin/signin_manager.h" |
35 #include "chrome/browser/signin/signin_manager_factory.h" | 36 #include "chrome/browser/signin/signin_manager_factory.h" |
36 #include "chrome/browser/signin/signin_tracker.h" | 37 #include "chrome/browser/signin/signin_tracker.h" |
37 #include "chrome/browser/ui/browser.h" | 38 #include "chrome/browser/ui/browser.h" |
38 #include "chrome/browser/ui/browser_finder.h" | 39 #include "chrome/browser/ui/browser_finder.h" |
39 #include "chrome/browser/ui/global_error/global_error_service.h" | 40 #include "chrome/browser/ui/global_error/global_error_service.h" |
(...skipping 14 matching lines...) Expand all Loading... |
54 #include "content/public/browser/notification_types.h" | 55 #include "content/public/browser/notification_types.h" |
55 #include "content/public/browser/user_metrics.h" | 56 #include "content/public/browser/user_metrics.h" |
56 #include "content/public/browser/web_contents.h" | 57 #include "content/public/browser/web_contents.h" |
57 #include "google_apis/gaia/gaia_auth_util.h" | 58 #include "google_apis/gaia/gaia_auth_util.h" |
58 #include "googleurl/src/gurl.h" | 59 #include "googleurl/src/gurl.h" |
59 | 60 |
60 using content::UserMetricsAction; | 61 using content::UserMetricsAction; |
61 | 62 |
62 namespace { | 63 namespace { |
63 | 64 |
| 65 // A bitfield formed from values in AutoImportState to record the state of |
| 66 // AutoImport. This is used in testing to verify import startup actions that |
| 67 // occur before an observer can be registered in the test. |
| 68 uint16 g_auto_import_state = first_run::AUTO_IMPORT_NONE; |
| 69 |
64 // Flags for functions of similar name. | 70 // Flags for functions of similar name. |
65 bool g_should_show_welcome_page = false; | 71 bool g_should_show_welcome_page = false; |
66 bool g_should_do_autofill_personal_data_manager_first_run = false; | 72 bool g_should_do_autofill_personal_data_manager_first_run = false; |
67 | 73 |
68 // Flags indicating whether a first-run profile auto import was performed, and | 74 // This class acts as an observer for the ImporterProgressObserver::ImportEnded |
69 // whether the importer process exited successfully. | 75 // callback. When the import process is started, certain errors may cause |
70 bool did_perform_profile_import = false; | 76 // ImportEnded() to be called synchronously, but the typical case is that |
71 bool profile_import_exited_successfully = false; | 77 // ImportEnded() is called asynchronously. Thus we have to handle both cases. |
| 78 class ImportEndedObserver : public importer::ImporterProgressObserver { |
| 79 public: |
| 80 ImportEndedObserver() : ended_(false), |
| 81 should_quit_message_loop_(false) {} |
| 82 virtual ~ImportEndedObserver() {} |
| 83 |
| 84 // importer::ImporterProgressObserver: |
| 85 virtual void ImportStarted() OVERRIDE {} |
| 86 virtual void ImportItemStarted(importer::ImportItem item) OVERRIDE {} |
| 87 virtual void ImportItemEnded(importer::ImportItem item) OVERRIDE {} |
| 88 virtual void ImportEnded() OVERRIDE { |
| 89 ended_ = true; |
| 90 if (should_quit_message_loop_) |
| 91 MessageLoop::current()->Quit(); |
| 92 } |
| 93 |
| 94 void set_should_quit_message_loop() { |
| 95 should_quit_message_loop_ = true; |
| 96 } |
| 97 |
| 98 bool ended() const { |
| 99 return ended_; |
| 100 } |
| 101 |
| 102 private: |
| 103 // Set if the import has ended. |
| 104 bool ended_; |
| 105 |
| 106 bool should_quit_message_loop_; |
| 107 }; |
72 | 108 |
73 // Helper class that performs delayed first-run tasks that need more of the | 109 // Helper class that performs delayed first-run tasks that need more of the |
74 // chrome infrastructure to be up and running before they can be attempted. | 110 // chrome infrastructure to be up and running before they can be attempted. |
75 class FirstRunDelayedTasks : public content::NotificationObserver { | 111 class FirstRunDelayedTasks : public content::NotificationObserver { |
76 public: | 112 public: |
77 enum Tasks { | 113 enum Tasks { |
78 NO_TASK, | 114 NO_TASK, |
79 INSTALL_EXTENSIONS | 115 INSTALL_EXTENSIONS |
80 }; | 116 }; |
81 | 117 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 if (user_prefs->GetBoolean(pref_path)) | 220 if (user_prefs->GetBoolean(pref_path)) |
185 *items |= import_type; | 221 *items |= import_type; |
186 } else { // no policy (recommended or managed) is set | 222 } else { // no policy (recommended or managed) is set |
187 if (should_import) | 223 if (should_import) |
188 *items |= import_type; | 224 *items |= import_type; |
189 } | 225 } |
190 | 226 |
191 user_prefs->ClearPref(pref_path); | 227 user_prefs->ClearPref(pref_path); |
192 } | 228 } |
193 | 229 |
194 // Imports bookmarks from an html file. The path to the file is provided in | 230 // Launches the import, via |importer_host|, from |source_profile| into |
195 // the command line. | 231 // |target_profile| for the items specified in the |items_to_import| bitfield. |
196 void ImportFromFile(Profile* profile, const CommandLine& cmdline) { | 232 // This may be done in a separate process depending on the platform, but it will |
197 base::FilePath file_path = | 233 // always block until done. |
198 cmdline.GetSwitchValuePath(switches::kImportFromFile); | 234 void ImportFromSourceProfile(ImporterHost* importer_host, |
199 if (file_path.empty()) { | 235 const importer::SourceProfile& source_profile, |
200 NOTREACHED(); | 236 Profile* target_profile, |
201 return; | 237 uint16 items_to_import) { |
202 } | 238 ImportEndedObserver observer; |
203 | |
204 // Deletes itself. | |
205 ImporterHost* importer_host = new ImporterHost; | |
206 importer_host->set_headless(); | |
207 | |
208 importer::SourceProfile source_profile; | |
209 source_profile.importer_type = importer::TYPE_BOOKMARKS_FILE; | |
210 source_profile.source_path = file_path; | |
211 | |
212 first_run::internal::ImportEndedObserver observer; | |
213 importer_host->SetObserver(&observer); | 239 importer_host->SetObserver(&observer); |
214 importer_host->StartImportSettings( | 240 importer_host->StartImportSettings(source_profile, |
215 source_profile, profile, importer::FAVORITES, new ProfileWriter(profile)); | 241 target_profile, |
| 242 items_to_import, |
| 243 new ProfileWriter(target_profile)); |
216 // If the import process has not errored out, block on it. | 244 // If the import process has not errored out, block on it. |
217 if (!observer.ended()) { | 245 if (!observer.ended()) { |
218 observer.set_should_quit_message_loop(); | 246 observer.set_should_quit_message_loop(); |
219 MessageLoop::current()->Run(); | 247 MessageLoop::current()->Run(); |
220 } | 248 } |
221 } | 249 } |
222 | 250 |
| 251 // Imports bookmarks from an html file whose path is provided by |
| 252 // |import_bookmarks_path|. |
| 253 void ImportFromFile(Profile* profile, |
| 254 ImporterHost* file_importer_host, |
| 255 const std::string& import_bookmarks_path) { |
| 256 importer::SourceProfile source_profile; |
| 257 source_profile.importer_type = importer::TYPE_BOOKMARKS_FILE; |
| 258 |
| 259 const base::FilePath::StringType& import_bookmarks_path_str = |
| 260 #if defined(OS_WIN) |
| 261 UTF8ToUTF16(import_bookmarks_path); |
| 262 #else |
| 263 import_bookmarks_path; |
| 264 #endif |
| 265 source_profile.source_path = base::FilePath(import_bookmarks_path_str); |
| 266 |
| 267 ImportFromSourceProfile(file_importer_host, source_profile, profile, |
| 268 importer::FAVORITES); |
| 269 g_auto_import_state |= first_run::AUTO_IMPORT_BOOKMARKS_FILE_IMPORTED; |
| 270 } |
| 271 |
| 272 // Imports settings from the first profile in |importer_list|. |
| 273 void ImportSettings(Profile* profile, |
| 274 ImporterHost* importer_host, |
| 275 scoped_refptr<ImporterList> importer_list, |
| 276 int items_to_import) { |
| 277 const importer::SourceProfile& source_profile = |
| 278 importer_list->GetSourceProfileAt(0); |
| 279 |
| 280 // Ensure that importers aren't requested to import items that they do not |
| 281 // support. If there is no overlap, skip. |
| 282 items_to_import &= source_profile.services_supported; |
| 283 if (items_to_import == 0) |
| 284 return; |
| 285 |
| 286 ImportFromSourceProfile(importer_host, source_profile, profile, |
| 287 items_to_import); |
| 288 g_auto_import_state |= first_run::AUTO_IMPORT_PROFILE_IMPORTED; |
| 289 } |
| 290 |
223 GURL UrlFromString(const std::string& in) { | 291 GURL UrlFromString(const std::string& in) { |
224 return GURL(in); | 292 return GURL(in); |
225 } | 293 } |
226 | 294 |
227 void ConvertStringVectorToGURLVector( | 295 void ConvertStringVectorToGURLVector( |
228 const std::vector<std::string>& src, | 296 const std::vector<std::string>& src, |
229 std::vector<GURL>* ret) { | 297 std::vector<GURL>* ret) { |
230 ret->resize(src.size()); | 298 ret->resize(src.size()); |
231 std::transform(src.begin(), src.end(), ret->begin(), &UrlFromString); | 299 std::transform(src.begin(), src.end(), ret->begin(), &UrlFromString); |
232 } | 300 } |
233 | 301 |
234 } // namespace | 302 } // namespace |
235 | 303 |
236 namespace first_run { | 304 namespace first_run { |
237 namespace internal { | 305 namespace internal { |
238 | 306 |
239 FirstRunState first_run_ = FIRST_RUN_UNKNOWN; | 307 FirstRunState first_run_ = FIRST_RUN_UNKNOWN; |
240 | 308 |
241 static base::LazyInstance<base::FilePath> master_prefs_path_for_testing | 309 static base::LazyInstance<base::FilePath> master_prefs_path_for_testing |
242 = LAZY_INSTANCE_INITIALIZER; | 310 = LAZY_INSTANCE_INITIALIZER; |
243 | 311 |
244 // TODO(gab): This will go back inline above when it is moved to first_run.cc | |
245 // (see TODO above), but needs to be separate for now to satisfy clang error: | |
246 // "[chromium-style] virtual methods with non-empty bodies shouldn't be declared | |
247 // inline". | |
248 void ImportEndedObserver::ImportEnded() { | |
249 ended_ = true; | |
250 if (should_quit_message_loop_) | |
251 MessageLoop::current()->Quit(); | |
252 } | |
253 | |
254 installer::MasterPreferences* | 312 installer::MasterPreferences* |
255 LoadMasterPrefs(base::FilePath* master_prefs_path) { | 313 LoadMasterPrefs(base::FilePath* master_prefs_path) { |
256 if (!master_prefs_path_for_testing.Get().empty()) | 314 if (!master_prefs_path_for_testing.Get().empty()) |
257 *master_prefs_path = master_prefs_path_for_testing.Get(); | 315 *master_prefs_path = master_prefs_path_for_testing.Get(); |
258 else | 316 else |
259 *master_prefs_path = base::FilePath(MasterPrefsPath()); | 317 *master_prefs_path = base::FilePath(MasterPrefsPath()); |
260 if (master_prefs_path->empty()) | 318 if (master_prefs_path->empty()) |
261 return NULL; | 319 return NULL; |
262 installer::MasterPreferences* install_prefs = | 320 installer::MasterPreferences* install_prefs = |
263 new installer::MasterPreferences(*master_prefs_path); | 321 new installer::MasterPreferences(*master_prefs_path); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 &value) && value) { | 405 &value) && value) { |
348 out_prefs->make_chrome_default = true; | 406 out_prefs->make_chrome_default = true; |
349 } | 407 } |
350 | 408 |
351 if (install_prefs.GetBool( | 409 if (install_prefs.GetBool( |
352 installer::master_preferences::kSuppressFirstRunDefaultBrowserPrompt, | 410 installer::master_preferences::kSuppressFirstRunDefaultBrowserPrompt, |
353 &value) && value) { | 411 &value) && value) { |
354 out_prefs->suppress_first_run_default_browser_prompt = true; | 412 out_prefs->suppress_first_run_default_browser_prompt = true; |
355 } | 413 } |
356 | 414 |
| 415 install_prefs.GetString( |
| 416 installer::master_preferences::kDistroImportBookmarksFromFilePref, |
| 417 &out_prefs->import_bookmarks_path); |
| 418 |
357 out_prefs->variations_seed = install_prefs.GetVariationsSeed(); | 419 out_prefs->variations_seed = install_prefs.GetVariationsSeed(); |
358 | 420 |
359 install_prefs.GetString( | 421 install_prefs.GetString( |
360 installer::master_preferences::kDistroSuppressDefaultBrowserPromptPref, | 422 installer::master_preferences::kDistroSuppressDefaultBrowserPromptPref, |
361 &out_prefs->suppress_default_browser_prompt_for_version); | 423 &out_prefs->suppress_default_browser_prompt_for_version); |
362 } | 424 } |
363 | 425 |
364 void SetDefaultBrowser(installer::MasterPreferences* install_prefs){ | 426 void SetDefaultBrowser(installer::MasterPreferences* install_prefs){ |
365 // Even on the first run we only allow for the user choice to take effect if | 427 // Even on the first run we only allow for the user choice to take effect if |
366 // no policy has been set by the admin. | 428 // no policy has been set by the admin. |
367 if (!g_browser_process->local_state()->IsManagedPreference( | 429 if (!g_browser_process->local_state()->IsManagedPreference( |
368 prefs::kDefaultBrowserSettingEnabled)) { | 430 prefs::kDefaultBrowserSettingEnabled)) { |
369 bool value = false; | 431 bool value = false; |
370 if (install_prefs->GetBool( | 432 if (install_prefs->GetBool( |
371 installer::master_preferences::kMakeChromeDefaultForUser, | 433 installer::master_preferences::kMakeChromeDefaultForUser, |
(...skipping 11 matching lines...) Expand all Loading... |
383 // -- Platform-specific functions -- | 445 // -- Platform-specific functions -- |
384 | 446 |
385 #if !defined(OS_LINUX) && !defined(OS_BSD) | 447 #if !defined(OS_LINUX) && !defined(OS_BSD) |
386 bool IsOrganicFirstRun() { | 448 bool IsOrganicFirstRun() { |
387 std::string brand; | 449 std::string brand; |
388 google_util::GetBrand(&brand); | 450 google_util::GetBrand(&brand); |
389 return google_util::IsOrganicFirstRun(brand); | 451 return google_util::IsOrganicFirstRun(brand); |
390 } | 452 } |
391 #endif | 453 #endif |
392 | 454 |
393 int ImportBookmarkFromFileIfNeeded(Profile* profile, | |
394 const CommandLine& cmdline) { | |
395 if (cmdline.HasSwitch(switches::kImportFromFile)) { | |
396 // Silently import preset bookmarks from file. | |
397 // This is an OEM scenario. | |
398 ImportFromFile(profile, cmdline); | |
399 } | |
400 // ImportBookmarkFromFileIfNeeded() will go away as part of | |
401 // http://crbug.com/219419, so it is fine to hardcode |true| for now. | |
402 return true; | |
403 } | |
404 | |
405 } // namespace internal | 455 } // namespace internal |
406 } // namespace first_run | 456 } // namespace first_run |
407 | 457 |
408 namespace first_run { | 458 namespace first_run { |
409 | 459 |
410 MasterPrefs::MasterPrefs() | 460 MasterPrefs::MasterPrefs() |
411 : ping_delay(0), | 461 : ping_delay(0), |
412 homepage_defined(false), | 462 homepage_defined(false), |
413 do_import_items(0), | 463 do_import_items(0), |
414 dont_import_items(0), | 464 dont_import_items(0), |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 bool retval = g_should_do_autofill_personal_data_manager_first_run; | 541 bool retval = g_should_do_autofill_personal_data_manager_first_run; |
492 g_should_do_autofill_personal_data_manager_first_run = false; | 542 g_should_do_autofill_personal_data_manager_first_run = false; |
493 return retval; | 543 return retval; |
494 } | 544 } |
495 | 545 |
496 void LogFirstRunMetric(FirstRunBubbleMetric metric) { | 546 void LogFirstRunMetric(FirstRunBubbleMetric metric) { |
497 UMA_HISTOGRAM_ENUMERATION("FirstRun.SearchEngineBubble", metric, | 547 UMA_HISTOGRAM_ENUMERATION("FirstRun.SearchEngineBubble", metric, |
498 NUM_FIRST_RUN_BUBBLE_METRICS); | 548 NUM_FIRST_RUN_BUBBLE_METRICS); |
499 } | 549 } |
500 | 550 |
501 namespace { | |
502 CommandLine* GetExtraArgumentsInstance() { | |
503 CR_DEFINE_STATIC_LOCAL(CommandLine, arguments, (CommandLine::NoProgram())); | |
504 return &arguments; | |
505 } | |
506 } // namespace | |
507 | |
508 void SetExtraArgumentsForImportProcess(const CommandLine& arguments) { | |
509 GetExtraArgumentsInstance()->AppendArguments(arguments, false); | |
510 } | |
511 | |
512 const CommandLine& GetExtraArgumentsForImportProcess() { | |
513 return *GetExtraArgumentsInstance(); | |
514 } | |
515 | |
516 // static | 551 // static |
517 void FirstRunBubbleLauncher::ShowFirstRunBubbleSoon() { | 552 void FirstRunBubbleLauncher::ShowFirstRunBubbleSoon() { |
518 SetShowFirstRunBubblePref(FIRST_RUN_BUBBLE_SHOW); | 553 SetShowFirstRunBubblePref(FIRST_RUN_BUBBLE_SHOW); |
519 // This FirstRunBubbleLauncher instance will manage its own lifetime. | 554 // This FirstRunBubbleLauncher instance will manage its own lifetime. |
520 new FirstRunBubbleLauncher(); | 555 new FirstRunBubbleLauncher(); |
521 } | 556 } |
522 | 557 |
523 FirstRunBubbleLauncher::FirstRunBubbleLauncher() { | 558 FirstRunBubbleLauncher::FirstRunBubbleLauncher() { |
524 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 559 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
525 content::NotificationService::AllSources()); | 560 content::NotificationService::AllSources()); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 if (!internal::ShowPostInstallEULAIfNeeded(install_prefs.get())) | 662 if (!internal::ShowPostInstallEULAIfNeeded(install_prefs.get())) |
628 return EULA_EXIT_NOW; | 663 return EULA_EXIT_NOW; |
629 | 664 |
630 if (!internal::CopyPrefFile(user_data_dir, master_prefs_path)) | 665 if (!internal::CopyPrefFile(user_data_dir, master_prefs_path)) |
631 DLOG(ERROR) << "Failed to copy master_preferences to user data dir."; | 666 DLOG(ERROR) << "Failed to copy master_preferences to user data dir."; |
632 | 667 |
633 DoDelayedInstallExtensionsIfNeeded(install_prefs.get()); | 668 DoDelayedInstallExtensionsIfNeeded(install_prefs.get()); |
634 | 669 |
635 internal::SetupMasterPrefsFromInstallPrefs(*install_prefs, out_prefs); | 670 internal::SetupMasterPrefsFromInstallPrefs(*install_prefs, out_prefs); |
636 | 671 |
637 internal::SetImportPreferencesAndLaunchImport(out_prefs, | |
638 install_prefs.get()); | |
639 | |
640 internal::SetDefaultBrowser(install_prefs.get()); | 672 internal::SetDefaultBrowser(install_prefs.get()); |
641 } | 673 } |
642 | 674 |
643 return DO_FIRST_RUN_TASKS; | 675 return DO_FIRST_RUN_TASKS; |
644 } | 676 } |
645 | 677 |
646 void AutoImport( | 678 void AutoImport( |
647 Profile* profile, | 679 Profile* profile, |
648 bool homepage_defined, | 680 bool homepage_defined, |
649 int import_items, | 681 int import_items, |
650 int dont_import_items) { | 682 int dont_import_items, |
| 683 const std::string& import_bookmarks_path) { |
651 #if !defined(USE_AURA) | 684 #if !defined(USE_AURA) |
652 // Deletes itself. | 685 // Deletes itself. |
653 ImporterHost* importer_host; | 686 ImporterHost* importer_host; |
654 // TODO(csilv,mirandac): Out-of-process import has only been qualified on | 687 // TODO(csilv,mirandac): Out-of-process import has only been qualified on |
655 // MacOS X, so we will only use it on that platform since it is required. | 688 // MacOS X and Windows, so we will only use it on those platforms. |
656 // Remove this conditional logic once oop import is qualified for | 689 // Linux still uses the in-process import (http://crbug.com/56816). |
657 // Linux/Windows. http://crbug.com/22142 | 690 #if defined(OS_MACOSX) || defined(OS_WIN) |
658 #if defined(OS_MACOSX) | |
659 importer_host = new ExternalProcessImporterHost; | 691 importer_host = new ExternalProcessImporterHost; |
660 #else | 692 #else |
661 importer_host = new ImporterHost; | 693 importer_host = new ImporterHost; |
662 #endif | 694 #endif |
663 | 695 |
664 base::FilePath local_state_path; | 696 base::FilePath local_state_path; |
665 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path); | 697 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path); |
666 bool local_state_file_exists = file_util::PathExists(local_state_path); | 698 bool local_state_file_exists = file_util::PathExists(local_state_path); |
667 | 699 |
668 scoped_refptr<ImporterList> importer_list(new ImporterList(NULL)); | 700 scoped_refptr<ImporterList> importer_list(new ImporterList(NULL)); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 SetImportItem(user_prefs, | 746 SetImportItem(user_prefs, |
715 prefs::kImportBookmarks, | 747 prefs::kImportBookmarks, |
716 import_items, | 748 import_items, |
717 dont_import_items, | 749 dont_import_items, |
718 importer::FAVORITES, | 750 importer::FAVORITES, |
719 &items); | 751 &items); |
720 | 752 |
721 importer::LogImporterUseToMetrics( | 753 importer::LogImporterUseToMetrics( |
722 "AutoImport", importer_list->GetSourceProfileAt(0).importer_type); | 754 "AutoImport", importer_list->GetSourceProfileAt(0).importer_type); |
723 | 755 |
724 profile_import_exited_successfully = | 756 ImportSettings(profile, importer_host, importer_list, items); |
725 internal::ImportSettings(profile, importer_host, importer_list, items); | 757 } |
726 DCHECK(profile_import_exited_successfully); | 758 |
| 759 if (!import_bookmarks_path.empty()) { |
| 760 // Deletes itself. |
| 761 ImporterHost* file_importer_host; |
| 762 // TODO(gab): Make Linux use OOP import as well (http://crbug.com/56816) and |
| 763 // get rid of these ugly ifdefs. |
| 764 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 765 file_importer_host = new ExternalProcessImporterHost; |
| 766 #else |
| 767 file_importer_host = new ImporterHost; |
| 768 #endif |
| 769 file_importer_host->set_headless(); |
| 770 |
| 771 ImportFromFile(profile, file_importer_host, import_bookmarks_path); |
727 } | 772 } |
728 | 773 |
729 content::RecordAction(UserMetricsAction("FirstRunDef_Accept")); | 774 content::RecordAction(UserMetricsAction("FirstRunDef_Accept")); |
730 | 775 |
731 #endif // !defined(USE_AURA) | 776 #endif // !defined(USE_AURA) |
732 did_perform_profile_import = true; | 777 g_auto_import_state |= AUTO_IMPORT_CALLED; |
733 } | 778 } |
734 | 779 |
735 void DoPostImportTasks(Profile* profile, bool make_chrome_default) { | 780 void DoPostImportTasks(Profile* profile, bool make_chrome_default) { |
736 if (make_chrome_default && | 781 if (make_chrome_default && |
737 ShellIntegration::CanSetAsDefaultBrowser() == | 782 ShellIntegration::CanSetAsDefaultBrowser() == |
738 ShellIntegration::SET_DEFAULT_UNATTENDED) { | 783 ShellIntegration::SET_DEFAULT_UNATTENDED) { |
739 ShellIntegration::SetAsDefaultBrowser(); | 784 ShellIntegration::SetAsDefaultBrowser(); |
740 } | 785 } |
741 | 786 |
742 // Display the first run bubble if there is a default search provider. | 787 // Display the first run bubble if there is a default search provider. |
743 TemplateURLService* template_url = | 788 TemplateURLService* template_url = |
744 TemplateURLServiceFactory::GetForProfile(profile); | 789 TemplateURLServiceFactory::GetForProfile(profile); |
745 if (template_url && template_url->GetDefaultSearchProvider()) | 790 if (template_url && template_url->GetDefaultSearchProvider()) |
746 FirstRunBubbleLauncher::ShowFirstRunBubbleSoon(); | 791 FirstRunBubbleLauncher::ShowFirstRunBubbleSoon(); |
747 SetShouldShowWelcomePage(); | 792 SetShouldShowWelcomePage(); |
748 SetShouldDoPersonalDataManagerFirstRun(); | 793 SetShouldDoPersonalDataManagerFirstRun(); |
749 | 794 |
750 internal::DoPostImportPlatformSpecificTasks(profile); | 795 internal::DoPostImportPlatformSpecificTasks(profile); |
751 } | 796 } |
752 | 797 |
753 bool DidPerformProfileImport(bool* exited_successfully) { | 798 uint16 auto_import_state() { |
754 if (exited_successfully) | 799 return g_auto_import_state; |
755 *exited_successfully = profile_import_exited_successfully; | |
756 return did_perform_profile_import; | |
757 } | 800 } |
758 | 801 |
759 } // namespace first_run | 802 } // namespace first_run |
OLD | NEW |