| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chrome_browser_main.h" | 5 #include "chrome/browser/chrome_browser_main.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 | 565 |
| 566 // This will be called after the command-line has been mutated by about:flags | 566 // This will be called after the command-line has been mutated by about:flags |
| 567 void ChromeBrowserMainParts::SetupMetricsAndFieldTrials() { | 567 void ChromeBrowserMainParts::SetupMetricsAndFieldTrials() { |
| 568 TRACE_EVENT0("startup", "ChromeBrowserMainParts::SetupMetricsAndFieldTrials"); | 568 TRACE_EVENT0("startup", "ChromeBrowserMainParts::SetupMetricsAndFieldTrials"); |
| 569 // Must initialize metrics after labs have been converted into switches, | 569 // Must initialize metrics after labs have been converted into switches, |
| 570 // but before field trials are set up (so that client ID is available for | 570 // but before field trials are set up (so that client ID is available for |
| 571 // one-time randomized field trials). | 571 // one-time randomized field trials). |
| 572 | 572 |
| 573 // Initialize FieldTrialList to support FieldTrials that use one-time | 573 // Initialize FieldTrialList to support FieldTrials that use one-time |
| 574 // randomization. | 574 // randomization. |
| 575 MetricsService* metrics = browser_process_->metrics_service(); | 575 metrics::MetricsService* metrics = browser_process_->metrics_service(); |
| 576 field_trial_list_.reset( | 576 field_trial_list_.reset( |
| 577 new base::FieldTrialList(metrics->CreateEntropyProvider().release())); | 577 new base::FieldTrialList(metrics->CreateEntropyProvider().release())); |
| 578 | 578 |
| 579 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 579 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 580 if (command_line->HasSwitch(switches::kEnableBenchmarking)) | 580 if (command_line->HasSwitch(switches::kEnableBenchmarking)) |
| 581 base::FieldTrial::EnableBenchmarking(); | 581 base::FieldTrial::EnableBenchmarking(); |
| 582 | 582 |
| 583 // Ensure any field trials specified on the command line are initialized. | 583 // Ensure any field trials specified on the command line are initialized. |
| 584 if (command_line->HasSwitch(switches::kForceFieldTrials)) { | 584 if (command_line->HasSwitch(switches::kForceFieldTrials)) { |
| 585 std::set<std::string> unforceable_field_trials; | 585 std::set<std::string> unforceable_field_trials; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 field_trial_synchronizer_ = new FieldTrialSynchronizer(); | 622 field_trial_synchronizer_ = new FieldTrialSynchronizer(); |
| 623 | 623 |
| 624 // Now that field trials have been created, initializes metrics recording. | 624 // Now that field trials have been created, initializes metrics recording. |
| 625 metrics->InitializeMetricsRecordingState(); | 625 metrics->InitializeMetricsRecordingState(); |
| 626 } | 626 } |
| 627 | 627 |
| 628 // ChromeBrowserMainParts: |SetupMetricsAndFieldTrials()| related -------------- | 628 // ChromeBrowserMainParts: |SetupMetricsAndFieldTrials()| related -------------- |
| 629 | 629 |
| 630 void ChromeBrowserMainParts::StartMetricsRecording() { | 630 void ChromeBrowserMainParts::StartMetricsRecording() { |
| 631 TRACE_EVENT0("startup", "ChromeBrowserMainParts::StartMetricsRecording"); | 631 TRACE_EVENT0("startup", "ChromeBrowserMainParts::StartMetricsRecording"); |
| 632 MetricsService* metrics = g_browser_process->metrics_service(); | 632 metrics::MetricsService* metrics = g_browser_process->metrics_service(); |
| 633 | 633 |
| 634 const bool only_do_metrics_recording = | 634 const bool only_do_metrics_recording = |
| 635 parsed_command_line_.HasSwitch(switches::kMetricsRecordingOnly) || | 635 parsed_command_line_.HasSwitch(switches::kMetricsRecordingOnly) || |
| 636 parsed_command_line_.HasSwitch(switches::kEnableBenchmarking); | 636 parsed_command_line_.HasSwitch(switches::kEnableBenchmarking); |
| 637 if (only_do_metrics_recording) { | 637 if (only_do_metrics_recording) { |
| 638 // If we're testing then we don't care what the user preference is, we turn | 638 // If we're testing then we don't care what the user preference is, we turn |
| 639 // on recording, but not reporting, otherwise tests fail. | 639 // on recording, but not reporting, otherwise tests fail. |
| 640 metrics->StartRecordingForTests(); | 640 metrics->StartRecordingForTests(); |
| 641 return; | 641 return; |
| 642 } | 642 } |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1227 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 1227 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 1228 if (sxs_linux::ShouldMigrateUserDataDir()) | 1228 if (sxs_linux::ShouldMigrateUserDataDir()) |
| 1229 return sxs_linux::MigrateUserDataDir(); | 1229 return sxs_linux::MigrateUserDataDir(); |
| 1230 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) | 1230 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 1231 | 1231 |
| 1232 // Desktop construction occurs here, (required before profile creation). | 1232 // Desktop construction occurs here, (required before profile creation). |
| 1233 PreProfileInit(); | 1233 PreProfileInit(); |
| 1234 | 1234 |
| 1235 // Profile creation ---------------------------------------------------------- | 1235 // Profile creation ---------------------------------------------------------- |
| 1236 | 1236 |
| 1237 MetricsService::SetExecutionPhase(MetricsService::CREATE_PROFILE, | 1237 metrics::MetricsService::SetExecutionPhase( |
| 1238 g_browser_process->local_state()); | 1238 metrics::MetricsService::CREATE_PROFILE, |
| 1239 g_browser_process->local_state()); |
| 1239 profile_ = CreatePrimaryProfile(parameters(), | 1240 profile_ = CreatePrimaryProfile(parameters(), |
| 1240 user_data_dir_, | 1241 user_data_dir_, |
| 1241 parsed_command_line()); | 1242 parsed_command_line()); |
| 1242 if (!profile_) | 1243 if (!profile_) |
| 1243 return content::RESULT_CODE_NORMAL_EXIT; | 1244 return content::RESULT_CODE_NORMAL_EXIT; |
| 1244 | 1245 |
| 1245 #if !defined(OS_ANDROID) | 1246 #if !defined(OS_ANDROID) |
| 1246 // The first run sentinel must be created after the process singleton was | 1247 // The first run sentinel must be created after the process singleton was |
| 1247 // grabbed and no early return paths were otherwise hit above. | 1248 // grabbed and no early return paths were otherwise hit above. |
| 1248 first_run::CreateSentinelIfNeeded(); | 1249 first_run::CreateSentinelIfNeeded(); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1399 base::debug::BeingDebugged()); | 1400 base::debug::BeingDebugged()); |
| 1400 | 1401 |
| 1401 language_usage_metrics::LanguageUsageMetrics::RecordAcceptLanguages( | 1402 language_usage_metrics::LanguageUsageMetrics::RecordAcceptLanguages( |
| 1402 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); | 1403 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); |
| 1403 language_usage_metrics::LanguageUsageMetrics::RecordApplicationLanguage( | 1404 language_usage_metrics::LanguageUsageMetrics::RecordApplicationLanguage( |
| 1404 browser_process_->GetApplicationLocale()); | 1405 browser_process_->GetApplicationLocale()); |
| 1405 | 1406 |
| 1406 // Start watching for hangs during startup. We disarm this hang detector when | 1407 // Start watching for hangs during startup. We disarm this hang detector when |
| 1407 // ThreadWatcher takes over or when browser is shutdown or when | 1408 // ThreadWatcher takes over or when browser is shutdown or when |
| 1408 // startup_watcher_ is deleted. | 1409 // startup_watcher_ is deleted. |
| 1409 MetricsService::SetExecutionPhase(MetricsService::STARTUP_TIMEBOMB_ARM, | 1410 metrics::MetricsService::SetExecutionPhase( |
| 1410 g_browser_process->local_state()); | 1411 metrics::MetricsService::STARTUP_TIMEBOMB_ARM, |
| 1412 g_browser_process->local_state()); |
| 1411 startup_watcher_->Arm(base::TimeDelta::FromSeconds(300)); | 1413 startup_watcher_->Arm(base::TimeDelta::FromSeconds(300)); |
| 1412 | 1414 |
| 1413 // On mobile, need for clean shutdown arises only when the application comes | 1415 // On mobile, need for clean shutdown arises only when the application comes |
| 1414 // to foreground (i.e. MetricsService::OnAppEnterForeground is called). | 1416 // to foreground (i.e. MetricsService::OnAppEnterForeground is called). |
| 1415 // http://crbug.com/179143 | 1417 // http://crbug.com/179143 |
| 1416 #if !defined(OS_ANDROID) | 1418 #if !defined(OS_ANDROID) |
| 1417 // Start watching for a hang. | 1419 // Start watching for a hang. |
| 1418 MetricsService::LogNeedForCleanShutdown(g_browser_process->local_state()); | 1420 metrics::MetricsService::LogNeedForCleanShutdown( |
| 1421 g_browser_process->local_state()); |
| 1419 #endif | 1422 #endif |
| 1420 | 1423 |
| 1421 #if defined(ENABLE_FULL_PRINTING) | 1424 #if defined(ENABLE_FULL_PRINTING) |
| 1422 // Create the instance of the cloud print proxy service so that it can launch | 1425 // Create the instance of the cloud print proxy service so that it can launch |
| 1423 // the service process if needed. This is needed because the service process | 1426 // the service process if needed. This is needed because the service process |
| 1424 // might have shutdown because an update was available. | 1427 // might have shutdown because an update was available. |
| 1425 // TODO(torne): this should maybe be done with | 1428 // TODO(torne): this should maybe be done with |
| 1426 // BrowserContextKeyedServiceFactory::ServiceIsCreatedWithBrowserContext() | 1429 // BrowserContextKeyedServiceFactory::ServiceIsCreatedWithBrowserContext() |
| 1427 // instead? | 1430 // instead? |
| 1428 CloudPrintProxyServiceFactory::GetForProfile(profile_); | 1431 CloudPrintProxyServiceFactory::GetForProfile(profile_); |
| 1429 #endif | 1432 #endif |
| 1430 | 1433 |
| 1431 // Start watching all browser threads for responsiveness. | 1434 // Start watching all browser threads for responsiveness. |
| 1432 MetricsService::SetExecutionPhase(MetricsService::THREAD_WATCHER_START, | 1435 metrics::MetricsService::SetExecutionPhase( |
| 1433 g_browser_process->local_state()); | 1436 metrics::MetricsService::THREAD_WATCHER_START, |
| 1437 g_browser_process->local_state()); |
| 1434 ThreadWatcherList::StartWatchingAll(parsed_command_line()); | 1438 ThreadWatcherList::StartWatchingAll(parsed_command_line()); |
| 1435 | 1439 |
| 1436 #if defined(OS_ANDROID) | 1440 #if defined(OS_ANDROID) |
| 1437 ThreadWatcherAndroid::RegisterApplicationStatusListener(); | 1441 ThreadWatcherAndroid::RegisterApplicationStatusListener(); |
| 1438 #endif | 1442 #endif |
| 1439 | 1443 |
| 1440 #if !defined(DISABLE_NACL) | 1444 #if !defined(DISABLE_NACL) |
| 1441 BrowserThread::PostTask( | 1445 BrowserThread::PostTask( |
| 1442 BrowserThread::IO, | 1446 BrowserThread::IO, |
| 1443 FROM_HERE, | 1447 FROM_HERE, |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1585 // across versions. | 1589 // across versions. |
| 1586 RecordBrowserStartupTime(); | 1590 RecordBrowserStartupTime(); |
| 1587 startup_timer_->SignalStartupComplete( | 1591 startup_timer_->SignalStartupComplete( |
| 1588 performance_monitor::StartupTimer::STARTUP_NORMAL); | 1592 performance_monitor::StartupTimer::STARTUP_NORMAL); |
| 1589 | 1593 |
| 1590 DCHECK(base::MessageLoopForUI::IsCurrent()); | 1594 DCHECK(base::MessageLoopForUI::IsCurrent()); |
| 1591 base::RunLoop run_loop; | 1595 base::RunLoop run_loop; |
| 1592 | 1596 |
| 1593 performance_monitor::PerformanceMonitor::GetInstance()->StartGatherCycle(); | 1597 performance_monitor::PerformanceMonitor::GetInstance()->StartGatherCycle(); |
| 1594 | 1598 |
| 1595 MetricsService::SetExecutionPhase(MetricsService::MAIN_MESSAGE_LOOP_RUN, | 1599 metrics::MetricsService::SetExecutionPhase( |
| 1596 g_browser_process->local_state()); | 1600 metrics::MetricsService::MAIN_MESSAGE_LOOP_RUN, |
| 1601 g_browser_process->local_state()); |
| 1597 run_loop.Run(); | 1602 run_loop.Run(); |
| 1598 | 1603 |
| 1599 return true; | 1604 return true; |
| 1600 #endif | 1605 #endif |
| 1601 } | 1606 } |
| 1602 | 1607 |
| 1603 void ChromeBrowserMainParts::PostMainMessageLoopRun() { | 1608 void ChromeBrowserMainParts::PostMainMessageLoopRun() { |
| 1604 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PostMainMessageLoopRun"); | 1609 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PostMainMessageLoopRun"); |
| 1605 #if defined(OS_ANDROID) | 1610 #if defined(OS_ANDROID) |
| 1606 // Chrome on Android does not use default MessageLoop. It has its own | 1611 // Chrome on Android does not use default MessageLoop. It has its own |
| 1607 // Android specific MessageLoop | 1612 // Android specific MessageLoop |
| 1608 NOTREACHED(); | 1613 NOTREACHED(); |
| 1609 #else | 1614 #else |
| 1610 | 1615 |
| 1611 // Start watching for jank during shutdown. It gets disarmed when | 1616 // Start watching for jank during shutdown. It gets disarmed when |
| 1612 // |shutdown_watcher_| object is destructed. | 1617 // |shutdown_watcher_| object is destructed. |
| 1613 MetricsService::SetExecutionPhase(MetricsService::SHUTDOWN_TIMEBOMB_ARM, | 1618 metrics::MetricsService::SetExecutionPhase( |
| 1614 g_browser_process->local_state()); | 1619 metrics::MetricsService::SHUTDOWN_TIMEBOMB_ARM, |
| 1620 g_browser_process->local_state()); |
| 1615 shutdown_watcher_->Arm(base::TimeDelta::FromSeconds(300)); | 1621 shutdown_watcher_->Arm(base::TimeDelta::FromSeconds(300)); |
| 1616 | 1622 |
| 1617 // Disarm the startup hang detector time bomb if it is still Arm'ed. | 1623 // Disarm the startup hang detector time bomb if it is still Arm'ed. |
| 1618 startup_watcher_->Disarm(); | 1624 startup_watcher_->Disarm(); |
| 1619 | 1625 |
| 1620 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) | 1626 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 1621 chrome_extra_parts_[i]->PostMainMessageLoopRun(); | 1627 chrome_extra_parts_[i]->PostMainMessageLoopRun(); |
| 1622 | 1628 |
| 1623 // Some tests don't set parameters.ui_task, so they started translate | 1629 // Some tests don't set parameters.ui_task, so they started translate |
| 1624 // language fetch that was never completed so we need to cleanup here | 1630 // language fetch that was never completed so we need to cleanup here |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1650 ignore_result(browser_process_.release()); | 1656 ignore_result(browser_process_.release()); |
| 1651 browser_shutdown::ShutdownPostThreadsStop(restart_last_session_); | 1657 browser_shutdown::ShutdownPostThreadsStop(restart_last_session_); |
| 1652 master_prefs_.reset(); | 1658 master_prefs_.reset(); |
| 1653 process_singleton_.reset(); | 1659 process_singleton_.reset(); |
| 1654 | 1660 |
| 1655 // We need to do this check as late as possible, but due to modularity, this | 1661 // We need to do this check as late as possible, but due to modularity, this |
| 1656 // may be the last point in Chrome. This would be more effective if done at | 1662 // may be the last point in Chrome. This would be more effective if done at |
| 1657 // a higher level on the stack, so that it is impossible for an early return | 1663 // a higher level on the stack, so that it is impossible for an early return |
| 1658 // to bypass this code. Perhaps we need a *final* hook that is called on all | 1664 // to bypass this code. Perhaps we need a *final* hook that is called on all |
| 1659 // paths from content/browser/browser_main. | 1665 // paths from content/browser/browser_main. |
| 1660 CHECK(MetricsService::UmaMetricsProperlyShutdown()); | 1666 CHECK(metrics::MetricsService::UmaMetricsProperlyShutdown()); |
| 1661 | 1667 |
| 1662 #if defined(OS_CHROMEOS) | 1668 #if defined(OS_CHROMEOS) |
| 1663 chromeos::CrosSettings::Shutdown(); | 1669 chromeos::CrosSettings::Shutdown(); |
| 1664 #endif | 1670 #endif |
| 1665 #endif | 1671 #endif |
| 1666 } | 1672 } |
| 1667 | 1673 |
| 1668 // Public members: | 1674 // Public members: |
| 1669 | 1675 |
| 1670 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { | 1676 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { |
| 1671 chrome_extra_parts_.push_back(parts); | 1677 chrome_extra_parts_.push_back(parts); |
| 1672 } | 1678 } |
| OLD | NEW |