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" | |
14 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
15 #include "base/path_service.h" | 14 #include "base/path_service.h" |
16 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
17 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
18 #include "base/time.h" | |
19 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
20 #include "build/build_config.h" | 18 #include "build/build_config.h" |
21 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
22 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
23 #include "chrome/browser/extensions/updater/extension_updater.h" | 21 #include "chrome/browser/extensions/updater/extension_updater.h" |
24 #include "chrome/browser/first_run/first_run_dialog.h" | 22 #include "chrome/browser/first_run/first_run_dialog.h" |
25 #include "chrome/browser/first_run/first_run_import_observer.h" | 23 #include "chrome/browser/first_run/first_run_import_observer.h" |
26 #include "chrome/browser/first_run/first_run_internal.h" | 24 #include "chrome/browser/first_run/first_run_internal.h" |
27 #include "chrome/browser/google/google_util.h" | 25 #include "chrome/browser/google/google_util.h" |
28 #include "chrome/browser/importer/external_process_importer_host.h" | 26 #include "chrome/browser/importer/external_process_importer_host.h" |
29 #include "chrome/browser/importer/importer_host.h" | 27 #include "chrome/browser/importer/importer_host.h" |
30 #include "chrome/browser/importer/importer_list.h" | 28 #include "chrome/browser/importer/importer_list.h" |
31 #include "chrome/browser/importer/importer_progress_dialog.h" | 29 #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" |
42 #include "chrome/browser/ui/browser_finder.h" | 40 #include "chrome/browser/ui/browser_finder.h" |
43 #include "chrome/browser/ui/browser_list.h" | |
44 #include "chrome/browser/ui/global_error/global_error_service.h" | 41 #include "chrome/browser/ui/global_error/global_error_service.h" |
45 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 42 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
46 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 43 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
47 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 44 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
48 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" | 45 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" |
49 #include "chrome/common/chrome_notification_types.h" | 46 #include "chrome/common/chrome_notification_types.h" |
50 #include "chrome/common/chrome_paths.h" | 47 #include "chrome/common/chrome_paths.h" |
51 #include "chrome/common/chrome_switches.h" | 48 #include "chrome/common/chrome_switches.h" |
52 #include "chrome/common/pref_names.h" | 49 #include "chrome/common/pref_names.h" |
53 #include "chrome/common/startup_metric_utils.h" | 50 #include "chrome/common/startup_metric_utils.h" |
54 #include "chrome/common/url_constants.h" | 51 #include "chrome/common/url_constants.h" |
55 #include "chrome/installer/util/master_preferences.h" | 52 #include "chrome/installer/util/master_preferences.h" |
56 #include "chrome/installer/util/master_preferences_constants.h" | 53 #include "chrome/installer/util/master_preferences_constants.h" |
57 #include "chrome/installer/util/util_constants.h" | 54 #include "chrome/installer/util/util_constants.h" |
58 #include "components/user_prefs/pref_registry_syncable.h" | 55 #include "components/user_prefs/pref_registry_syncable.h" |
59 #include "content/public/browser/notification_service.h" | 56 #include "content/public/browser/notification_service.h" |
60 #include "content/public/browser/notification_types.h" | 57 #include "content/public/browser/notification_types.h" |
61 #include "content/public/browser/user_metrics.h" | 58 #include "content/public/browser/user_metrics.h" |
62 #include "content/public/browser/web_contents.h" | 59 #include "content/public/browser/web_contents.h" |
63 #include "google_apis/gaia/gaia_auth_util.h" | 60 #include "google_apis/gaia/gaia_auth_util.h" |
64 #include "googleurl/src/gurl.h" | 61 #include "googleurl/src/gurl.h" |
65 | 62 |
66 using content::UserMetricsAction; | 63 using content::UserMetricsAction; |
67 | 64 |
68 namespace { | 65 namespace { |
69 | 66 |
70 // How long to delay showing the first run bubble (in milliseconds). | |
71 const int kFirstRunBubbleDelayMs = 200; | |
72 | |
73 // Flags for functions of similar name. | 67 // Flags for functions of similar name. |
74 bool should_show_welcome_page_ = false; | 68 bool should_show_welcome_page_ = false; |
75 bool should_do_autofill_personal_data_manager_first_run_ = false; | 69 bool should_do_autofill_personal_data_manager_first_run_ = false; |
76 | 70 |
77 // Flags indicating whether a first-run profile auto import was performed, and | 71 // Flags indicating whether a first-run profile auto import was performed, and |
78 // whether the importer process exited successfully. | 72 // whether the importer process exited successfully. |
79 bool did_perform_profile_import = false; | 73 bool did_perform_profile_import = false; |
80 bool profile_import_exited_successfully = false; | 74 bool profile_import_exited_successfully = false; |
81 | 75 |
82 // Helper class that performs delayed first-run tasks that need more of the | 76 // Helper class that performs delayed first-run tasks that need more of the |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 return *GetExtraArgumentsInstance(); | 508 return *GetExtraArgumentsInstance(); |
515 } | 509 } |
516 | 510 |
517 // static | 511 // static |
518 void FirstRunBubbleLauncher::ShowFirstRunBubbleSoon() { | 512 void FirstRunBubbleLauncher::ShowFirstRunBubbleSoon() { |
519 SetShowFirstRunBubblePref(FIRST_RUN_BUBBLE_SHOW); | 513 SetShowFirstRunBubblePref(FIRST_RUN_BUBBLE_SHOW); |
520 // This FirstRunBubbleLauncher instance will manage its own lifetime. | 514 // This FirstRunBubbleLauncher instance will manage its own lifetime. |
521 new FirstRunBubbleLauncher(); | 515 new FirstRunBubbleLauncher(); |
522 } | 516 } |
523 | 517 |
524 FirstRunBubbleLauncher::FirstRunBubbleLauncher() | 518 FirstRunBubbleLauncher::FirstRunBubbleLauncher() { |
525 : browser_(NULL) { | |
526 BrowserList::AddObserver(this); | |
527 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 519 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
528 content::NotificationService::AllSources()); | 520 content::NotificationService::AllSources()); |
529 } | 521 } |
530 | 522 |
531 FirstRunBubbleLauncher::~FirstRunBubbleLauncher() { | 523 FirstRunBubbleLauncher::~FirstRunBubbleLauncher() {} |
532 BrowserList::RemoveObserver(this); | |
533 } | |
534 | 524 |
535 void FirstRunBubbleLauncher::Observe( | 525 void FirstRunBubbleLauncher::Observe( |
536 int type, | 526 int type, |
537 const content::NotificationSource& source, | 527 const content::NotificationSource& source, |
538 const content::NotificationDetails& details) { | 528 const content::NotificationDetails& details) { |
539 DCHECK_EQ(type, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME); | 529 DCHECK_EQ(type, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME); |
540 Browser* browser = chrome::FindBrowserWithWebContents( | 530 Browser* browser = chrome::FindBrowserWithWebContents( |
541 content::Source<content::WebContents>(source).ptr()); | 531 content::Source<content::WebContents>(source).ptr()); |
542 if (!browser || !browser->is_type_tabbed()) | 532 if (!browser || !browser->is_type_tabbed()) |
543 return; | 533 return; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 return; | 579 return; |
590 } | 580 } |
591 } | 581 } |
592 | 582 |
593 // Suppress the first run bubble if a global error bubble is pending. | 583 // Suppress the first run bubble if a global error bubble is pending. |
594 GlobalErrorService* global_error_service = | 584 GlobalErrorService* global_error_service = |
595 GlobalErrorServiceFactory::GetForProfile(browser->profile()); | 585 GlobalErrorServiceFactory::GetForProfile(browser->profile()); |
596 if (global_error_service->GetFirstGlobalErrorWithBubbleView() != NULL) | 586 if (global_error_service->GetFirstGlobalErrorWithBubbleView() != NULL) |
597 return; | 587 return; |
598 | 588 |
599 // Make sure we don't get notified again after resetting the | |
600 // kShowFirstRunBubbleOption preference below. | |
601 registrar_.Remove(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
602 content::NotificationService::AllSources()); | |
603 | |
604 // Reset the preference and notifications to avoid showing the bubble again. | 589 // Reset the preference and notifications to avoid showing the bubble again. |
605 prefs->SetInteger(prefs::kShowFirstRunBubbleOption, | 590 prefs->SetInteger(prefs::kShowFirstRunBubbleOption, |
606 FIRST_RUN_BUBBLE_DONT_SHOW); | 591 FIRST_RUN_BUBBLE_DONT_SHOW); |
607 | 592 |
608 // Show the bubble soon. | |
609 browser_ = browser; | |
610 base::MessageLoop::current()->PostDelayedTask( | |
611 FROM_HERE, | |
612 base::Bind( | |
613 &FirstRunBubbleLauncher::DoShowFirstRunBubble, | |
614 AsWeakPtr()), | |
615 base::TimeDelta::FromMilliseconds(kFirstRunBubbleDelayMs)); | |
616 } | |
617 | |
618 void FirstRunBubbleLauncher::OnBrowserRemoved(Browser* browser) { | |
619 if (browser_ == browser) { | |
620 // Destroy this bubble launcher. | |
621 delete this; | |
622 } | |
623 } | |
624 | |
625 void FirstRunBubbleLauncher::DoShowFirstRunBubble() { | |
626 DCHECK(browser_); | |
627 | |
628 // Show the bubble now and destroy this bubble launcher. | 593 // Show the bubble now and destroy this bubble launcher. |
629 browser_->ShowFirstRunBubble(); | 594 browser->ShowFirstRunBubble(); |
630 delete this; | 595 delete this; |
631 } | 596 } |
632 | 597 |
633 void SetMasterPrefsPathForTesting(const base::FilePath& master_prefs) { | 598 void SetMasterPrefsPathForTesting(const base::FilePath& master_prefs) { |
634 internal::master_prefs_path_for_testing.Get() = master_prefs; | 599 internal::master_prefs_path_for_testing.Get() = master_prefs; |
635 } | 600 } |
636 | 601 |
637 ProcessMasterPreferencesResult ProcessMasterPreferences( | 602 ProcessMasterPreferencesResult ProcessMasterPreferences( |
638 const base::FilePath& user_data_dir, | 603 const base::FilePath& user_data_dir, |
639 MasterPrefs* out_prefs) { | 604 MasterPrefs* out_prefs) { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 internal::DoPostImportPlatformSpecificTasks(); | 763 internal::DoPostImportPlatformSpecificTasks(); |
799 } | 764 } |
800 | 765 |
801 bool DidPerformProfileImport(bool* exited_successfully) { | 766 bool DidPerformProfileImport(bool* exited_successfully) { |
802 if (exited_successfully) | 767 if (exited_successfully) |
803 *exited_successfully = profile_import_exited_successfully; | 768 *exited_successfully = profile_import_exited_successfully; |
804 return did_perform_profile_import; | 769 return did_perform_profile_import; |
805 } | 770 } |
806 | 771 |
807 } // namespace first_run | 772 } // namespace first_run |
OLD | NEW |