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/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
14 #include "base/path_service.h" | 15 #include "base/path_service.h" |
15 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
16 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
| 18 #include "base/time.h" |
17 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
18 #include "build/build_config.h" | 20 #include "build/build_config.h" |
19 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/extensions/extension_service.h" | 22 #include "chrome/browser/extensions/extension_service.h" |
21 #include "chrome/browser/extensions/updater/extension_updater.h" | 23 #include "chrome/browser/extensions/updater/extension_updater.h" |
22 #include "chrome/browser/first_run/first_run_dialog.h" | 24 #include "chrome/browser/first_run/first_run_dialog.h" |
23 #include "chrome/browser/first_run/first_run_import_observer.h" | 25 #include "chrome/browser/first_run/first_run_import_observer.h" |
24 #include "chrome/browser/first_run/first_run_internal.h" | 26 #include "chrome/browser/first_run/first_run_internal.h" |
25 #include "chrome/browser/google/google_util.h" | 27 #include "chrome/browser/google/google_util.h" |
26 #include "chrome/browser/importer/external_process_importer_host.h" | 28 #include "chrome/browser/importer/external_process_importer_host.h" |
27 #include "chrome/browser/importer/importer_host.h" | 29 #include "chrome/browser/importer/importer_host.h" |
28 #include "chrome/browser/importer/importer_list.h" | 30 #include "chrome/browser/importer/importer_list.h" |
29 #include "chrome/browser/importer/importer_progress_dialog.h" | 31 #include "chrome/browser/importer/importer_progress_dialog.h" |
30 #include "chrome/browser/importer/importer_progress_observer.h" | 32 #include "chrome/browser/importer/importer_progress_observer.h" |
31 #include "chrome/browser/process_singleton.h" | 33 #include "chrome/browser/process_singleton.h" |
32 #include "chrome/browser/profiles/profile_manager.h" | 34 #include "chrome/browser/profiles/profile_manager.h" |
33 #include "chrome/browser/search_engines/template_url_service.h" | 35 #include "chrome/browser/search_engines/template_url_service.h" |
34 #include "chrome/browser/search_engines/template_url_service_factory.h" | 36 #include "chrome/browser/search_engines/template_url_service_factory.h" |
35 #include "chrome/browser/shell_integration.h" | 37 #include "chrome/browser/shell_integration.h" |
36 #include "chrome/browser/ui/browser.h" | 38 #include "chrome/browser/ui/browser.h" |
37 #include "chrome/browser/ui/browser_finder.h" | 39 #include "chrome/browser/ui/browser_finder.h" |
| 40 #include "chrome/browser/ui/browser_list.h" |
38 #include "chrome/browser/ui/global_error/global_error_service.h" | 41 #include "chrome/browser/ui/global_error/global_error_service.h" |
39 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 42 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
40 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 43 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
41 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 44 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
42 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" | 45 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" |
43 #include "chrome/common/chrome_notification_types.h" | 46 #include "chrome/common/chrome_notification_types.h" |
44 #include "chrome/common/chrome_paths.h" | 47 #include "chrome/common/chrome_paths.h" |
45 #include "chrome/common/chrome_switches.h" | 48 #include "chrome/common/chrome_switches.h" |
46 #include "chrome/common/pref_names.h" | 49 #include "chrome/common/pref_names.h" |
47 #include "chrome/common/startup_metric_utils.h" | 50 #include "chrome/common/startup_metric_utils.h" |
48 #include "chrome/common/url_constants.h" | 51 #include "chrome/common/url_constants.h" |
49 #include "chrome/installer/util/master_preferences.h" | 52 #include "chrome/installer/util/master_preferences.h" |
50 #include "chrome/installer/util/master_preferences_constants.h" | 53 #include "chrome/installer/util/master_preferences_constants.h" |
51 #include "chrome/installer/util/util_constants.h" | 54 #include "chrome/installer/util/util_constants.h" |
52 #include "components/user_prefs/pref_registry_syncable.h" | 55 #include "components/user_prefs/pref_registry_syncable.h" |
53 #include "content/public/browser/notification_service.h" | 56 #include "content/public/browser/notification_service.h" |
54 #include "content/public/browser/notification_types.h" | 57 #include "content/public/browser/notification_types.h" |
55 #include "content/public/browser/user_metrics.h" | 58 #include "content/public/browser/user_metrics.h" |
56 #include "content/public/browser/web_contents.h" | 59 #include "content/public/browser/web_contents.h" |
57 #include "google_apis/gaia/gaia_auth_util.h" | 60 #include "google_apis/gaia/gaia_auth_util.h" |
58 #include "googleurl/src/gurl.h" | 61 #include "googleurl/src/gurl.h" |
59 | 62 |
60 using content::UserMetricsAction; | 63 using content::UserMetricsAction; |
61 | 64 |
62 namespace { | 65 namespace { |
63 | 66 |
| 67 // How long to delay showing the first run bubble (in milliseconds). |
| 68 const int kFirstRunBubbleDelayMs = 200; |
| 69 |
64 // Flags for functions of similar name. | 70 // Flags for functions of similar name. |
65 bool should_show_welcome_page_ = false; | 71 bool should_show_welcome_page_ = false; |
66 bool should_do_autofill_personal_data_manager_first_run_ = false; | 72 bool 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 // Flags indicating whether a first-run profile auto import was performed, and |
69 // whether the importer process exited successfully. | 75 // whether the importer process exited successfully. |
70 bool did_perform_profile_import = false; | 76 bool did_perform_profile_import = false; |
71 bool profile_import_exited_successfully = false; | 77 bool profile_import_exited_successfully = false; |
72 | 78 |
73 // Helper class that performs delayed first-run tasks that need more of the | 79 // 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... |
505 return *GetExtraArgumentsInstance(); | 511 return *GetExtraArgumentsInstance(); |
506 } | 512 } |
507 | 513 |
508 // static | 514 // static |
509 void FirstRunBubbleLauncher::ShowFirstRunBubbleSoon() { | 515 void FirstRunBubbleLauncher::ShowFirstRunBubbleSoon() { |
510 SetShowFirstRunBubblePref(FIRST_RUN_BUBBLE_SHOW); | 516 SetShowFirstRunBubblePref(FIRST_RUN_BUBBLE_SHOW); |
511 // This FirstRunBubbleLauncher instance will manage its own lifetime. | 517 // This FirstRunBubbleLauncher instance will manage its own lifetime. |
512 new FirstRunBubbleLauncher(); | 518 new FirstRunBubbleLauncher(); |
513 } | 519 } |
514 | 520 |
515 FirstRunBubbleLauncher::FirstRunBubbleLauncher() { | 521 FirstRunBubbleLauncher::FirstRunBubbleLauncher() |
| 522 : browser_(NULL) { |
| 523 BrowserList::AddObserver(this); |
516 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 524 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
517 content::NotificationService::AllSources()); | 525 content::NotificationService::AllSources()); |
518 } | 526 } |
519 | 527 |
520 FirstRunBubbleLauncher::~FirstRunBubbleLauncher() {} | 528 FirstRunBubbleLauncher::~FirstRunBubbleLauncher() { |
| 529 BrowserList::RemoveObserver(this); |
| 530 } |
521 | 531 |
522 void FirstRunBubbleLauncher::Observe( | 532 void FirstRunBubbleLauncher::Observe( |
523 int type, | 533 int type, |
524 const content::NotificationSource& source, | 534 const content::NotificationSource& source, |
525 const content::NotificationDetails& details) { | 535 const content::NotificationDetails& details) { |
526 DCHECK_EQ(type, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME); | 536 DCHECK_EQ(type, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME); |
527 Browser* browser = chrome::FindBrowserWithWebContents( | 537 Browser* browser = chrome::FindBrowserWithWebContents( |
528 content::Source<content::WebContents>(source).ptr()); | 538 content::Source<content::WebContents>(source).ptr()); |
529 if (!browser || !browser->is_type_tabbed()) | 539 if (!browser || !browser->is_type_tabbed()) |
530 return; | 540 return; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 return; | 573 return; |
564 } | 574 } |
565 } | 575 } |
566 | 576 |
567 // Suppress the first run bubble if a global error bubble is pending. | 577 // Suppress the first run bubble if a global error bubble is pending. |
568 GlobalErrorService* global_error_service = | 578 GlobalErrorService* global_error_service = |
569 GlobalErrorServiceFactory::GetForProfile(browser->profile()); | 579 GlobalErrorServiceFactory::GetForProfile(browser->profile()); |
570 if (global_error_service->GetFirstGlobalErrorWithBubbleView() != NULL) | 580 if (global_error_service->GetFirstGlobalErrorWithBubbleView() != NULL) |
571 return; | 581 return; |
572 | 582 |
| 583 // Make sure we don't get notified again after resetting the |
| 584 // kShowFirstRunBubbleOption preference below. |
| 585 registrar_.Remove(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 586 content::NotificationService::AllSources()); |
| 587 |
573 // Reset the preference and notifications to avoid showing the bubble again. | 588 // Reset the preference and notifications to avoid showing the bubble again. |
574 prefs->SetInteger(prefs::kShowFirstRunBubbleOption, | 589 prefs->SetInteger(prefs::kShowFirstRunBubbleOption, |
575 FIRST_RUN_BUBBLE_DONT_SHOW); | 590 FIRST_RUN_BUBBLE_DONT_SHOW); |
576 | 591 |
| 592 // Show the bubble soon. |
| 593 browser_ = browser; |
| 594 base::MessageLoop::current()->PostDelayedTask( |
| 595 FROM_HERE, |
| 596 base::Bind( |
| 597 &FirstRunBubbleLauncher::DoShowFirstRunBubble, |
| 598 AsWeakPtr()), |
| 599 base::TimeDelta::FromMilliseconds(kFirstRunBubbleDelayMs)); |
| 600 } |
| 601 |
| 602 void FirstRunBubbleLauncher::OnBrowserRemoved(Browser* browser) { |
| 603 if (browser_ == browser) { |
| 604 // Destroy this bubble launcher. |
| 605 delete this; |
| 606 } |
| 607 } |
| 608 |
| 609 void FirstRunBubbleLauncher::DoShowFirstRunBubble() { |
| 610 DCHECK(browser_); |
| 611 |
577 // Show the bubble now and destroy this bubble launcher. | 612 // Show the bubble now and destroy this bubble launcher. |
578 browser->ShowFirstRunBubble(); | 613 browser_->ShowFirstRunBubble(); |
579 delete this; | 614 delete this; |
580 } | 615 } |
581 | 616 |
582 void SetMasterPrefsPathForTesting(const base::FilePath& master_prefs) { | 617 void SetMasterPrefsPathForTesting(const base::FilePath& master_prefs) { |
583 internal::master_prefs_path_for_testing.Get() = master_prefs; | 618 internal::master_prefs_path_for_testing.Get() = master_prefs; |
584 } | 619 } |
585 | 620 |
586 ProcessMasterPreferencesResult ProcessMasterPreferences( | 621 ProcessMasterPreferencesResult ProcessMasterPreferences( |
587 const base::FilePath& user_data_dir, | 622 const base::FilePath& user_data_dir, |
588 MasterPrefs* out_prefs) { | 623 MasterPrefs* out_prefs) { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 internal::DoPostImportPlatformSpecificTasks(); | 782 internal::DoPostImportPlatformSpecificTasks(); |
748 } | 783 } |
749 | 784 |
750 bool DidPerformProfileImport(bool* exited_successfully) { | 785 bool DidPerformProfileImport(bool* exited_successfully) { |
751 if (exited_successfully) | 786 if (exited_successfully) |
752 *exited_successfully = profile_import_exited_successfully; | 787 *exited_successfully = profile_import_exited_successfully; |
753 return did_perform_profile_import; | 788 return did_perform_profile_import; |
754 } | 789 } |
755 | 790 |
756 } // namespace first_run | 791 } // namespace first_run |
OLD | NEW |