Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Side by Side Diff: chrome/browser/chrome_browser_main.cc

Issue 256143006: Refactor MetricsStateManager class out of MetricsService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 // Must initialize metrics after labs have been converted into switches, 550 // Must initialize metrics after labs have been converted into switches,
551 // but before field trials are set up (so that client ID is available for 551 // but before field trials are set up (so that client ID is available for
552 // one-time randomized field trials). 552 // one-time randomized field trials).
553 #if defined(ARCH_CPU_64_BITS) 553 #if defined(ARCH_CPU_64_BITS)
554 MetricsLog::set_version_extension("-64"); 554 MetricsLog::set_version_extension("-64");
555 #endif // defined(ARCH_CPU_64_BITS) 555 #endif // defined(ARCH_CPU_64_BITS)
556 556
557 // Initialize FieldTrialList to support FieldTrials that use one-time 557 // Initialize FieldTrialList to support FieldTrials that use one-time
558 // randomization. 558 // randomization.
559 MetricsService* metrics = browser_process_->metrics_service(); 559 MetricsService* metrics = browser_process_->metrics_service();
560 MetricsService::ReportingState reporting_state =
561 IsMetricsReportingEnabled() ? MetricsService::REPORTING_ENABLED :
562 MetricsService::REPORTING_DISABLED;
563 if (reporting_state == MetricsService::REPORTING_ENABLED)
564 metrics->ForceClientIdCreation(); // Needed below.
565 field_trial_list_.reset( 560 field_trial_list_.reset(
566 new base::FieldTrialList( 561 new base::FieldTrialList(metrics->CreateEntropyProvider().release()));
567 metrics->CreateEntropyProvider(reporting_state).release()));
568 562
569 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 563 const CommandLine* command_line = CommandLine::ForCurrentProcess();
570 if (command_line->HasSwitch(switches::kEnableBenchmarking)) 564 if (command_line->HasSwitch(switches::kEnableBenchmarking))
571 base::FieldTrial::EnableBenchmarking(); 565 base::FieldTrial::EnableBenchmarking();
572 566
573 // Ensure any field trials specified on the command line are initialized. 567 // Ensure any field trials specified on the command line are initialized.
574 // Also stop the metrics service so that we don't pollute UMA. 568 // Also stop the metrics service so that we don't pollute UMA.
575 if (command_line->HasSwitch(switches::kForceFieldTrials)) { 569 if (command_line->HasSwitch(switches::kForceFieldTrials)) {
576 std::set<std::string> unforceable_field_trials; 570 std::set<std::string> unforceable_field_trials;
577 #if defined(OFFICIAL_BUILD) 571 #if defined(OFFICIAL_BUILD)
(...skipping 27 matching lines...) Expand all
605 // This must be called after the local state is initialized. 599 // This must be called after the local state is initialized.
606 browser_field_trials_.SetupFieldTrials(local_state_); 600 browser_field_trials_.SetupFieldTrials(local_state_);
607 601
608 // Initialize FieldTrialSynchronizer system. This is a singleton and is used 602 // Initialize FieldTrialSynchronizer system. This is a singleton and is used
609 // for posting tasks via base::Bind. Its deleted when it goes out of scope. 603 // for posting tasks via base::Bind. Its deleted when it goes out of scope.
610 // Even though base::Bind does AddRef and Release, the object will not be 604 // Even though base::Bind does AddRef and Release, the object will not be
611 // deleted after the Task is executed. 605 // deleted after the Task is executed.
612 field_trial_synchronizer_ = new FieldTrialSynchronizer(); 606 field_trial_synchronizer_ = new FieldTrialSynchronizer();
613 607
614 // Now that field trials have been created, initializes metrics recording. 608 // Now that field trials have been created, initializes metrics recording.
615 metrics->InitializeMetricsRecordingState(reporting_state); 609 metrics->InitializeMetricsRecordingState();
616 } 610 }
617 611
618 // ChromeBrowserMainParts: |SetupMetricsAndFieldTrials()| related -------------- 612 // ChromeBrowserMainParts: |SetupMetricsAndFieldTrials()| related --------------
619 613
620 void ChromeBrowserMainParts::StartMetricsRecording() { 614 void ChromeBrowserMainParts::StartMetricsRecording() {
621 TRACE_EVENT0("startup", "ChromeBrowserMainParts::StartMetricsRecording"); 615 TRACE_EVENT0("startup", "ChromeBrowserMainParts::StartMetricsRecording");
622 MetricsService* metrics = g_browser_process->metrics_service(); 616 MetricsService* metrics = g_browser_process->metrics_service();
623 617
624 const bool only_do_metrics_recording = 618 const bool only_do_metrics_recording =
625 parsed_command_line_.HasSwitch(switches::kMetricsRecordingOnly) || 619 parsed_command_line_.HasSwitch(switches::kMetricsRecordingOnly) ||
626 parsed_command_line_.HasSwitch(switches::kEnableBenchmarking); 620 parsed_command_line_.HasSwitch(switches::kEnableBenchmarking);
627 if (only_do_metrics_recording) { 621 if (only_do_metrics_recording) {
628 // If we're testing then we don't care what the user preference is, we turn 622 // If we're testing then we don't care what the user preference is, we turn
629 // on recording, but not reporting, otherwise tests fail. 623 // on recording, but not reporting, otherwise tests fail.
630 metrics->StartRecordingForTests(); 624 metrics->StartRecordingForTests();
631 return; 625 return;
632 } 626 }
633 627
634 metrics->CheckForClonedInstall(); 628 metrics->CheckForClonedInstall();
635 629 const bool metrics_enabled = metrics->StartIfMetricsReportingEnabled();
636 if (IsMetricsReportingEnabled()) 630 if (metrics_enabled) {
637 metrics->Start(); 631 browser_process_->rappor_service()->Start(
638 } 632 browser_process_->local_state(),
639 633 browser_process_->system_request_context());
640 bool ChromeBrowserMainParts::IsMetricsReportingEnabled() { 634 }
641 // If the user permits metrics reporting with the checkbox in the
642 // prefs, we turn on recording. We disable metrics completely for
643 // non-official builds. This can be forced with a flag.
644 const CommandLine* command_line = CommandLine::ForCurrentProcess();
645 if (command_line->HasSwitch(switches::kEnableMetricsReportingForTesting))
646 return true;
647
648 bool enabled = false;
649 // The debug build doesn't send UMA logs when FieldTrials are forced.
650 if (command_line->HasSwitch(switches::kForceFieldTrials))
651 return false;
652
653 #if defined(GOOGLE_CHROME_BUILD)
654 #if defined(OS_CHROMEOS)
655 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref,
656 &enabled);
657 #else
658 enabled = local_state_->GetBoolean(prefs::kMetricsReportingEnabled);
659 #endif // #if defined(OS_CHROMEOS)
660 #endif // defined(GOOGLE_CHROME_BUILD)
661 return enabled;
662 } 635 }
663 636
664 void ChromeBrowserMainParts::RecordBrowserStartupTime() { 637 void ChromeBrowserMainParts::RecordBrowserStartupTime() {
665 // Don't record any metrics if UI was displayed before this point e.g. 638 // Don't record any metrics if UI was displayed before this point e.g.
666 // warning dialogs. 639 // warning dialogs.
667 if (startup_metric_utils::WasNonBrowserUIDisplayed()) 640 if (startup_metric_utils::WasNonBrowserUIDisplayed())
668 return; 641 return;
669 642
670 #if defined(OS_ANDROID) 643 #if defined(OS_ANDROID)
671 // On Android the first run is handled in Java code, and the C++ side of 644 // 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
1082 1055
1083 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { 1056 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
1084 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreMainMessageLoopRunImpl"); 1057 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreMainMessageLoopRunImpl");
1085 // Android updates the metrics service dynamically depending on whether the 1058 // Android updates the metrics service dynamically depending on whether the
1086 // application is in the foreground or not. Do not start here. 1059 // application is in the foreground or not. Do not start here.
1087 #if !defined(OS_ANDROID) 1060 #if !defined(OS_ANDROID)
1088 // Now that the file thread has been started, start recording. 1061 // Now that the file thread has been started, start recording.
1089 StartMetricsRecording(); 1062 StartMetricsRecording();
1090 #endif 1063 #endif
1091 1064
1092 if (IsMetricsReportingEnabled()) {
1093 browser_process_->rappor_service()->Start(
1094 browser_process_->local_state(),
1095 browser_process_->system_request_context());
1096 }
1097
1098 // Create watchdog thread after creating all other threads because it will 1065 // Create watchdog thread after creating all other threads because it will
1099 // watch the other threads and they must be running. 1066 // watch the other threads and they must be running.
1100 browser_process_->watchdog_thread(); 1067 browser_process_->watchdog_thread();
1101 1068
1102 // Do any initializating in the browser process that requires all threads 1069 // Do any initializating in the browser process that requires all threads
1103 // running. 1070 // running.
1104 browser_process_->PreMainMessageLoopRun(); 1071 browser_process_->PreMainMessageLoopRun();
1105 1072
1106 // Record last shutdown time into a histogram. 1073 // Record last shutdown time into a histogram.
1107 browser_shutdown::ReadLastShutdownInfo(); 1074 browser_shutdown::ReadLastShutdownInfo();
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 chromeos::CrosSettings::Shutdown(); 1646 chromeos::CrosSettings::Shutdown();
1680 #endif 1647 #endif
1681 #endif 1648 #endif
1682 } 1649 }
1683 1650
1684 // Public members: 1651 // Public members:
1685 1652
1686 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { 1653 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) {
1687 chrome_extra_parts_.push_back(parts); 1654 chrome_extra_parts_.push_back(parts);
1688 } 1655 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698