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/chrome_browser_main.h" | 5 #include "chrome/browser/chrome_browser_main.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 | 671 |
672 void ChromeBrowserMainParts::PostMainMessageLoopStart() { | 672 void ChromeBrowserMainParts::PostMainMessageLoopStart() { |
673 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) | 673 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
674 chrome_extra_parts_[i]->PostMainMessageLoopStart(); | 674 chrome_extra_parts_[i]->PostMainMessageLoopStart(); |
675 } | 675 } |
676 | 676 |
677 int ChromeBrowserMainParts::PreCreateThreads() { | 677 int ChromeBrowserMainParts::PreCreateThreads() { |
678 result_code_ = PreCreateThreadsImpl(); | 678 result_code_ = PreCreateThreadsImpl(); |
679 // These members must be initialized before returning from this function. | 679 // These members must be initialized before returning from this function. |
680 DCHECK(master_prefs_.get()); | 680 DCHECK(master_prefs_.get()); |
| 681 #if !defined(OS_ANDROID) |
681 DCHECK(browser_creator_.get()); | 682 DCHECK(browser_creator_.get()); |
| 683 #endif |
682 return result_code_; | 684 return result_code_; |
683 } | 685 } |
684 | 686 |
685 int ChromeBrowserMainParts::PreCreateThreadsImpl() { | 687 int ChromeBrowserMainParts::PreCreateThreadsImpl() { |
686 run_message_loop_ = false; | 688 run_message_loop_ = false; |
687 #if defined(OS_WIN) | 689 #if defined(OS_WIN) |
688 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_); | 690 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_); |
689 #else | 691 #else |
690 // Getting the user data dir can fail if the directory isn't | 692 // Getting the user data dir can fail if the directory isn't |
691 // creatable, for example; on Windows in code below we bring up a | 693 // creatable, for example; on Windows in code below we bring up a |
692 // dialog prompting the user to pick a different directory. | 694 // dialog prompting the user to pick a different directory. |
693 // However, ProcessSingleton needs a real user_data_dir on Mac/Linux, | 695 // However, ProcessSingleton needs a real user_data_dir on Mac/Linux, |
694 // so it's better to fail here than fail mysteriously elsewhere. | 696 // so it's better to fail here than fail mysteriously elsewhere. |
695 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_)) | 697 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_)) |
696 << "Must be able to get user data directory!"; | 698 << "Must be able to get user data directory!"; |
697 #endif | 699 #endif |
698 | 700 |
| 701 // Android's first run is done in Java instead of native. |
| 702 #if !defined(OS_ANDROID) |
699 process_singleton_.reset(new ProcessSingleton(user_data_dir_)); | 703 process_singleton_.reset(new ProcessSingleton(user_data_dir_)); |
700 // Ensure ProcessSingleton won't process messages too early. It will be | 704 // Ensure ProcessSingleton won't process messages too early. It will be |
701 // unlocked in PostBrowserStart(). | 705 // unlocked in PostBrowserStart(). |
702 process_singleton_->Lock(NULL); | 706 process_singleton_->Lock(NULL); |
703 | 707 |
704 is_first_run_ = | 708 is_first_run_ = |
705 (first_run::IsChromeFirstRun() || | 709 (first_run::IsChromeFirstRun() || |
706 parsed_command_line().HasSwitch(switches::kFirstRun)) && | 710 parsed_command_line().HasSwitch(switches::kFirstRun)) && |
707 !HasImportSwitch(parsed_command_line()); | 711 !HasImportSwitch(parsed_command_line()); |
| 712 #endif |
708 browser_process_.reset(new BrowserProcessImpl(parsed_command_line())); | 713 browser_process_.reset(new BrowserProcessImpl(parsed_command_line())); |
709 | 714 |
710 if (parsed_command_line().HasSwitch(switches::kEnableProfiling)) { | 715 if (parsed_command_line().HasSwitch(switches::kEnableProfiling)) { |
711 // User wants to override default tracking status. | 716 // User wants to override default tracking status. |
712 std::string flag = | 717 std::string flag = |
713 parsed_command_line().GetSwitchValueASCII(switches::kEnableProfiling); | 718 parsed_command_line().GetSwitchValueASCII(switches::kEnableProfiling); |
714 // Default to basic profiling (no parent child support). | 719 // Default to basic profiling (no parent child support). |
715 tracked_objects::ThreadData::Status status = | 720 tracked_objects::ThreadData::Status status = |
716 tracked_objects::ThreadData::PROFILING_ACTIVE; | 721 tracked_objects::ThreadData::PROFILING_ACTIVE; |
717 if (flag.compare("0") != 0) | 722 if (flag.compare("0") != 0) |
718 status = tracked_objects::ThreadData::DEACTIVATED; | 723 status = tracked_objects::ThreadData::DEACTIVATED; |
719 else if (flag.compare("child") != 0) | 724 else if (flag.compare("child") != 0) |
720 status = tracked_objects::ThreadData::PROFILING_CHILDREN_ACTIVE; | 725 status = tracked_objects::ThreadData::PROFILING_CHILDREN_ACTIVE; |
721 tracked_objects::ThreadData::InitializeAndSetTrackingStatus(status); | 726 tracked_objects::ThreadData::InitializeAndSetTrackingStatus(status); |
722 } | 727 } |
723 | 728 |
724 if (parsed_command_line().HasSwitch(switches::kProfilingOutputFile)) { | 729 if (parsed_command_line().HasSwitch(switches::kProfilingOutputFile)) { |
725 tracking_objects_.set_output_file_path( | 730 tracking_objects_.set_output_file_path( |
726 parsed_command_line().GetSwitchValuePath( | 731 parsed_command_line().GetSwitchValuePath( |
727 switches::kProfilingOutputFile)); | 732 switches::kProfilingOutputFile)); |
728 } | 733 } |
729 | 734 |
730 local_state_ = InitializeLocalState(parsed_command_line(), is_first_run_); | 735 local_state_ = InitializeLocalState(parsed_command_line(), is_first_run_); |
731 | 736 |
732 // These members must be initialized before returning from this function. | 737 // These members must be initialized before returning from this function. |
733 master_prefs_.reset(new first_run::MasterPrefs); | 738 master_prefs_.reset(new first_run::MasterPrefs); |
| 739 |
| 740 #if !defined(OS_ANDROID) |
| 741 // Android doesn't use StartupBrowserCreator. |
734 browser_creator_.reset(new StartupBrowserCreator); | 742 browser_creator_.reset(new StartupBrowserCreator); |
| 743 // TODO(yfriedman): Refactor Android to re-use UMABrowsingActivityObserver |
735 chrome::UMABrowsingActivityObserver::Init(); | 744 chrome::UMABrowsingActivityObserver::Init(); |
| 745 #endif |
736 | 746 |
737 // Convert active labs into switches. This needs to be done before | 747 // Convert active labs into switches. This needs to be done before |
738 // ResourceBundle::InitSharedInstanceWithLocale as some loaded resources are | 748 // ResourceBundle::InitSharedInstanceWithLocale as some loaded resources are |
739 // affected by experiment flags (--touch-optimized-ui in particular). Not | 749 // affected by experiment flags (--touch-optimized-ui in particular). Not |
740 // needed on Android as there aren't experimental flags. | 750 // needed on Android as there aren't experimental flags. |
741 about_flags::ConvertFlagsToSwitches(local_state_, | 751 about_flags::ConvertFlagsToSwitches(local_state_, |
742 CommandLine::ForCurrentProcess()); | 752 CommandLine::ForCurrentProcess()); |
743 local_state_->UpdateCommandLinePrefStore(CommandLine::ForCurrentProcess()); | 753 local_state_->UpdateCommandLinePrefStore(CommandLine::ForCurrentProcess()); |
744 | 754 |
745 // Reset the command line in the crash report details, since we may have | 755 // Reset the command line in the crash report details, since we may have |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 if (ShellIntegration::CanSetAsDefaultBrowser() == | 818 if (ShellIntegration::CanSetAsDefaultBrowser() == |
809 ShellIntegration::SET_DEFAULT_UNATTENDED) | 819 ShellIntegration::SET_DEFAULT_UNATTENDED) |
810 ShellIntegration::SetAsDefaultBrowser(); | 820 ShellIntegration::SetAsDefaultBrowser(); |
811 } | 821 } |
812 #else | 822 #else |
813 // We don't support retention experiments on Mac or Linux. | 823 // We don't support retention experiments on Mac or Linux. |
814 return content::RESULT_CODE_NORMAL_EXIT; | 824 return content::RESULT_CODE_NORMAL_EXIT; |
815 #endif // defined(OS_WIN) | 825 #endif // defined(OS_WIN) |
816 } | 826 } |
817 | 827 |
| 828 // Android does first run in Java instead of native. |
| 829 #if !defined(OS_ANDROID) |
818 // On first run, we need to process the predictor preferences before the | 830 // On first run, we need to process the predictor preferences before the |
819 // browser's profile_manager object is created, but after ResourceBundle | 831 // browser's profile_manager object is created, but after ResourceBundle |
820 // is initialized. | 832 // is initialized. |
821 first_run_ui_bypass_ = false; // True to skip first run UI. | 833 first_run_ui_bypass_ = false; // True to skip first run UI. |
822 if (is_first_run_) { | 834 if (is_first_run_) { |
823 first_run_ui_bypass_ = !first_run::ProcessMasterPreferences( | 835 first_run_ui_bypass_ = !first_run::ProcessMasterPreferences( |
824 user_data_dir_, master_prefs_.get()); | 836 user_data_dir_, master_prefs_.get()); |
825 AddFirstRunNewTabs(browser_creator_.get(), master_prefs_->new_tabs); | 837 AddFirstRunNewTabs(browser_creator_.get(), master_prefs_->new_tabs); |
826 | 838 |
827 // If we are running in App mode, we do not want to show the importer | 839 // If we are running in App mode, we do not want to show the importer |
828 // (first run) UI. | 840 // (first run) UI. |
829 if (!first_run_ui_bypass_ && | 841 if (!first_run_ui_bypass_ && |
830 (parsed_command_line().HasSwitch(switches::kApp) || | 842 (parsed_command_line().HasSwitch(switches::kApp) || |
831 parsed_command_line().HasSwitch(switches::kAppId) || | 843 parsed_command_line().HasSwitch(switches::kAppId) || |
832 parsed_command_line().HasSwitch(switches::kNoFirstRun))) | 844 parsed_command_line().HasSwitch(switches::kNoFirstRun))) |
833 first_run_ui_bypass_ = true; | 845 first_run_ui_bypass_ = true; |
834 | 846 |
835 // Create Sentinel if no-first-run argument is passed in. | 847 // Create Sentinel if no-first-run argument is passed in. |
836 if (parsed_command_line().HasSwitch(switches::kNoFirstRun)) | 848 if (parsed_command_line().HasSwitch(switches::kNoFirstRun)) |
837 first_run::CreateSentinel(); | 849 first_run::CreateSentinel(); |
838 } | 850 } |
| 851 #endif |
839 | 852 |
840 // TODO(viettrungluu): why don't we run this earlier? | 853 // TODO(viettrungluu): why don't we run this earlier? |
841 if (!parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) | 854 if (!parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) |
842 WarnAboutMinimumSystemRequirements(); | 855 WarnAboutMinimumSystemRequirements(); |
843 | 856 |
844 #if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_MACOSX) | 857 #if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_MACOSX) |
845 // Set the product channel for crash reports. | 858 // Set the product channel for crash reports. |
846 child_process_logging::SetChannel( | 859 child_process_logging::SetChannel( |
847 chrome::VersionInfo::GetVersionStringModifier()); | 860 chrome::VersionInfo::GetVersionStringModifier()); |
848 #endif | 861 #endif |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) | 923 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
911 chrome_extra_parts_[i]->PostProfileInit(); | 924 chrome_extra_parts_[i]->PostProfileInit(); |
912 } | 925 } |
913 | 926 |
914 void ChromeBrowserMainParts::PreBrowserStart() { | 927 void ChromeBrowserMainParts::PreBrowserStart() { |
915 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) | 928 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
916 chrome_extra_parts_[i]->PreBrowserStart(); | 929 chrome_extra_parts_[i]->PreBrowserStart(); |
917 } | 930 } |
918 | 931 |
919 void ChromeBrowserMainParts::PostBrowserStart() { | 932 void ChromeBrowserMainParts::PostBrowserStart() { |
| 933 #if !defined(OS_ANDROID) |
920 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kVisitURLs)) | 934 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kVisitURLs)) |
921 RunPageCycler(); | 935 RunPageCycler(); |
| 936 #endif |
922 | 937 |
923 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) | 938 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
924 chrome_extra_parts_[i]->PostBrowserStart(); | 939 chrome_extra_parts_[i]->PostBrowserStart(); |
| 940 #if !defined(OS_ANDROID) |
925 // Allow ProcessSingleton to process messages. | 941 // Allow ProcessSingleton to process messages. |
926 process_singleton_->Unlock(); | 942 process_singleton_->Unlock(); |
| 943 #endif |
927 } | 944 } |
928 | 945 |
| 946 #if !defined(OS_ANDROID) |
929 void ChromeBrowserMainParts::RunPageCycler() { | 947 void ChromeBrowserMainParts::RunPageCycler() { |
930 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 948 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
931 // We assume a native desktop for tests, but we will need to find a way to | 949 // We assume a native desktop for tests, but we will need to find a way to |
932 // get the proper host desktop type once we start running these tests in ASH. | 950 // get the proper host desktop type once we start running these tests in ASH. |
933 Browser* browser = browser::FindBrowserWithProfile( | 951 Browser* browser = browser::FindBrowserWithProfile( |
934 profile_, chrome::HOST_DESKTOP_TYPE_NATIVE); | 952 profile_, chrome::HOST_DESKTOP_TYPE_NATIVE); |
935 DCHECK(browser); | 953 DCHECK(browser); |
936 PageCycler* page_cycler = NULL; | 954 PageCycler* page_cycler = NULL; |
937 FilePath input_file = | 955 FilePath input_file = |
938 command_line->GetSwitchValuePath(switches::kVisitURLs); | 956 command_line->GetSwitchValuePath(switches::kVisitURLs); |
939 page_cycler = new PageCycler(browser, input_file); | 957 page_cycler = new PageCycler(browser, input_file); |
940 page_cycler->set_errors_file( | 958 page_cycler->set_errors_file( |
941 input_file.AddExtension(FILE_PATH_LITERAL(".errors"))); | 959 input_file.AddExtension(FILE_PATH_LITERAL(".errors"))); |
942 if (command_line->HasSwitch(switches::kRecordStats)) { | 960 if (command_line->HasSwitch(switches::kRecordStats)) { |
943 page_cycler->set_stats_file( | 961 page_cycler->set_stats_file( |
944 command_line->GetSwitchValuePath(switches::kRecordStats)); | 962 command_line->GetSwitchValuePath(switches::kRecordStats)); |
945 } | 963 } |
946 page_cycler->Run(); | 964 page_cycler->Run(); |
947 } | 965 } |
| 966 #endif // !defined(OS_ANDROID) |
948 | 967 |
949 void ChromeBrowserMainParts::SetupPlatformFieldTrials() { | 968 void ChromeBrowserMainParts::SetupPlatformFieldTrials() { |
950 // Base class implementation of this does nothing. | 969 // Base class implementation of this does nothing. |
951 } | 970 } |
952 | 971 |
953 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { | 972 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { |
| 973 // Android updates the metrics service dynamically depending on whether the |
| 974 // application is in the foreground or not. Do not start here. |
| 975 #if !defined(OS_ANDROID) |
954 // Now that the file thread has been started, start recording. | 976 // Now that the file thread has been started, start recording. |
955 StartMetricsRecording(); | 977 StartMetricsRecording(); |
| 978 #endif |
956 | 979 |
957 // Create watchdog thread after creating all other threads because it will | 980 // Create watchdog thread after creating all other threads because it will |
958 // watch the other threads and they must be running. | 981 // watch the other threads and they must be running. |
959 browser_process_->watchdog_thread(); | 982 browser_process_->watchdog_thread(); |
960 | 983 |
961 // Do any initializating in the browser process that requires all threads | 984 // Do any initializating in the browser process that requires all threads |
962 // running. | 985 // running. |
963 browser_process_->PreMainMessageLoopRun(); | 986 browser_process_->PreMainMessageLoopRun(); |
964 | 987 |
965 // Record last shutdown time into a histogram. | 988 // Record last shutdown time into a histogram. |
(...skipping 17 matching lines...) Expand all Loading... |
983 parsed_command_line_); | 1006 parsed_command_line_); |
984 } | 1007 } |
985 #endif | 1008 #endif |
986 | 1009 |
987 if (parsed_command_line().HasSwitch(switches::kMakeDefaultBrowser)) { | 1010 if (parsed_command_line().HasSwitch(switches::kMakeDefaultBrowser)) { |
988 return ShellIntegration::SetAsDefaultBrowser() ? | 1011 return ShellIntegration::SetAsDefaultBrowser() ? |
989 static_cast<int>(content::RESULT_CODE_NORMAL_EXIT) : | 1012 static_cast<int>(content::RESULT_CODE_NORMAL_EXIT) : |
990 static_cast<int>(chrome::RESULT_CODE_SHELL_INTEGRATION_FAILED); | 1013 static_cast<int>(chrome::RESULT_CODE_SHELL_INTEGRATION_FAILED); |
991 } | 1014 } |
992 | 1015 |
| 1016 // Android doesn't support extensions and doesn't implement ProcessSingleton. |
| 1017 #if !defined(OS_ANDROID) |
993 // If the command line specifies --pack-extension, attempt the pack extension | 1018 // If the command line specifies --pack-extension, attempt the pack extension |
994 // startup action and exit. | 1019 // startup action and exit. |
995 if (parsed_command_line().HasSwitch(switches::kPackExtension)) { | 1020 if (parsed_command_line().HasSwitch(switches::kPackExtension)) { |
996 extensions::StartupHelper extension_startup_helper; | 1021 extensions::StartupHelper extension_startup_helper; |
997 if (extension_startup_helper.PackExtension(parsed_command_line())) | 1022 if (extension_startup_helper.PackExtension(parsed_command_line())) |
998 return content::RESULT_CODE_NORMAL_EXIT; | 1023 return content::RESULT_CODE_NORMAL_EXIT; |
999 return chrome::RESULT_CODE_PACK_EXTENSION_ERROR; | 1024 return chrome::RESULT_CODE_PACK_EXTENSION_ERROR; |
1000 } | 1025 } |
1001 | 1026 |
1002 bool pass_command_line = true; | 1027 bool pass_command_line = true; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1041 "directory. This means that running multiple instances " | 1066 "directory. This means that running multiple instances " |
1042 "would start multiple browser processes rather than " | 1067 "would start multiple browser processes rather than " |
1043 "opening a new window in the existing process. Aborting " | 1068 "opening a new window in the existing process. Aborting " |
1044 "now to avoid profile corruption."; | 1069 "now to avoid profile corruption."; |
1045 return chrome::RESULT_CODE_PROFILE_IN_USE; | 1070 return chrome::RESULT_CODE_PROFILE_IN_USE; |
1046 | 1071 |
1047 default: | 1072 default: |
1048 NOTREACHED(); | 1073 NOTREACHED(); |
1049 } | 1074 } |
1050 } | 1075 } |
| 1076 #endif // !defined(OS_ANDROID) |
1051 | 1077 |
1052 #if defined(USE_X11) | 1078 #if defined(USE_X11) |
1053 SetBrowserX11ErrorHandlers(); | 1079 SetBrowserX11ErrorHandlers(); |
1054 #endif | 1080 #endif |
1055 | 1081 |
1056 // Desktop construction occurs here, (required before profile creation). | 1082 // Desktop construction occurs here, (required before profile creation). |
1057 PreProfileInit(); | 1083 PreProfileInit(); |
1058 | 1084 |
1059 // Profile creation ---------------------------------------------------------- | 1085 // Profile creation ---------------------------------------------------------- |
1060 | 1086 |
1061 if (is_first_run_) { | 1087 if (is_first_run_) { |
1062 // Warn the ProfileManager that an import process will run, possibly | 1088 // Warn the ProfileManager that an import process will run, possibly |
1063 // locking the WebDataService directory of the next Profile created. | 1089 // locking the WebDataService directory of the next Profile created. |
1064 browser_process_->profile_manager()->SetWillImport(); | 1090 browser_process_->profile_manager()->SetWillImport(); |
1065 } | 1091 } |
1066 | 1092 |
1067 profile_ = CreateProfile(parameters(), user_data_dir_, parsed_command_line()); | 1093 profile_ = CreateProfile(parameters(), user_data_dir_, parsed_command_line()); |
1068 if (!profile_) | 1094 if (!profile_) |
1069 return content::RESULT_CODE_NORMAL_EXIT; | 1095 return content::RESULT_CODE_NORMAL_EXIT; |
1070 | 1096 |
| 1097 #if defined(ENABLE_BACKGROUND) |
1071 // Autoload any profiles which are running background apps. | 1098 // Autoload any profiles which are running background apps. |
1072 // TODO(rlp): Do this on a separate thread. See http://crbug.com/99075. | 1099 // TODO(rlp): Do this on a separate thread. See http://crbug.com/99075. |
1073 browser_process_->profile_manager()->AutoloadProfiles(); | 1100 browser_process_->profile_manager()->AutoloadProfiles(); |
1074 | 1101 #endif |
1075 // Post-profile init --------------------------------------------------------- | 1102 // Post-profile init --------------------------------------------------------- |
1076 | 1103 |
1077 #if !defined(OS_MACOSX) | 1104 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
1078 // Importing other browser settings is done in a browser-like process | 1105 // Importing other browser settings is done in a browser-like process |
1079 // that exits when this task has finished. | 1106 // that exits when this task has finished. |
1080 // TODO(port): Port the Mac's IPC-based implementation to other platforms to | 1107 // TODO(port): Port the Mac's IPC-based implementation to other platforms to |
1081 // replace this implementation. http://crbug.com/22142 | 1108 // replace this implementation. http://crbug.com/22142 |
1082 if (HasImportSwitch(parsed_command_line())) { | 1109 if (HasImportSwitch(parsed_command_line())) { |
1083 return first_run::ImportNow(profile_, parsed_command_line()); | 1110 return first_run::ImportNow(profile_, parsed_command_line()); |
1084 } | 1111 } |
1085 #endif | 1112 #endif |
1086 | 1113 |
1087 #if defined(OS_WIN) | 1114 #if defined(OS_WIN) |
1088 // Do the tasks if chrome has been upgraded while it was last running. | 1115 // Do the tasks if chrome has been upgraded while it was last running. |
1089 if (!already_running && upgrade_util::DoUpgradeTasks(parsed_command_line())) | 1116 if (!already_running && upgrade_util::DoUpgradeTasks(parsed_command_line())) |
1090 return content::RESULT_CODE_NORMAL_EXIT; | 1117 return content::RESULT_CODE_NORMAL_EXIT; |
1091 | 1118 |
1092 // Check if there is any machine level Chrome installed on the current | 1119 // Check if there is any machine level Chrome installed on the current |
1093 // machine. If yes and the current Chrome process is user level, we do not | 1120 // machine. If yes and the current Chrome process is user level, we do not |
1094 // allow the user level Chrome to run. So we notify the user and uninstall | 1121 // allow the user level Chrome to run. So we notify the user and uninstall |
1095 // user level Chrome. | 1122 // user level Chrome. |
1096 // Note this check should only happen here, after all the checks above | 1123 // Note this check should only happen here, after all the checks above |
1097 // (uninstall, resource bundle initialization, other chrome browser | 1124 // (uninstall, resource bundle initialization, other chrome browser |
1098 // processes etc). | 1125 // processes etc). |
1099 // Do not allow this to occur for Chrome Frame user-to-system handoffs. | 1126 // Do not allow this to occur for Chrome Frame user-to-system handoffs. |
1100 if (!parsed_command_line().HasSwitch(switches::kChromeFrame) && | 1127 if (!parsed_command_line().HasSwitch(switches::kChromeFrame) && |
1101 ChromeBrowserMainPartsWin::CheckMachineLevelInstall()) { | 1128 ChromeBrowserMainPartsWin::CheckMachineLevelInstall()) { |
1102 return chrome::RESULT_CODE_MACHINE_LEVEL_INSTALL_EXISTS; | 1129 return chrome::RESULT_CODE_MACHINE_LEVEL_INSTALL_EXISTS; |
1103 } | 1130 } |
1104 #endif | 1131 #endif |
1105 | 1132 |
| 1133 #if !defined(OS_ANDROID) |
1106 // Create the TranslateManager singleton. | 1134 // Create the TranslateManager singleton. |
1107 translate_manager_ = TranslateManager::GetInstance(); | 1135 translate_manager_ = TranslateManager::GetInstance(); |
1108 DCHECK(translate_manager_ != NULL); | 1136 DCHECK(translate_manager_ != NULL); |
1109 | 1137 |
1110 // Initialize Managed Mode. | 1138 // Initialize Managed Mode. |
1111 ManagedMode::Init(profile_); | 1139 ManagedMode::Init(profile_); |
| 1140 #endif |
1112 | 1141 |
1113 // TODO(stevenjb): Move WIN and MACOSX specific code to appropriate Parts. | 1142 // TODO(stevenjb): Move WIN and MACOSX specific code to appropriate Parts. |
1114 // (requires supporting early exit). | 1143 // (requires supporting early exit). |
1115 PostProfileInit(); | 1144 PostProfileInit(); |
1116 | 1145 |
| 1146 #if !defined(OS_ANDROID) |
1117 // Show the First Run UI if this is the first time Chrome has been run on | 1147 // Show the First Run UI if this is the first time Chrome has been run on |
1118 // this computer, or we're being compelled to do so by a command line flag. | 1148 // this computer, or we're being compelled to do so by a command line flag. |
1119 // Note that this be done _after_ the PrefService is initialized and all | 1149 // Note that this be done _after_ the PrefService is initialized and all |
1120 // preferences are registered, since some of the code that the importer | 1150 // preferences are registered, since some of the code that the importer |
1121 // touches reads preferences. | 1151 // touches reads preferences. |
1122 if (is_first_run_) { | 1152 if (is_first_run_) { |
1123 if (!first_run_ui_bypass_) { | 1153 if (!first_run_ui_bypass_) { |
1124 first_run::AutoImport(profile_, | 1154 first_run::AutoImport(profile_, |
1125 master_prefs_->homepage_defined, | 1155 master_prefs_->homepage_defined, |
1126 master_prefs_->do_import_items, | 1156 master_prefs_->do_import_items, |
(...skipping 14 matching lines...) Expand all Loading... |
1141 chrome::SetNewHomePagePrefs(profile_->GetPrefs()); | 1171 chrome::SetNewHomePagePrefs(profile_->GetPrefs()); |
1142 browser_process_->profile_manager()->OnImportFinished(profile_); | 1172 browser_process_->profile_manager()->OnImportFinished(profile_); |
1143 | 1173 |
1144 if (!master_prefs_->suppress_first_run_default_browser_prompt) { | 1174 if (!master_prefs_->suppress_first_run_default_browser_prompt) { |
1145 browser_creator_->set_show_main_browser_window( | 1175 browser_creator_->set_show_main_browser_window( |
1146 !chrome::ShowFirstRunDefaultBrowserPrompt(profile_)); | 1176 !chrome::ShowFirstRunDefaultBrowserPrompt(profile_)); |
1147 } else { | 1177 } else { |
1148 browser_creator_->set_is_default_browser_dialog_suppressed(true); | 1178 browser_creator_->set_is_default_browser_dialog_suppressed(true); |
1149 } | 1179 } |
1150 } // if (is_first_run_) | 1180 } // if (is_first_run_) |
| 1181 #endif // !defined(OS_ANDROID) |
1151 | 1182 |
1152 #if defined(OS_WIN) | 1183 #if defined(OS_WIN) |
1153 // Sets things up so that if we crash from this point on, a dialog will | 1184 // Sets things up so that if we crash from this point on, a dialog will |
1154 // popup asking the user to restart chrome. It is done this late to avoid | 1185 // popup asking the user to restart chrome. It is done this late to avoid |
1155 // testing against a bunch of special cases that are taken care early on. | 1186 // testing against a bunch of special cases that are taken care early on. |
1156 ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment( | 1187 ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment( |
1157 parsed_command_line()); | 1188 parsed_command_line()); |
1158 | 1189 |
1159 // Registers Chrome with the Windows Restart Manager, which will restore the | 1190 // Registers Chrome with the Windows Restart Manager, which will restore the |
1160 // Chrome session when the computer is restarted after a system update. | 1191 // Chrome session when the computer is restarted after a system update. |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1315 #endif | 1346 #endif |
1316 | 1347 |
1317 PreBrowserStart(); | 1348 PreBrowserStart(); |
1318 | 1349 |
1319 // Instantiate the notification UI manager, as this triggers a perf timer | 1350 // Instantiate the notification UI manager, as this triggers a perf timer |
1320 // used to measure startup time. TODO(stevenjb): Figure out what is actually | 1351 // used to measure startup time. TODO(stevenjb): Figure out what is actually |
1321 // triggering the timer and call that explicitly in the approprate place. | 1352 // triggering the timer and call that explicitly in the approprate place. |
1322 // http://crbug.com/105065. | 1353 // http://crbug.com/105065. |
1323 browser_process_->notification_ui_manager(); | 1354 browser_process_->notification_ui_manager(); |
1324 | 1355 |
| 1356 #if !defined(OS_ANDROID) |
1325 // Most general initialization is behind us, but opening a | 1357 // Most general initialization is behind us, but opening a |
1326 // tab and/or session restore and such is still to be done. | 1358 // tab and/or session restore and such is still to be done. |
1327 base::TimeTicks browser_open_start = base::TimeTicks::Now(); | 1359 base::TimeTicks browser_open_start = base::TimeTicks::Now(); |
1328 | 1360 |
1329 // We are in regular browser boot sequence. Open initial tabs and enter the | 1361 // We are in regular browser boot sequence. Open initial tabs and enter the |
1330 // main message loop. | 1362 // main message loop. |
1331 int result_code; | 1363 int result_code; |
1332 #if defined(OS_CHROMEOS) | 1364 #if defined(OS_CHROMEOS) |
1333 // On ChromeOS multiple profiles doesn't apply, and will break if we load | 1365 // On ChromeOS multiple profiles doesn't apply, and will break if we load |
1334 // them this early as the cryptohome hasn't yet been mounted (which happens | 1366 // them this early as the cryptohome hasn't yet been mounted (which happens |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1385 profile_->GetPrefs()); | 1417 profile_->GetPrefs()); |
1386 } | 1418 } |
1387 } | 1419 } |
1388 #endif | 1420 #endif |
1389 | 1421 |
1390 run_message_loop_ = true; | 1422 run_message_loop_ = true; |
1391 } else { | 1423 } else { |
1392 run_message_loop_ = false; | 1424 run_message_loop_ = false; |
1393 } | 1425 } |
1394 browser_creator_.reset(); | 1426 browser_creator_.reset(); |
| 1427 #endif // !defined(OS_ANDROID) |
1395 | 1428 |
1396 PostBrowserStart(); | 1429 PostBrowserStart(); |
1397 | 1430 |
1398 if (parameters().ui_task) { | 1431 if (parameters().ui_task) { |
1399 // We end the startup timer here if we have parameters to run, because we | 1432 // We end the startup timer here if we have parameters to run, because we |
1400 // never start to run the main loop (where we normally stop the timer). | 1433 // never start to run the main loop (where we normally stop the timer). |
1401 startup_timer_->SignalStartupComplete( | 1434 startup_timer_->SignalStartupComplete( |
1402 performance_monitor::StartupTimer::STARTUP_TEST); | 1435 performance_monitor::StartupTimer::STARTUP_TEST); |
1403 parameters().ui_task->Run(); | 1436 parameters().ui_task->Run(); |
1404 delete parameters().ui_task; | 1437 delete parameters().ui_task; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1494 ThreadWatcherList::StopWatchingAll(); | 1527 ThreadWatcherList::StopWatchingAll(); |
1495 | 1528 |
1496 browser_process_->metrics_service()->Stop(); | 1529 browser_process_->metrics_service()->Stop(); |
1497 | 1530 |
1498 restart_last_session_ = browser_shutdown::ShutdownPreThreadsStop(); | 1531 restart_last_session_ = browser_shutdown::ShutdownPreThreadsStop(); |
1499 browser_process_->StartTearDown(); | 1532 browser_process_->StartTearDown(); |
1500 #endif | 1533 #endif |
1501 } | 1534 } |
1502 | 1535 |
1503 void ChromeBrowserMainParts::PostDestroyThreads() { | 1536 void ChromeBrowserMainParts::PostDestroyThreads() { |
| 1537 #if defined(OS_ANDROID) |
| 1538 // On Android, there is no quit/exit. So the browser's main message loop will |
| 1539 // not finish. |
| 1540 NOTREACHED(); |
| 1541 #else |
1504 browser_process_->PostDestroyThreads(); | 1542 browser_process_->PostDestroyThreads(); |
1505 // browser_shutdown takes care of deleting browser_process, so we need to | 1543 // browser_shutdown takes care of deleting browser_process, so we need to |
1506 // release it. | 1544 // release it. |
1507 ignore_result(browser_process_.release()); | 1545 ignore_result(browser_process_.release()); |
1508 browser_shutdown::ShutdownPostThreadsStop(restart_last_session_); | 1546 browser_shutdown::ShutdownPostThreadsStop(restart_last_session_); |
1509 master_prefs_.reset(); | 1547 master_prefs_.reset(); |
1510 process_singleton_.reset(); | 1548 process_singleton_.reset(); |
1511 | 1549 |
1512 // We need to do this check as late as possible, but due to modularity, this | 1550 // We need to do this check as late as possible, but due to modularity, this |
1513 // may be the last point in Chrome. This would be more effective if done at | 1551 // may be the last point in Chrome. This would be more effective if done at |
1514 // a higher level on the stack, so that it is impossible for an early return | 1552 // a higher level on the stack, so that it is impossible for an early return |
1515 // to bypass this code. Perhaps we need a *final* hook that is called on all | 1553 // to bypass this code. Perhaps we need a *final* hook that is called on all |
1516 // paths from content/browser/browser_main. | 1554 // paths from content/browser/browser_main. |
1517 CHECK(MetricsService::UmaMetricsProperlyShutdown()); | 1555 CHECK(MetricsService::UmaMetricsProperlyShutdown()); |
| 1556 #endif |
1518 } | 1557 } |
1519 | 1558 |
1520 // Public members: | 1559 // Public members: |
1521 | 1560 |
1522 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { | 1561 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { |
1523 chrome_extra_parts_.push_back(parts); | 1562 chrome_extra_parts_.push_back(parts); |
1524 } | 1563 } |
1525 | 1564 |
1526 // Misc ------------------------------------------------------------------------ | 1565 // Misc ------------------------------------------------------------------------ |
1527 | 1566 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1563 if (base::win::GetVersion() <= base::win::VERSION_XP) | 1602 if (base::win::GetVersion() <= base::win::VERSION_XP) |
1564 uma_name += "_XP"; | 1603 uma_name += "_XP"; |
1565 | 1604 |
1566 uma_name += "_PreRead_"; | 1605 uma_name += "_PreRead_"; |
1567 uma_name += pre_read_percentage; | 1606 uma_name += pre_read_percentage; |
1568 AddPreReadHistogramTime(uma_name.c_str(), time); | 1607 AddPreReadHistogramTime(uma_name.c_str(), time); |
1569 } | 1608 } |
1570 #endif | 1609 #endif |
1571 #endif | 1610 #endif |
1572 } | 1611 } |
OLD | NEW |