| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 |
| 11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/debug/trace_event.h" | 14 #include "base/debug/trace_event.h" |
| 15 #include "base/file_path.h" | 15 #include "base/file_path.h" |
| 16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
| 17 #include "base/mac/scoped_nsautorelease_pool.h" | |
| 18 #include "base/metrics/field_trial.h" | 17 #include "base/metrics/field_trial.h" |
| 19 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
| 20 #include "base/path_service.h" | 19 #include "base/path_service.h" |
| 21 #include "base/process_util.h" | 20 #include "base/process_util.h" |
| 22 #include "base/string_number_conversions.h" | 21 #include "base/string_number_conversions.h" |
| 23 #include "base/string_piece.h" | 22 #include "base/string_piece.h" |
| 24 #include "base/string_split.h" | 23 #include "base/string_split.h" |
| 25 #include "base/string_util.h" | 24 #include "base/string_util.h" |
| 26 #include "base/sys_string_conversions.h" | 25 #include "base/sys_string_conversions.h" |
| 27 #include "base/threading/platform_thread.h" | 26 #include "base/threading/platform_thread.h" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 #include "content/browser/user_metrics.h" | 167 #include "content/browser/user_metrics.h" |
| 169 #include "net/base/net_util.h" | 168 #include "net/base/net_util.h" |
| 170 #include "printing/printed_document.h" | 169 #include "printing/printed_document.h" |
| 171 #include "ui/base/l10n/l10n_util_win.h" | 170 #include "ui/base/l10n/l10n_util_win.h" |
| 172 #include "ui/gfx/platform_font_win.h" | 171 #include "ui/gfx/platform_font_win.h" |
| 173 #endif // defined(OS_WIN) | 172 #endif // defined(OS_WIN) |
| 174 | 173 |
| 175 #if defined(OS_MACOSX) | 174 #if defined(OS_MACOSX) |
| 176 #include <Security/Security.h> | 175 #include <Security/Security.h> |
| 177 | 176 |
| 177 #include "base/mac/scoped_nsautorelease_pool.h" |
| 178 #include "chrome/browser/mac/install_from_dmg.h" | 178 #include "chrome/browser/mac/install_from_dmg.h" |
| 179 #include "chrome/browser/mac/keystone_glue.h" | 179 #include "chrome/browser/mac/keystone_glue.h" |
| 180 #endif | 180 #endif |
| 181 | 181 |
| 182 #if defined(TOOLKIT_VIEWS) | 182 #if defined(TOOLKIT_VIEWS) |
| 183 #include "chrome/browser/ui/views/chrome_views_delegate.h" | 183 #include "chrome/browser/ui/views/chrome_views_delegate.h" |
| 184 #include "views/desktop/desktop_window_view.h" | 184 #include "views/desktop/desktop_window_view.h" |
| 185 #include "views/focus/accelerator_handler.h" | 185 #include "views/focus/accelerator_handler.h" |
| 186 #include "views/widget/widget.h" | 186 #include "views/widget/widget.h" |
| 187 #if defined(TOOLKIT_USES_GTK) | 187 #if defined(TOOLKIT_USES_GTK) |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 // tests the resources need to be reused as many places in the UI cache | 444 // tests the resources need to be reused as many places in the UI cache |
| 445 // SkBitmaps from the ResourceBundle. | 445 // SkBitmaps from the ResourceBundle. |
| 446 ResourceBundle::CleanupSharedInstance(); | 446 ResourceBundle::CleanupSharedInstance(); |
| 447 } | 447 } |
| 448 | 448 |
| 449 if (!new_user_data_dir.empty()) { | 449 if (!new_user_data_dir.empty()) { |
| 450 // Because of the way CommandLine parses, it's sufficient to append a new | 450 // Because of the way CommandLine parses, it's sufficient to append a new |
| 451 // --user-data-dir switch. The last flag of the same name wins. | 451 // --user-data-dir switch. The last flag of the same name wins. |
| 452 // TODO(tc): It would be nice to remove the flag we don't want, but that | 452 // TODO(tc): It would be nice to remove the flag we don't want, but that |
| 453 // sounds risky if we parse differently than CommandLineToArgvW. | 453 // sounds risky if we parse differently than CommandLineToArgvW. |
| 454 CommandLine new_command_line = parameters.command_line_; | 454 CommandLine new_command_line = parameters.command_line; |
| 455 new_command_line.AppendSwitchPath(switches::kUserDataDir, | 455 new_command_line.AppendSwitchPath(switches::kUserDataDir, |
| 456 new_user_data_dir); | 456 new_user_data_dir); |
| 457 base::LaunchProcess(new_command_line, base::LaunchOptions(), NULL); | 457 base::LaunchProcess(new_command_line, base::LaunchOptions(), NULL); |
| 458 } | 458 } |
| 459 #endif | 459 #endif |
| 460 #else | 460 #else |
| 461 // TODO(port): fix this. See comments near the definition of | 461 // TODO(port): fix this. See comments near the definition of |
| 462 // user_data_dir. It is better to CHECK-fail here than it is to | 462 // user_data_dir. It is better to CHECK-fail here than it is to |
| 463 // silently exit because of missing code in the above test. | 463 // silently exit because of missing code in the above test. |
| 464 CHECK(profile) << "Cannot get default profile."; | 464 CHECK(profile) << "Cannot get default profile."; |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 const char kMissingLocaleDataTitle[] = "Missing File Error"; | 675 const char kMissingLocaleDataTitle[] = "Missing File Error"; |
| 676 const char kMissingLocaleDataMessage[] = | 676 const char kMissingLocaleDataMessage[] = |
| 677 "Unable to find locale data files. Please reinstall."; | 677 "Unable to find locale data files. Please reinstall."; |
| 678 } // namespace chrome_browser | 678 } // namespace chrome_browser |
| 679 | 679 |
| 680 // BrowserMainParts ------------------------------------------------------------ | 680 // BrowserMainParts ------------------------------------------------------------ |
| 681 | 681 |
| 682 ChromeBrowserMainParts::ChromeBrowserMainParts( | 682 ChromeBrowserMainParts::ChromeBrowserMainParts( |
| 683 const MainFunctionParams& parameters) | 683 const MainFunctionParams& parameters) |
| 684 : parameters_(parameters), | 684 : parameters_(parameters), |
| 685 parsed_command_line_(parameters.command_line_), | 685 parsed_command_line_(parameters.command_line), |
| 686 result_code_(content::RESULT_CODE_NORMAL_EXIT), | 686 result_code_(content::RESULT_CODE_NORMAL_EXIT), |
| 687 shutdown_watcher_(new ShutdownWatcherHelper()), | 687 shutdown_watcher_(new ShutdownWatcherHelper()), |
| 688 record_search_engine_(false), | 688 record_search_engine_(false), |
| 689 translate_manager_(NULL), | 689 translate_manager_(NULL), |
| 690 profile_(NULL), | 690 profile_(NULL), |
| 691 run_message_loop_(true), | 691 run_message_loop_(true), |
| 692 notify_result_(ProcessSingleton::PROCESS_NONE) { | 692 notify_result_(ProcessSingleton::PROCESS_NONE) { |
| 693 // If we're running tests (ui_task is non-null). | 693 // If we're running tests (ui_task is non-null). |
| 694 if (parameters.ui_task) | 694 if (parameters.ui_task) |
| 695 browser_defaults::enable_help_app = false; | 695 browser_defaults::enable_help_app = false; |
| (...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1655 #if defined(OS_MACOSX) | 1655 #if defined(OS_MACOSX) |
| 1656 if (!parsed_command_line().HasSwitch(switches::kNoFirstRun)) { | 1656 if (!parsed_command_line().HasSwitch(switches::kNoFirstRun)) { |
| 1657 // Disk image installation is sort of a first-run task, so it shares the | 1657 // Disk image installation is sort of a first-run task, so it shares the |
| 1658 // kNoFirstRun switch. | 1658 // kNoFirstRun switch. |
| 1659 if (MaybeInstallFromDiskImage()) { | 1659 if (MaybeInstallFromDiskImage()) { |
| 1660 // The application was installed and the installed copy has been | 1660 // The application was installed and the installed copy has been |
| 1661 // launched. This process is now obsolete. Exit. | 1661 // launched. This process is now obsolete. Exit. |
| 1662 return content::RESULT_CODE_NORMAL_EXIT; | 1662 return content::RESULT_CODE_NORMAL_EXIT; |
| 1663 } | 1663 } |
| 1664 } | 1664 } |
| 1665 base::mac::ScopedNSAutoreleasePool* pool = parameters().autorelease_pool; |
| 1665 #endif | 1666 #endif |
| 1666 | 1667 |
| 1667 // Show the First Run UI if this is the first time Chrome has been run on | 1668 // Show the First Run UI if this is the first time Chrome has been run on |
| 1668 // this computer, or we're being compelled to do so by a command line flag. | 1669 // this computer, or we're being compelled to do so by a command line flag. |
| 1669 // Note that this be done _after_ the PrefService is initialized and all | 1670 // Note that this be done _after_ the PrefService is initialized and all |
| 1670 // preferences are registered, since some of the code that the importer | 1671 // preferences are registered, since some of the code that the importer |
| 1671 // touches reads preferences. | 1672 // touches reads preferences. |
| 1672 if (is_first_run) { | 1673 if (is_first_run) { |
| 1673 if (!first_run_ui_bypass) { | 1674 if (!first_run_ui_bypass) { |
| 1674 FirstRun::AutoImport(profile_, | 1675 FirstRun::AutoImport(profile_, |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1878 // Initialize GpuDataManager and collect preliminary gpu info on FILE thread. | 1879 // Initialize GpuDataManager and collect preliminary gpu info on FILE thread. |
| 1879 // Upon completion, it posts GpuBlacklist auto update task on UI thread. | 1880 // Upon completion, it posts GpuBlacklist auto update task on UI thread. |
| 1880 BrowserThread::PostTask( | 1881 BrowserThread::PostTask( |
| 1881 BrowserThread::FILE, FROM_HERE, | 1882 BrowserThread::FILE, FROM_HERE, |
| 1882 base::Bind(&GpuBlacklistUpdater::SetupOnFileThread)); | 1883 base::Bind(&GpuBlacklistUpdater::SetupOnFileThread)); |
| 1883 | 1884 |
| 1884 // Start watching all browser threads for responsiveness. | 1885 // Start watching all browser threads for responsiveness. |
| 1885 ThreadWatcherList::StartWatchingAll(parsed_command_line()); | 1886 ThreadWatcherList::StartWatchingAll(parsed_command_line()); |
| 1886 | 1887 |
| 1887 int result_code = content::RESULT_CODE_NORMAL_EXIT; | 1888 int result_code = content::RESULT_CODE_NORMAL_EXIT; |
| 1888 base::mac::ScopedNSAutoreleasePool* pool = parameters().autorelease_pool_; | |
| 1889 if (parameters().ui_task) { | 1889 if (parameters().ui_task) { |
| 1890 // We are in test mode. Run one task and enter the main message loop. | 1890 // We are in test mode. Run one task and enter the main message loop. |
| 1891 #if defined(OS_MACOSX) |
| 1891 if (pool) | 1892 if (pool) |
| 1892 pool->Recycle(); | 1893 pool->Recycle(); |
| 1894 #endif |
| 1893 parameters().ui_task->Run(); | 1895 parameters().ui_task->Run(); |
| 1894 delete parameters().ui_task; | 1896 delete parameters().ui_task; |
| 1895 } else { | 1897 } else { |
| 1896 // Most general initialization is behind us, but opening a | 1898 // Most general initialization is behind us, but opening a |
| 1897 // tab and/or session restore and such is still to be done. | 1899 // tab and/or session restore and such is still to be done. |
| 1898 base::TimeTicks browser_open_start = base::TimeTicks::Now(); | 1900 base::TimeTicks browser_open_start = base::TimeTicks::Now(); |
| 1899 | 1901 |
| 1900 // We are in regular browser boot sequence. Open initial tabs and enter the | 1902 // We are in regular browser boot sequence. Open initial tabs and enter the |
| 1901 // main message loop. | 1903 // main message loop. |
| 1902 if (browser_init.Start(parsed_command_line(), FilePath(), profile_, | 1904 if (browser_init.Start(parsed_command_line(), FilePath(), profile_, |
| 1903 &result_code)) { | 1905 &result_code)) { |
| 1904 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) | 1906 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) |
| 1905 // Initialize autoupdate timer. Timer callback costs basically nothing | 1907 // Initialize autoupdate timer. Timer callback costs basically nothing |
| 1906 // when browser is not in persistent mode, so it's OK to let it ride on | 1908 // when browser is not in persistent mode, so it's OK to let it ride on |
| 1907 // the main thread. This needs to be done here because we don't want | 1909 // the main thread. This needs to be done here because we don't want |
| 1908 // to start the timer when Chrome is run inside a test harness. | 1910 // to start the timer when Chrome is run inside a test harness. |
| 1909 g_browser_process->StartAutoupdateTimer(); | 1911 g_browser_process->StartAutoupdateTimer(); |
| 1910 #endif | 1912 #endif |
| 1911 | 1913 |
| 1912 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 1914 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 1913 // On Linux, the running exe will be updated if an upgrade becomes | 1915 // On Linux, the running exe will be updated if an upgrade becomes |
| 1914 // available while the browser is running. We need to save the last | 1916 // available while the browser is running. We need to save the last |
| 1915 // modified time of the exe, so we can compare to determine if there is | 1917 // modified time of the exe, so we can compare to determine if there is |
| 1916 // an upgrade while the browser is kept alive by a persistent extension. | 1918 // an upgrade while the browser is kept alive by a persistent extension. |
| 1917 upgrade_util::SaveLastModifiedTimeOfExe(); | 1919 upgrade_util::SaveLastModifiedTimeOfExe(); |
| 1918 #endif | 1920 #endif |
| 1919 | 1921 |
| 1920 // Record now as the last successful chrome start. | 1922 // Record now as the last successful chrome start. |
| 1921 GoogleUpdateSettings::SetLastRunTime(); | 1923 GoogleUpdateSettings::SetLastRunTime(); |
| 1924 |
| 1925 #if defined(OS_MACOSX) |
| 1922 // Call Recycle() here as late as possible, before going into the loop | 1926 // Call Recycle() here as late as possible, before going into the loop |
| 1923 // because Start() will add things to it while creating the main window. | 1927 // because Start() will add things to it while creating the main window. |
| 1924 if (pool) | 1928 if (pool) |
| 1925 pool->Recycle(); | 1929 pool->Recycle(); |
| 1930 #endif |
| 1926 | 1931 |
| 1927 RecordPreReadExperimentTime("Startup.BrowserOpenTabs", | 1932 RecordPreReadExperimentTime("Startup.BrowserOpenTabs", |
| 1928 base::TimeTicks::Now() - browser_open_start); | 1933 base::TimeTicks::Now() - browser_open_start); |
| 1929 | 1934 |
| 1930 // TODO(mad): Move this call in a proper place on CrOS. | 1935 // TODO(mad): Move this call in a proper place on CrOS. |
| 1931 // http://crosbug.com/17687 | 1936 // http://crosbug.com/17687 |
| 1932 #if !defined(OS_CHROMEOS) | 1937 #if !defined(OS_CHROMEOS) |
| 1933 // If we're running tests (ui_task is non-null), then we don't want to | 1938 // If we're running tests (ui_task is non-null), then we don't want to |
| 1934 // call FetchLanguageListFromTranslateServer | 1939 // call FetchLanguageListFromTranslateServer |
| 1935 if (parameters().ui_task == NULL && translate_manager_ != NULL) { | 1940 if (parameters().ui_task == NULL && translate_manager_ != NULL) { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2077 } | 2082 } |
| 2078 | 2083 |
| 2079 void ChromeBrowserMainParts::ToolkitInitialized() { | 2084 void ChromeBrowserMainParts::ToolkitInitialized() { |
| 2080 #if defined(TOOLKIT_VIEWS) | 2085 #if defined(TOOLKIT_VIEWS) |
| 2081 // The delegate needs to be set before any UI is created so that windows | 2086 // The delegate needs to be set before any UI is created so that windows |
| 2082 // display the correct icon. | 2087 // display the correct icon. |
| 2083 if (!views::ViewsDelegate::views_delegate) | 2088 if (!views::ViewsDelegate::views_delegate) |
| 2084 views::ViewsDelegate::views_delegate = new ChromeViewsDelegate; | 2089 views::ViewsDelegate::views_delegate = new ChromeViewsDelegate; |
| 2085 | 2090 |
| 2086 // TODO(beng): Move to WidgetImpl and implement on Windows too! | 2091 // TODO(beng): Move to WidgetImpl and implement on Windows too! |
| 2087 if (parameters().command_line_.HasSwitch(switches::kDebugViewsPaint)) | 2092 if (parameters().command_line.HasSwitch(switches::kDebugViewsPaint)) |
| 2088 views::Widget::SetDebugPaintEnabled(true); | 2093 views::Widget::SetDebugPaintEnabled(true); |
| 2089 #endif | 2094 #endif |
| 2090 | 2095 |
| 2091 #if defined(OS_WIN) | 2096 #if defined(OS_WIN) |
| 2092 gfx::PlatformFontWin::adjust_font_callback = &AdjustUIFont; | 2097 gfx::PlatformFontWin::adjust_font_callback = &AdjustUIFont; |
| 2093 gfx::PlatformFontWin::get_minimum_font_size_callback = &GetMinimumFontSize; | 2098 gfx::PlatformFontWin::get_minimum_font_size_callback = &GetMinimumFontSize; |
| 2094 #endif | 2099 #endif |
| 2095 } | 2100 } |
| 2096 | 2101 |
| 2097 // This code is specific to the Windows-only PreReadExperiment field-trial. | 2102 // This code is specific to the Windows-only PreReadExperiment field-trial. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2114 if (env->GetVar(chrome::kPreReadEnvironmentVariable, &pre_read) && | 2119 if (env->GetVar(chrome::kPreReadEnvironmentVariable, &pre_read) && |
| 2115 (pre_read == "0" || pre_read == "1")) { | 2120 (pre_read == "0" || pre_read == "1")) { |
| 2116 std::string uma_name(name); | 2121 std::string uma_name(name); |
| 2117 uma_name += "_PreRead"; | 2122 uma_name += "_PreRead"; |
| 2118 uma_name += pre_read == "1" ? "Enabled" : "Disabled"; | 2123 uma_name += pre_read == "1" ? "Enabled" : "Disabled"; |
| 2119 AddPreReadHistogramTime(uma_name.c_str(), time); | 2124 AddPreReadHistogramTime(uma_name.c_str(), time); |
| 2120 } | 2125 } |
| 2121 #endif | 2126 #endif |
| 2122 #endif | 2127 #endif |
| 2123 } | 2128 } |
| OLD | NEW |