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 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 // Must initialize metrics after labs have been converted into switches, | 555 // Must initialize metrics after labs have been converted into switches, |
556 // but before field trials are set up (so that client ID is available for | 556 // but before field trials are set up (so that client ID is available for |
557 // one-time randomized field trials). | 557 // one-time randomized field trials). |
558 #if defined(ARCH_CPU_64_BITS) | 558 #if defined(ARCH_CPU_64_BITS) |
559 MetricsLog::set_version_extension("-64"); | 559 MetricsLog::set_version_extension("-64"); |
560 #endif // defined(ARCH_CPU_64_BITS) | 560 #endif // defined(ARCH_CPU_64_BITS) |
561 | 561 |
562 // Initialize FieldTrialList to support FieldTrials that use one-time | 562 // Initialize FieldTrialList to support FieldTrials that use one-time |
563 // randomization. | 563 // randomization. |
564 MetricsService* metrics = browser_process_->metrics_service(); | 564 MetricsService* metrics = browser_process_->metrics_service(); |
565 MetricsService::ReportingState reporting_state = | |
566 IsMetricsReportingEnabled() ? MetricsService::REPORTING_ENABLED : | |
567 MetricsService::REPORTING_DISABLED; | |
568 if (reporting_state == MetricsService::REPORTING_ENABLED) | |
569 metrics->ForceClientIdCreation(); // Needed below. | |
570 field_trial_list_.reset( | 565 field_trial_list_.reset( |
571 new base::FieldTrialList( | 566 new base::FieldTrialList(metrics->CreateEntropyProvider().release())); |
572 metrics->CreateEntropyProvider(reporting_state).release())); | |
573 | 567 |
574 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 568 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
575 if (command_line->HasSwitch(switches::kEnableBenchmarking)) | 569 if (command_line->HasSwitch(switches::kEnableBenchmarking)) |
576 base::FieldTrial::EnableBenchmarking(); | 570 base::FieldTrial::EnableBenchmarking(); |
577 | 571 |
578 // Ensure any field trials specified on the command line are initialized. | 572 // Ensure any field trials specified on the command line are initialized. |
579 // Also stop the metrics service so that we don't pollute UMA. | 573 // Also stop the metrics service so that we don't pollute UMA. |
580 if (command_line->HasSwitch(switches::kForceFieldTrials)) { | 574 if (command_line->HasSwitch(switches::kForceFieldTrials)) { |
581 std::set<std::string> unforceable_field_trials; | 575 std::set<std::string> unforceable_field_trials; |
582 #if defined(OFFICIAL_BUILD) | 576 #if defined(OFFICIAL_BUILD) |
(...skipping 27 matching lines...) Expand all Loading... |
610 // This must be called after the local state is initialized. | 604 // This must be called after the local state is initialized. |
611 browser_field_trials_.SetupFieldTrials(local_state_); | 605 browser_field_trials_.SetupFieldTrials(local_state_); |
612 | 606 |
613 // Initialize FieldTrialSynchronizer system. This is a singleton and is used | 607 // Initialize FieldTrialSynchronizer system. This is a singleton and is used |
614 // for posting tasks via base::Bind. Its deleted when it goes out of scope. | 608 // for posting tasks via base::Bind. Its deleted when it goes out of scope. |
615 // Even though base::Bind does AddRef and Release, the object will not be | 609 // Even though base::Bind does AddRef and Release, the object will not be |
616 // deleted after the Task is executed. | 610 // deleted after the Task is executed. |
617 field_trial_synchronizer_ = new FieldTrialSynchronizer(); | 611 field_trial_synchronizer_ = new FieldTrialSynchronizer(); |
618 | 612 |
619 // Now that field trials have been created, initializes metrics recording. | 613 // Now that field trials have been created, initializes metrics recording. |
620 metrics->InitializeMetricsRecordingState(reporting_state); | 614 metrics->InitializeMetricsRecordingState(); |
621 } | 615 } |
622 | 616 |
623 // ChromeBrowserMainParts: |SetupMetricsAndFieldTrials()| related -------------- | 617 // ChromeBrowserMainParts: |SetupMetricsAndFieldTrials()| related -------------- |
624 | 618 |
625 void ChromeBrowserMainParts::StartMetricsRecording() { | 619 void ChromeBrowserMainParts::StartMetricsRecording() { |
626 TRACE_EVENT0("startup", "ChromeBrowserMainParts::StartMetricsRecording"); | 620 TRACE_EVENT0("startup", "ChromeBrowserMainParts::StartMetricsRecording"); |
627 MetricsService* metrics = g_browser_process->metrics_service(); | 621 MetricsService* metrics = g_browser_process->metrics_service(); |
628 | 622 |
629 const bool only_do_metrics_recording = | 623 const bool only_do_metrics_recording = |
630 parsed_command_line_.HasSwitch(switches::kMetricsRecordingOnly) || | 624 parsed_command_line_.HasSwitch(switches::kMetricsRecordingOnly) || |
631 parsed_command_line_.HasSwitch(switches::kEnableBenchmarking); | 625 parsed_command_line_.HasSwitch(switches::kEnableBenchmarking); |
632 if (only_do_metrics_recording) { | 626 if (only_do_metrics_recording) { |
633 // If we're testing then we don't care what the user preference is, we turn | 627 // If we're testing then we don't care what the user preference is, we turn |
634 // on recording, but not reporting, otherwise tests fail. | 628 // on recording, but not reporting, otherwise tests fail. |
635 metrics->StartRecordingForTests(); | 629 metrics->StartRecordingForTests(); |
636 return; | 630 return; |
637 } | 631 } |
638 | 632 |
639 metrics->CheckForClonedInstall(); | 633 metrics->CheckForClonedInstall(); |
640 | 634 const bool metrics_enabled = metrics->StartIfMetricsReportingEnabled(); |
641 if (IsMetricsReportingEnabled()) | 635 if (metrics_enabled) { |
642 metrics->Start(); | 636 // TODO(asvitkine): Since this function is not run on Android, RAPPOR is |
643 } | 637 // currently disabled there. http://crbug.com/370041 |
644 | 638 browser_process_->rappor_service()->Start( |
645 bool ChromeBrowserMainParts::IsMetricsReportingEnabled() { | 639 browser_process_->local_state(), |
646 // If the user permits metrics reporting with the checkbox in the | 640 browser_process_->system_request_context()); |
647 // prefs, we turn on recording. We disable metrics completely for | 641 } |
648 // non-official builds. This can be forced with a flag. | |
649 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
650 if (command_line->HasSwitch(switches::kEnableMetricsReportingForTesting)) | |
651 return true; | |
652 | |
653 bool enabled = false; | |
654 // The debug build doesn't send UMA logs when FieldTrials are forced. | |
655 if (command_line->HasSwitch(switches::kForceFieldTrials)) | |
656 return false; | |
657 | |
658 #if defined(GOOGLE_CHROME_BUILD) | |
659 #if defined(OS_CHROMEOS) | |
660 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, | |
661 &enabled); | |
662 #else | |
663 enabled = local_state_->GetBoolean(prefs::kMetricsReportingEnabled); | |
664 #endif // #if defined(OS_CHROMEOS) | |
665 #endif // defined(GOOGLE_CHROME_BUILD) | |
666 return enabled; | |
667 } | 642 } |
668 | 643 |
669 void ChromeBrowserMainParts::RecordBrowserStartupTime() { | 644 void ChromeBrowserMainParts::RecordBrowserStartupTime() { |
670 // Don't record any metrics if UI was displayed before this point e.g. | 645 // Don't record any metrics if UI was displayed before this point e.g. |
671 // warning dialogs. | 646 // warning dialogs. |
672 if (startup_metric_utils::WasNonBrowserUIDisplayed()) | 647 if (startup_metric_utils::WasNonBrowserUIDisplayed()) |
673 return; | 648 return; |
674 | 649 |
675 #if defined(OS_ANDROID) | 650 #if defined(OS_ANDROID) |
676 // On Android the first run is handled in Java code, and the C++ side of | 651 // On Android the first run is handled in Java code, and the C++ side of |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1087 | 1062 |
1088 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { | 1063 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { |
1089 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreMainMessageLoopRunImpl"); | 1064 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreMainMessageLoopRunImpl"); |
1090 // Android updates the metrics service dynamically depending on whether the | 1065 // Android updates the metrics service dynamically depending on whether the |
1091 // application is in the foreground or not. Do not start here. | 1066 // application is in the foreground or not. Do not start here. |
1092 #if !defined(OS_ANDROID) | 1067 #if !defined(OS_ANDROID) |
1093 // Now that the file thread has been started, start recording. | 1068 // Now that the file thread has been started, start recording. |
1094 StartMetricsRecording(); | 1069 StartMetricsRecording(); |
1095 #endif | 1070 #endif |
1096 | 1071 |
1097 if (IsMetricsReportingEnabled()) { | |
1098 browser_process_->rappor_service()->Start( | |
1099 browser_process_->local_state(), | |
1100 browser_process_->system_request_context()); | |
1101 } | |
1102 | |
1103 // Create watchdog thread after creating all other threads because it will | 1072 // Create watchdog thread after creating all other threads because it will |
1104 // watch the other threads and they must be running. | 1073 // watch the other threads and they must be running. |
1105 browser_process_->watchdog_thread(); | 1074 browser_process_->watchdog_thread(); |
1106 | 1075 |
1107 // Do any initializating in the browser process that requires all threads | 1076 // Do any initializating in the browser process that requires all threads |
1108 // running. | 1077 // running. |
1109 browser_process_->PreMainMessageLoopRun(); | 1078 browser_process_->PreMainMessageLoopRun(); |
1110 | 1079 |
1111 // Record last shutdown time into a histogram. | 1080 // Record last shutdown time into a histogram. |
1112 browser_shutdown::ReadLastShutdownInfo(); | 1081 browser_shutdown::ReadLastShutdownInfo(); |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1684 chromeos::CrosSettings::Shutdown(); | 1653 chromeos::CrosSettings::Shutdown(); |
1685 #endif | 1654 #endif |
1686 #endif | 1655 #endif |
1687 } | 1656 } |
1688 | 1657 |
1689 // Public members: | 1658 // Public members: |
1690 | 1659 |
1691 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { | 1660 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { |
1692 chrome_extra_parts_.push_back(parts); | 1661 chrome_extra_parts_.push_back(parts); |
1693 } | 1662 } |
OLD | NEW |