Introduce ProfilerMetricsProvider
[chromium-blink-merge.git] / chrome / browser / chrome_browser_main.cc
blobc8118f0a8fa57a973780eed7cf1367a5bb0a598a
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chrome_browser_main.h"
7 #include <set>
8 #include <string>
9 #include <vector>
11 #include "base/at_exit.h"
12 #include "base/bind.h"
13 #include "base/command_line.h"
14 #include "base/debug/crash_logging.h"
15 #include "base/debug/debugger.h"
16 #include "base/debug/trace_event.h"
17 #include "base/file_util.h"
18 #include "base/files/file_path.h"
19 #include "base/metrics/field_trial.h"
20 #include "base/metrics/histogram.h"
21 #include "base/path_service.h"
22 #include "base/prefs/json_pref_store.h"
23 #include "base/prefs/pref_registry_simple.h"
24 #include "base/prefs/pref_service.h"
25 #include "base/prefs/pref_value_store.h"
26 #include "base/prefs/scoped_user_pref_update.h"
27 #include "base/process/process_info.h"
28 #include "base/run_loop.h"
29 #include "base/strings/string_number_conversions.h"
30 #include "base/strings/string_piece.h"
31 #include "base/strings/string_split.h"
32 #include "base/strings/sys_string_conversions.h"
33 #include "base/strings/utf_string_conversions.h"
34 #include "base/sys_info.h"
35 #include "base/threading/platform_thread.h"
36 #include "base/time/time.h"
37 #include "base/values.h"
38 #include "build/build_config.h"
39 #include "chrome/browser/about_flags.h"
40 #include "chrome/browser/browser_process.h"
41 #include "chrome/browser/browser_process_impl.h"
42 #include "chrome/browser/browser_process_platform_part.h"
43 #include "chrome/browser/browser_shutdown.h"
44 #include "chrome/browser/chrome_browser_main_extra_parts.h"
45 #include "chrome/browser/component_updater/cld_component_installer.h"
46 #include "chrome/browser/component_updater/component_updater_service.h"
47 #include "chrome/browser/component_updater/flash_component_installer.h"
48 #include "chrome/browser/component_updater/pnacl/pnacl_component_installer.h"
49 #include "chrome/browser/component_updater/recovery_component_installer.h"
50 #include "chrome/browser/component_updater/swiftshader_component_installer.h"
51 #include "chrome/browser/component_updater/widevine_cdm_component_installer.h"
52 #include "chrome/browser/defaults.h"
53 #include "chrome/browser/extensions/extension_service.h"
54 #include "chrome/browser/extensions/startup_helper.h"
55 #include "chrome/browser/first_run/first_run.h"
56 #include "chrome/browser/first_run/upgrade_util.h"
57 #include "chrome/browser/google/google_search_counter.h"
58 #include "chrome/browser/google/google_util.h"
59 #include "chrome/browser/gpu/gl_string_manager.h"
60 #include "chrome/browser/gpu/three_d_api_observer.h"
61 #include "chrome/browser/jankometer.h"
62 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
63 #include "chrome/browser/metrics/field_trial_synchronizer.h"
64 #include "chrome/browser/metrics/metrics_service.h"
65 #include "chrome/browser/metrics/thread_watcher.h"
66 #include "chrome/browser/metrics/tracking_synchronizer.h"
67 #include "chrome/browser/metrics/variations/variations_http_header_provider.h"
68 #include "chrome/browser/metrics/variations/variations_service.h"
69 #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
70 #include "chrome/browser/net/chrome_net_log.h"
71 #include "chrome/browser/net/crl_set_fetcher.h"
72 #include "chrome/browser/notifications/desktop_notification_service.h"
73 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
74 #include "chrome/browser/performance_monitor/performance_monitor.h"
75 #include "chrome/browser/performance_monitor/startup_timer.h"
76 #include "chrome/browser/plugins/plugin_prefs.h"
77 #include "chrome/browser/pref_service_flags_storage.h"
78 #include "chrome/browser/prefs/chrome_pref_service_factory.h"
79 #include "chrome/browser/prefs/command_line_pref_store.h"
80 #include "chrome/browser/prefs/pref_metrics_service.h"
81 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
82 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h"
83 #include "chrome/browser/process_singleton.h"
84 #include "chrome/browser/profiles/profile.h"
85 #include "chrome/browser/profiles/profile_manager.h"
86 #include "chrome/browser/profiles/profiles_state.h"
87 #include "chrome/browser/shell_integration.h"
88 #include "chrome/browser/translate/translate_service.h"
89 #include "chrome/browser/ui/app_list/app_list_service.h"
90 #include "chrome/browser/ui/browser.h"
91 #include "chrome/browser/ui/browser_finder.h"
92 #include "chrome/browser/ui/host_desktop.h"
93 #include "chrome/browser/ui/startup/bad_flags_prompt.h"
94 #include "chrome/browser/ui/startup/default_browser_prompt.h"
95 #include "chrome/browser/ui/startup/startup_browser_creator.h"
96 #include "chrome/browser/ui/uma_browsing_activity_observer.h"
97 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
98 #include "chrome/common/chrome_constants.h"
99 #include "chrome/common/chrome_paths.h"
100 #include "chrome/common/chrome_result_codes.h"
101 #include "chrome/common/chrome_switches.h"
102 #include "chrome/common/crash_keys.h"
103 #include "chrome/common/env_vars.h"
104 #include "chrome/common/logging_chrome.h"
105 #include "chrome/common/net/net_resource_provider.h"
106 #include "chrome/common/pref_names.h"
107 #include "chrome/common/profiling.h"
108 #include "chrome/installer/util/google_update_settings.h"
109 #include "components/language_usage_metrics/language_usage_metrics.h"
110 #include "components/nacl/browser/nacl_browser.h"
111 #include "components/nacl/browser/nacl_process_host.h"
112 #include "components/rappor/rappor_service.h"
113 #include "components/signin/core/common/profile_management_switches.h"
114 #include "components/startup_metric_utils/startup_metric_utils.h"
115 #include "components/translate/core/browser/translate_download_manager.h"
116 #include "content/public/browser/browser_thread.h"
117 #include "content/public/browser/notification_observer.h"
118 #include "content/public/browser/notification_registrar.h"
119 #include "content/public/browser/notification_service.h"
120 #include "content/public/browser/notification_types.h"
121 #include "content/public/browser/site_instance.h"
122 #include "content/public/common/content_client.h"
123 #include "content/public/common/content_switches.h"
124 #include "content/public/common/main_function_params.h"
125 #include "extensions/browser/extension_protocols.h"
126 #include "grit/app_locale_settings.h"
127 #include "grit/browser_resources.h"
128 #include "grit/chromium_strings.h"
129 #include "grit/generated_resources.h"
130 #include "grit/platform_locale_settings.h"
131 #include "net/base/net_module.h"
132 #include "net/base/sdch_manager.h"
133 #include "net/cookies/cookie_monster.h"
134 #include "net/http/http_network_layer.h"
135 #include "net/http/http_stream_factory.h"
136 #include "net/url_request/url_request.h"
137 #include "ui/base/l10n/l10n_util.h"
138 #include "ui/base/layout.h"
139 #include "ui/base/resource/resource_bundle.h"
141 #if defined(OS_ANDROID)
142 #include "chrome/browser/metrics/thread_watcher_android.h"
143 #else
144 #include "chrome/browser/feedback/feedback_profile_observer.h"
145 #endif
147 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
148 #include "chrome/browser/first_run/upgrade_util_linux.h"
149 #include "chrome/browser/sxs_linux.h"
150 #endif
152 #if defined(OS_CHROMEOS)
153 #include "chrome/browser/chromeos/settings/cros_settings.h"
154 #include "chromeos/chromeos_switches.h"
155 #include "chromeos/settings/cros_settings_names.h"
156 #endif
158 // TODO(port): several win-only methods have been pulled out of this, but
159 // BrowserMain() as a whole needs to be broken apart so that it's usable by
160 // other platforms. For now, it's just a stub. This is a serious work in
161 // progress and should not be taken as an indication of a real refactoring.
163 #if defined(OS_WIN)
164 #include "base/environment.h" // For PreRead experiment.
165 #include "base/win/windows_version.h"
166 #include "chrome/browser/browser_util_win.h"
167 #include "chrome/browser/chrome_browser_main_win.h"
168 #include "chrome/browser/first_run/try_chrome_dialog_view.h"
169 #include "chrome/browser/first_run/upgrade_util_win.h"
170 #include "chrome/browser/ui/network_profile_bubble.h"
171 #include "chrome/common/net/url_fixer_upper.h"
172 #include "chrome/installer/util/helper.h"
173 #include "chrome/installer/util/install_util.h"
174 #include "chrome/installer/util/shell_util.h"
175 #include "net/base/net_util.h"
176 #include "ui/base/l10n/l10n_util_win.h"
177 #include "ui/gfx/win/dpi.h"
178 #endif // defined(OS_WIN)
180 #if defined(OS_MACOSX)
181 #include <Security/Security.h>
183 #include "base/mac/scoped_nsautorelease_pool.h"
184 #include "chrome/browser/mac/keystone_glue.h"
185 #endif
187 #if defined(ENABLE_FULL_PRINTING) && !defined(OFFICIAL_BUILD)
188 #include "printing/printed_document.h"
189 #endif
191 #if defined(ENABLE_RLZ)
192 #include "chrome/browser/rlz/rlz.h"
193 #endif
195 #if defined(ENABLE_WEBRTC)
196 #include "chrome/browser/media/webrtc_log_util.h"
197 #endif
199 #if defined(USE_AURA)
200 #include "ui/aura/env.h"
201 #endif
203 using content::BrowserThread;
205 namespace {
207 // This function provides some ways to test crash and assertion handling
208 // behavior of the program.
209 void HandleTestParameters(const CommandLine& command_line) {
210 // This parameter causes an assertion.
211 if (command_line.HasSwitch(switches::kBrowserAssertTest)) {
212 DCHECK(false);
215 // This parameter causes a null pointer crash (crash reporter trigger).
216 if (command_line.HasSwitch(switches::kBrowserCrashTest)) {
217 int* bad_pointer = NULL;
218 *bad_pointer = 0;
222 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
223 void AddFirstRunNewTabs(StartupBrowserCreator* browser_creator,
224 const std::vector<GURL>& new_tabs) {
225 for (std::vector<GURL>::const_iterator it = new_tabs.begin();
226 it != new_tabs.end(); ++it) {
227 if (it->is_valid())
228 browser_creator->AddFirstRunTab(*it);
231 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
233 // Returns the new local state object, guaranteed non-NULL.
234 // |local_state_task_runner| must be a shutdown-blocking task runner.
235 PrefService* InitializeLocalState(
236 base::SequencedTaskRunner* local_state_task_runner,
237 const CommandLine& parsed_command_line) {
238 TRACE_EVENT0("startup", "ChromeBrowserMainParts::InitializeLocalState")
239 base::FilePath local_state_path;
240 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path);
241 bool local_state_file_exists = base::PathExists(local_state_path);
243 // Load local state. This includes the application locale so we know which
244 // locale dll to load. This also causes local state prefs to be registered.
245 PrefService* local_state = g_browser_process->local_state();
246 DCHECK(local_state);
248 #if defined(OS_WIN)
249 if (first_run::IsChromeFirstRun()) {
250 // During first run we read the google_update registry key to find what
251 // language the user selected when downloading the installer. This
252 // becomes our default language in the prefs.
253 // Other platforms obey the system locale.
254 base::string16 install_lang;
255 if (GoogleUpdateSettings::GetLanguage(&install_lang)) {
256 local_state->SetString(prefs::kApplicationLocale,
257 base::UTF16ToASCII(install_lang));
260 #endif // defined(OS_WIN)
262 // If the local state file for the current profile doesn't exist and the
263 // parent profile command line flag is present, then we should inherit some
264 // local state from the parent profile.
265 // Checking that the local state file for the current profile doesn't exist
266 // is the most robust way to determine whether we need to inherit or not
267 // since the parent profile command line flag can be present even when the
268 // current profile is not a new one, and in that case we do not want to
269 // inherit and reset the user's setting.
271 // TODO(mnissler): We should probably just instantiate a
272 // JSONPrefStore here instead of an entire PrefService. Once this is
273 // addressed, the call to browser_prefs::RegisterLocalState can move
274 // to chrome_prefs::CreateLocalState.
275 if (!local_state_file_exists &&
276 parsed_command_line.HasSwitch(switches::kParentProfile)) {
277 base::FilePath parent_profile =
278 parsed_command_line.GetSwitchValuePath(switches::kParentProfile);
279 scoped_refptr<PrefRegistrySimple> registry = new PrefRegistrySimple();
280 scoped_ptr<PrefService> parent_local_state(
281 chrome_prefs::CreateLocalState(
282 parent_profile,
283 local_state_task_runner,
284 g_browser_process->policy_service(),
285 registry,
286 false));
287 registry->RegisterStringPref(prefs::kApplicationLocale, std::string());
288 // Right now, we only inherit the locale setting from the parent profile.
289 local_state->SetString(
290 prefs::kApplicationLocale,
291 parent_local_state->GetString(prefs::kApplicationLocale));
294 #if defined(OS_CHROMEOS)
295 if (parsed_command_line.HasSwitch(chromeos::switches::kLoginManager)) {
296 std::string owner_locale = local_state->GetString(prefs::kOwnerLocale);
297 // Ensure that we start with owner's locale.
298 if (!owner_locale.empty() &&
299 local_state->GetString(prefs::kApplicationLocale) != owner_locale &&
300 !local_state->IsManagedPreference(prefs::kApplicationLocale)) {
301 local_state->SetString(prefs::kApplicationLocale, owner_locale);
304 #endif
306 return local_state;
309 // Initializes the primary profile, possibly doing some user prompting to pick
310 // a fallback profile. Returns the newly created profile, or NULL if startup
311 // should not continue.
312 Profile* CreatePrimaryProfile(const content::MainFunctionParams& parameters,
313 const base::FilePath& user_data_dir,
314 const CommandLine& parsed_command_line) {
315 TRACE_EVENT0("startup", "ChromeBrowserMainParts::CreateProfile")
316 base::Time start = base::Time::Now();
317 if (profiles::IsMultipleProfilesEnabled() &&
318 parsed_command_line.HasSwitch(switches::kProfileDirectory)) {
319 g_browser_process->local_state()->SetString(prefs::kProfileLastUsed,
320 parsed_command_line.GetSwitchValueASCII(switches::kProfileDirectory));
321 // Clear kProfilesLastActive since the user only wants to launch a specific
322 // profile.
323 ListPrefUpdate update(g_browser_process->local_state(),
324 prefs::kProfilesLastActive);
325 base::ListValue* profile_list = update.Get();
326 profile_list->Clear();
329 Profile* profile = NULL;
330 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
331 // On ChromeOS and Android the ProfileManager will use the same path as the
332 // one we got passed. GetActiveUserProfile will therefore use the correct path
333 // automatically.
334 DCHECK_EQ(user_data_dir.value(),
335 g_browser_process->profile_manager()->user_data_dir().value());
336 profile = ProfileManager::GetActiveUserProfile();
337 #else
338 base::FilePath profile_path =
339 GetStartupProfilePath(user_data_dir, parsed_command_line);
340 profile = g_browser_process->profile_manager()->GetProfile(
341 profile_path);
343 // If we're using the --new-profile-management flag and this profile is
344 // signed out, then we should show the user manager instead. By switching
345 // the active profile to the guest profile we ensure that no
346 // browser windows will be opened for the guest profile.
347 if (switches::IsNewProfileManagement() && !profile->IsGuestSession()) {
348 ProfileInfoCache& cache =
349 g_browser_process->profile_manager()->GetProfileInfoCache();
350 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_path);
352 if (cache.ProfileIsSigninRequiredAtIndex(profile_index))
353 profile = g_browser_process->profile_manager()->GetProfile(
354 ProfileManager::GetGuestProfilePath());
356 #endif
357 if (profile) {
358 UMA_HISTOGRAM_LONG_TIMES(
359 "Startup.CreateFirstProfile", base::Time::Now() - start);
360 return profile;
363 #if !defined(OS_WIN)
364 // TODO(port): fix this. See comments near the definition of
365 // user_data_dir. It is better to CHECK-fail here than it is to
366 // silently exit because of missing code in the above test.
367 CHECK(profile) << "Cannot get default profile.";
368 #endif
370 return NULL;
373 #if defined(OS_MACOSX)
374 OSStatus KeychainCallback(SecKeychainEvent keychain_event,
375 SecKeychainCallbackInfo* info, void* context) {
376 return noErr;
378 #endif
380 void RegisterComponentsForUpdate(const CommandLine& command_line) {
381 component_updater::ComponentUpdateService* cus =
382 g_browser_process->component_updater();
384 // Registration can be before or after cus->Start() so it is ok to post
385 // a task to the UI thread to do registration once you done the necessary
386 // file IO to know you existing component version.
387 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
388 RegisterRecoveryComponent(cus, g_browser_process->local_state());
389 RegisterPepperFlashComponent(cus);
390 RegisterSwiftShaderComponent(cus);
391 #endif
393 #if !defined(OS_ANDROID)
394 g_browser_process->pnacl_component_installer()->RegisterPnaclComponent(
395 cus, command_line);
396 #endif
398 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
399 RegisterWidevineCdmComponent(cus);
400 #endif
402 #if !defined(OS_CHROMEOS)
403 // CRLSetFetcher attempts to load a CRL set from either the local disk or
404 // network.
405 if (!command_line.HasSwitch(switches::kDisableCRLSets))
406 g_browser_process->crl_set_fetcher()->StartInitialLoad(cus);
407 #endif
409 #if defined(CLD2_DYNAMIC_MODE) && defined(CLD2_IS_COMPONENT)
410 RegisterCldComponent(cus);
411 #endif
413 cus->Start();
416 #if !defined(OS_ANDROID)
417 bool ProcessSingletonNotificationCallback(
418 const CommandLine& command_line,
419 const base::FilePath& current_directory) {
420 // Drop the request if the browser process is already in shutdown path.
421 if (!g_browser_process || g_browser_process->IsShuttingDown())
422 return false;
424 if (command_line.HasSwitch(switches::kOriginalProcessStartTime)) {
425 std::string start_time_string =
426 command_line.GetSwitchValueASCII(switches::kOriginalProcessStartTime);
427 int64 remote_start_time;
428 if (base::StringToInt64(start_time_string, &remote_start_time)) {
429 base::TimeDelta elapsed =
430 base::Time::Now() - base::Time::FromInternalValue(remote_start_time);
431 if (command_line.HasSwitch(switches::kFastStart)) {
432 UMA_HISTOGRAM_LONG_TIMES(
433 "Startup.WarmStartTimeFromRemoteProcessStartFast", elapsed);
434 } else {
435 UMA_HISTOGRAM_LONG_TIMES(
436 "Startup.WarmStartTimeFromRemoteProcessStart", elapsed);
441 g_browser_process->platform_part()->PlatformSpecificCommandLineProcessing(
442 command_line);
444 base::FilePath user_data_dir =
445 g_browser_process->profile_manager()->user_data_dir();
446 base::FilePath startup_profile_dir =
447 GetStartupProfilePath(user_data_dir, command_line);
449 StartupBrowserCreator::ProcessCommandLineAlreadyRunning(
450 command_line, current_directory, startup_profile_dir);
451 return true;
453 #endif // !defined(OS_ANDROID)
455 void LaunchDevToolsHandlerIfNeeded(const CommandLine& command_line) {
456 if (command_line.HasSwitch(::switches::kRemoteDebuggingPort)) {
457 std::string port_str =
458 command_line.GetSwitchValueASCII(::switches::kRemoteDebuggingPort);
459 int port;
460 if (base::StringToInt(port_str, &port) && port >= 0 && port < 65535) {
461 g_browser_process->CreateDevToolsHttpProtocolHandler(
462 chrome::HOST_DESKTOP_TYPE_NATIVE,
463 "127.0.0.1",
464 port);
465 } else {
466 DLOG(WARNING) << "Invalid http debugger port number " << port;
471 // Heap allocated class that listens for first page load, kicks off stat
472 // recording and then deletes itself.
473 class LoadCompleteListener : public content::NotificationObserver {
474 public:
475 LoadCompleteListener() {
476 registrar_.Add(this,
477 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
478 content::NotificationService::AllSources());
480 virtual ~LoadCompleteListener() {}
482 // content::NotificationObserver implementation.
483 virtual void Observe(int type,
484 const content::NotificationSource& source,
485 const content::NotificationDetails& details) OVERRIDE {
486 DCHECK_EQ(content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, type);
487 startup_metric_utils::OnInitialPageLoadComplete();
488 delete this;
491 private:
492 content::NotificationRegistrar registrar_;
493 DISALLOW_COPY_AND_ASSIGN(LoadCompleteListener);
496 } // namespace
498 namespace chrome_browser {
500 // This error message is not localized because we failed to load the
501 // localization data files.
502 #if defined(OS_WIN)
503 const char kMissingLocaleDataTitle[] = "Missing File Error";
504 #endif
506 #if defined(OS_WIN)
507 // TODO(port) This should be used on Linux Aura as well. http://crbug.com/338969
508 const char kMissingLocaleDataMessage[] =
509 "Unable to find locale data files. Please reinstall.";
510 #endif
512 } // namespace chrome_browser
514 // BrowserMainParts ------------------------------------------------------------
516 // static
517 bool ChromeBrowserMainParts::disable_enforcing_cookie_policies_for_tests_ =
518 false;
520 ChromeBrowserMainParts::ChromeBrowserMainParts(
521 const content::MainFunctionParams& parameters)
522 : parameters_(parameters),
523 parsed_command_line_(parameters.command_line),
524 result_code_(content::RESULT_CODE_NORMAL_EXIT),
525 startup_watcher_(new StartupTimeBomb()),
526 shutdown_watcher_(new ShutdownWatcherHelper()),
527 startup_timer_(new performance_monitor::StartupTimer()),
528 browser_field_trials_(parameters.command_line),
529 profile_(NULL),
530 run_message_loop_(true),
531 notify_result_(ProcessSingleton::PROCESS_NONE),
532 local_state_(NULL),
533 restart_last_session_(false) {
534 // If we're running tests (ui_task is non-null).
535 if (parameters.ui_task)
536 browser_defaults::enable_help_app = false;
538 // Chrome disallows cookies by default. All code paths that want to use
539 // cookies need to go through one of Chrome's URLRequestContexts which have
540 // a ChromeNetworkDelegate attached that selectively allows cookies again.
541 if (!disable_enforcing_cookie_policies_for_tests_)
542 net::URLRequest::SetDefaultCookiePolicyToBlock();
545 ChromeBrowserMainParts::~ChromeBrowserMainParts() {
546 for (int i = static_cast<int>(chrome_extra_parts_.size())-1; i >= 0; --i)
547 delete chrome_extra_parts_[i];
548 chrome_extra_parts_.clear();
551 // This will be called after the command-line has been mutated by about:flags
552 void ChromeBrowserMainParts::SetupMetricsAndFieldTrials() {
553 TRACE_EVENT0("startup", "ChromeBrowserMainParts::SetupMetricsAndFieldTrials");
554 // Must initialize metrics after labs have been converted into switches,
555 // but before field trials are set up (so that client ID is available for
556 // one-time randomized field trials).
558 // Initialize FieldTrialList to support FieldTrials that use one-time
559 // randomization.
560 MetricsService* metrics = browser_process_->metrics_service();
561 field_trial_list_.reset(
562 new base::FieldTrialList(metrics->CreateEntropyProvider().release()));
564 const CommandLine* command_line = CommandLine::ForCurrentProcess();
565 if (command_line->HasSwitch(switches::kEnableBenchmarking))
566 base::FieldTrial::EnableBenchmarking();
568 // Ensure any field trials specified on the command line are initialized.
569 if (command_line->HasSwitch(switches::kForceFieldTrials)) {
570 std::set<std::string> unforceable_field_trials;
571 #if defined(OFFICIAL_BUILD)
572 unforceable_field_trials.insert("SettingsEnforcement");
573 #endif // defined(OFFICIAL_BUILD)
575 // Create field trials without activating them, so that this behaves in a
576 // consistent manner with field trials created from the server.
577 bool result = base::FieldTrialList::CreateTrialsFromString(
578 command_line->GetSwitchValueASCII(switches::kForceFieldTrials),
579 base::FieldTrialList::DONT_ACTIVATE_TRIALS,
580 unforceable_field_trials);
581 CHECK(result) << "Invalid --" << switches::kForceFieldTrials
582 << " list specified.";
584 if (command_line->HasSwitch(switches::kForceVariationIds)) {
585 // Create default variation ids which will always be included in the
586 // X-Client-Data request header.
587 chrome_variations::VariationsHttpHeaderProvider* provider =
588 chrome_variations::VariationsHttpHeaderProvider::GetInstance();
589 bool result = provider->SetDefaultVariationIds(
590 command_line->GetSwitchValueASCII(switches::kForceVariationIds));
591 CHECK(result) << "Invalid --" << switches::kForceVariationIds
592 << " list specified.";
594 chrome_variations::VariationsService* variations_service =
595 browser_process_->variations_service();
596 if (variations_service)
597 variations_service->CreateTrialsFromSeed();
599 // This must be called after the local state is initialized.
600 browser_field_trials_.SetupFieldTrials(local_state_);
602 // Initialize FieldTrialSynchronizer system. This is a singleton and is used
603 // for posting tasks via base::Bind. Its deleted when it goes out of scope.
604 // Even though base::Bind does AddRef and Release, the object will not be
605 // deleted after the Task is executed.
606 field_trial_synchronizer_ = new FieldTrialSynchronizer();
608 // Now that field trials have been created, initializes metrics recording.
609 metrics->InitializeMetricsRecordingState();
612 // ChromeBrowserMainParts: |SetupMetricsAndFieldTrials()| related --------------
614 void ChromeBrowserMainParts::StartMetricsRecording() {
615 TRACE_EVENT0("startup", "ChromeBrowserMainParts::StartMetricsRecording");
616 MetricsService* metrics = g_browser_process->metrics_service();
618 const bool only_do_metrics_recording =
619 parsed_command_line_.HasSwitch(switches::kMetricsRecordingOnly) ||
620 parsed_command_line_.HasSwitch(switches::kEnableBenchmarking);
621 if (only_do_metrics_recording) {
622 // If we're testing then we don't care what the user preference is, we turn
623 // on recording, but not reporting, otherwise tests fail.
624 metrics->StartRecordingForTests();
625 return;
628 metrics->CheckForClonedInstall(
629 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
630 const bool metrics_enabled = metrics->StartIfMetricsReportingEnabled();
631 if (metrics_enabled) {
632 // TODO(asvitkine): Since this function is not run on Android, RAPPOR is
633 // currently disabled there. http://crbug.com/370041
634 browser_process_->rappor_service()->Start(
635 browser_process_->local_state(),
636 browser_process_->system_request_context());
640 void ChromeBrowserMainParts::RecordBrowserStartupTime() {
641 // Don't record any metrics if UI was displayed before this point e.g.
642 // warning dialogs.
643 if (startup_metric_utils::WasNonBrowserUIDisplayed())
644 return;
646 #if defined(OS_ANDROID)
647 // On Android the first run is handled in Java code, and the C++ side of
648 // Chrome doesn't know if this is the first run. This will cause some
649 // inaccuracy in the UMA statistics, but this should be minor (first runs are
650 // rare).
651 bool is_first_run = false;
652 #else
653 bool is_first_run = first_run::IsChromeFirstRun();
654 #endif
656 // CurrentProcessInfo::CreationTime() is currently only implemented on some
657 // platforms.
658 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX)
659 const base::Time process_creation_time =
660 base::CurrentProcessInfo::CreationTime();
662 if (!is_first_run && !process_creation_time.is_null()) {
663 base::TimeDelta delay = base::Time::Now() - process_creation_time;
664 UMA_HISTOGRAM_LONG_TIMES_100("Startup.BrowserMessageLoopStartTime", delay);
666 #endif // defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX)
668 // Record collected startup metrics.
669 startup_metric_utils::OnBrowserStartupComplete(is_first_run);
671 // Deletes self.
672 new LoadCompleteListener();
675 // -----------------------------------------------------------------------------
676 // TODO(viettrungluu): move more/rest of BrowserMain() into BrowserMainParts.
678 #if defined(OS_WIN)
679 #define DLLEXPORT __declspec(dllexport)
681 // We use extern C for the prototype DLLEXPORT to avoid C++ name mangling.
682 extern "C" {
683 DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded();
686 DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded() {
687 // Need an instance of AtExitManager to handle singleton creations and
688 // deletions. We need this new instance because, the old instance created
689 // in ChromeMain() got destructed when the function returned.
690 base::AtExitManager exit_manager;
691 upgrade_util::RelaunchChromeBrowserWithNewCommandLineIfNeeded();
693 #endif
695 // content::BrowserMainParts implementation ------------------------------------
697 void ChromeBrowserMainParts::PreEarlyInitialization() {
698 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreEarlyInitialization");
699 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
700 chrome_extra_parts_[i]->PreEarlyInitialization();
703 void ChromeBrowserMainParts::PostEarlyInitialization() {
704 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PostEarlyInitialization");
705 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
706 chrome_extra_parts_[i]->PostEarlyInitialization();
709 void ChromeBrowserMainParts::ToolkitInitialized() {
710 TRACE_EVENT0("startup", "ChromeBrowserMainParts::ToolkitInitialized");
711 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
712 chrome_extra_parts_[i]->ToolkitInitialized();
715 void ChromeBrowserMainParts::PreMainMessageLoopStart() {
716 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreMainMessageLoopStart");
717 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
718 chrome_extra_parts_[i]->PreMainMessageLoopStart();
721 void ChromeBrowserMainParts::PostMainMessageLoopStart() {
722 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PostMainMessageLoopStart");
723 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
724 chrome_extra_parts_[i]->PostMainMessageLoopStart();
727 int ChromeBrowserMainParts::PreCreateThreads() {
728 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreCreateThreads");
729 result_code_ = PreCreateThreadsImpl();
731 if (result_code_ == content::RESULT_CODE_NORMAL_EXIT) {
732 #if !defined(OS_ANDROID)
733 // These members must be initialized before exiting this function normally.
734 DCHECK(master_prefs_.get());
735 DCHECK(browser_creator_.get());
736 #endif
737 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
738 chrome_extra_parts_[i]->PreCreateThreads();
741 return result_code_;
744 int ChromeBrowserMainParts::PreCreateThreadsImpl() {
745 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreCreateThreadsImpl")
746 run_message_loop_ = false;
747 #if !defined(OS_ANDROID)
748 chrome::MaybeShowInvalidUserDataDirWarningDialog();
749 #endif
750 if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_))
751 return chrome::RESULT_CODE_MISSING_DATA;
753 // Force MediaCaptureDevicesDispatcher to be created on UI thread.
754 MediaCaptureDevicesDispatcher::GetInstance();
756 // Android's first run is done in Java instead of native.
757 #if !defined(OS_ANDROID)
758 process_singleton_.reset(new ChromeProcessSingleton(
759 user_data_dir_, base::Bind(&ProcessSingletonNotificationCallback)));
761 // Cache first run state early.
762 first_run::IsChromeFirstRun();
763 #endif
765 scoped_refptr<base::SequencedTaskRunner> local_state_task_runner =
766 JsonPrefStore::GetTaskRunnerForFile(
767 base::FilePath(chrome::kLocalStorePoolName),
768 BrowserThread::GetBlockingPool());
771 TRACE_EVENT0("startup",
772 "ChromeBrowserMainParts::PreCreateThreadsImpl:InitBrowswerProcessImpl");
773 browser_process_.reset(new BrowserProcessImpl(local_state_task_runner.get(),
774 parsed_command_line()));
777 if (parsed_command_line().HasSwitch(switches::kEnableProfiling)) {
778 TRACE_EVENT0("startup",
779 "ChromeBrowserMainParts::PreCreateThreadsImpl:InitProfiling");
780 // User wants to override default tracking status.
781 std::string flag =
782 parsed_command_line().GetSwitchValueASCII(switches::kEnableProfiling);
783 // Default to basic profiling (no parent child support).
784 tracked_objects::ThreadData::Status status =
785 tracked_objects::ThreadData::PROFILING_ACTIVE;
786 if (flag.compare("0") != 0)
787 status = tracked_objects::ThreadData::DEACTIVATED;
788 else if (flag.compare("child") != 0)
789 status = tracked_objects::ThreadData::PROFILING_CHILDREN_ACTIVE;
790 tracked_objects::ThreadData::InitializeAndSetTrackingStatus(status);
793 if (parsed_command_line().HasSwitch(switches::kProfilingOutputFile)) {
794 tracking_objects_.set_output_file_path(
795 parsed_command_line().GetSwitchValuePath(
796 switches::kProfilingOutputFile));
799 local_state_ = InitializeLocalState(
800 local_state_task_runner.get(), parsed_command_line());
802 #if !defined(OS_ANDROID)
803 // These members must be initialized before returning from this function.
804 master_prefs_.reset(new first_run::MasterPrefs);
805 // Android doesn't use StartupBrowserCreator.
806 browser_creator_.reset(new StartupBrowserCreator);
807 // TODO(yfriedman): Refactor Android to re-use UMABrowsingActivityObserver
808 chrome::UMABrowsingActivityObserver::Init();
809 #endif
811 #if !defined(OS_CHROMEOS)
812 // Convert active labs into switches. This needs to be done before
813 // ResourceBundle::InitSharedInstanceWithLocale as some loaded resources are
814 // affected by experiment flags (--touch-optimized-ui in particular).
815 // On ChromeOS system level flags are applied from the device settings from
816 // the session manager.
818 TRACE_EVENT0("startup",
819 "ChromeBrowserMainParts::PreCreateThreadsImpl:ConvertFlags");
820 about_flags::PrefServiceFlagsStorage flags_storage_(
821 g_browser_process->local_state());
822 about_flags::ConvertFlagsToSwitches(&flags_storage_,
823 CommandLine::ForCurrentProcess(),
824 about_flags::kAddSentinels);
826 #endif
828 local_state_->UpdateCommandLinePrefStore(
829 new CommandLinePrefStore(CommandLine::ForCurrentProcess()));
831 // Reset the command line in the crash report details, since we may have
832 // just changed it to include experiments.
833 crash_keys::SetSwitchesFromCommandLine(CommandLine::ForCurrentProcess());
835 // Mac starts it earlier in |PreMainMessageLoopStart()| (because it is
836 // needed when loading the MainMenu.nib and the language doesn't depend on
837 // anything since it comes from Cocoa.
838 #if defined(OS_MACOSX)
839 std::string locale =
840 parameters().ui_task ? "en-US" : l10n_util::GetLocaleOverride();
841 browser_process_->SetApplicationLocale(locale);
842 #else
843 const std::string locale =
844 local_state_->GetString(prefs::kApplicationLocale);
846 // On a POSIX OS other than ChromeOS, the parameter that is passed to the
847 // method InitSharedInstance is ignored.
849 TRACE_EVENT_BEGIN0("startup",
850 "ChromeBrowserMainParts::PreCreateThreadsImpl:InitResourceBundle");
851 const std::string loaded_locale =
852 ResourceBundle::InitSharedInstanceWithLocale(locale, NULL);
853 TRACE_EVENT_END0("startup",
854 "ChromeBrowserMainParts::PreCreateThreadsImpl:InitResourceBundle");
856 if (loaded_locale.empty() &&
857 !parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) {
858 ShowMissingLocaleMessageBox();
859 return chrome::RESULT_CODE_MISSING_DATA;
861 CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale;
862 browser_process_->SetApplicationLocale(loaded_locale);
864 base::FilePath resources_pack_path;
865 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
867 TRACE_EVENT0("startup",
868 "ChromeBrowserMainParts::PreCreateThreadsImpl:AddDataPack");
869 ResourceBundle::GetSharedInstance().AddDataPackFromPath(
870 resources_pack_path, ui::SCALE_FACTOR_NONE);
872 #endif // defined(OS_MACOSX)
874 // Android does first run in Java instead of native.
875 // Chrome OS has its own out-of-box-experience code.
876 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
877 // On first run, we need to process the predictor preferences before the
878 // browser's profile_manager object is created, but after ResourceBundle
879 // is initialized.
880 if (first_run::IsChromeFirstRun()) {
881 first_run::ProcessMasterPreferencesResult pmp_result =
882 first_run::ProcessMasterPreferences(user_data_dir_,
883 master_prefs_.get());
884 if (pmp_result == first_run::EULA_EXIT_NOW)
885 return chrome::RESULT_CODE_EULA_REFUSED;
887 if (!parsed_command_line().HasSwitch(switches::kApp) &&
888 !parsed_command_line().HasSwitch(switches::kAppId) &&
889 !parsed_command_line().HasSwitch(switches::kShowAppList)) {
890 AddFirstRunNewTabs(browser_creator_.get(), master_prefs_->new_tabs);
893 // TODO(macourteau): refactor preferences that are copied from
894 // master_preferences into local_state, as a "local_state" section in
895 // master preferences. If possible, a generic solution would be prefered
896 // over a copy one-by-one of specific preferences. Also see related TODO
897 // in first_run.h.
899 // Store the initial VariationsService seed in local state, if it exists
900 // in master prefs.
901 if (!master_prefs_->variations_seed.empty()) {
902 local_state_->SetString(prefs::kVariationsSeed,
903 master_prefs_->variations_seed);
904 if (!master_prefs_->variations_seed_signature.empty()) {
905 local_state_->SetString(prefs::kVariationsSeedSignature,
906 master_prefs_->variations_seed_signature);
908 // Set the variation seed date to the current system time. If the user's
909 // clock is incorrect, this may cause some field trial expiry checks to
910 // not do the right thing until the next seed update from the server,
911 // when this value will be updated.
912 local_state_->SetInt64(prefs::kVariationsSeedDate,
913 base::Time::Now().ToInternalValue());
916 if (!master_prefs_->suppress_default_browser_prompt_for_version.empty()) {
917 local_state_->SetString(
918 prefs::kBrowserSuppressDefaultBrowserPrompt,
919 master_prefs_->suppress_default_browser_prompt_for_version);
922 AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)->HandleFirstRun();
924 #endif
926 #if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_MACOSX)
927 // Set the product channel for crash reports.
928 base::debug::SetCrashKeyValue(crash_keys::kChannel,
929 chrome::VersionInfo::GetVersionStringModifier());
930 #endif
932 // Initialize tracking synchronizer system.
933 tracking_synchronizer_ = new chrome_browser_metrics::TrackingSynchronizer();
935 // Now that all preferences have been registered, set the install date
936 // for the uninstall metrics if this is our first run. This only actually
937 // gets used if the user has metrics reporting enabled at uninstall time.
938 int64 install_date = local_state_->GetInt64(prefs::kInstallDate);
939 if (install_date == 0)
940 local_state_->SetInt64(prefs::kInstallDate, base::Time::Now().ToTimeT());
942 #if defined(OS_MACOSX)
943 // Get the Keychain API to register for distributed notifications on the main
944 // thread, which has a proper CFRunloop, instead of later on the I/O thread,
945 // which doesn't. This ensures those notifications will get delivered
946 // properly. See issue 37766.
947 // (Note that the callback mask here is empty. I don't want to register for
948 // any callbacks, I just want to initialize the mechanism.)
949 SecKeychainAddCallback(&KeychainCallback, 0, NULL);
950 #endif
952 #if defined(OS_CHROMEOS)
953 // Must be done after g_browser_process is constructed, before
954 // SetupMetricsAndFieldTrials().
955 chromeos::CrosSettings::Initialize();
956 #endif
958 // Now the command line has been mutated based on about:flags, we can setup
959 // metrics and initialize field trials. The field trials are needed by
960 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads.
961 SetupMetricsAndFieldTrials();
963 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this.
964 browser_process_->PreCreateThreads();
966 return content::RESULT_CODE_NORMAL_EXIT;
969 void ChromeBrowserMainParts::PreMainMessageLoopRun() {
970 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreMainMessageLoopRun");
971 result_code_ = PreMainMessageLoopRunImpl();
973 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
974 chrome_extra_parts_[i]->PreMainMessageLoopRun();
977 // PreMainMessageLoopRun calls these extra stages in the following order:
978 // PreMainMessageLoopRunImpl()
979 // ... initial setup, including browser_process_ setup.
980 // PreProfileInit()
981 // ... additional setup, including CreateProfile()
982 // PostProfileInit()
983 // ... additional setup
984 // PreBrowserStart()
985 // ... browser_creator_->Start (OR parameters().ui_task->Run())
986 // PostBrowserStart()
988 void ChromeBrowserMainParts::PreProfileInit() {
989 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreProfileInit");
991 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
992 chrome_extra_parts_[i]->PreProfileInit();
994 #if !defined(OS_ANDROID)
995 // Initialize the feedback uploader so it can setup notifications for profile
996 // creation.
997 feedback::FeedbackProfileObserver::Initialize();
999 ProfileManager* profile_manager = g_browser_process->profile_manager();
1001 // First check if any ephemeral profiles are left behind because of browser
1002 // crash and schedule them for deletion and then proceed with getting the set
1003 // of profiles to open.
1004 ProfileInfoCache& profile_cache = profile_manager->GetProfileInfoCache();
1005 size_t profiles_count = profile_cache.GetNumberOfProfiles();
1006 std::vector<base::FilePath> profiles_to_delete;
1007 for (size_t i = 0; i < profiles_count; ++i) {
1008 if (profile_cache.ProfileIsEphemeralAtIndex(i))
1009 profiles_to_delete.push_back(profile_cache.GetPathOfProfileAtIndex(i));
1012 if (profiles_to_delete.size()) {
1013 for (size_t i = 0; i < profiles_to_delete.size(); ++i) {
1014 profile_manager->ScheduleProfileForDeletion(
1015 profiles_to_delete[i], ProfileManager::CreateCallback());
1017 // Clean up stale profiles immediately after browser start.
1018 BrowserThread::PostTask(
1019 BrowserThread::FILE, FROM_HERE,
1020 base::Bind(&ProfileManager::CleanUpStaleProfiles, profiles_to_delete));
1022 #endif // OS_ANDROID
1025 void ChromeBrowserMainParts::PostProfileInit() {
1026 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PostProfileInit");
1027 LaunchDevToolsHandlerIfNeeded(parsed_command_line());
1028 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1029 chrome_extra_parts_[i]->PostProfileInit();
1032 void ChromeBrowserMainParts::PreBrowserStart() {
1033 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreBrowserStart");
1034 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1035 chrome_extra_parts_[i]->PreBrowserStart();
1037 three_d_observer_.reset(new ThreeDAPIObserver());
1040 void ChromeBrowserMainParts::PostBrowserStart() {
1041 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PostBrowserStart");
1042 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1043 chrome_extra_parts_[i]->PostBrowserStart();
1044 #if !defined(OS_ANDROID)
1045 // Allow ProcessSingleton to process messages.
1046 process_singleton_->Unlock();
1047 #endif
1048 #if defined(ENABLE_WEBRTC)
1049 // Set up a task to delete old WebRTC log files for all profiles. Use a delay
1050 // to reduce the impact on startup time.
1051 BrowserThread::PostDelayedTask(
1052 BrowserThread::UI,
1053 FROM_HERE,
1054 base::Bind(&WebRtcLogUtil::DeleteOldWebRtcLogFilesForAllProfiles),
1055 base::TimeDelta::FromMinutes(1));
1056 #endif
1059 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
1060 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreMainMessageLoopRunImpl");
1061 // Android updates the metrics service dynamically depending on whether the
1062 // application is in the foreground or not. Do not start here.
1063 #if !defined(OS_ANDROID)
1064 // Now that the file thread has been started, start recording.
1065 StartMetricsRecording();
1066 #endif
1068 // Create watchdog thread after creating all other threads because it will
1069 // watch the other threads and they must be running.
1070 browser_process_->watchdog_thread();
1072 // Do any initializating in the browser process that requires all threads
1073 // running.
1074 browser_process_->PreMainMessageLoopRun();
1076 // Record last shutdown time into a histogram.
1077 browser_shutdown::ReadLastShutdownInfo();
1079 #if defined(OS_WIN)
1080 // On Windows, we use our startup as an opportunity to do upgrade/uninstall
1081 // tasks. Those care whether the browser is already running. On Linux/Mac,
1082 // upgrade/uninstall happen separately.
1083 bool already_running = browser_util::IsBrowserAlreadyRunning();
1085 // If the command line specifies 'uninstall' then we need to work here
1086 // unless we detect another chrome browser running.
1087 if (parsed_command_line().HasSwitch(switches::kUninstall)) {
1088 return DoUninstallTasks(already_running);
1091 if (parsed_command_line().HasSwitch(switches::kHideIcons) ||
1092 parsed_command_line().HasSwitch(switches::kShowIcons)) {
1093 return ChromeBrowserMainPartsWin::HandleIconsCommands(
1094 parsed_command_line_);
1096 #endif
1098 if (parsed_command_line().HasSwitch(switches::kMakeDefaultBrowser)) {
1099 return ShellIntegration::SetAsDefaultBrowser() ?
1100 static_cast<int>(content::RESULT_CODE_NORMAL_EXIT) :
1101 static_cast<int>(chrome::RESULT_CODE_SHELL_INTEGRATION_FAILED);
1104 #if defined(USE_AURA)
1105 // Make sure aura::Env has been initialized.
1106 CHECK(aura::Env::GetInstance());
1107 #endif
1109 // Android doesn't support extensions and doesn't implement ProcessSingleton.
1110 #if !defined(OS_ANDROID)
1111 // If the command line specifies --pack-extension, attempt the pack extension
1112 // startup action and exit.
1113 if (parsed_command_line().HasSwitch(switches::kPackExtension)) {
1114 extensions::StartupHelper extension_startup_helper;
1115 if (extension_startup_helper.PackExtension(parsed_command_line()))
1116 return content::RESULT_CODE_NORMAL_EXIT;
1117 return chrome::RESULT_CODE_PACK_EXTENSION_ERROR;
1120 // If we're being launched just to check the connector policy, we are
1121 // short-lived and don't want to be passing that switch off.
1122 bool pass_command_line = !parsed_command_line().HasSwitch(
1123 switches::kCheckCloudPrintConnectorPolicy);
1125 if (pass_command_line) {
1126 // When another process is running, use that process instead of starting a
1127 // new one. NotifyOtherProcess will currently give the other process up to
1128 // 20 seconds to respond. Note that this needs to be done before we attempt
1129 // to read the profile.
1130 notify_result_ = process_singleton_->NotifyOtherProcessOrCreate();
1131 switch (notify_result_) {
1132 case ProcessSingleton::PROCESS_NONE:
1133 // No process already running, fall through to starting a new one.
1134 break;
1136 case ProcessSingleton::PROCESS_NOTIFIED:
1137 #if defined(OS_POSIX) && !defined(OS_MACOSX)
1138 printf("%s\n", base::SysWideToNativeMB(base::UTF16ToWide(
1139 l10n_util::GetStringUTF16(IDS_USED_EXISTING_BROWSER))).c_str());
1140 #endif
1141 // Having a differentiated return type for testing allows for tests to
1142 // verify proper handling of some switches. When not testing, stick to
1143 // the standard Unix convention of returning zero when things went as
1144 // expected.
1145 if (parsed_command_line().HasSwitch(switches::kTestType))
1146 return chrome::RESULT_CODE_NORMAL_EXIT_PROCESS_NOTIFIED;
1147 return content::RESULT_CODE_NORMAL_EXIT;
1149 case ProcessSingleton::PROFILE_IN_USE:
1150 return chrome::RESULT_CODE_PROFILE_IN_USE;
1152 case ProcessSingleton::LOCK_ERROR:
1153 LOG(ERROR) << "Failed to create a ProcessSingleton for your profile "
1154 "directory. This means that running multiple instances "
1155 "would start multiple browser processes rather than "
1156 "opening a new window in the existing process. Aborting "
1157 "now to avoid profile corruption.";
1158 return chrome::RESULT_CODE_PROFILE_IN_USE;
1160 default:
1161 NOTREACHED();
1164 #endif // !defined(OS_ANDROID)
1166 // Handle special early return paths (which couldn't be processed even earlier
1167 // as they require the process singleton to be held) first.
1169 std::string try_chrome =
1170 parsed_command_line().GetSwitchValueASCII(switches::kTryChromeAgain);
1171 if (!try_chrome.empty()) {
1172 #if defined(OS_WIN)
1173 // Setup.exe has determined that we need to run a retention experiment
1174 // and has lauched chrome to show the experiment UI. It is guaranteed that
1175 // no other Chrome is currently running as the process singleton was
1176 // sucessfully grabbed above.
1177 int try_chrome_int;
1178 base::StringToInt(try_chrome, &try_chrome_int);
1179 TryChromeDialogView::Result answer = TryChromeDialogView::Show(
1180 try_chrome_int,
1181 base::Bind(&ChromeProcessSingleton::SetActiveModalDialog,
1182 base::Unretained(process_singleton_.get())));
1183 if (answer == TryChromeDialogView::NOT_NOW)
1184 return chrome::RESULT_CODE_NORMAL_EXIT_CANCEL;
1185 if (answer == TryChromeDialogView::UNINSTALL_CHROME)
1186 return chrome::RESULT_CODE_NORMAL_EXIT_EXP2;
1187 // At this point the user is willing to try chrome again.
1188 if (answer == TryChromeDialogView::TRY_CHROME_AS_DEFAULT) {
1189 // Only set in the unattended case, the interactive case is Windows 8.
1190 if (ShellIntegration::CanSetAsDefaultBrowser() ==
1191 ShellIntegration::SET_DEFAULT_UNATTENDED)
1192 ShellIntegration::SetAsDefaultBrowser();
1194 #else
1195 // We don't support retention experiments on Mac or Linux.
1196 return content::RESULT_CODE_NORMAL_EXIT;
1197 #endif // defined(OS_WIN)
1200 #if defined(OS_WIN)
1201 // Do the tasks if chrome has been upgraded while it was last running.
1202 if (!already_running && upgrade_util::DoUpgradeTasks(parsed_command_line()))
1203 return content::RESULT_CODE_NORMAL_EXIT;
1205 // Check if there is any machine level Chrome installed on the current
1206 // machine. If yes and the current Chrome process is user level, we do not
1207 // allow the user level Chrome to run. So we notify the user and uninstall
1208 // user level Chrome.
1209 // Note this check needs to happen here (after the process singleton was
1210 // obtained but before potentially creating the first run sentinel).
1211 if (ChromeBrowserMainPartsWin::CheckMachineLevelInstall())
1212 return chrome::RESULT_CODE_MACHINE_LEVEL_INSTALL_EXISTS;
1213 #endif // defined(OS_WIN)
1215 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1216 if (sxs_linux::ShouldMigrateUserDataDir())
1217 return sxs_linux::MigrateUserDataDir();
1218 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS)
1220 // Desktop construction occurs here, (required before profile creation).
1221 PreProfileInit();
1223 // Profile creation ----------------------------------------------------------
1225 MetricsService::SetExecutionPhase(MetricsService::CREATE_PROFILE,
1226 g_browser_process->local_state());
1227 profile_ = CreatePrimaryProfile(parameters(),
1228 user_data_dir_,
1229 parsed_command_line());
1230 if (!profile_)
1231 return content::RESULT_CODE_NORMAL_EXIT;
1233 #if !defined(OS_ANDROID)
1234 // The first run sentinel must be created after the process singleton was
1235 // grabbed and no early return paths were otherwise hit above.
1236 first_run::CreateSentinelIfNeeded();
1237 #endif // !defined(OS_ANDROID)
1239 #if defined(ENABLE_BACKGROUND)
1240 // Autoload any profiles which are running background apps.
1241 // TODO(rlp): Do this on a separate thread. See http://crbug.com/99075.
1242 browser_process_->profile_manager()->AutoloadProfiles();
1243 #endif
1244 // Post-profile init ---------------------------------------------------------
1246 TranslateService::Initialize();
1248 // Needs to be done before PostProfileInit, since login manager on CrOS is
1249 // called inside PostProfileInit.
1250 content::WebUIControllerFactory::RegisterFactory(
1251 ChromeWebUIControllerFactory::GetInstance());
1253 // NaClBrowserDelegateImpl is accessed inside PostProfileInit().
1254 // So make sure to create it before that.
1255 #if !defined(DISABLE_NACL)
1256 NaClBrowserDelegateImpl* delegate =
1257 new NaClBrowserDelegateImpl(browser_process_->profile_manager());
1258 nacl::NaClBrowser::SetDelegate(delegate);
1259 #endif
1261 // TODO(stevenjb): Move WIN and MACOSX specific code to appropriate Parts.
1262 // (requires supporting early exit).
1263 PostProfileInit();
1265 // Retrieve cached GL strings from local state and use them for GPU
1266 // blacklist decisions.
1267 if (g_browser_process->gl_string_manager())
1268 g_browser_process->gl_string_manager()->Initialize();
1270 // Create an instance of GpuModeManager to watch gpu mode pref change.
1271 g_browser_process->gpu_mode_manager();
1273 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
1274 // Show the First Run UI if this is the first time Chrome has been run on
1275 // this computer, or we're being compelled to do so by a command line flag.
1276 // Note that this be done _after_ the PrefService is initialized and all
1277 // preferences are registered, since some of the code that the importer
1278 // touches reads preferences.
1279 if (first_run::IsChromeFirstRun()) {
1280 first_run::AutoImport(profile_,
1281 master_prefs_->homepage_defined,
1282 master_prefs_->do_import_items,
1283 master_prefs_->dont_import_items,
1284 master_prefs_->import_bookmarks_path);
1286 // Note: this can pop the first run consent dialog on linux.
1287 first_run::DoPostImportTasks(profile_,
1288 master_prefs_->make_chrome_default_for_user);
1290 if (!master_prefs_->suppress_first_run_default_browser_prompt) {
1291 browser_creator_->set_show_main_browser_window(
1292 !chrome::ShowFirstRunDefaultBrowserPrompt(profile_));
1293 } else {
1294 browser_creator_->set_is_default_browser_dialog_suppressed(true);
1297 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
1299 #if defined(OS_WIN)
1300 // Sets things up so that if we crash from this point on, a dialog will
1301 // popup asking the user to restart chrome. It is done this late to avoid
1302 // testing against a bunch of special cases that are taken care early on.
1303 ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment(
1304 parsed_command_line());
1306 // Registers Chrome with the Windows Restart Manager, which will restore the
1307 // Chrome session when the computer is restarted after a system update.
1308 // This could be run as late as WM_QUERYENDSESSION for system update reboots,
1309 // but should run on startup if extended to handle crashes/hangs/patches.
1310 // Also, better to run once here than once for each HWND's WM_QUERYENDSESSION.
1311 if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
1312 ChromeBrowserMainPartsWin::RegisterApplicationRestart(
1313 parsed_command_line());
1316 // Verify that the profile is not on a network share and if so prepare to show
1317 // notification to the user.
1318 if (NetworkProfileBubble::ShouldCheckNetworkProfile(profile_)) {
1319 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
1320 base::Bind(&NetworkProfileBubble::CheckNetworkProfile,
1321 profile_->GetPath()));
1323 #endif // OS_WIN
1325 #if defined(ENABLE_RLZ) && !defined(OS_CHROMEOS)
1326 // Init the RLZ library. This just binds the dll and schedules a task on the
1327 // file thread to be run sometime later. If this is the first run we record
1328 // the installation event.
1329 PrefService* pref_service = profile_->GetPrefs();
1330 int ping_delay = first_run::IsChromeFirstRun() ? master_prefs_->ping_delay :
1331 pref_service->GetInteger(first_run::GetPingDelayPrefName().c_str());
1332 // Negative ping delay means to send ping immediately after a first search is
1333 // recorded.
1334 RLZTracker::InitRlzFromProfileDelayed(
1335 profile_, first_run::IsChromeFirstRun(), ping_delay < 0,
1336 base::TimeDelta::FromMilliseconds(abs(ping_delay)));
1337 #endif // defined(ENABLE_RLZ) && !defined(OS_CHROMEOS)
1339 // Configure modules that need access to resources.
1340 net::NetModule::SetResourceProvider(chrome_common_net::NetResourceProvider);
1342 // In unittest mode, this will do nothing. In normal mode, this will create
1343 // the global IntranetRedirectDetector instance, which will promptly go to
1344 // sleep for seven seconds (to avoid slowing startup), and wake up afterwards
1345 // to see if it should do anything else.
1347 // A simpler way of doing all this would be to have some function which could
1348 // give the time elapsed since startup, and simply have this object check that
1349 // when asked to initialize itself, but this doesn't seem to exist.
1351 // This can't be created in the BrowserProcessImpl constructor because it
1352 // needs to read prefs that get set after that runs.
1353 browser_process_->intranet_redirect_detector();
1354 GoogleSearchCounter::RegisterForNotifications();
1356 if (parsed_command_line().HasSwitch(switches::kEnableSdchOverHttps)) {
1357 net::SdchManager::EnableSecureSchemeSupport(true);
1358 } else {
1359 // Check SDCH field trial.
1360 const char kSdchFieldTrialName[] = "SDCH";
1361 const char kEnabledAllGroupName[] = "EnabledAll";
1362 const char kEnabledHttpOnlyGroupName[] = "EnabledHttpOnly";
1363 const char kDisabledAllGroupName[] = "DisabledAll";
1365 base::StringPiece sdch_trial_group =
1366 base::FieldTrialList::FindFullName(kSdchFieldTrialName);
1367 if (sdch_trial_group.starts_with(kEnabledAllGroupName)) {
1368 net::SdchManager::EnableSecureSchemeSupport(true);
1369 net::SdchManager::EnableSdchSupport(true);
1370 } else if (sdch_trial_group.starts_with(kEnabledHttpOnlyGroupName)) {
1371 net::SdchManager::EnableSdchSupport(true);
1372 } else if (sdch_trial_group.starts_with(kDisabledAllGroupName)) {
1373 net::SdchManager::EnableSdchSupport(false);
1377 if (parsed_command_line().HasSwitch(switches::kEnableWatchdog))
1378 InstallJankometer(parsed_command_line());
1380 #if defined(ENABLE_FULL_PRINTING) && !defined(OFFICIAL_BUILD)
1381 if (parsed_command_line().HasSwitch(switches::kDebugPrint)) {
1382 base::FilePath path =
1383 parsed_command_line().GetSwitchValuePath(switches::kDebugPrint);
1384 printing::PrintedDocument::set_debug_dump_path(path);
1386 #endif
1388 HandleTestParameters(parsed_command_line());
1389 browser_process_->metrics_service()->RecordBreakpadHasDebugger(
1390 base::debug::BeingDebugged());
1392 language_usage_metrics::LanguageUsageMetrics::RecordAcceptLanguages(
1393 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
1394 language_usage_metrics::LanguageUsageMetrics::RecordApplicationLanguage(
1395 browser_process_->GetApplicationLocale());
1397 // Start watching for hangs during startup. We disarm this hang detector when
1398 // ThreadWatcher takes over or when browser is shutdown or when
1399 // startup_watcher_ is deleted.
1400 MetricsService::SetExecutionPhase(MetricsService::STARTUP_TIMEBOMB_ARM,
1401 g_browser_process->local_state());
1402 startup_watcher_->Arm(base::TimeDelta::FromSeconds(300));
1404 // On mobile, need for clean shutdown arises only when the application comes
1405 // to foreground (i.e. MetricsService::OnAppEnterForeground is called).
1406 // http://crbug.com/179143
1407 #if !defined(OS_ANDROID)
1408 // Start watching for a hang.
1409 MetricsService::LogNeedForCleanShutdown(g_browser_process->local_state());
1410 #endif
1412 #if defined(ENABLE_FULL_PRINTING)
1413 // Create the instance of the cloud print proxy service so that it can launch
1414 // the service process if needed. This is needed because the service process
1415 // might have shutdown because an update was available.
1416 // TODO(torne): this should maybe be done with
1417 // BrowserContextKeyedServiceFactory::ServiceIsCreatedWithBrowserContext()
1418 // instead?
1419 CloudPrintProxyServiceFactory::GetForProfile(profile_);
1420 #endif
1422 // Start watching all browser threads for responsiveness.
1423 MetricsService::SetExecutionPhase(MetricsService::THREAD_WATCHER_START,
1424 g_browser_process->local_state());
1425 ThreadWatcherList::StartWatchingAll(parsed_command_line());
1427 #if defined(OS_ANDROID)
1428 ThreadWatcherAndroid::RegisterApplicationStatusListener();
1429 #endif
1431 #if !defined(DISABLE_NACL)
1432 BrowserThread::PostTask(
1433 BrowserThread::IO,
1434 FROM_HERE,
1435 base::Bind(nacl::NaClProcessHost::EarlyStartup));
1436 #endif
1438 // Make sure initial prefs are recorded
1439 PrefMetricsService::Factory::GetForProfile(profile_);
1441 PreBrowserStart();
1443 // Instantiate the notification UI manager, as this triggers a perf timer
1444 // used to measure startup time. TODO(stevenjb): Figure out what is actually
1445 // triggering the timer and call that explicitly in the approprate place.
1446 // http://crbug.com/105065.
1447 browser_process_->notification_ui_manager();
1449 if (!parsed_command_line().HasSwitch(switches::kDisableComponentUpdate))
1450 RegisterComponentsForUpdate(parsed_command_line());
1452 #if defined(OS_ANDROID)
1453 chrome_variations::VariationsService* variations_service =
1454 browser_process_->variations_service();
1455 if (variations_service) {
1456 variations_service->set_policy_pref_service(profile_->GetPrefs());
1457 variations_service->StartRepeatedVariationsSeedFetch();
1459 TranslateDownloadManager::RequestLanguageList(profile_->GetPrefs());
1461 #else
1462 // Most general initialization is behind us, but opening a
1463 // tab and/or session restore and such is still to be done.
1464 base::TimeTicks browser_open_start = base::TimeTicks::Now();
1466 // We are in regular browser boot sequence. Open initial tabs and enter the
1467 // main message loop.
1468 int result_code;
1469 #if defined(OS_CHROMEOS)
1470 // On ChromeOS multiple profiles doesn't apply, and will break if we load
1471 // them this early as the cryptohome hasn't yet been mounted (which happens
1472 // only once we log in.
1473 std::vector<Profile*> last_opened_profiles;
1474 #else
1475 std::vector<Profile*> last_opened_profiles =
1476 g_browser_process->profile_manager()->GetLastOpenedProfiles();
1477 #endif
1479 if (browser_creator_->Start(parsed_command_line(), base::FilePath(),
1480 profile_, last_opened_profiles, &result_code)) {
1481 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
1482 // Initialize autoupdate timer. Timer callback costs basically nothing
1483 // when browser is not in persistent mode, so it's OK to let it ride on
1484 // the main thread. This needs to be done here because we don't want
1485 // to start the timer when Chrome is run inside a test harness.
1486 browser_process_->StartAutoupdateTimer();
1487 #endif
1489 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1490 // On Linux, the running exe will be updated if an upgrade becomes
1491 // available while the browser is running. We need to save the last
1492 // modified time of the exe, so we can compare to determine if there is
1493 // an upgrade while the browser is kept alive by a persistent extension.
1494 upgrade_util::SaveLastModifiedTimeOfExe();
1495 #endif
1497 // Record now as the last successful chrome start.
1498 GoogleUpdateSettings::SetLastRunTime();
1500 #if defined(OS_MACOSX)
1501 // Call Recycle() here as late as possible, before going into the loop
1502 // because Start() will add things to it while creating the main window.
1503 if (parameters().autorelease_pool)
1504 parameters().autorelease_pool->Recycle();
1505 #endif
1507 base::TimeDelta delay = base::TimeTicks::Now() - browser_open_start;
1508 UMA_HISTOGRAM_LONG_TIMES_100("Startup.BrowserOpenTabs", delay);
1510 // If we're running tests (ui_task is non-null), then we don't want to
1511 // call RequestLanguageList or StartRepeatedVariationsSeedFetch or
1512 // RequestLanguageList
1513 if (parameters().ui_task == NULL) {
1514 // Request new variations seed information from server.
1515 chrome_variations::VariationsService* variations_service =
1516 browser_process_->variations_service();
1517 if (variations_service) {
1518 variations_service->StartRepeatedVariationsSeedFetch();
1520 #if defined(OS_WIN)
1521 variations_service->StartGoogleUpdateRegistrySync();
1522 #endif
1525 TranslateDownloadManager::RequestLanguageList(profile_->GetPrefs());
1528 run_message_loop_ = true;
1529 } else {
1530 run_message_loop_ = false;
1532 browser_creator_.reset();
1533 #endif // !defined(OS_ANDROID)
1535 performance_monitor::PerformanceMonitor::GetInstance()->Initialize();
1537 PostBrowserStart();
1539 chrome_prefs::SchedulePrefHashStoresUpdateCheck(profile_->GetPath());
1541 if (parameters().ui_task) {
1542 // We end the startup timer here if we have parameters to run, because we
1543 // never start to run the main loop (where we normally stop the timer).
1544 startup_timer_->SignalStartupComplete(
1545 performance_monitor::StartupTimer::STARTUP_TEST);
1546 parameters().ui_task->Run();
1547 delete parameters().ui_task;
1548 run_message_loop_ = false;
1550 #if defined(OS_ANDROID)
1551 // We never run the C++ main loop on Android, since the UI thread message
1552 // loop is controlled by the OS, so this is as close as we can get to
1553 // the start of the main loop
1554 if (result_code_ <= 0) {
1555 RecordBrowserStartupTime();
1557 #endif
1558 return result_code_;
1561 bool ChromeBrowserMainParts::MainMessageLoopRun(int* result_code) {
1562 TRACE_EVENT0("startup", "ChromeBrowserMainParts::MainMessageLoopRun");
1563 #if defined(OS_ANDROID)
1564 // Chrome on Android does not use default MessageLoop. It has its own
1565 // Android specific MessageLoop
1566 NOTREACHED();
1567 return true;
1568 #else
1569 // Set the result code set in PreMainMessageLoopRun or set above.
1570 *result_code = result_code_;
1571 if (!run_message_loop_)
1572 return true; // Don't run the default message loop.
1574 // These should be invoked as close to the start of the browser's
1575 // UI thread message loop as possible to get a stable measurement
1576 // across versions.
1577 RecordBrowserStartupTime();
1578 startup_timer_->SignalStartupComplete(
1579 performance_monitor::StartupTimer::STARTUP_NORMAL);
1581 DCHECK(base::MessageLoopForUI::IsCurrent());
1582 base::RunLoop run_loop;
1584 performance_monitor::PerformanceMonitor::GetInstance()->StartGatherCycle();
1586 MetricsService::SetExecutionPhase(MetricsService::MAIN_MESSAGE_LOOP_RUN,
1587 g_browser_process->local_state());
1588 run_loop.Run();
1590 return true;
1591 #endif
1594 void ChromeBrowserMainParts::PostMainMessageLoopRun() {
1595 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PostMainMessageLoopRun");
1596 #if defined(OS_ANDROID)
1597 // Chrome on Android does not use default MessageLoop. It has its own
1598 // Android specific MessageLoop
1599 NOTREACHED();
1600 #else
1602 // Start watching for jank during shutdown. It gets disarmed when
1603 // |shutdown_watcher_| object is destructed.
1604 MetricsService::SetExecutionPhase(MetricsService::SHUTDOWN_TIMEBOMB_ARM,
1605 g_browser_process->local_state());
1606 shutdown_watcher_->Arm(base::TimeDelta::FromSeconds(300));
1608 // Disarm the startup hang detector time bomb if it is still Arm'ed.
1609 startup_watcher_->Disarm();
1611 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1612 chrome_extra_parts_[i]->PostMainMessageLoopRun();
1614 // Some tests don't set parameters.ui_task, so they started translate
1615 // language fetch that was never completed so we need to cleanup here
1616 // otherwise it will be done by the destructor in a wrong thread.
1617 TranslateService::Shutdown(parameters().ui_task == NULL);
1619 if (notify_result_ == ProcessSingleton::PROCESS_NONE)
1620 process_singleton_->Cleanup();
1622 // Stop all tasks that might run on WatchDogThread.
1623 ThreadWatcherList::StopWatchingAll();
1625 browser_process_->metrics_service()->Stop();
1627 restart_last_session_ = browser_shutdown::ShutdownPreThreadsStop();
1628 browser_process_->StartTearDown();
1629 #endif
1632 void ChromeBrowserMainParts::PostDestroyThreads() {
1633 #if defined(OS_ANDROID)
1634 // On Android, there is no quit/exit. So the browser's main message loop will
1635 // not finish.
1636 NOTREACHED();
1637 #else
1638 browser_process_->PostDestroyThreads();
1639 // browser_shutdown takes care of deleting browser_process, so we need to
1640 // release it.
1641 ignore_result(browser_process_.release());
1642 browser_shutdown::ShutdownPostThreadsStop(restart_last_session_);
1643 master_prefs_.reset();
1644 process_singleton_.reset();
1646 // We need to do this check as late as possible, but due to modularity, this
1647 // may be the last point in Chrome. This would be more effective if done at
1648 // a higher level on the stack, so that it is impossible for an early return
1649 // to bypass this code. Perhaps we need a *final* hook that is called on all
1650 // paths from content/browser/browser_main.
1651 CHECK(MetricsService::UmaMetricsProperlyShutdown());
1653 #if defined(OS_CHROMEOS)
1654 chromeos::CrosSettings::Shutdown();
1655 #endif
1656 #endif
1659 // Public members:
1661 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) {
1662 chrome_extra_parts_.push_back(parts);