| 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 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1092 BrowserThread::PostDelayedTask( | 1092 BrowserThread::PostDelayedTask( |
| 1093 BrowserThread::UI, | 1093 BrowserThread::UI, |
| 1094 FROM_HERE, | 1094 FROM_HERE, |
| 1095 base::Bind(&WebRtcLogUtil::DeleteOldWebRtcLogFilesForAllProfiles), | 1095 base::Bind(&WebRtcLogUtil::DeleteOldWebRtcLogFilesForAllProfiles), |
| 1096 base::TimeDelta::FromMinutes(1)); | 1096 base::TimeDelta::FromMinutes(1)); |
| 1097 #endif | 1097 #endif |
| 1098 } | 1098 } |
| 1099 | 1099 |
| 1100 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { | 1100 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { |
| 1101 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreMainMessageLoopRunImpl"); | 1101 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreMainMessageLoopRunImpl"); |
| 1102 VLOG(2) << "PreMainMessageLoopRunImpl : BEGIN"; |
| 1102 // Android updates the metrics service dynamically depending on whether the | 1103 // Android updates the metrics service dynamically depending on whether the |
| 1103 // application is in the foreground or not. Do not start here. | 1104 // application is in the foreground or not. Do not start here. |
| 1104 #if !defined(OS_ANDROID) | 1105 #if !defined(OS_ANDROID) |
| 1105 // Now that the file thread has been started, start recording. | 1106 // Now that the file thread has been started, start recording. |
| 1106 StartMetricsRecording(); | 1107 StartMetricsRecording(); |
| 1107 #endif | 1108 #endif |
| 1108 | 1109 |
| 1109 if (!base::debug::BeingDebugged()) { | 1110 if (!base::debug::BeingDebugged()) { |
| 1110 // Create watchdog thread after creating all other threads because it will | 1111 // Create watchdog thread after creating all other threads because it will |
| 1111 // watch the other threads and they must be running. | 1112 // watch the other threads and they must be running. |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1300 // NaClBrowserDelegateImpl is accessed inside PostProfileInit(). | 1301 // NaClBrowserDelegateImpl is accessed inside PostProfileInit(). |
| 1301 // So make sure to create it before that. | 1302 // So make sure to create it before that. |
| 1302 #if !defined(DISABLE_NACL) | 1303 #if !defined(DISABLE_NACL) |
| 1303 NaClBrowserDelegateImpl* delegate = | 1304 NaClBrowserDelegateImpl* delegate = |
| 1304 new NaClBrowserDelegateImpl(browser_process_->profile_manager()); | 1305 new NaClBrowserDelegateImpl(browser_process_->profile_manager()); |
| 1305 nacl::NaClBrowser::SetDelegate(delegate); | 1306 nacl::NaClBrowser::SetDelegate(delegate); |
| 1306 #endif | 1307 #endif |
| 1307 | 1308 |
| 1308 // TODO(stevenjb): Move WIN and MACOSX specific code to appropriate Parts. | 1309 // TODO(stevenjb): Move WIN and MACOSX specific code to appropriate Parts. |
| 1309 // (requires supporting early exit). | 1310 // (requires supporting early exit). |
| 1311 VLOG(2) << "PreMainMessageLoopRunImpl : PostProfileInit"; |
| 1310 PostProfileInit(); | 1312 PostProfileInit(); |
| 1311 | 1313 |
| 1312 // Retrieve cached GL strings from local state and use them for GPU | 1314 // Retrieve cached GL strings from local state and use them for GPU |
| 1313 // blacklist decisions. | 1315 // blacklist decisions. |
| 1314 if (g_browser_process->gl_string_manager()) | 1316 if (g_browser_process->gl_string_manager()) |
| 1315 g_browser_process->gl_string_manager()->Initialize(); | 1317 g_browser_process->gl_string_manager()->Initialize(); |
| 1316 | 1318 |
| 1317 // Create an instance of GpuModeManager to watch gpu mode pref change. | 1319 // Create an instance of GpuModeManager to watch gpu mode pref change. |
| 1318 g_browser_process->gpu_mode_manager(); | 1320 g_browser_process->gpu_mode_manager(); |
| 1319 | 1321 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1419 } | 1421 } |
| 1420 | 1422 |
| 1421 #if defined(ENABLE_FULL_PRINTING) && !defined(OFFICIAL_BUILD) | 1423 #if defined(ENABLE_FULL_PRINTING) && !defined(OFFICIAL_BUILD) |
| 1422 if (parsed_command_line().HasSwitch(switches::kDebugPrint)) { | 1424 if (parsed_command_line().HasSwitch(switches::kDebugPrint)) { |
| 1423 base::FilePath path = | 1425 base::FilePath path = |
| 1424 parsed_command_line().GetSwitchValuePath(switches::kDebugPrint); | 1426 parsed_command_line().GetSwitchValuePath(switches::kDebugPrint); |
| 1425 printing::PrintedDocument::set_debug_dump_path(path); | 1427 printing::PrintedDocument::set_debug_dump_path(path); |
| 1426 } | 1428 } |
| 1427 #endif | 1429 #endif |
| 1428 | 1430 |
| 1431 VLOG(2) << "PreMainMessageLoopRunImpl : HandleTestParameters"; |
| 1429 HandleTestParameters(parsed_command_line()); | 1432 HandleTestParameters(parsed_command_line()); |
| 1430 browser_process_->metrics_service()->RecordBreakpadHasDebugger( | 1433 browser_process_->metrics_service()->RecordBreakpadHasDebugger( |
| 1431 base::debug::BeingDebugged()); | 1434 base::debug::BeingDebugged()); |
| 1432 | 1435 |
| 1433 language_usage_metrics::LanguageUsageMetrics::RecordAcceptLanguages( | 1436 language_usage_metrics::LanguageUsageMetrics::RecordAcceptLanguages( |
| 1434 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); | 1437 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); |
| 1435 language_usage_metrics::LanguageUsageMetrics::RecordApplicationLanguage( | 1438 language_usage_metrics::LanguageUsageMetrics::RecordApplicationLanguage( |
| 1436 browser_process_->GetApplicationLocale()); | 1439 browser_process_->GetApplicationLocale()); |
| 1437 | 1440 |
| 1438 // Start watching for hangs during startup. We disarm this hang detector when | 1441 // Start watching for hangs during startup. We disarm this hang detector when |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1474 #if !defined(DISABLE_NACL) | 1477 #if !defined(DISABLE_NACL) |
| 1475 BrowserThread::PostTask( | 1478 BrowserThread::PostTask( |
| 1476 BrowserThread::IO, | 1479 BrowserThread::IO, |
| 1477 FROM_HERE, | 1480 FROM_HERE, |
| 1478 base::Bind(nacl::NaClProcessHost::EarlyStartup)); | 1481 base::Bind(nacl::NaClProcessHost::EarlyStartup)); |
| 1479 #endif | 1482 #endif |
| 1480 | 1483 |
| 1481 // Make sure initial prefs are recorded | 1484 // Make sure initial prefs are recorded |
| 1482 PrefMetricsService::Factory::GetForProfile(profile_); | 1485 PrefMetricsService::Factory::GetForProfile(profile_); |
| 1483 | 1486 |
| 1487 VLOG(2) << "PreMainMessageLoopRunImpl : PreBrowserStart"; |
| 1484 PreBrowserStart(); | 1488 PreBrowserStart(); |
| 1485 | 1489 |
| 1486 // Instantiate the notification UI manager, as this triggers a perf timer | 1490 // Instantiate the notification UI manager, as this triggers a perf timer |
| 1487 // used to measure startup time. TODO(stevenjb): Figure out what is actually | 1491 // used to measure startup time. TODO(stevenjb): Figure out what is actually |
| 1488 // triggering the timer and call that explicitly in the approprate place. | 1492 // triggering the timer and call that explicitly in the approprate place. |
| 1489 // http://crbug.com/105065. | 1493 // http://crbug.com/105065. |
| 1490 browser_process_->notification_ui_manager(); | 1494 browser_process_->notification_ui_manager(); |
| 1491 | 1495 |
| 1492 if (!parsed_command_line().HasSwitch(switches::kDisableComponentUpdate)) | 1496 if (!parsed_command_line().HasSwitch(switches::kDisableComponentUpdate)) |
| 1493 RegisterComponentsForUpdate(); | 1497 RegisterComponentsForUpdate(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1513 #if defined(OS_CHROMEOS) | 1517 #if defined(OS_CHROMEOS) |
| 1514 // On ChromeOS multiple profiles doesn't apply, and will break if we load | 1518 // On ChromeOS multiple profiles doesn't apply, and will break if we load |
| 1515 // them this early as the cryptohome hasn't yet been mounted (which happens | 1519 // them this early as the cryptohome hasn't yet been mounted (which happens |
| 1516 // only once we log in. | 1520 // only once we log in. |
| 1517 std::vector<Profile*> last_opened_profiles; | 1521 std::vector<Profile*> last_opened_profiles; |
| 1518 #else | 1522 #else |
| 1519 std::vector<Profile*> last_opened_profiles = | 1523 std::vector<Profile*> last_opened_profiles = |
| 1520 g_browser_process->profile_manager()->GetLastOpenedProfiles(); | 1524 g_browser_process->profile_manager()->GetLastOpenedProfiles(); |
| 1521 #endif | 1525 #endif |
| 1522 | 1526 |
| 1527 VLOG(2) << "PreMainMessageLoopRunImpl : browser_creator_->Start"; |
| 1523 if (browser_creator_->Start(parsed_command_line(), base::FilePath(), | 1528 if (browser_creator_->Start(parsed_command_line(), base::FilePath(), |
| 1524 profile_, last_opened_profiles, &result_code)) { | 1529 profile_, last_opened_profiles, &result_code)) { |
| 1525 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) | 1530 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
| 1526 // Initialize autoupdate timer. Timer callback costs basically nothing | 1531 // Initialize autoupdate timer. Timer callback costs basically nothing |
| 1527 // when browser is not in persistent mode, so it's OK to let it ride on | 1532 // when browser is not in persistent mode, so it's OK to let it ride on |
| 1528 // the main thread. This needs to be done here because we don't want | 1533 // the main thread. This needs to be done here because we don't want |
| 1529 // to start the timer when Chrome is run inside a test harness. | 1534 // to start the timer when Chrome is run inside a test harness. |
| 1530 browser_process_->StartAutoupdateTimer(); | 1535 browser_process_->StartAutoupdateTimer(); |
| 1531 #endif | 1536 #endif |
| 1532 | 1537 |
| 1533 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 1538 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 1534 // On Linux, the running exe will be updated if an upgrade becomes | 1539 // On Linux, the running exe will be updated if an upgrade becomes |
| 1535 // available while the browser is running. We need to save the last | 1540 // available while the browser is running. We need to save the last |
| 1536 // modified time of the exe, so we can compare to determine if there is | 1541 // modified time of the exe, so we can compare to determine if there is |
| 1537 // an upgrade while the browser is kept alive by a persistent extension. | 1542 // an upgrade while the browser is kept alive by a persistent extension. |
| 1538 upgrade_util::SaveLastModifiedTimeOfExe(); | 1543 upgrade_util::SaveLastModifiedTimeOfExe(); |
| 1539 #endif | 1544 #endif |
| 1540 | 1545 |
| 1546 VLOG(2) << "PreMainMessageLoopRunImpl : SetLastRunTime"; |
| 1541 // Record now as the last successful chrome start. | 1547 // Record now as the last successful chrome start. |
| 1542 GoogleUpdateSettings::SetLastRunTime(); | 1548 GoogleUpdateSettings::SetLastRunTime(); |
| 1543 | 1549 |
| 1544 #if defined(OS_MACOSX) | 1550 #if defined(OS_MACOSX) |
| 1545 // Call Recycle() here as late as possible, before going into the loop | 1551 // Call Recycle() here as late as possible, before going into the loop |
| 1546 // because Start() will add things to it while creating the main window. | 1552 // because Start() will add things to it while creating the main window. |
| 1547 if (parameters().autorelease_pool) | 1553 if (parameters().autorelease_pool) |
| 1548 parameters().autorelease_pool->Recycle(); | 1554 parameters().autorelease_pool->Recycle(); |
| 1549 #endif | 1555 #endif |
| 1550 | 1556 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1567 } | 1573 } |
| 1568 | 1574 |
| 1569 translate::TranslateDownloadManager::RequestLanguageList( | 1575 translate::TranslateDownloadManager::RequestLanguageList( |
| 1570 profile_->GetPrefs()); | 1576 profile_->GetPrefs()); |
| 1571 } | 1577 } |
| 1572 | 1578 |
| 1573 run_message_loop_ = true; | 1579 run_message_loop_ = true; |
| 1574 } else { | 1580 } else { |
| 1575 run_message_loop_ = false; | 1581 run_message_loop_ = false; |
| 1576 } | 1582 } |
| 1583 VLOG(2) << "PreMainMessageLoopRunImpl : browser_creator_.reset()"; |
| 1577 browser_creator_.reset(); | 1584 browser_creator_.reset(); |
| 1578 | 1585 |
| 1579 process_power_collector_.reset(new ProcessPowerCollector); | 1586 process_power_collector_.reset(new ProcessPowerCollector); |
| 1580 process_power_collector_->Initialize(); | 1587 process_power_collector_->Initialize(); |
| 1581 #endif // !defined(OS_ANDROID) | 1588 #endif // !defined(OS_ANDROID) |
| 1582 | 1589 |
| 1590 VLOG(2) << "PreMainMessageLoopRunImpl : PostBrowserStart"; |
| 1583 PostBrowserStart(); | 1591 PostBrowserStart(); |
| 1584 | 1592 |
| 1585 if (parameters().ui_task) { | 1593 if (parameters().ui_task) { |
| 1586 parameters().ui_task->Run(); | 1594 parameters().ui_task->Run(); |
| 1587 delete parameters().ui_task; | 1595 delete parameters().ui_task; |
| 1588 run_message_loop_ = false; | 1596 run_message_loop_ = false; |
| 1589 } | 1597 } |
| 1590 #if defined(OS_ANDROID) | 1598 #if defined(OS_ANDROID) |
| 1591 // We never run the C++ main loop on Android, since the UI thread message | 1599 // We never run the C++ main loop on Android, since the UI thread message |
| 1592 // loop is controlled by the OS, so this is as close as we can get to | 1600 // loop is controlled by the OS, so this is as close as we can get to |
| 1593 // the start of the main loop | 1601 // the start of the main loop |
| 1594 if (result_code_ <= 0) { | 1602 if (result_code_ <= 0) { |
| 1595 RecordBrowserStartupTime(); | 1603 RecordBrowserStartupTime(); |
| 1596 } | 1604 } |
| 1597 #endif | 1605 #endif |
| 1606 VLOG(2) << "PreMainMessageLoopRunImpl : END"; |
| 1598 return result_code_; | 1607 return result_code_; |
| 1599 } | 1608 } |
| 1600 | 1609 |
| 1601 bool ChromeBrowserMainParts::MainMessageLoopRun(int* result_code) { | 1610 bool ChromeBrowserMainParts::MainMessageLoopRun(int* result_code) { |
| 1602 TRACE_EVENT0("startup", "ChromeBrowserMainParts::MainMessageLoopRun"); | 1611 TRACE_EVENT0("startup", "ChromeBrowserMainParts::MainMessageLoopRun"); |
| 1612 VLOG(2) << "MainMessageLoopRun : BEGIN"; |
| 1603 #if defined(OS_ANDROID) | 1613 #if defined(OS_ANDROID) |
| 1604 // Chrome on Android does not use default MessageLoop. It has its own | 1614 // Chrome on Android does not use default MessageLoop. It has its own |
| 1605 // Android specific MessageLoop | 1615 // Android specific MessageLoop |
| 1606 NOTREACHED(); | 1616 NOTREACHED(); |
| 1607 return true; | 1617 return true; |
| 1608 #else | 1618 #else |
| 1609 // Set the result code set in PreMainMessageLoopRun or set above. | 1619 // Set the result code set in PreMainMessageLoopRun or set above. |
| 1610 *result_code = result_code_; | 1620 *result_code = result_code_; |
| 1611 if (!run_message_loop_) | 1621 if (!run_message_loop_) |
| 1612 return true; // Don't run the default message loop. | 1622 return true; // Don't run the default message loop. |
| 1613 | 1623 |
| 1614 // These should be invoked as close to the start of the browser's | 1624 // These should be invoked as close to the start of the browser's |
| 1615 // UI thread message loop as possible to get a stable measurement | 1625 // UI thread message loop as possible to get a stable measurement |
| 1616 // across versions. | 1626 // across versions. |
| 1617 RecordBrowserStartupTime(); | 1627 RecordBrowserStartupTime(); |
| 1618 | 1628 |
| 1629 VLOG(2) << "MainMessageLoopRun : RunLoop"; |
| 1619 DCHECK(base::MessageLoopForUI::IsCurrent()); | 1630 DCHECK(base::MessageLoopForUI::IsCurrent()); |
| 1620 base::RunLoop run_loop; | 1631 base::RunLoop run_loop; |
| 1621 | 1632 |
| 1622 performance_monitor::PerformanceMonitor::GetInstance()->StartGatherCycle(); | 1633 performance_monitor::PerformanceMonitor::GetInstance()->StartGatherCycle(); |
| 1623 | 1634 |
| 1624 metrics::MetricsService::SetExecutionPhase( | 1635 metrics::MetricsService::SetExecutionPhase( |
| 1625 metrics::MetricsService::MAIN_MESSAGE_LOOP_RUN, | 1636 metrics::MetricsService::MAIN_MESSAGE_LOOP_RUN, |
| 1626 g_browser_process->local_state()); | 1637 g_browser_process->local_state()); |
| 1627 run_loop.Run(); | 1638 run_loop.Run(); |
| 1628 | 1639 |
| 1640 VLOG(2) << "MainMessageLoopRun : END"; |
| 1629 return true; | 1641 return true; |
| 1630 #endif | 1642 #endif |
| 1631 } | 1643 } |
| 1632 | 1644 |
| 1633 void ChromeBrowserMainParts::PostMainMessageLoopRun() { | 1645 void ChromeBrowserMainParts::PostMainMessageLoopRun() { |
| 1634 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PostMainMessageLoopRun"); | 1646 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PostMainMessageLoopRun"); |
| 1635 #if defined(OS_ANDROID) | 1647 #if defined(OS_ANDROID) |
| 1636 // Chrome on Android does not use default MessageLoop. It has its own | 1648 // Chrome on Android does not use default MessageLoop. It has its own |
| 1637 // Android specific MessageLoop | 1649 // Android specific MessageLoop |
| 1638 NOTREACHED(); | 1650 NOTREACHED(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1698 chromeos::CrosSettings::Shutdown(); | 1710 chromeos::CrosSettings::Shutdown(); |
| 1699 #endif | 1711 #endif |
| 1700 #endif | 1712 #endif |
| 1701 } | 1713 } |
| 1702 | 1714 |
| 1703 // Public members: | 1715 // Public members: |
| 1704 | 1716 |
| 1705 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { | 1717 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { |
| 1706 chrome_extra_parts_.push_back(parts); | 1718 chrome_extra_parts_.push_back(parts); |
| 1707 } | 1719 } |
| OLD | NEW |