Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: chrome/browser/browser_main.cc

Issue 7779040: Start moving code from BrowserMain to content, so that it can be reused by all embedders of conte... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix windows unittest Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/browser_main.h ('k') | chrome/browser/browser_main_gtk.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/browser_main.h" 5 #include "chrome/browser/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/allocator/allocator_shim.h"
12 #include "base/at_exit.h" 11 #include "base/at_exit.h"
13 #include "base/command_line.h" 12 #include "base/command_line.h"
14 #include "base/debug/trace_event.h" 13 #include "base/debug/trace_event.h"
15 #include "base/file_path.h" 14 #include "base/file_path.h"
16 #include "base/file_util.h" 15 #include "base/file_util.h"
17 #include "base/mac/scoped_nsautorelease_pool.h" 16 #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/system_monitor/system_monitor.h"
28 #include "base/threading/platform_thread.h" 26 #include "base/threading/platform_thread.h"
29 #include "base/threading/thread_restrictions.h" 27 #include "base/threading/thread_restrictions.h"
30 #include "base/time.h" 28 #include "base/time.h"
31 #include "base/utf_string_conversions.h" 29 #include "base/utf_string_conversions.h"
32 #include "base/values.h" 30 #include "base/values.h"
33 #include "build/build_config.h" 31 #include "build/build_config.h"
34 #include "chrome/browser/about_flags.h" 32 #include "chrome/browser/about_flags.h"
35 #include "chrome/browser/browser_main_win.h" 33 #include "chrome/browser/browser_main_win.h"
36 #include "chrome/browser/browser_process.h" 34 #include "chrome/browser/browser_process.h"
37 #include "chrome/browser/browser_process_impl.h" 35 #include "chrome/browser/browser_process_impl.h"
38 #include "chrome/browser/browser_shutdown.h" 36 #include "chrome/browser/browser_shutdown.h"
39 #include "chrome/browser/chrome_content_browser_client.h"
40 #include "chrome/browser/defaults.h" 37 #include "chrome/browser/defaults.h"
41 #include "chrome/browser/extensions/extension_protocols.h" 38 #include "chrome/browser/extensions/extension_protocols.h"
42 #include "chrome/browser/extensions/extension_service.h" 39 #include "chrome/browser/extensions/extension_service.h"
43 #include "chrome/browser/extensions/extensions_startup.h" 40 #include "chrome/browser/extensions/extensions_startup.h"
44 #include "chrome/browser/first_run/first_run.h" 41 #include "chrome/browser/first_run/first_run.h"
45 #include "chrome/browser/first_run/first_run_browser_process.h" 42 #include "chrome/browser/first_run/first_run_browser_process.h"
46 #include "chrome/browser/first_run/upgrade_util.h" 43 #include "chrome/browser/first_run/upgrade_util.h"
47 #include "chrome/browser/google/google_url_tracker.h" 44 #include "chrome/browser/google/google_url_tracker.h"
48 #include "chrome/browser/instant/instant_field_trial.h" 45 #include "chrome/browser/instant/instant_field_trial.h"
49 #include "chrome/browser/jankometer.h" 46 #include "chrome/browser/jankometer.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 #include "chrome/common/jstemplate_builder.h" 86 #include "chrome/common/jstemplate_builder.h"
90 #include "chrome/common/logging_chrome.h" 87 #include "chrome/common/logging_chrome.h"
91 #include "chrome/common/net/net_resource_provider.h" 88 #include "chrome/common/net/net_resource_provider.h"
92 #include "chrome/common/pref_names.h" 89 #include "chrome/common/pref_names.h"
93 #include "chrome/common/profiling.h" 90 #include "chrome/common/profiling.h"
94 #include "chrome/installer/util/google_update_settings.h" 91 #include "chrome/installer/util/google_update_settings.h"
95 #include "content/browser/browser_thread.h" 92 #include "content/browser/browser_thread.h"
96 #include "content/browser/renderer_host/resource_dispatcher_host.h" 93 #include "content/browser/renderer_host/resource_dispatcher_host.h"
97 #include "content/common/child_process.h" 94 #include "content/common/child_process.h"
98 #include "content/common/content_client.h" 95 #include "content/common/content_client.h"
99 #include "content/common/hi_res_timer_manager.h"
100 #include "content/common/main_function_params.h" 96 #include "content/common/main_function_params.h"
101 #include "grit/app_locale_settings.h" 97 #include "grit/app_locale_settings.h"
102 #include "grit/chromium_strings.h" 98 #include "grit/chromium_strings.h"
103 #include "grit/generated_resources.h" 99 #include "grit/generated_resources.h"
104 #include "grit/platform_locale_settings.h" 100 #include "grit/platform_locale_settings.h"
105 #include "net/base/cookie_monster.h" 101 #include "net/base/cookie_monster.h"
106 #include "net/base/net_module.h" 102 #include "net/base/net_module.h"
107 #include "net/base/network_change_notifier.h"
108 #include "net/http/http_basic_stream.h" 103 #include "net/http/http_basic_stream.h"
109 #include "net/http/http_network_layer.h" 104 #include "net/http/http_network_layer.h"
110 #include "net/http/http_stream_factory.h" 105 #include "net/http/http_stream_factory.h"
111 #include "net/socket/client_socket_pool_base.h" 106 #include "net/socket/client_socket_pool_base.h"
112 #include "net/socket/client_socket_pool_manager.h" 107 #include "net/socket/client_socket_pool_manager.h"
113 #include "net/socket/tcp_client_socket.h"
114 #include "net/spdy/spdy_session.h" 108 #include "net/spdy/spdy_session.h"
115 #include "net/spdy/spdy_session_pool.h" 109 #include "net/spdy/spdy_session_pool.h"
116 #include "net/url_request/url_request.h" 110 #include "net/url_request/url_request.h"
117 #include "net/url_request/url_request_throttler_manager.h" 111 #include "net/url_request/url_request_throttler_manager.h"
118 #include "net/websockets/websocket_job.h" 112 #include "net/websockets/websocket_job.h"
119 #include "ui/base/l10n/l10n_util.h" 113 #include "ui/base/l10n/l10n_util.h"
120 #include "ui/base/resource/resource_bundle.h" 114 #include "ui/base/resource/resource_bundle.h"
121 115
122 #if defined(USE_LINUX_BREAKPAD) 116 #if defined(USE_LINUX_BREAKPAD)
123 #include "base/linux_util.h" 117 #include "base/linux_util.h"
124 #include "chrome/app/breakpad_linux.h" 118 #include "chrome/app/breakpad_linux.h"
125 #endif 119 #endif
126 120
127 #if defined(OS_POSIX) && !defined(OS_MACOSX) 121 #if defined(OS_POSIX) && !defined(OS_MACOSX)
128 #include <dbus/dbus-glib.h>
129
130 #include "chrome/browser/browser_main_gtk.h" 122 #include "chrome/browser/browser_main_gtk.h"
131 #include "chrome/browser/ui/gtk/gtk_util.h" 123 #include "chrome/browser/ui/gtk/gtk_util.h"
132 #endif 124 #endif
133 125
134 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 126 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
135 #include "chrome/browser/first_run/upgrade_util_linux.h" 127 #include "chrome/browser/first_run/upgrade_util_linux.h"
136 #endif 128 #endif
137 129
138 #if defined(OS_CHROMEOS) 130 #if defined(OS_CHROMEOS)
139 #include "chrome/browser/chromeos/boot_times_loader.h" 131 #include "chrome/browser/chromeos/boot_times_loader.h"
140 #include "chrome/browser/chromeos/brightness_observer.h" 132 #include "chrome/browser/chromeos/brightness_observer.h"
141 #include "chrome/browser/chromeos/cros_settings_names.h" 133 #include "chrome/browser/chromeos/cros_settings_names.h"
142 #include "chrome/browser/chromeos/cros/cros_library.h" 134 #include "chrome/browser/chromeos/cros/cros_library.h"
143 #include "chrome/browser/chromeos/cros/screen_lock_library.h" 135 #include "chrome/browser/chromeos/cros/screen_lock_library.h"
144 #include "chrome/browser/chromeos/customization_document.h" 136 #include "chrome/browser/chromeos/customization_document.h"
145 #include "chrome/browser/chromeos/external_metrics.h" 137 #include "chrome/browser/chromeos/external_metrics.h"
146 #include "chrome/browser/chromeos/login/authenticator.h" 138 #include "chrome/browser/chromeos/login/authenticator.h"
147 #include "chrome/browser/chromeos/login/login_utils.h" 139 #include "chrome/browser/chromeos/login/login_utils.h"
148 #include "chrome/browser/chromeos/login/ownership_service.h" 140 #include "chrome/browser/chromeos/login/ownership_service.h"
149 #include "chrome/browser/chromeos/login/screen_locker.h" 141 #include "chrome/browser/chromeos/login/screen_locker.h"
150 #include "chrome/browser/chromeos/login/user_manager.h" 142 #include "chrome/browser/chromeos/login/user_manager.h"
151 #include "chrome/browser/chromeos/net/cros_network_change_notifier_factory.h"
152 #include "chrome/browser/chromeos/system_key_event_listener.h" 143 #include "chrome/browser/chromeos/system_key_event_listener.h"
153 #include "chrome/browser/chromeos/user_cros_settings_provider.h" 144 #include "chrome/browser/chromeos/user_cros_settings_provider.h"
154 #include "chrome/browser/chromeos/xinput_hierarchy_changed_event_listener.h" 145 #include "chrome/browser/chromeos/xinput_hierarchy_changed_event_listener.h"
155 #include "chrome/browser/oom_priority_manager.h" 146 #include "chrome/browser/oom_priority_manager.h"
156 #include "chrome/browser/ui/views/browser_dialogs.h" 147 #include "chrome/browser/ui/views/browser_dialogs.h"
157 #endif 148 #endif
158 149
159 // TODO(port): several win-only methods have been pulled out of this, but 150 // TODO(port): several win-only methods have been pulled out of this, but
160 // BrowserMain() as a whole needs to be broken apart so that it's usable by 151 // BrowserMain() as a whole needs to be broken apart so that it's usable by
161 // other platforms. For now, it's just a stub. This is a serious work in 152 // other platforms. For now, it's just a stub. This is a serious work in
162 // progress and should not be taken as an indication of a real refactoring. 153 // progress and should not be taken as an indication of a real refactoring.
163 154
164 #if defined(OS_WIN) 155 #if defined(OS_WIN)
165 #include <windows.h>
166 #include <commctrl.h>
167 #include <shellapi.h>
168 156
169 #include "base/environment.h" // For PreRead experiment. 157 #include "base/environment.h" // For PreRead experiment.
170 #include "base/win/scoped_com_initializer.h" 158 #include "base/win/scoped_com_initializer.h"
171 #include "base/win/windows_version.h" 159 #include "base/win/windows_version.h"
172 #include "chrome/browser/browser_trial.h" 160 #include "chrome/browser/browser_trial.h"
173 #include "chrome/browser/browser_util_win.h" 161 #include "chrome/browser/browser_util_win.h"
174 #include "chrome/browser/first_run/try_chrome_dialog_view.h" 162 #include "chrome/browser/first_run/try_chrome_dialog_view.h"
175 #include "chrome/browser/first_run/upgrade_util_win.h" 163 #include "chrome/browser/first_run/upgrade_util_win.h"
176 #include "chrome/browser/net/url_fixer_upper.h" 164 #include "chrome/browser/net/url_fixer_upper.h"
177 #include "chrome/browser/rlz/rlz.h" 165 #include "chrome/browser/rlz/rlz.h"
178 #include "chrome/browser/ui/views/user_data_dir_dialog.h" 166 #include "chrome/browser/ui/views/user_data_dir_dialog.h"
179 #include "chrome/installer/util/helper.h" 167 #include "chrome/installer/util/helper.h"
180 #include "chrome/installer/util/install_util.h" 168 #include "chrome/installer/util/install_util.h"
181 #include "chrome/installer/util/shell_util.h" 169 #include "chrome/installer/util/shell_util.h"
182 #include "content/browser/user_metrics.h" 170 #include "content/browser/user_metrics.h"
183 #include "content/common/sandbox_policy.h"
184 #include "net/base/net_util.h" 171 #include "net/base/net_util.h"
185 #include "net/base/sdch_manager.h" 172 #include "net/base/sdch_manager.h"
186 #include "printing/printed_document.h" 173 #include "printing/printed_document.h"
187 #include "sandbox/src/sandbox.h"
188 #include "ui/base/l10n/l10n_util_win.h" 174 #include "ui/base/l10n/l10n_util_win.h"
189 #include "ui/gfx/platform_font_win.h" 175 #include "ui/gfx/platform_font_win.h"
190 #endif // defined(OS_WIN) 176 #endif // defined(OS_WIN)
191 177
192 #if defined(OS_MACOSX) 178 #if defined(OS_MACOSX)
193 #include <Security/Security.h> 179 #include <Security/Security.h>
194 180
195 #include "chrome/browser/mac/install_from_dmg.h" 181 #include "chrome/browser/mac/install_from_dmg.h"
196 #endif 182 #endif
197 183
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 !local_state->IsManagedPreference(prefs::kApplicationLocale)) { 418 !local_state->IsManagedPreference(prefs::kApplicationLocale)) {
433 local_state->SetString(prefs::kApplicationLocale, owner_locale); 419 local_state->SetString(prefs::kApplicationLocale, owner_locale);
434 local_state->ScheduleSavePersistentPrefs(); 420 local_state->ScheduleSavePersistentPrefs();
435 } 421 }
436 } 422 }
437 #endif 423 #endif
438 424
439 return local_state; 425 return local_state;
440 } 426 }
441 427
442 // Windows-specific initialization code for the sandbox broker services. This
443 // is just a NOP on non-Windows platforms to reduce ifdefs later on.
444 void InitializeBrokerServices(const MainFunctionParams& parameters,
445 const CommandLine& parsed_command_line) {
446 #if defined(OS_WIN)
447 sandbox::BrokerServices* broker_services =
448 parameters.sandbox_info_.BrokerServices();
449 if (broker_services) {
450 sandbox::InitBrokerServices(broker_services);
451 if (!parsed_command_line.HasSwitch(switches::kNoSandbox)) {
452 bool use_winsta = !parsed_command_line.HasSwitch(
453 switches::kDisableAltWinstation);
454 // Precreate the desktop and window station used by the renderers.
455 sandbox::TargetPolicy* policy = broker_services->CreatePolicy();
456 sandbox::ResultCode result = policy->CreateAlternateDesktop(use_winsta);
457 CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result);
458 policy->Release();
459 }
460 }
461 #endif
462 }
463
464 // Initializes the profile, possibly doing some user prompting to pick a 428 // Initializes the profile, possibly doing some user prompting to pick a
465 // fallback profile. Returns the newly created profile, or NULL if startup 429 // fallback profile. Returns the newly created profile, or NULL if startup
466 // should not continue. 430 // should not continue.
467 Profile* CreateProfile(const MainFunctionParams& parameters, 431 Profile* CreateProfile(const MainFunctionParams& parameters,
468 const FilePath& user_data_dir, 432 const FilePath& user_data_dir,
469 const CommandLine& parsed_command_line) { 433 const CommandLine& parsed_command_line) {
470 Profile* profile; 434 Profile* profile;
471 if (ProfileManager::IsMultipleProfilesEnabled()) { 435 if (ProfileManager::IsMultipleProfilesEnabled()) {
472 if (parsed_command_line.HasSwitch(switches::kProfileDirectory)) { 436 if (parsed_command_line.HasSwitch(switches::kProfileDirectory)) {
473 g_browser_process->local_state()->SetString(prefs::kProfileLastUsed, 437 g_browser_process->local_state()->SetString(prefs::kProfileLastUsed,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 491
528 int GetMinimumFontSize() { 492 int GetMinimumFontSize() {
529 int min_font_size; 493 int min_font_size;
530 base::StringToInt(l10n_util::GetStringUTF16(IDS_MINIMUM_UI_FONT_SIZE), 494 base::StringToInt(l10n_util::GetStringUTF16(IDS_MINIMUM_UI_FONT_SIZE),
531 &min_font_size); 495 &min_font_size);
532 return min_font_size; 496 return min_font_size;
533 } 497 }
534 498
535 #endif 499 #endif
536 500
537 #if defined(TOOLKIT_USES_GTK)
538 static void GLibLogHandler(const gchar* log_domain,
539 GLogLevelFlags log_level,
540 const gchar* message,
541 gpointer userdata) {
542 if (!log_domain)
543 log_domain = "<unknown>";
544 if (!message)
545 message = "<no message>";
546
547 if (strstr(message, "Loading IM context type") ||
548 strstr(message, "wrong ELF class: ELFCLASS64")) {
549 // http://crbug.com/9643
550 // Until we have a real 64-bit build or all of these 32-bit package issues
551 // are sorted out, don't fatal on ELF 32/64-bit mismatch warnings and don't
552 // spam the user with more than one of them.
553 static bool alerted = false;
554 if (!alerted) {
555 LOG(ERROR) << "Bug 9643: " << log_domain << ": " << message;
556 alerted = true;
557 }
558 } else if (strstr(message, "Theme file for default has no") ||
559 strstr(message, "Theme directory") ||
560 strstr(message, "theme pixmap")) {
561 LOG(ERROR) << "GTK theme error: " << message;
562 } else if (strstr(message, "gtk_drag_dest_leave: assertion")) {
563 LOG(ERROR) << "Drag destination deleted: http://crbug.com/18557";
564 } else if (strstr(message, "Out of memory") &&
565 strstr(log_domain, "<unknown>")) {
566 LOG(ERROR) << "DBus call timeout or out of memory: "
567 << "http://crosbug.com/15496";
568 } else {
569 LOG(DFATAL) << log_domain << ": " << message;
570 }
571 }
572
573 static void SetUpGLibLogHandler() {
574 // Register GLib-handled assertions to go through our logging system.
575 const char* kLogDomains[] = { NULL, "Gtk", "Gdk", "GLib", "GLib-GObject" };
576 for (size_t i = 0; i < arraysize(kLogDomains); i++) {
577 g_log_set_handler(kLogDomains[i],
578 static_cast<GLogLevelFlags>(G_LOG_FLAG_RECURSION |
579 G_LOG_FLAG_FATAL |
580 G_LOG_LEVEL_ERROR |
581 G_LOG_LEVEL_CRITICAL |
582 G_LOG_LEVEL_WARNING),
583 GLibLogHandler,
584 NULL);
585 }
586 }
587 #endif
588
589 void InitializeToolkit(const MainFunctionParams& parameters) {
590 // TODO(evan): this function is rather subtle, due to the variety
591 // of intersecting ifdefs we have. To keep it easy to follow, there
592 // are no #else branches on any #ifs.
593
594 #if defined(TOOLKIT_USES_GTK)
595 // We want to call g_thread_init(), but in some codepaths (tests) it
596 // is possible it has already been called. In older versions of
597 // GTK, it is an error to call g_thread_init twice; unfortunately,
598 // the API to tell whether it has been called already was also only
599 // added in a newer version of GTK! Thankfully, this non-intuitive
600 // check is actually equivalent and sufficient to work around the
601 // error.
602 if (!g_thread_supported())
603 g_thread_init(NULL);
604 // Glib type system initialization. Needed at least for gconf,
605 // used in net/proxy/proxy_config_service_linux.cc. Most likely
606 // this is superfluous as gtk_init() ought to do this. It's
607 // definitely harmless, so retained as a reminder of this
608 // requirement for gconf.
609 g_type_init();
610 // We use glib-dbus for geolocation and it's possible other libraries
611 // (e.g. gnome-keyring) will use it, so initialize its threading here
612 // as well.
613 dbus_g_thread_init();
614 gfx::GtkInitFromCommandLine(parameters.command_line_);
615 SetUpGLibLogHandler();
616 #endif
617
618 #if defined(TOOLKIT_GTK)
619 // It is important for this to happen before the first run dialog, as it
620 // styles the dialog as well.
621 gtk_util::InitRCStyles();
622 #endif
623
624 #if defined(TOOLKIT_VIEWS)
625 // The delegate needs to be set before any UI is created so that windows
626 // display the correct icon.
627 if (!views::ViewsDelegate::views_delegate)
628 views::ViewsDelegate::views_delegate = new ChromeViewsDelegate;
629
630 // TODO(beng): Move to WidgetImpl and implement on Windows too!
631 if (parameters.command_line_.HasSwitch(switches::kDebugViewsPaint))
632 views::Widget::SetDebugPaintEnabled(true);
633 #endif
634
635 #if defined(OS_WIN)
636 gfx::PlatformFontWin::adjust_font_callback = &AdjustUIFont;
637 gfx::PlatformFontWin::get_minimum_font_size_callback = &GetMinimumFontSize;
638
639 // Init common control sex.
640 INITCOMMONCONTROLSEX config;
641 config.dwSize = sizeof(config);
642 config.dwICC = ICC_WIN95_CLASSES;
643 if (!InitCommonControlsEx(&config))
644 LOG_GETLASTERROR(FATAL);
645 #endif
646 }
647
648 #if defined(OS_CHROMEOS) 501 #if defined(OS_CHROMEOS)
649 502
650 // Class is used to login using passed username and password. 503 // Class is used to login using passed username and password.
651 // The instance will be deleted upon success or failure. 504 // The instance will be deleted upon success or failure.
652 class StubLogin : public chromeos::LoginStatusConsumer, 505 class StubLogin : public chromeos::LoginStatusConsumer,
653 public chromeos::LoginUtils::Delegate { 506 public chromeos::LoginUtils::Delegate {
654 public: 507 public:
655 StubLogin(std::string username, std::string password) { 508 StubLogin(std::string username, std::string password) {
656 authenticator_ = chromeos::LoginUtils::Get()->CreateAuthenticator(this); 509 authenticator_ = chromeos::LoginUtils::Get()->CreateAuthenticator(this);
657 authenticator_.get()->AuthenticateToLogin( 510 authenticator_.get()->AuthenticateToLogin(
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 namespace chrome_browser { 683 namespace chrome_browser {
831 // This error message is not localized because we failed to load the 684 // This error message is not localized because we failed to load the
832 // localization data files. 685 // localization data files.
833 const char kMissingLocaleDataTitle[] = "Missing File Error"; 686 const char kMissingLocaleDataTitle[] = "Missing File Error";
834 const char kMissingLocaleDataMessage[] = 687 const char kMissingLocaleDataMessage[] =
835 "Unable to find locale data files. Please reinstall."; 688 "Unable to find locale data files. Please reinstall.";
836 } // namespace chrome_browser 689 } // namespace chrome_browser
837 690
838 // BrowserMainParts ------------------------------------------------------------ 691 // BrowserMainParts ------------------------------------------------------------
839 692
840 BrowserMainParts::BrowserMainParts(const MainFunctionParams& parameters) 693 ChromeBrowserMainParts::ChromeBrowserMainParts(
841 : parameters_(parameters), 694 const MainFunctionParams& parameters)
842 parsed_command_line_(parameters.command_line_) { 695 : BrowserMainParts(parameters),
696 shutdown_watcher_(new ShutdownWatcherHelper()) {
697 // If we're running tests (ui_task is non-null).
698 if (parameters.ui_task)
699 browser_defaults::enable_help_app = false;
843 } 700 }
844 701
845 BrowserMainParts::~BrowserMainParts() { 702 ChromeBrowserMainParts::~ChromeBrowserMainParts() {
846 } 703 }
847 704
848 // BrowserMainParts: |EarlyInitialization()| and related ----------------------- 705 void ChromeBrowserMainParts::SetupHistogramSynchronizer() {
849
850 void BrowserMainParts::EarlyInitialization() {
851 PreEarlyInitialization();
852
853 if (parsed_command_line().HasSwitch(switches::kEnableBenchmarking))
854 base::FieldTrial::EnableBenchmarking();
855
856 InitializeSSL();
857
858 if (parsed_command_line().HasSwitch(switches::kDisableSSLFalseStart))
859 net::SSLConfigService::DisableFalseStart();
860 if (parsed_command_line().HasSwitch(switches::kEnableSSLCachedInfo))
861 net::SSLConfigService::EnableCachedInfo();
862 if (parsed_command_line().HasSwitch(switches::kEnableOriginBoundCerts))
863 net::SSLConfigService::EnableOriginBoundCerts();
864 if (parsed_command_line().HasSwitch(
865 switches::kEnableDNSCertProvenanceChecking)) {
866 net::SSLConfigService::EnableDNSCertProvenanceChecking();
867 }
868
869 // TODO(abarth): Should this move to InitializeNetworkOptions? This doesn't
870 // seem dependent on InitializeSSL().
871 if (parsed_command_line().HasSwitch(switches::kEnableTcpFastOpen))
872 net::set_tcp_fastopen_enabled(true);
873
874 PostEarlyInitialization();
875 }
876
877 void BrowserMainParts::SetupHistogramSynchronizer() {
878 histogram_synchronizer_ = new HistogramSynchronizer(); 706 histogram_synchronizer_ = new HistogramSynchronizer();
879 } 707 }
880 708
881 // This will be called after the command-line has been mutated by about:flags 709 // This will be called after the command-line has been mutated by about:flags
882 MetricsService* BrowserMainParts::SetupMetricsAndFieldTrials( 710 MetricsService* ChromeBrowserMainParts::SetupMetricsAndFieldTrials(
883 const CommandLine& parsed_command_line, 711 const CommandLine& parsed_command_line,
884 PrefService* local_state) { 712 PrefService* local_state) {
885 // Must initialize metrics after labs have been converted into switches, 713 // Must initialize metrics after labs have been converted into switches,
886 // but before field trials are set up (so that client ID is available for 714 // but before field trials are set up (so that client ID is available for
887 // one-time randomized field trials). 715 // one-time randomized field trials).
888 MetricsService* metrics = InitializeMetrics(parsed_command_line, local_state); 716 MetricsService* metrics = InitializeMetrics(parsed_command_line, local_state);
889 717
890 // Initialize FieldTrialList to support FieldTrials that use one-time 718 // Initialize FieldTrialList to support FieldTrials that use one-time
891 // randomization. The client ID will be empty if the user has not opted 719 // randomization. The client ID will be empty if the user has not opted
892 // to send metrics. 720 // to send metrics.
(...skipping 11 matching lines...) Expand all
904 732
905 return metrics; 733 return metrics;
906 } 734 }
907 735
908 // This is an A/B test for the maximum number of persistent connections per 736 // This is an A/B test for the maximum number of persistent connections per
909 // host. Currently Chrome, Firefox, and IE8 have this value set at 6. Safari 737 // host. Currently Chrome, Firefox, and IE8 have this value set at 6. Safari
910 // uses 4, and Fasterfox (a plugin for Firefox that supposedly configures it to 738 // uses 4, and Fasterfox (a plugin for Firefox that supposedly configures it to
911 // run faster) uses 8. We would like to see how much of an effect this value has 739 // run faster) uses 8. We would like to see how much of an effect this value has
912 // on browsing. Too large a value might cause us to run into SYN flood detection 740 // on browsing. Too large a value might cause us to run into SYN flood detection
913 // mechanisms. 741 // mechanisms.
914 void BrowserMainParts::ConnectionFieldTrial() { 742 void ChromeBrowserMainParts::ConnectionFieldTrial() {
915 const base::FieldTrial::Probability kConnectDivisor = 100; 743 const base::FieldTrial::Probability kConnectDivisor = 100;
916 const base::FieldTrial::Probability kConnectProbability = 1; // 1% prob. 744 const base::FieldTrial::Probability kConnectProbability = 1; // 1% prob.
917 745
918 // After June 30, 2011 builds, it will always be in default group. 746 // After June 30, 2011 builds, it will always be in default group.
919 scoped_refptr<base::FieldTrial> connect_trial( 747 scoped_refptr<base::FieldTrial> connect_trial(
920 new base::FieldTrial( 748 new base::FieldTrial(
921 "ConnCountImpact", kConnectDivisor, "conn_count_6", 2011, 6, 30)); 749 "ConnCountImpact", kConnectDivisor, "conn_count_6", 2011, 6, 30));
922 750
923 // This (6) is the current default value. Having this group declared here 751 // This (6) is the current default value. Having this group declared here
924 // makes it straightforward to modify |kConnectProbability| such that the same 752 // makes it straightforward to modify |kConnectProbability| such that the same
(...skipping 28 matching lines...) Expand all
953 } 781 }
954 782
955 // A/B test for determining a value for unused socket timeout. Currently the 783 // A/B test for determining a value for unused socket timeout. Currently the
956 // timeout defaults to 10 seconds. Having this value set too low won't allow us 784 // timeout defaults to 10 seconds. Having this value set too low won't allow us
957 // to take advantage of idle sockets. Setting it to too high could possibly 785 // to take advantage of idle sockets. Setting it to too high could possibly
958 // result in more ERR_CONNECTION_RESETs, since some servers will kill a socket 786 // result in more ERR_CONNECTION_RESETs, since some servers will kill a socket
959 // before we time it out. Since these are "unused" sockets, we won't retry the 787 // before we time it out. Since these are "unused" sockets, we won't retry the
960 // connection and instead show an error to the user. So we need to be 788 // connection and instead show an error to the user. So we need to be
961 // conservative here. We've seen that some servers will close the socket after 789 // conservative here. We've seen that some servers will close the socket after
962 // as short as 10 seconds. See http://crbug.com/84313 for more details. 790 // as short as 10 seconds. See http://crbug.com/84313 for more details.
963 void BrowserMainParts::SocketTimeoutFieldTrial() { 791 void ChromeBrowserMainParts::SocketTimeoutFieldTrial() {
964 const base::FieldTrial::Probability kIdleSocketTimeoutDivisor = 100; 792 const base::FieldTrial::Probability kIdleSocketTimeoutDivisor = 100;
965 // 1% probability for all experimental settings. 793 // 1% probability for all experimental settings.
966 const base::FieldTrial::Probability kSocketTimeoutProbability = 1; 794 const base::FieldTrial::Probability kSocketTimeoutProbability = 1;
967 795
968 // After June 30, 2011 builds, it will always be in default group. 796 // After June 30, 2011 builds, it will always be in default group.
969 scoped_refptr<base::FieldTrial> socket_timeout_trial( 797 scoped_refptr<base::FieldTrial> socket_timeout_trial(
970 new base::FieldTrial("IdleSktToImpact", kIdleSocketTimeoutDivisor, 798 new base::FieldTrial("IdleSktToImpact", kIdleSocketTimeoutDivisor,
971 "idle_timeout_10", 2011, 6, 30)); 799 "idle_timeout_10", 2011, 6, 30));
972 const int socket_timeout_10 = socket_timeout_trial->kDefaultGroupNumber; 800 const int socket_timeout_10 = socket_timeout_trial->kDefaultGroupNumber;
973 801
(...skipping 10 matching lines...) Expand all
984 net::ClientSocketPool::set_unused_idle_socket_timeout(5); 812 net::ClientSocketPool::set_unused_idle_socket_timeout(5);
985 } else if (idle_to_trial_group == socket_timeout_10) { 813 } else if (idle_to_trial_group == socket_timeout_10) {
986 net::ClientSocketPool::set_unused_idle_socket_timeout(10); 814 net::ClientSocketPool::set_unused_idle_socket_timeout(10);
987 } else if (idle_to_trial_group == socket_timeout_20) { 815 } else if (idle_to_trial_group == socket_timeout_20) {
988 net::ClientSocketPool::set_unused_idle_socket_timeout(20); 816 net::ClientSocketPool::set_unused_idle_socket_timeout(20);
989 } else { 817 } else {
990 NOTREACHED(); 818 NOTREACHED();
991 } 819 }
992 } 820 }
993 821
994 void BrowserMainParts::ProxyConnectionsFieldTrial() { 822 void ChromeBrowserMainParts::ProxyConnectionsFieldTrial() {
995 const base::FieldTrial::Probability kProxyConnectionsDivisor = 100; 823 const base::FieldTrial::Probability kProxyConnectionsDivisor = 100;
996 // 25% probability 824 // 25% probability
997 const base::FieldTrial::Probability kProxyConnectionProbability = 1; 825 const base::FieldTrial::Probability kProxyConnectionProbability = 1;
998 826
999 // After June 30, 2011 builds, it will always be in default group. 827 // After June 30, 2011 builds, it will always be in default group.
1000 scoped_refptr<base::FieldTrial> proxy_connection_trial( 828 scoped_refptr<base::FieldTrial> proxy_connection_trial(
1001 new base::FieldTrial("ProxyConnectionImpact", kProxyConnectionsDivisor, 829 new base::FieldTrial("ProxyConnectionImpact", kProxyConnectionsDivisor,
1002 "proxy_connections_32", 2011, 6, 30)); 830 "proxy_connections_32", 2011, 6, 30));
1003 831
1004 // This (32 connections per proxy server) is the current default value. 832 // This (32 connections per proxy server) is the current default value.
(...skipping 25 matching lines...) Expand all
1030 } 858 }
1031 } 859 }
1032 860
1033 // When --use-spdy not set, users will be in A/B test for spdy. 861 // When --use-spdy not set, users will be in A/B test for spdy.
1034 // group A (npn_with_spdy): this means npn and spdy are enabled. In case server 862 // group A (npn_with_spdy): this means npn and spdy are enabled. In case server
1035 // supports spdy, browser will use spdy. 863 // supports spdy, browser will use spdy.
1036 // group B (npn_with_http): this means npn is enabled but spdy won't be used. 864 // group B (npn_with_http): this means npn is enabled but spdy won't be used.
1037 // Http is still used for all requests. 865 // Http is still used for all requests.
1038 // default group: no npn or spdy is involved. The "old" non-spdy 866 // default group: no npn or spdy is involved. The "old" non-spdy
1039 // chrome behavior. 867 // chrome behavior.
1040 void BrowserMainParts::SpdyFieldTrial() { 868 void ChromeBrowserMainParts::SpdyFieldTrial() {
1041 if (parsed_command_line().HasSwitch(switches::kUseSpdy)) { 869 if (parsed_command_line().HasSwitch(switches::kUseSpdy)) {
1042 std::string spdy_mode = 870 std::string spdy_mode =
1043 parsed_command_line().GetSwitchValueASCII(switches::kUseSpdy); 871 parsed_command_line().GetSwitchValueASCII(switches::kUseSpdy);
1044 net::HttpNetworkLayer::EnableSpdy(spdy_mode); 872 net::HttpNetworkLayer::EnableSpdy(spdy_mode);
1045 } else { 873 } else {
1046 #if !defined(OS_CHROMEOS) 874 #if !defined(OS_CHROMEOS)
1047 bool is_spdy_trial = false; 875 bool is_spdy_trial = false;
1048 const base::FieldTrial::Probability kSpdyDivisor = 100; 876 const base::FieldTrial::Probability kSpdyDivisor = 100;
1049 base::FieldTrial::Probability npnhttp_probability = 5; 877 base::FieldTrial::Probability npnhttp_probability = 5;
1050 878
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 base::StringToInt(parsed_command_line().GetSwitchValueASCII( 926 base::StringToInt(parsed_command_line().GetSwitchValueASCII(
1099 switches::kMaxSpdyConcurrentStreams), 927 switches::kMaxSpdyConcurrentStreams),
1100 &value); 928 &value);
1101 if (value > 0) 929 if (value > 0)
1102 net::SpdySession::set_max_concurrent_streams(value); 930 net::SpdySession::set_max_concurrent_streams(value);
1103 } 931 }
1104 } 932 }
1105 933
1106 // If --socket-reuse-policy is not specified, run an A/B test for choosing the 934 // If --socket-reuse-policy is not specified, run an A/B test for choosing the
1107 // warmest socket. 935 // warmest socket.
1108 void BrowserMainParts::WarmConnectionFieldTrial() { 936 void ChromeBrowserMainParts::WarmConnectionFieldTrial() {
1109 const CommandLine& command_line = parsed_command_line(); 937 const CommandLine& command_line = parsed_command_line();
1110 if (command_line.HasSwitch(switches::kSocketReusePolicy)) { 938 if (command_line.HasSwitch(switches::kSocketReusePolicy)) {
1111 std::string socket_reuse_policy_str = command_line.GetSwitchValueASCII( 939 std::string socket_reuse_policy_str = command_line.GetSwitchValueASCII(
1112 switches::kSocketReusePolicy); 940 switches::kSocketReusePolicy);
1113 int policy = -1; 941 int policy = -1;
1114 base::StringToInt(socket_reuse_policy_str, &policy); 942 base::StringToInt(socket_reuse_policy_str, &policy);
1115 943
1116 const int policy_list[] = { 0, 1, 2 }; 944 const int policy_list[] = { 0, 1, 2 };
1117 VLOG(1) << "Setting socket_reuse_policy = " << policy; 945 VLOG(1) << "Setting socket_reuse_policy = " << policy;
1118 SetSocketReusePolicy(policy, policy_list, arraysize(policy_list)); 946 SetSocketReusePolicy(policy, policy_list, arraysize(policy_list));
(...skipping 20 matching lines...) Expand all
1139 967
1140 const int policy_list[] = { warmest_socket, warm_socket, 968 const int policy_list[] = { warmest_socket, warm_socket,
1141 last_accessed_socket }; 969 last_accessed_socket };
1142 SetSocketReusePolicy(warmest_socket_trial_group, policy_list, 970 SetSocketReusePolicy(warmest_socket_trial_group, policy_list,
1143 arraysize(policy_list)); 971 arraysize(policy_list));
1144 } 972 }
1145 973
1146 // If neither --enable-connect-backup-jobs or --disable-connect-backup-jobs is 974 // If neither --enable-connect-backup-jobs or --disable-connect-backup-jobs is
1147 // specified, run an A/B test for automatically establishing backup TCP 975 // specified, run an A/B test for automatically establishing backup TCP
1148 // connections when a certain timeout value is exceeded. 976 // connections when a certain timeout value is exceeded.
1149 void BrowserMainParts::ConnectBackupJobsFieldTrial() { 977 void ChromeBrowserMainParts::ConnectBackupJobsFieldTrial() {
1150 if (parsed_command_line().HasSwitch(switches::kEnableConnectBackupJobs)) { 978 if (parsed_command_line().HasSwitch(switches::kEnableConnectBackupJobs)) {
1151 net::internal::ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled( 979 net::internal::ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(
1152 true); 980 true);
1153 } else if (parsed_command_line().HasSwitch( 981 } else if (parsed_command_line().HasSwitch(
1154 switches::kDisableConnectBackupJobs)) { 982 switches::kDisableConnectBackupJobs)) {
1155 net::internal::ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled( 983 net::internal::ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(
1156 false); 984 false);
1157 } else { 985 } else {
1158 const base::FieldTrial::Probability kConnectBackupJobsDivisor = 100; 986 const base::FieldTrial::Probability kConnectBackupJobsDivisor = 100;
1159 // 1% probability. 987 // 1% probability.
1160 const base::FieldTrial::Probability kConnectBackupJobsProbability = 1; 988 const base::FieldTrial::Probability kConnectBackupJobsProbability = 1;
1161 // After June 30, 2011 builds, it will always be in default group. 989 // After June 30, 2011 builds, it will always be in default group.
1162 scoped_refptr<base::FieldTrial> trial( 990 scoped_refptr<base::FieldTrial> trial(
1163 new base::FieldTrial("ConnnectBackupJobs", 991 new base::FieldTrial("ConnnectBackupJobs",
1164 kConnectBackupJobsDivisor, "ConnectBackupJobsEnabled", 2011, 6, 992 kConnectBackupJobsDivisor, "ConnectBackupJobsEnabled", 2011, 6,
1165 30)); 993 30));
1166 const int connect_backup_jobs_enabled = trial->kDefaultGroupNumber; 994 const int connect_backup_jobs_enabled = trial->kDefaultGroupNumber;
1167 trial->AppendGroup("ConnectBackupJobsDisabled", 995 trial->AppendGroup("ConnectBackupJobsDisabled",
1168 kConnectBackupJobsProbability); 996 kConnectBackupJobsProbability);
1169 const int trial_group = trial->group(); 997 const int trial_group = trial->group();
1170 net::internal::ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled( 998 net::internal::ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(
1171 trial_group == connect_backup_jobs_enabled); 999 trial_group == connect_backup_jobs_enabled);
1172 } 1000 }
1173 } 1001 }
1174 1002
1175 // Test the impact on subsequent Google searches of getting suggestions from 1003 // Test the impact on subsequent Google searches of getting suggestions from
1176 // www.google.TLD instead of clients1.google.TLD. 1004 // www.google.TLD instead of clients1.google.TLD.
1177 void BrowserMainParts::SuggestPrefixFieldTrial() { 1005 void ChromeBrowserMainParts::SuggestPrefixFieldTrial() {
1178 const base::FieldTrial::Probability kSuggestPrefixDivisor = 100; 1006 const base::FieldTrial::Probability kSuggestPrefixDivisor = 100;
1179 // 50% probability. 1007 // 50% probability.
1180 const base::FieldTrial::Probability kSuggestPrefixProbability = 50; 1008 const base::FieldTrial::Probability kSuggestPrefixProbability = 50;
1181 // After Jan 1, 2012, it will always be in default group. 1009 // After Jan 1, 2012, it will always be in default group.
1182 scoped_refptr<base::FieldTrial> trial( 1010 scoped_refptr<base::FieldTrial> trial(
1183 new base::FieldTrial("SuggestHostPrefix", 1011 new base::FieldTrial("SuggestHostPrefix",
1184 kSuggestPrefixDivisor, "Default_Prefix", 2012, 1, 1)); 1012 kSuggestPrefixDivisor, "Default_Prefix", 2012, 1, 1));
1185 trial->AppendGroup("Www_Prefix", kSuggestPrefixProbability); 1013 trial->AppendGroup("Www_Prefix", kSuggestPrefixProbability);
1186 // The field trial is detected directly, so we don't need to call anything. 1014 // The field trial is detected directly, so we don't need to call anything.
1187 } 1015 }
1188 1016
1189 // BrowserMainParts: |MainMessageLoopStart()| and related ---------------------- 1017 // ChromeBrowserMainParts: |SetupMetricsAndFieldTrials()| related --------------
1190
1191 void BrowserMainParts::MainMessageLoopStart() {
1192 PreMainMessageLoopStart();
1193
1194 main_message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI));
1195
1196 // TODO(viettrungluu): should these really go before setting the thread name?
1197 system_monitor_.reset(new base::SystemMonitor);
1198 hi_res_timer_manager_.reset(new HighResolutionTimerManager);
1199
1200 InitializeMainThread();
1201
1202 network_change_notifier_.reset(net::NetworkChangeNotifier::Create());
1203
1204 PostMainMessageLoopStart();
1205 Profiling::MainMessageLoopStarted();
1206 }
1207
1208 void BrowserMainParts::InitializeMainThread() {
1209 const char* kThreadName = "CrBrowserMain";
1210 base::PlatformThread::SetName(kThreadName);
1211 main_message_loop().set_thread_name(kThreadName);
1212
1213 // Register the main thread by instantiating it, but don't call any methods.
1214 main_thread_.reset(new BrowserThread(BrowserThread::UI,
1215 MessageLoop::current()));
1216 }
1217
1218 // BrowserMainParts: |SetupMetricsAndFieldTrials()| related --------------------
1219 1018
1220 // Initializes the metrics service with the configuration for this process, 1019 // Initializes the metrics service with the configuration for this process,
1221 // returning the created service (guaranteed non-NULL). 1020 // returning the created service (guaranteed non-NULL).
1222 MetricsService* BrowserMainParts::InitializeMetrics( 1021 MetricsService* ChromeBrowserMainParts::InitializeMetrics(
1223 const CommandLine& parsed_command_line, 1022 const CommandLine& parsed_command_line,
1224 const PrefService* local_state) { 1023 const PrefService* local_state) {
1225 #if defined(OS_WIN) 1024 #if defined(OS_WIN)
1226 if (parsed_command_line.HasSwitch(switches::kChromeFrame)) 1025 if (parsed_command_line.HasSwitch(switches::kChromeFrame))
1227 MetricsLog::set_version_extension("-F"); 1026 MetricsLog::set_version_extension("-F");
1228 #elif defined(ARCH_CPU_64_BITS) 1027 #elif defined(ARCH_CPU_64_BITS)
1229 MetricsLog::set_version_extension("-64"); 1028 MetricsLog::set_version_extension("-64");
1230 #endif // defined(OS_WIN) 1029 #endif // defined(OS_WIN)
1231 1030
1232 MetricsService* metrics = g_browser_process->metrics_service(); 1031 MetricsService* metrics = g_browser_process->metrics_service();
(...skipping 16 matching lines...) Expand all
1249 bool enabled = local_state->GetBoolean(prefs::kMetricsReportingEnabled); 1048 bool enabled = local_state->GetBoolean(prefs::kMetricsReportingEnabled);
1250 #endif // #if defined(OS_CHROMEOS) 1049 #endif // #if defined(OS_CHROMEOS)
1251 if (enabled) { 1050 if (enabled) {
1252 metrics->Start(); 1051 metrics->Start();
1253 } 1052 }
1254 #endif // defined(GOOGLE_CHROME_BUILD) 1053 #endif // defined(GOOGLE_CHROME_BUILD)
1255 1054
1256 return metrics; 1055 return metrics;
1257 } 1056 }
1258 1057
1259 void BrowserMainParts::SetupFieldTrials(bool metrics_recording_enabled, 1058 void ChromeBrowserMainParts::SetupFieldTrials(bool metrics_recording_enabled,
1260 bool proxy_policy_is_set) { 1059 bool proxy_policy_is_set) {
1261 // Note: make sure to call ConnectionFieldTrial() before 1060 // Note: make sure to call ConnectionFieldTrial() before
1262 // ProxyConnectionsFieldTrial(). 1061 // ProxyConnectionsFieldTrial().
1263 ConnectionFieldTrial(); 1062 ConnectionFieldTrial();
1264 SocketTimeoutFieldTrial(); 1063 SocketTimeoutFieldTrial();
1265 // If a policy is defining the number of active connections this field test 1064 // If a policy is defining the number of active connections this field test
1266 // shoud not be performed. 1065 // shoud not be performed.
1267 if (!proxy_policy_is_set) 1066 if (!proxy_policy_is_set)
1268 ProxyConnectionsFieldTrial(); 1067 ProxyConnectionsFieldTrial();
1269 prerender::ConfigurePrefetchAndPrerender(parsed_command_line()); 1068 prerender::ConfigurePrefetchAndPrerender(parsed_command_line());
1270 InstantFieldTrial::Activate(); 1069 InstantFieldTrial::Activate();
(...skipping 22 matching lines...) Expand all
1293 1092
1294 DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded() { 1093 DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded() {
1295 // Need an instance of AtExitManager to handle singleton creations and 1094 // Need an instance of AtExitManager to handle singleton creations and
1296 // deletions. We need this new instance because, the old instance created 1095 // deletions. We need this new instance because, the old instance created
1297 // in ChromeMain() got destructed when the function returned. 1096 // in ChromeMain() got destructed when the function returned.
1298 base::AtExitManager exit_manager; 1097 base::AtExitManager exit_manager;
1299 upgrade_util::RelaunchChromeBrowserWithNewCommandLineIfNeeded(); 1098 upgrade_util::RelaunchChromeBrowserWithNewCommandLineIfNeeded();
1300 } 1099 }
1301 #endif 1100 #endif
1302 1101
1303 // Main routine for running as the Browser process. 1102 void ChromeBrowserMainParts::PostMainMessageLoopStart() {
1304 int BrowserMain(const MainFunctionParams& parameters) { 1103 Profiling::MainMessageLoopStarted();
1305 // Create ShutdownWatcherHelper object for watching jank during shutdown. 1104 }
1306 // Please keep |shutdown_watcher| as the first object constructed, and hence
1307 // it is destroyed last.
1308 ShutdownWatcherHelper shutdown_watcher;
1309 1105
1310 TRACE_EVENT_BEGIN_ETW("BrowserMain", 0, ""); 1106 void ChromeBrowserMainParts::ToolkitInitialized() {
1107 #if defined(TOOLKIT_VIEWS)
1108 // The delegate needs to be set before any UI is created so that windows
1109 // display the correct icon.
1110 if (!views::ViewsDelegate::views_delegate)
1111 views::ViewsDelegate::views_delegate = new ChromeViewsDelegate;
1311 1112
1312 // Override the default ContentBrowserClient to let Chrome participate in 1113 // TODO(beng): Move to WidgetImpl and implement on Windows too!
1313 // content logic. 1114 if (parameters().command_line_.HasSwitch(switches::kDebugViewsPaint))
1314 chrome::ChromeContentBrowserClient browser_client; 1115 views::Widget::SetDebugPaintEnabled(true);
1315 content::GetContentClient()->set_browser(&browser_client);
1316
1317 // If we're running tests (ui_task is non-null).
1318 if (parameters.ui_task)
1319 browser_defaults::enable_help_app = false;
1320
1321 scoped_ptr<BrowserMainParts>
1322 parts(BrowserMainParts::CreateBrowserMainParts(parameters));
1323
1324 parts->EarlyInitialization();
1325
1326 // Must happen before we try to use a message loop or display any UI.
1327 InitializeToolkit(parameters);
1328
1329 #if defined(OS_CHROMEOS)
1330 // Initialize CrosLibrary only for the browser, unless running tests
1331 // (which do their own CrosLibrary setup).
1332 if (!parameters.ui_task) {
1333 bool use_stub = parameters.command_line_.HasSwitch(switches::kStubCros);
1334 chromeos::CrosLibrary::Initialize(use_stub);
1335 }
1336 // Replace the default NetworkChangeNotifierFactory with ChromeOS specific
1337 // implementation.
1338 net::NetworkChangeNotifier::SetFactory(
1339 new chromeos::CrosNetworkChangeNotifierFactory());
1340 #endif 1116 #endif
1341 1117
1342 parts->MainMessageLoopStart(); 1118 #if defined(OS_WIN)
1119 gfx::PlatformFontWin::adjust_font_callback = &AdjustUIFont;
1120 gfx::PlatformFontWin::get_minimum_font_size_callback = &GetMinimumFontSize;
1121 #endif
1122 }
1343 1123
1344 // WARNING: If we get a WM_ENDSESSION, objects created on the stack here 1124 int ChromeBrowserMainParts::TemporaryContinue() {
1345 // are NOT deleted. If you need something to run during WM_ENDSESSION add it
1346 // to browser_shutdown::Shutdown or BrowserProcess::EndSession.
1347
1348 // !!!!!!!!!! READ ME !!!!!!!!!!
1349 // I (viettrungluu) am in the process of refactoring |BrowserMain()|. If you
1350 // need to add something above this comment, read the documentation in
1351 // browser_main.h. If you need to add something below, please do the
1352 // following:
1353 // - Figure out where you should add your code. Do NOT just pick a random
1354 // location "which works".
1355 // - Document the dependencies apart from compile-time-checkable ones. What
1356 // must happen before your new code is executed? Does your new code need to
1357 // run before something else? Are there performance reasons for executing
1358 // your code at that point?
1359 // - If you need to create a (persistent) object, heap allocate it and keep a
1360 // |scoped_ptr| to it rather than allocating it on the stack. Otherwise
1361 // I'll have to convert your code when I refactor.
1362 // - Unless your new code is just a couple of lines, factor it out into a
1363 // function with a well-defined purpose. Do NOT just add it inline in
1364 // |BrowserMain()|.
1365 // Thanks!
1366
1367 // TODO(viettrungluu): put the remainder into BrowserMainParts
1368 const CommandLine& parsed_command_line = parameters.command_line_;
1369 base::mac::ScopedNSAutoreleasePool* pool = parameters.autorelease_pool_;
1370
1371 #if defined(OS_WIN) && !defined(NO_TCMALLOC)
1372 // When linking shared libraries, NO_TCMALLOC is defined, and dynamic
1373 // allocator selection is not supported.
1374
1375 // Make this call before going multithreaded, or spawning any subprocesses.
1376 base::allocator::SetupSubprocessAllocator();
1377 #endif // OS_WIN
1378
1379 FilePath user_data_dir; 1125 FilePath user_data_dir;
1380 #if defined(OS_WIN) 1126 #if defined(OS_WIN)
1381 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); 1127 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
1382 #else 1128 #else
1383 // Getting the user data dir can fail if the directory isn't 1129 // Getting the user data dir can fail if the directory isn't
1384 // creatable, for example; on Windows in code below we bring up a 1130 // creatable, for example; on Windows in code below we bring up a
1385 // dialog prompting the user to pick a different directory. 1131 // dialog prompting the user to pick a different directory.
1386 // However, ProcessSingleton needs a real user_data_dir on Mac/Linux, 1132 // However, ProcessSingleton needs a real user_data_dir on Mac/Linux,
1387 // so it's better to fail here than fail mysteriously elsewhere. 1133 // so it's better to fail here than fail mysteriously elsewhere.
1388 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) 1134 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir))
1389 << "Must be able to get user data directory!"; 1135 << "Must be able to get user data directory!";
1390 #endif 1136 #endif
1391 1137
1392 ProcessSingleton process_singleton(user_data_dir); 1138 ProcessSingleton process_singleton(user_data_dir);
1393 1139
1394 bool is_first_run = FirstRun::IsChromeFirstRun() || 1140 bool is_first_run = FirstRun::IsChromeFirstRun() ||
1395 parsed_command_line.HasSwitch(switches::kFirstRun); 1141 parsed_command_line().HasSwitch(switches::kFirstRun);
1396 1142
1397 scoped_ptr<BrowserProcessImpl> browser_process; 1143 scoped_ptr<BrowserProcessImpl> browser_process;
1398 if (parsed_command_line.HasSwitch(switches::kImport) || 1144 if (parsed_command_line().HasSwitch(switches::kImport) ||
1399 parsed_command_line.HasSwitch(switches::kImportFromFile)) { 1145 parsed_command_line().HasSwitch(switches::kImportFromFile)) {
1400 // We use different BrowserProcess when importing so no GoogleURLTracker is 1146 // We use different BrowserProcess when importing so no GoogleURLTracker is
1401 // instantiated (as it makes a net::URLRequest and we don't have an IO 1147 // instantiated (as it makes a net::URLRequest and we don't have an IO
1402 // thread, see bug #1292702). 1148 // thread, see bug #1292702).
1403 browser_process.reset(new FirstRunBrowserProcess(parsed_command_line)); 1149 browser_process.reset(new FirstRunBrowserProcess(parsed_command_line()));
1404 is_first_run = false; 1150 is_first_run = false;
1405 } else { 1151 } else {
1406 browser_process.reset(new BrowserProcessImpl(parsed_command_line)); 1152 browser_process.reset(new BrowserProcessImpl(parsed_command_line()));
1407 } 1153 }
1408 1154
1409 // BrowserProcessImpl's constructor should set g_browser_process.
1410 DCHECK(g_browser_process);
1411
1412 // This forces the TabCloseableStateWatcher to be created and, on chromeos, 1155 // This forces the TabCloseableStateWatcher to be created and, on chromeos,
1413 // register for the notifications it needs to track the closeable state of 1156 // register for the notifications it needs to track the closeable state of
1414 // tabs. 1157 // tabs.
1415 g_browser_process->tab_closeable_state_watcher(); 1158 g_browser_process->tab_closeable_state_watcher();
1416 1159
1417 // The broker service initialization needs to run early because it will 1160 PrefService* local_state = InitializeLocalState(parsed_command_line(),
1418 // initialize the sandbox broker, which requires the process to swap its
1419 // window station. During this time all the UI will be broken. This has to
1420 // run before threads and windows are created.
1421 InitializeBrokerServices(parameters, parsed_command_line);
1422
1423 // Initialize histogram statistics gathering system.
1424 base::StatisticsRecorder statistics;
1425
1426 PrefService* local_state = InitializeLocalState(parsed_command_line,
1427 is_first_run); 1161 is_first_run);
1428 1162
1429 #if defined(USE_LINUX_BREAKPAD) 1163 #if defined(USE_LINUX_BREAKPAD)
1430 // Needs to be called after we have chrome::DIR_USER_DATA and 1164 // Needs to be called after we have chrome::DIR_USER_DATA and
1431 // g_browser_process. 1165 // g_browser_process.
1432 g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE, 1166 g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE,
1433 new GetLinuxDistroTask()); 1167 new GetLinuxDistroTask());
1434 1168
1435 if (IsCrashReportingEnabled(local_state)) 1169 if (IsCrashReportingEnabled(local_state))
1436 InitCrashReporter(); 1170 InitCrashReporter();
1437 #endif 1171 #endif
1438 1172
1439 // If we're running tests (ui_task is non-null), then the ResourceBundle 1173 // If we're running tests (ui_task is non-null), then the ResourceBundle
1440 // has already been initialized. 1174 // has already been initialized.
1441 if (parameters.ui_task) { 1175 if (parameters().ui_task) {
1442 g_browser_process->SetApplicationLocale("en-US"); 1176 g_browser_process->SetApplicationLocale("en-US");
1443 } else { 1177 } else {
1444 // Mac starts it earlier in |PreMainMessageLoopStart()| (because it is 1178 // Mac starts it earlier in |PreMainMessageLoopStart()| (because it is
1445 // needed when loading the MainMenu.nib and the language doesn't depend on 1179 // needed when loading the MainMenu.nib and the language doesn't depend on
1446 // anything since it comes from Cocoa. 1180 // anything since it comes from Cocoa.
1447 #if defined(OS_MACOSX) 1181 #if defined(OS_MACOSX)
1448 g_browser_process->SetApplicationLocale(l10n_util::GetLocaleOverride()); 1182 g_browser_process->SetApplicationLocale(l10n_util::GetLocaleOverride());
1449 #else 1183 #else
1450 const std::string locale = 1184 const std::string locale =
1451 local_state->GetString(prefs::kApplicationLocale); 1185 local_state->GetString(prefs::kApplicationLocale);
1452 // On a POSIX OS other than ChromeOS, the parameter that is passed to the 1186 // On a POSIX OS other than ChromeOS, the parameter that is passed to the
1453 // method InitSharedInstance is ignored. 1187 // method InitSharedInstance is ignored.
1454 const std::string loaded_locale = 1188 const std::string loaded_locale =
1455 ResourceBundle::InitSharedInstance(locale); 1189 ResourceBundle::InitSharedInstance(locale);
1456 if (loaded_locale.empty() && 1190 if (loaded_locale.empty() &&
1457 !parsed_command_line.HasSwitch(switches::kNoErrorDialogs)) { 1191 !parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) {
1458 ShowMissingLocaleMessageBox(); 1192 ShowMissingLocaleMessageBox();
1459 return chrome::RESULT_CODE_MISSING_DATA; 1193 return chrome::RESULT_CODE_MISSING_DATA;
1460 } 1194 }
1461 CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale; 1195 CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale;
1462 g_browser_process->SetApplicationLocale(loaded_locale); 1196 g_browser_process->SetApplicationLocale(loaded_locale);
1463 1197
1464 FilePath resources_pack_path; 1198 FilePath resources_pack_path;
1465 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); 1199 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
1466 ResourceBundle::AddDataPackToSharedInstance(resources_pack_path); 1200 ResourceBundle::AddDataPackToSharedInstance(resources_pack_path);
1467 #endif // defined(OS_MACOSX) 1201 #endif // defined(OS_MACOSX)
1468 } 1202 }
1469 1203
1470 #if defined(TOOLKIT_GTK) 1204 #if defined(TOOLKIT_GTK)
1471 g_set_application_name(l10n_util::GetStringUTF8(IDS_PRODUCT_NAME).c_str()); 1205 g_set_application_name(l10n_util::GetStringUTF8(IDS_PRODUCT_NAME).c_str());
1472 #endif 1206 #endif
1473 1207
1474 std::string try_chrome = 1208 std::string try_chrome =
1475 parsed_command_line.GetSwitchValueASCII(switches::kTryChromeAgain); 1209 parsed_command_line().GetSwitchValueASCII(switches::kTryChromeAgain);
1476 if (!try_chrome.empty()) { 1210 if (!try_chrome.empty()) {
1477 #if defined(OS_WIN) 1211 #if defined(OS_WIN)
1478 // Setup.exe has determined that we need to run a retention experiment 1212 // Setup.exe has determined that we need to run a retention experiment
1479 // and has lauched chrome to show the experiment UI. 1213 // and has lauched chrome to show the experiment UI.
1480 if (process_singleton.FoundOtherProcessWindow()) { 1214 if (process_singleton.FoundOtherProcessWindow()) {
1481 // It seems that we don't need to run the experiment since chrome 1215 // It seems that we don't need to run the experiment since chrome
1482 // in the same profile is already running. 1216 // in the same profile is already running.
1483 VLOG(1) << "Retention experiment not required"; 1217 VLOG(1) << "Retention experiment not required";
1484 return TryChromeDialogView::NOT_NOW; 1218 return TryChromeDialogView::NOT_NOW;
1485 } 1219 }
(...skipping 14 matching lines...) Expand all
1500 #if defined(OS_CHROMEOS) 1234 #if defined(OS_CHROMEOS)
1501 // This needs to be called after the locale has been set. 1235 // This needs to be called after the locale has been set.
1502 RegisterTranslateableItems(); 1236 RegisterTranslateableItems();
1503 #endif 1237 #endif
1504 1238
1505 #if defined(TOOLKIT_VIEWS) 1239 #if defined(TOOLKIT_VIEWS)
1506 views::Widget::SetPureViews( 1240 views::Widget::SetPureViews(
1507 CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePureViews)); 1241 CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePureViews));
1508 // Launch the views desktop shell window and register it as the default parent 1242 // Launch the views desktop shell window and register it as the default parent
1509 // for all unparented views widgets. 1243 // for all unparented views widgets.
1510 if (parsed_command_line.HasSwitch(switches::kViewsDesktop)) { 1244 if (parsed_command_line().HasSwitch(switches::kViewsDesktop)) {
1511 std::string desktop_type_cmd = 1245 std::string desktop_type_cmd =
1512 parsed_command_line.GetSwitchValueASCII(switches::kViewsDesktop); 1246 parsed_command_line().GetSwitchValueASCII(switches::kViewsDesktop);
1513 views::desktop::DesktopWindowView::DesktopType desktop_type; 1247 views::desktop::DesktopWindowView::DesktopType desktop_type;
1514 if (desktop_type_cmd == "netbook") 1248 if (desktop_type_cmd == "netbook")
1515 desktop_type = views::desktop::DesktopWindowView::DESKTOP_NETBOOK; 1249 desktop_type = views::desktop::DesktopWindowView::DESKTOP_NETBOOK;
1516 else if (desktop_type_cmd == "other") 1250 else if (desktop_type_cmd == "other")
1517 desktop_type = views::desktop::DesktopWindowView::DESKTOP_OTHER; 1251 desktop_type = views::desktop::DesktopWindowView::DESKTOP_OTHER;
1518 else 1252 else
1519 desktop_type = views::desktop::DesktopWindowView::DESKTOP_DEFAULT; 1253 desktop_type = views::desktop::DesktopWindowView::DESKTOP_DEFAULT;
1520 views::desktop::DesktopWindowView::CreateDesktopWindow(desktop_type); 1254 views::desktop::DesktopWindowView::CreateDesktopWindow(desktop_type);
1521 ChromeViewsDelegate* chrome_views_delegate = 1255 ChromeViewsDelegate* chrome_views_delegate =
1522 static_cast<ChromeViewsDelegate*>(views::ViewsDelegate::views_delegate); 1256 static_cast<ChromeViewsDelegate*>(views::ViewsDelegate::views_delegate);
(...skipping 10 matching lines...) Expand all
1533 FirstRun::MasterPrefs master_prefs; 1267 FirstRun::MasterPrefs master_prefs;
1534 bool first_run_ui_bypass = false; // True to skip first run UI. 1268 bool first_run_ui_bypass = false; // True to skip first run UI.
1535 if (is_first_run) { 1269 if (is_first_run) {
1536 first_run_ui_bypass = 1270 first_run_ui_bypass =
1537 !FirstRun::ProcessMasterPreferences(user_data_dir, &master_prefs); 1271 !FirstRun::ProcessMasterPreferences(user_data_dir, &master_prefs);
1538 AddFirstRunNewTabs(&browser_init, master_prefs.new_tabs); 1272 AddFirstRunNewTabs(&browser_init, master_prefs.new_tabs);
1539 1273
1540 // If we are running in App mode, we do not want to show the importer 1274 // If we are running in App mode, we do not want to show the importer
1541 // (first run) UI. 1275 // (first run) UI.
1542 if (!first_run_ui_bypass && 1276 if (!first_run_ui_bypass &&
1543 (parsed_command_line.HasSwitch(switches::kApp) || 1277 (parsed_command_line().HasSwitch(switches::kApp) ||
1544 parsed_command_line.HasSwitch(switches::kAppId) || 1278 parsed_command_line().HasSwitch(switches::kAppId) ||
1545 parsed_command_line.HasSwitch(switches::kNoFirstRun))) 1279 parsed_command_line().HasSwitch(switches::kNoFirstRun)))
1546 first_run_ui_bypass = true; 1280 first_run_ui_bypass = true;
1547 } 1281 }
1548 1282
1549 // TODO(viettrungluu): why don't we run this earlier? 1283 // TODO(viettrungluu): why don't we run this earlier?
1550 if (!parsed_command_line.HasSwitch(switches::kNoErrorDialogs)) 1284 if (!parsed_command_line().HasSwitch(switches::kNoErrorDialogs))
1551 WarnAboutMinimumSystemRequirements(); 1285 WarnAboutMinimumSystemRequirements();
1552 1286
1553 // Enable print preview once for supported platforms. 1287 // Enable print preview once for supported platforms.
1554 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_CHROMEOS) 1288 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_CHROMEOS)
1555 local_state->RegisterBooleanPref(prefs::kPrintingPrintPreviewEnabledOnce, 1289 local_state->RegisterBooleanPref(prefs::kPrintingPrintPreviewEnabledOnce,
1556 false, 1290 false,
1557 PrefService::UNSYNCABLE_PREF); 1291 PrefService::UNSYNCABLE_PREF);
1558 if (!local_state->GetBoolean(prefs::kPrintingPrintPreviewEnabledOnce)) { 1292 if (!local_state->GetBoolean(prefs::kPrintingPrintPreviewEnabledOnce)) {
1559 local_state->SetBoolean(prefs::kPrintingPrintPreviewEnabledOnce, true); 1293 local_state->SetBoolean(prefs::kPrintingPrintPreviewEnabledOnce, true);
1560 about_flags::SetExperimentEnabled(local_state, "print-preview", true); 1294 about_flags::SetExperimentEnabled(local_state, "print-preview", true);
1561 } 1295 }
1562 #endif 1296 #endif
1563 1297
1564 // Convert active labs into switches. Modifies the current command line. 1298 // Convert active labs into switches. Modifies the current command line.
1565 about_flags::ConvertFlagsToSwitches(local_state, 1299 about_flags::ConvertFlagsToSwitches(local_state,
1566 CommandLine::ForCurrentProcess()); 1300 CommandLine::ForCurrentProcess());
1567 1301
1568 InitializeNetworkOptions(parsed_command_line); 1302 InitializeNetworkOptions(parsed_command_line());
1569 InitializeURLRequestThrottlerManager(browser_process->net_log()); 1303 InitializeURLRequestThrottlerManager(browser_process->net_log());
1570 1304
1571 // Initialize histogram synchronizer system. This is a singleton and is used 1305 // Initialize histogram synchronizer system. This is a singleton and is used
1572 // for posting tasks via NewRunnableMethod. Its deleted when it goes out of 1306 // for posting tasks via NewRunnableMethod. Its deleted when it goes out of
1573 // scope. Even though NewRunnableMethod does AddRef and Release, the object 1307 // scope. Even though NewRunnableMethod does AddRef and Release, the object
1574 // will not be deleted after the Task is executed. 1308 // will not be deleted after the Task is executed.
1575 parts->SetupHistogramSynchronizer(); 1309 SetupHistogramSynchronizer();
1576 1310
1577 // Now the command line has been mutated based on about:flags, we can 1311 // Now the command line has been mutated based on about:flags, we can
1578 // set up metrics and initialize field trials. 1312 // set up metrics and initialize field trials.
1579 MetricsService* metrics = parts->SetupMetricsAndFieldTrials( 1313 MetricsService* metrics = SetupMetricsAndFieldTrials(
1580 parsed_command_line, local_state); 1314 parsed_command_line(), local_state);
1581 1315
1582 // Now that all preferences have been registered, set the install date 1316 // Now that all preferences have been registered, set the install date
1583 // for the uninstall metrics if this is our first run. This only actually 1317 // for the uninstall metrics if this is our first run. This only actually
1584 // gets used if the user has metrics reporting enabled at uninstall time. 1318 // gets used if the user has metrics reporting enabled at uninstall time.
1585 int64 install_date = 1319 int64 install_date =
1586 local_state->GetInt64(prefs::kUninstallMetricsInstallDate); 1320 local_state->GetInt64(prefs::kUninstallMetricsInstallDate);
1587 if (install_date == 0) { 1321 if (install_date == 0) {
1588 local_state->SetInt64(prefs::kUninstallMetricsInstallDate, 1322 local_state->SetInt64(prefs::kUninstallMetricsInstallDate,
1589 base::Time::Now().ToTimeT()); 1323 base::Time::Now().ToTimeT());
1590 } 1324 }
(...skipping 27 matching lines...) Expand all
1618 browser_shutdown::ReadLastShutdownInfo(); 1352 browser_shutdown::ReadLastShutdownInfo();
1619 1353
1620 #if defined(OS_WIN) 1354 #if defined(OS_WIN)
1621 // On Windows, we use our startup as an opportunity to do upgrade/uninstall 1355 // On Windows, we use our startup as an opportunity to do upgrade/uninstall
1622 // tasks. Those care whether the browser is already running. On Linux/Mac, 1356 // tasks. Those care whether the browser is already running. On Linux/Mac,
1623 // upgrade/uninstall happen separately. 1357 // upgrade/uninstall happen separately.
1624 bool already_running = browser_util::IsBrowserAlreadyRunning(); 1358 bool already_running = browser_util::IsBrowserAlreadyRunning();
1625 1359
1626 // If the command line specifies 'uninstall' then we need to work here 1360 // If the command line specifies 'uninstall' then we need to work here
1627 // unless we detect another chrome browser running. 1361 // unless we detect another chrome browser running.
1628 if (parsed_command_line.HasSwitch(switches::kUninstall)) 1362 if (parsed_command_line().HasSwitch(switches::kUninstall))
1629 return DoUninstallTasks(already_running); 1363 return DoUninstallTasks(already_running);
1630 #endif 1364 #endif
1631 1365
1632 if (parsed_command_line.HasSwitch(switches::kHideIcons) || 1366 if (parsed_command_line().HasSwitch(switches::kHideIcons) ||
1633 parsed_command_line.HasSwitch(switches::kShowIcons)) 1367 parsed_command_line().HasSwitch(switches::kShowIcons))
1634 return HandleIconsCommands(parsed_command_line); 1368 return HandleIconsCommands(parsed_command_line());
1635 if (parsed_command_line.HasSwitch(switches::kMakeDefaultBrowser)) { 1369 if (parsed_command_line().HasSwitch(switches::kMakeDefaultBrowser)) {
1636 return ShellIntegration::SetAsDefaultBrowser() ? 1370 return ShellIntegration::SetAsDefaultBrowser() ?
1637 static_cast<int>(content::RESULT_CODE_NORMAL_EXIT) : 1371 static_cast<int>(content::RESULT_CODE_NORMAL_EXIT) :
1638 static_cast<int>(chrome::RESULT_CODE_SHELL_INTEGRATION_FAILED); 1372 static_cast<int>(chrome::RESULT_CODE_SHELL_INTEGRATION_FAILED);
1639 } 1373 }
1640 1374
1641 // If the command line specifies --pack-extension, attempt the pack extension 1375 // If the command line specifies --pack-extension, attempt the pack extension
1642 // startup action and exit. 1376 // startup action and exit.
1643 if (parsed_command_line.HasSwitch(switches::kPackExtension)) { 1377 if (parsed_command_line().HasSwitch(switches::kPackExtension)) {
1644 ExtensionsStartupUtil extension_startup_util; 1378 ExtensionsStartupUtil extension_startup_util;
1645 if (extension_startup_util.PackExtension(parsed_command_line)) { 1379 if (extension_startup_util.PackExtension(parsed_command_line())) {
1646 return content::RESULT_CODE_NORMAL_EXIT; 1380 return content::RESULT_CODE_NORMAL_EXIT;
1647 } else { 1381 } else {
1648 return chrome::RESULT_CODE_PACK_EXTENSION_ERROR; 1382 return chrome::RESULT_CODE_PACK_EXTENSION_ERROR;
1649 } 1383 }
1650 } 1384 }
1651 1385
1652 #if !defined(OS_MACOSX) 1386 #if !defined(OS_MACOSX)
1653 // In environments other than Mac OS X we support import of settings 1387 // In environments other than Mac OS X we support import of settings
1654 // from other browsers. In case this process is a short-lived "import" 1388 // from other browsers. In case this process is a short-lived "import"
1655 // process that another browser runs just to import the settings, we 1389 // process that another browser runs just to import the settings, we
1656 // don't want to be checking for another browser process, by design. 1390 // don't want to be checking for another browser process, by design.
1657 if (!(parsed_command_line.HasSwitch(switches::kImport) || 1391 if (!(parsed_command_line().HasSwitch(switches::kImport) ||
1658 parsed_command_line.HasSwitch(switches::kImportFromFile))) { 1392 parsed_command_line().HasSwitch(switches::kImportFromFile))) {
1659 #endif 1393 #endif
1660 // When another process is running, use that process instead of starting a 1394 // When another process is running, use that process instead of starting a
1661 // new one. NotifyOtherProcess will currently give the other process up to 1395 // new one. NotifyOtherProcess will currently give the other process up to
1662 // 20 seconds to respond. Note that this needs to be done before we attempt 1396 // 20 seconds to respond. Note that this needs to be done before we attempt
1663 // to read the profile. 1397 // to read the profile.
1664 switch (process_singleton.NotifyOtherProcessOrCreate()) { 1398 switch (process_singleton.NotifyOtherProcessOrCreate()) {
1665 case ProcessSingleton::PROCESS_NONE: 1399 case ProcessSingleton::PROCESS_NONE:
1666 // No process already running, fall through to starting a new one. 1400 // No process already running, fall through to starting a new one.
1667 break; 1401 break;
1668 1402
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1701 // Initialize the screen locker now so that it can receive 1435 // Initialize the screen locker now so that it can receive
1702 // LOGIN_USER_CHANGED notification from UserManager. 1436 // LOGIN_USER_CHANGED notification from UserManager.
1703 chromeos::ScreenLocker::InitClass(); 1437 chromeos::ScreenLocker::InitClass();
1704 1438
1705 // This forces the ProfileManager to be created and register for the 1439 // This forces the ProfileManager to be created and register for the
1706 // notification it needs to track the logged in user. 1440 // notification it needs to track the logged in user.
1707 g_browser_process->profile_manager(); 1441 g_browser_process->profile_manager();
1708 1442
1709 // TODO(abarth): Should this move to InitializeNetworkOptions()? 1443 // TODO(abarth): Should this move to InitializeNetworkOptions()?
1710 // Allow access to file:// on ChromeOS for tests. 1444 // Allow access to file:// on ChromeOS for tests.
1711 if (parsed_command_line.HasSwitch(switches::kAllowFileAccess)) 1445 if (parsed_command_line().HasSwitch(switches::kAllowFileAccess))
1712 net::URLRequest::AllowFileAccess(); 1446 net::URLRequest::AllowFileAccess();
1713 1447
1714 // There are two use cases for kLoginUser: 1448 // There are two use cases for kLoginUser:
1715 // 1) if passed in tandem with kLoginPassword, to drive a "StubLogin" 1449 // 1) if passed in tandem with kLoginPassword, to drive a "StubLogin"
1716 // 2) if passed alone, to signal that the indicated user has already 1450 // 2) if passed alone, to signal that the indicated user has already
1717 // logged in and we should behave accordingly. 1451 // logged in and we should behave accordingly.
1718 // This handles case 2. 1452 // This handles case 2.
1719 if (parsed_command_line.HasSwitch(switches::kLoginUser) && 1453 if (parsed_command_line().HasSwitch(switches::kLoginUser) &&
1720 !parsed_command_line.HasSwitch(switches::kLoginPassword)) { 1454 !parsed_command_line().HasSwitch(switches::kLoginPassword)) {
1721 std::string username = 1455 std::string username =
1722 parsed_command_line.GetSwitchValueASCII(switches::kLoginUser); 1456 parsed_command_line().GetSwitchValueASCII(switches::kLoginUser);
1723 VLOG(1) << "Relaunching browser for user: " << username; 1457 VLOG(1) << "Relaunching browser for user: " << username;
1724 chromeos::UserManager::Get()->UserLoggedIn(username); 1458 chromeos::UserManager::Get()->UserLoggedIn(username);
1725 1459
1726 // Redirects Chrome logging to the user data dir. 1460 // Redirects Chrome logging to the user data dir.
1727 logging::RedirectChromeLogging(parsed_command_line); 1461 logging::RedirectChromeLogging(parsed_command_line());
1728 1462
1729 // Initialize user policy before creating the profile so the profile 1463 // Initialize user policy before creating the profile so the profile
1730 // initialization code sees policy settings. 1464 // initialization code sees policy settings.
1731 g_browser_process->browser_policy_connector()->InitializeUserPolicy( 1465 g_browser_process->browser_policy_connector()->InitializeUserPolicy(
1732 username); 1466 username);
1733 } 1467 }
1734 #endif 1468 #endif
1735 1469
1736 if (is_first_run) { 1470 if (is_first_run) {
1737 // Warn the ProfileManager that an import process will run, possibly 1471 // Warn the ProfileManager that an import process will run, possibly
1738 // locking the WebDataService directory of the next Profile created. 1472 // locking the WebDataService directory of the next Profile created.
1739 g_browser_process->profile_manager()->SetWillImport(); 1473 g_browser_process->profile_manager()->SetWillImport();
1740 } 1474 }
1741 1475
1742 Profile* profile = CreateProfile(parameters, user_data_dir, 1476 Profile* profile = CreateProfile(parameters(), user_data_dir,
1743 parsed_command_line); 1477 parsed_command_line());
1744 if (!profile) 1478 if (!profile)
1745 return content::RESULT_CODE_NORMAL_EXIT; 1479 return content::RESULT_CODE_NORMAL_EXIT;
1746 1480
1747 // Post-profile init --------------------------------------------------------- 1481 // Post-profile init ---------------------------------------------------------
1748 1482
1749 #if defined(OS_CHROMEOS) 1483 #if defined(OS_CHROMEOS)
1750 // Pass the TokenService pointer to the policy connector so user policy can 1484 // Pass the TokenService pointer to the policy connector so user policy can
1751 // grab a token and register with the policy server. 1485 // grab a token and register with the policy server.
1752 // TODO(mnissler): Remove once OAuth is the only authentication mechanism. 1486 // TODO(mnissler): Remove once OAuth is the only authentication mechanism.
1753 if (parsed_command_line.HasSwitch(switches::kLoginUser) && 1487 if (parsed_command_line().HasSwitch(switches::kLoginUser) &&
1754 !parsed_command_line.HasSwitch(switches::kLoginPassword)) { 1488 !parsed_command_line().HasSwitch(switches::kLoginPassword)) {
1755 g_browser_process->browser_policy_connector()->SetUserPolicyTokenService( 1489 g_browser_process->browser_policy_connector()->SetUserPolicyTokenService(
1756 profile->GetTokenService()); 1490 profile->GetTokenService());
1757 } 1491 }
1758 #endif 1492 #endif
1759 1493
1760 PrefService* user_prefs = profile->GetPrefs(); 1494 PrefService* user_prefs = profile->GetPrefs();
1761 DCHECK(user_prefs); 1495 DCHECK(user_prefs);
1762 1496
1763 // Tests should be able to tune login manager before showing it. 1497 // Tests should be able to tune login manager before showing it.
1764 // Thus only show login manager in normal (non-testing) mode. 1498 // Thus only show login manager in normal (non-testing) mode.
1765 if (!parameters.ui_task) { 1499 if (!parameters().ui_task) {
1766 OptionallyRunChromeOSLoginManager(parsed_command_line, profile); 1500 OptionallyRunChromeOSLoginManager(parsed_command_line(), profile);
1767 } 1501 }
1768 1502
1769 #if !defined(OS_MACOSX) 1503 #if !defined(OS_MACOSX)
1770 // Importing other browser settings is done in a browser-like process 1504 // Importing other browser settings is done in a browser-like process
1771 // that exits when this task has finished. 1505 // that exits when this task has finished.
1772 // TODO(port): Port the Mac's IPC-based implementation to other platforms to 1506 // TODO(port): Port the Mac's IPC-based implementation to other platforms to
1773 // replace this implementation. http://crbug.com/22142 1507 // replace this implementation. http://crbug.com/22142
1774 if (parsed_command_line.HasSwitch(switches::kImport) || 1508 if (parsed_command_line().HasSwitch(switches::kImport) ||
1775 parsed_command_line.HasSwitch(switches::kImportFromFile)) { 1509 parsed_command_line().HasSwitch(switches::kImportFromFile)) {
1776 return FirstRun::ImportNow(profile, parsed_command_line); 1510 return FirstRun::ImportNow(profile, parsed_command_line());
1777 } 1511 }
1778 #endif 1512 #endif
1779 1513
1780 #if defined(OS_WIN) 1514 #if defined(OS_WIN)
1781 // Do the tasks if chrome has been upgraded while it was last running. 1515 // Do the tasks if chrome has been upgraded while it was last running.
1782 if (!already_running && upgrade_util::DoUpgradeTasks(parsed_command_line)) 1516 if (!already_running && upgrade_util::DoUpgradeTasks(parsed_command_line()))
1783 return content::RESULT_CODE_NORMAL_EXIT; 1517 return content::RESULT_CODE_NORMAL_EXIT;
1784 #endif 1518 #endif
1785 1519
1786 // Check if there is any machine level Chrome installed on the current 1520 // Check if there is any machine level Chrome installed on the current
1787 // machine. If yes and the current Chrome process is user level, we do not 1521 // machine. If yes and the current Chrome process is user level, we do not
1788 // allow the user level Chrome to run. So we notify the user and uninstall 1522 // allow the user level Chrome to run. So we notify the user and uninstall
1789 // user level Chrome. 1523 // user level Chrome.
1790 // Note this check should only happen here, after all the checks above 1524 // Note this check should only happen here, after all the checks above
1791 // (uninstall, resource bundle initialization, other chrome browser 1525 // (uninstall, resource bundle initialization, other chrome browser
1792 // processes etc). 1526 // processes etc).
1793 // Do not allow this to occur for Chrome Frame user-to-system handoffs. 1527 // Do not allow this to occur for Chrome Frame user-to-system handoffs.
1794 if (!parsed_command_line.HasSwitch(switches::kChromeFrame) && 1528 if (!parsed_command_line().HasSwitch(switches::kChromeFrame) &&
1795 CheckMachineLevelInstall()) 1529 CheckMachineLevelInstall())
1796 return chrome::RESULT_CODE_MACHINE_LEVEL_INSTALL_EXISTS; 1530 return chrome::RESULT_CODE_MACHINE_LEVEL_INSTALL_EXISTS;
1797 1531
1798 // Create the TranslateManager singleton. 1532 // Create the TranslateManager singleton.
1799 TranslateManager* translate_manager = TranslateManager::GetInstance(); 1533 TranslateManager* translate_manager = TranslateManager::GetInstance();
1800 DCHECK(translate_manager != NULL); 1534 DCHECK(translate_manager != NULL);
1801 1535
1802 #if defined(OS_MACOSX) 1536 #if defined(OS_MACOSX)
1803 if (!parsed_command_line.HasSwitch(switches::kNoFirstRun)) { 1537 if (!parsed_command_line().HasSwitch(switches::kNoFirstRun)) {
1804 // Disk image installation is sort of a first-run task, so it shares the 1538 // Disk image installation is sort of a first-run task, so it shares the
1805 // kNoFirstRun switch. 1539 // kNoFirstRun switch.
1806 if (MaybeInstallFromDiskImage()) { 1540 if (MaybeInstallFromDiskImage()) {
1807 // The application was installed and the installed copy has been 1541 // The application was installed and the installed copy has been
1808 // launched. This process is now obsolete. Exit. 1542 // launched. This process is now obsolete. Exit.
1809 return content::RESULT_CODE_NORMAL_EXIT; 1543 return content::RESULT_CODE_NORMAL_EXIT;
1810 } 1544 }
1811 } 1545 }
1812 #endif 1546 #endif
1813 1547
(...skipping 23 matching lines...) Expand all
1837 #endif // OS_POSIX 1571 #endif // OS_POSIX
1838 } // if (!first_run_ui_bypass) 1572 } // if (!first_run_ui_bypass)
1839 1573
1840 Browser::SetNewHomePagePrefs(user_prefs); 1574 Browser::SetNewHomePagePrefs(user_prefs);
1841 g_browser_process->profile_manager()->OnImportFinished(profile); 1575 g_browser_process->profile_manager()->OnImportFinished(profile);
1842 } // if (is_first_run) 1576 } // if (is_first_run)
1843 1577
1844 // Sets things up so that if we crash from this point on, a dialog will 1578 // Sets things up so that if we crash from this point on, a dialog will
1845 // popup asking the user to restart chrome. It is done this late to avoid 1579 // popup asking the user to restart chrome. It is done this late to avoid
1846 // testing against a bunch of special cases that are taken care early on. 1580 // testing against a bunch of special cases that are taken care early on.
1847 PrepareRestartOnCrashEnviroment(parsed_command_line); 1581 PrepareRestartOnCrashEnviroment(parsed_command_line());
1848 1582
1849 #if defined(OS_WIN) 1583 #if defined(OS_WIN)
1850 // Registers Chrome with the Windows Restart Manager, which will restore the 1584 // Registers Chrome with the Windows Restart Manager, which will restore the
1851 // Chrome session when the computer is restarted after a system update. 1585 // Chrome session when the computer is restarted after a system update.
1852 // This could be run as late as WM_QUERYENDSESSION for system update reboots, 1586 // This could be run as late as WM_QUERYENDSESSION for system update reboots,
1853 // but should run on startup if extended to handle crashes/hangs/patches. 1587 // but should run on startup if extended to handle crashes/hangs/patches.
1854 // Also, better to run once here than once for each HWND's WM_QUERYENDSESSION. 1588 // Also, better to run once here than once for each HWND's WM_QUERYENDSESSION.
1855 if (base::win::GetVersion() >= base::win::VERSION_VISTA) 1589 if (base::win::GetVersion() >= base::win::VERSION_VISTA)
1856 RegisterApplicationRestart(parsed_command_line); 1590 RegisterApplicationRestart(parsed_command_line());
1857 #endif // OS_WIN 1591 #endif // OS_WIN
1858 1592
1859 // Initialize and maintain network predictor module, which handles DNS 1593 // Initialize and maintain network predictor module, which handles DNS
1860 // pre-resolution, as well as TCP/IP connection pre-warming. 1594 // pre-resolution, as well as TCP/IP connection pre-warming.
1861 // This also registers an observer to discard data when closing incognito 1595 // This also registers an observer to discard data when closing incognito
1862 // mode. 1596 // mode.
1863 bool preconnect_enabled = true; // Default status (easy to change!). 1597 bool preconnect_enabled = true; // Default status (easy to change!).
1864 if (parsed_command_line.HasSwitch(switches::kDisablePreconnect)) 1598 if (parsed_command_line().HasSwitch(switches::kDisablePreconnect))
1865 preconnect_enabled = false; 1599 preconnect_enabled = false;
1866 else if (parsed_command_line.HasSwitch(switches::kEnablePreconnect)) 1600 else if (parsed_command_line().HasSwitch(switches::kEnablePreconnect))
1867 preconnect_enabled = true; 1601 preconnect_enabled = true;
1868 chrome_browser_net::PredictorInit dns_prefetch( 1602 chrome_browser_net::PredictorInit dns_prefetch(
1869 user_prefs, 1603 user_prefs,
1870 local_state, 1604 local_state,
1871 preconnect_enabled); 1605 preconnect_enabled);
1872 1606
1873 #if defined(OS_WIN) 1607 #if defined(OS_WIN)
1874 base::win::ScopedCOMInitializer com_initializer; 1608 base::win::ScopedCOMInitializer com_initializer;
1875 1609
1876 #if defined(GOOGLE_CHROME_BUILD) 1610 #if defined(GOOGLE_CHROME_BUILD)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1935 base::FieldTrial::Probability kSDCH_DIVISOR = 1000; 1669 base::FieldTrial::Probability kSDCH_DIVISOR = 1000;
1936 base::FieldTrial::Probability kSDCH_DISABLE_PROBABILITY = 1; // 0.1% prob. 1670 base::FieldTrial::Probability kSDCH_DISABLE_PROBABILITY = 1; // 0.1% prob.
1937 // After June 30, 2011 builds, it will always be in default group. 1671 // After June 30, 2011 builds, it will always be in default group.
1938 scoped_refptr<base::FieldTrial> sdch_trial( 1672 scoped_refptr<base::FieldTrial> sdch_trial(
1939 new base::FieldTrial("GlobalSdch", kSDCH_DIVISOR, "global_enable_sdch", 1673 new base::FieldTrial("GlobalSdch", kSDCH_DIVISOR, "global_enable_sdch",
1940 2011, 6, 30)); 1674 2011, 6, 30));
1941 int sdch_enabled = sdch_trial->kDefaultGroupNumber; 1675 int sdch_enabled = sdch_trial->kDefaultGroupNumber;
1942 1676
1943 // Use default of "" so that all domains are supported. 1677 // Use default of "" so that all domains are supported.
1944 std::string sdch_supported_domain(""); 1678 std::string sdch_supported_domain("");
1945 if (parsed_command_line.HasSwitch(switches::kSdchFilter)) { 1679 if (parsed_command_line().HasSwitch(switches::kSdchFilter)) {
1946 sdch_supported_domain = 1680 sdch_supported_domain =
1947 parsed_command_line.GetSwitchValueASCII(switches::kSdchFilter); 1681 parsed_command_line().GetSwitchValueASCII(switches::kSdchFilter);
1948 } else { 1682 } else {
1949 sdch_trial->AppendGroup("global_disable_sdch", 1683 sdch_trial->AppendGroup("global_disable_sdch",
1950 kSDCH_DISABLE_PROBABILITY); 1684 kSDCH_DISABLE_PROBABILITY);
1951 if (sdch_enabled != sdch_trial->group()) 1685 if (sdch_enabled != sdch_trial->group())
1952 sdch_supported_domain = "never_enabled_sdch_for_any_domain"; 1686 sdch_supported_domain = "never_enabled_sdch_for_any_domain";
1953 } 1687 }
1954 1688
1955 net::SdchManager sdch_manager; // Singleton database. 1689 net::SdchManager sdch_manager; // Singleton database.
1956 sdch_manager.set_sdch_fetcher(new SdchDictionaryFetcher); 1690 sdch_manager.set_sdch_fetcher(new SdchDictionaryFetcher);
1957 sdch_manager.EnableSdchSupport(sdch_supported_domain); 1691 sdch_manager.EnableSdchSupport(sdch_supported_domain);
1958 1692
1959 InstallJankometer(parsed_command_line); 1693 InstallJankometer(parsed_command_line());
1960 1694
1961 #if defined(OS_WIN) && !defined(GOOGLE_CHROME_BUILD) 1695 #if defined(OS_WIN) && !defined(GOOGLE_CHROME_BUILD)
1962 if (parsed_command_line.HasSwitch(switches::kDebugPrint)) { 1696 if (parsed_command_line().HasSwitch(switches::kDebugPrint)) {
1963 FilePath path = 1697 FilePath path =
1964 parsed_command_line.GetSwitchValuePath(switches::kDebugPrint); 1698 parsed_command_line().GetSwitchValuePath(switches::kDebugPrint);
1965 printing::PrintedDocument::set_debug_dump_path(path); 1699 printing::PrintedDocument::set_debug_dump_path(path);
1966 } 1700 }
1967 #endif 1701 #endif
1968 1702
1969 #if defined(TOUCH_UI) 1703 #if defined(TOUCH_UI)
1970 views::TouchFactory::GetInstance()->set_keep_mouse_cursor( 1704 views::TouchFactory::GetInstance()->set_keep_mouse_cursor(
1971 CommandLine::ForCurrentProcess()->HasSwitch(switches::kKeepMouseCursor)); 1705 CommandLine::ForCurrentProcess()->HasSwitch(switches::kKeepMouseCursor));
1972 #endif 1706 #endif
1973 1707
1974 HandleTestParameters(parsed_command_line); 1708 HandleTestParameters(parsed_command_line());
1975 RecordBreakpadStatusUMA(metrics); 1709 RecordBreakpadStatusUMA(metrics);
1976 about_flags::RecordUMAStatistics(local_state); 1710 about_flags::RecordUMAStatistics(local_state);
1977 LanguageUsageMetrics::RecordAcceptLanguages( 1711 LanguageUsageMetrics::RecordAcceptLanguages(
1978 profile->GetPrefs()->GetString(prefs::kAcceptLanguages)); 1712 profile->GetPrefs()->GetString(prefs::kAcceptLanguages));
1979 LanguageUsageMetrics::RecordApplicationLanguage( 1713 LanguageUsageMetrics::RecordApplicationLanguage(
1980 g_browser_process->GetApplicationLocale()); 1714 g_browser_process->GetApplicationLocale());
1981 1715
1982 #if defined(OS_CHROMEOS) 1716 #if defined(OS_CHROMEOS)
1983 metrics->StartExternalMetrics(); 1717 metrics->StartExternalMetrics();
1984 1718
1985 // Initialize the brightness observer so that we'll display an onscreen 1719 // Initialize the brightness observer so that we'll display an onscreen
1986 // indication of brightness changes during login. 1720 // indication of brightness changes during login.
1987 static chromeos::BrightnessObserver* brightness_observer = 1721 static chromeos::BrightnessObserver* brightness_observer =
1988 new chromeos::BrightnessObserver(); 1722 new chromeos::BrightnessObserver();
1989 chromeos::CrosLibrary::Get()->GetBrightnessLibrary()->AddObserver( 1723 chromeos::CrosLibrary::Get()->GetBrightnessLibrary()->AddObserver(
1990 brightness_observer); 1724 brightness_observer);
1991 1725
1992 // Listen for system key events so that the user will be able to adjust the 1726 // Listen for system key events so that the user will be able to adjust the
1993 // volume on the login screen. 1727 // volume on the login screen.
1994 chromeos::SystemKeyEventListener::GetInstance(); 1728 chromeos::SystemKeyEventListener::GetInstance();
1995 1729
1996 // Listen for XI_HierarchyChanged events. 1730 // Listen for XI_HierarchyChanged events.
1997 chromeos::XInputHierarchyChangedEventListener::GetInstance(); 1731 chromeos::XInputHierarchyChangedEventListener::GetInstance();
1998 #endif 1732 #endif
1999 1733
2000 // The extension service may be available at this point. If the command line 1734 // The extension service may be available at this point. If the command line
2001 // specifies --uninstall-extension, attempt the uninstall extension startup 1735 // specifies --uninstall-extension, attempt the uninstall extension startup
2002 // action. 1736 // action.
2003 if (parsed_command_line.HasSwitch(switches::kUninstallExtension)) { 1737 if (parsed_command_line().HasSwitch(switches::kUninstallExtension)) {
2004 ExtensionsStartupUtil ext_startup_util; 1738 ExtensionsStartupUtil ext_startup_util;
2005 if (ext_startup_util.UninstallExtension(parsed_command_line, profile)) { 1739 if (ext_startup_util.UninstallExtension(parsed_command_line(), profile)) {
2006 return content::RESULT_CODE_NORMAL_EXIT; 1740 return content::RESULT_CODE_NORMAL_EXIT;
2007 } else { 1741 } else {
2008 return chrome::RESULT_CODE_UNINSTALL_EXTENSION_ERROR; 1742 return chrome::RESULT_CODE_UNINSTALL_EXTENSION_ERROR;
2009 } 1743 }
2010 } 1744 }
2011 1745
2012 #if defined(OS_WIN) 1746 #if defined(OS_WIN)
2013 // We check this here because if the profile is OTR (chromeos possibility) 1747 // We check this here because if the profile is OTR (chromeos possibility)
2014 // it won't still be accessible after browser is destroyed. 1748 // it won't still be accessible after browser is destroyed.
2015 bool record_search_engine = is_first_run && !profile->IsOffTheRecord(); 1749 bool record_search_engine = is_first_run && !profile->IsOffTheRecord();
2016 #endif 1750 #endif
2017 1751
2018 // ChildProcess:: is a misnomer unless you consider context. Use 1752 // ChildProcess:: is a misnomer unless you consider context. Use
2019 // of --wait-for-debugger only makes sense when Chrome itself is a 1753 // of --wait-for-debugger only makes sense when Chrome itself is a
2020 // child process (e.g. when launched by PyAuto). 1754 // child process (e.g. when launched by PyAuto).
2021 if (parsed_command_line.HasSwitch(switches::kWaitForDebugger)) { 1755 if (parsed_command_line().HasSwitch(switches::kWaitForDebugger)) {
2022 ChildProcess::WaitForDebugger("Browser"); 1756 ChildProcess::WaitForDebugger("Browser");
2023 } 1757 }
2024 1758
2025 #if defined(OS_CHROMEOS) 1759 #if defined(OS_CHROMEOS)
2026 // Run the Out of Memory priority manager while in this scope. Wait 1760 // Run the Out of Memory priority manager while in this scope. Wait
2027 // until here to start so that we give the most amount of time for 1761 // until here to start so that we give the most amount of time for
2028 // the other services to start up before we start adjusting the oom 1762 // the other services to start up before we start adjusting the oom
2029 // priority. In reality, it doesn't matter much where in this scope 1763 // priority. In reality, it doesn't matter much where in this scope
2030 // this is started, but it must be started in this scope so it will 1764 // this is started, but it must be started in this scope so it will
2031 // also be terminated when this scope exits. 1765 // also be terminated when this scope exits.
2032 scoped_ptr<browser::OomPriorityManager> oom_priority_manager( 1766 scoped_ptr<browser::OomPriorityManager> oom_priority_manager(
2033 new browser::OomPriorityManager); 1767 new browser::OomPriorityManager);
2034 #endif 1768 #endif
2035 1769
2036 // Create the instance of the cloud print proxy service so that it can launch 1770 // Create the instance of the cloud print proxy service so that it can launch
2037 // the service process if needed. This is needed because the service process 1771 // the service process if needed. This is needed because the service process
2038 // might have shutdown because an update was available. 1772 // might have shutdown because an update was available.
2039 // TODO(torne): this should maybe be done with 1773 // TODO(torne): this should maybe be done with
2040 // ProfileKeyedServiceFactory::ServiceIsCreatedWithProfile() instead? 1774 // ProfileKeyedServiceFactory::ServiceIsCreatedWithProfile() instead?
2041 CloudPrintProxyServiceFactory::GetForProfile(profile); 1775 CloudPrintProxyServiceFactory::GetForProfile(profile);
2042 1776
2043 // Initialize GpuDataManager and collect preliminary gpu info on FILE thread. 1777 // Initialize GpuDataManager and collect preliminary gpu info on FILE thread.
2044 // Upon completion, it posts GpuBlacklist auto update task on UI thread. 1778 // Upon completion, it posts GpuBlacklist auto update task on UI thread.
2045 BrowserThread::PostTask( 1779 BrowserThread::PostTask(
2046 BrowserThread::FILE, FROM_HERE, 1780 BrowserThread::FILE, FROM_HERE,
2047 NewRunnableFunction(&GpuBlacklistUpdater::SetupOnFileThread)); 1781 NewRunnableFunction(&GpuBlacklistUpdater::SetupOnFileThread));
2048 1782
2049 // Start watching all browser threads for responsiveness. 1783 // Start watching all browser threads for responsiveness.
2050 ThreadWatcherList::StartWatchingAll(parsed_command_line); 1784 ThreadWatcherList::StartWatchingAll(parsed_command_line());
2051 1785
2052 int result_code = content::RESULT_CODE_NORMAL_EXIT; 1786 int result_code = content::RESULT_CODE_NORMAL_EXIT;
2053 if (parameters.ui_task) { 1787 base::mac::ScopedNSAutoreleasePool* pool = parameters().autorelease_pool_;
1788 if (parameters().ui_task) {
2054 // We are in test mode. Run one task and enter the main message loop. 1789 // We are in test mode. Run one task and enter the main message loop.
2055 if (pool) 1790 if (pool)
2056 pool->Recycle(); 1791 pool->Recycle();
2057 parameters.ui_task->Run(); 1792 parameters().ui_task->Run();
2058 delete parameters.ui_task; 1793 delete parameters().ui_task;
2059 } else { 1794 } else {
2060 // Most general initialization is behind us, but opening a 1795 // Most general initialization is behind us, but opening a
2061 // tab and/or session restore and such is still to be done. 1796 // tab and/or session restore and such is still to be done.
2062 base::TimeTicks browser_open_start = base::TimeTicks::Now(); 1797 base::TimeTicks browser_open_start = base::TimeTicks::Now();
2063 1798
2064 // We are in regular browser boot sequence. Open initial tabs and enter the 1799 // We are in regular browser boot sequence. Open initial tabs and enter the
2065 // main message loop. 1800 // main message loop.
2066 if (browser_init.Start(parsed_command_line, FilePath(), profile, 1801 if (browser_init.Start(parsed_command_line(), FilePath(), profile,
2067 &result_code)) { 1802 &result_code)) {
2068 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) 1803 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
2069 // Initialize autoupdate timer. Timer callback costs basically nothing 1804 // Initialize autoupdate timer. Timer callback costs basically nothing
2070 // when browser is not in persistent mode, so it's OK to let it ride on 1805 // when browser is not in persistent mode, so it's OK to let it ride on
2071 // the main thread. This needs to be done here because we don't want 1806 // the main thread. This needs to be done here because we don't want
2072 // to start the timer when Chrome is run inside a test harness. 1807 // to start the timer when Chrome is run inside a test harness.
2073 g_browser_process->StartAutoupdateTimer(); 1808 g_browser_process->StartAutoupdateTimer();
2074 #endif 1809 #endif
2075 1810
2076 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 1811 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
(...skipping 12 matching lines...) Expand all
2089 pool->Recycle(); 1824 pool->Recycle();
2090 1825
2091 RecordPreReadExperimentTime("Startup.BrowserOpenTabs", 1826 RecordPreReadExperimentTime("Startup.BrowserOpenTabs",
2092 base::TimeTicks::Now() - browser_open_start); 1827 base::TimeTicks::Now() - browser_open_start);
2093 1828
2094 // TODO(mad): Move this call in a proper place on CrOS. 1829 // TODO(mad): Move this call in a proper place on CrOS.
2095 // http://crosbug.com/17687 1830 // http://crosbug.com/17687
2096 #if !defined(OS_CHROMEOS) 1831 #if !defined(OS_CHROMEOS)
2097 // If we're running tests (ui_task is non-null), then we don't want to 1832 // If we're running tests (ui_task is non-null), then we don't want to
2098 // call FetchLanguageListFromTranslateServer 1833 // call FetchLanguageListFromTranslateServer
2099 if (parameters.ui_task == NULL && translate_manager != NULL) { 1834 if (parameters().ui_task == NULL && translate_manager != NULL) {
2100 // TODO(willchan): Get rid of this after TranslateManager doesn't use 1835 // TODO(willchan): Get rid of this after TranslateManager doesn't use
2101 // the default request context. http://crbug.com/89396. 1836 // the default request context. http://crbug.com/89396.
2102 // This is necessary to force |default_request_context_| to be 1837 // This is necessary to force |default_request_context_| to be
2103 // initialized. 1838 // initialized.
2104 profile->GetRequestContext(); 1839 profile->GetRequestContext();
2105 translate_manager->FetchLanguageListFromTranslateServer(user_prefs); 1840 translate_manager->FetchLanguageListFromTranslateServer(user_prefs);
2106 } 1841 }
2107 #endif 1842 #endif
2108 1843
2109 RunUIMessageLoop(browser_process.get()); 1844 RunUIMessageLoop(browser_process.get());
2110 } 1845 }
2111 } 1846 }
2112 1847
2113 // Start watching for jank during shutdown. It gets disarmed when 1848 // Start watching for jank during shutdown. It gets disarmed when
2114 // |shutdown_watcher| object is destructed. 1849 // |shutdown_watcher_| object is destructed.
2115 shutdown_watcher.Arm(base::TimeDelta::FromSeconds(25)); 1850 shutdown_watcher_->Arm(base::TimeDelta::FromSeconds(25));
2116 1851
2117 #if defined(OS_WIN) 1852 #if defined(OS_WIN)
2118 // If it's the first run, log the search engine chosen. We wait until 1853 // If it's the first run, log the search engine chosen. We wait until
2119 // shutdown because otherwise we can't be sure the user has finished 1854 // shutdown because otherwise we can't be sure the user has finished
2120 // selecting a search engine through the dialog reached from the first run 1855 // selecting a search engine through the dialog reached from the first run
2121 // bubble link. 1856 // bubble link.
2122 if (record_search_engine) { 1857 if (record_search_engine) {
2123 TemplateURLService* url_service = 1858 TemplateURLService* url_service =
2124 TemplateURLServiceFactory::GetForProfile(profile); 1859 TemplateURLServiceFactory::GetForProfile(profile);
2125 const TemplateURL* default_search_engine = 1860 const TemplateURL* default_search_engine =
(...skipping 29 matching lines...) Expand all
2155 "Chrome.SearchSelectExempt", 1890 "Chrome.SearchSelectExempt",
2156 search_engine_type, 1891 search_engine_type,
2157 SEARCH_ENGINE_MAX); 1892 SEARCH_ENGINE_MAX);
2158 } 1893 }
2159 } 1894 }
2160 #endif 1895 #endif
2161 1896
2162 // Some tests don't set parameters.ui_task, so they started translate 1897 // Some tests don't set parameters.ui_task, so they started translate
2163 // language fetch that was never completed so we need to cleanup here 1898 // language fetch that was never completed so we need to cleanup here
2164 // otherwise it will be done by the destructor in a wrong thread. 1899 // otherwise it will be done by the destructor in a wrong thread.
2165 if (parameters.ui_task == NULL && translate_manager != NULL) 1900 if (parameters().ui_task == NULL && translate_manager != NULL)
2166 translate_manager->CleanupPendingUlrFetcher(); 1901 translate_manager->CleanupPendingUlrFetcher();
2167 1902
2168 1903
2169 process_singleton.Cleanup(); 1904 process_singleton.Cleanup();
2170 1905
2171 // Stop all tasks that might run on WatchDogThread. 1906 // Stop all tasks that might run on WatchDogThread.
2172 ThreadWatcherList::StopWatchingAll(); 1907 ThreadWatcherList::StopWatchingAll();
2173 1908
2174 metrics->Stop(); 1909 metrics->Stop();
2175 1910
2176 // browser_shutdown takes care of deleting browser_process, so we need to 1911 // browser_shutdown takes care of deleting browser_process, so we need to
2177 // release it. 1912 // release it.
2178 ignore_result(browser_process.release()); 1913 ignore_result(browser_process.release());
2179 browser_shutdown::Shutdown(); 1914 browser_shutdown::Shutdown();
2180 1915
2181 // Release BrowserMainParts here, before shutting down CrosLibrary, since
2182 // some of the classes initialized there have CrosLibrary dependencies.
2183 parts.reset(NULL);
satorux1 2011/09/07 17:10:31 The comment says the BrowserMainParts is explicitl
jam 2011/09/07 17:37:48 Do you have any specifics that worry you? We need
satorux1 2011/09/07 18:50:15 I don't have specific concerns. Steven who added C
stevenjb 2011/09/07 22:27:55 This definitely changes things. We need to change
jam 2011/09/08 00:33:56 yep I have removed that in my next cl
2184
2185 #if defined(OS_CHROMEOS)
2186 if (!parameters.ui_task)
2187 chromeos::CrosLibrary::Shutdown();
2188
2189 // To be precise, logout (browser shutdown) is not yet done, but the
2190 // remaining work is negligible, hence we say LogoutDone here.
2191 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("LogoutDone",
2192 false);
2193 chromeos::BootTimesLoader::Get()->WriteLogoutTimes();
2194 #endif
2195 TRACE_EVENT_END_ETW("BrowserMain", 0, 0);
2196 return result_code; 1916 return result_code;
2197 } 1917 }
2198 1918
2199 // This code is specific to the Windows-only PreReadExperiment field-trial. 1919 // This code is specific to the Windows-only PreReadExperiment field-trial.
2200 void RecordPreReadExperimentTime(const char* name, base::TimeDelta time) { 1920 void RecordPreReadExperimentTime(const char* name, base::TimeDelta time) {
2201 DCHECK(name != NULL); 1921 DCHECK(name != NULL);
2202 1922
2203 // This gets called with different histogram names, so we don't want to use 1923 // This gets called with different histogram names, so we don't want to use
2204 // the UMA_HISTOGRAM_CUSTOM_TIMES macro--it uses a static variable, and the 1924 // the UMA_HISTOGRAM_CUSTOM_TIMES macro--it uses a static variable, and the
2205 // first call wins. 1925 // first call wins.
(...skipping 10 matching lines...) Expand all
2216 if (env->GetVar(chrome::kPreReadEnvironmentVariable, &pre_read) && 1936 if (env->GetVar(chrome::kPreReadEnvironmentVariable, &pre_read) &&
2217 (pre_read == "0" || pre_read == "1")) { 1937 (pre_read == "0" || pre_read == "1")) {
2218 std::string uma_name(name); 1938 std::string uma_name(name);
2219 uma_name += "_PreRead"; 1939 uma_name += "_PreRead";
2220 uma_name += pre_read == "1" ? "Enabled" : "Disabled"; 1940 uma_name += pre_read == "1" ? "Enabled" : "Disabled";
2221 AddPreReadHistogramTime(uma_name.c_str(), time); 1941 AddPreReadHistogramTime(uma_name.c_str(), time);
2222 } 1942 }
2223 #endif 1943 #endif
2224 #endif 1944 #endif
2225 } 1945 }
OLDNEW
« no previous file with comments | « chrome/browser/browser_main.h ('k') | chrome/browser/browser_main_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698