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