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

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 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 browser_process_->rappor_service()->Start(
643 } 637 browser_process_->local_state(),
644 638 browser_process_->system_request_context());
Ilya Sherman 2014/05/02 05:12:38 Hmm, are you sure that it's safe to move this code
Alexei Svitkine (slow) 2014/05/02 15:21:46 You're correct that this will disable RAPPOR on An
Alexei Svitkine (slow) 2014/05/02 15:31:16 Actually, I think my comment above is not quite co
645 bool ChromeBrowserMainParts::IsMetricsReportingEnabled() { 639 }
646 // If the user permits metrics reporting with the checkbox in the
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;
667 } 640 }
668 641
669 void ChromeBrowserMainParts::RecordBrowserStartupTime() { 642 void ChromeBrowserMainParts::RecordBrowserStartupTime() {
670 // Don't record any metrics if UI was displayed before this point e.g. 643 // Don't record any metrics if UI was displayed before this point e.g.
671 // warning dialogs. 644 // warning dialogs.
672 if (startup_metric_utils::WasNonBrowserUIDisplayed()) 645 if (startup_metric_utils::WasNonBrowserUIDisplayed())
673 return; 646 return;
674 647
675 #if defined(OS_ANDROID) 648 #if defined(OS_ANDROID)
676 // On Android the first run is handled in Java code, and the C++ side of 649 // 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
1087 1060
1088 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { 1061 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
1089 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreMainMessageLoopRunImpl"); 1062 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreMainMessageLoopRunImpl");
1090 // Android updates the metrics service dynamically depending on whether the 1063 // Android updates the metrics service dynamically depending on whether the
1091 // application is in the foreground or not. Do not start here. 1064 // application is in the foreground or not. Do not start here.
1092 #if !defined(OS_ANDROID) 1065 #if !defined(OS_ANDROID)
1093 // Now that the file thread has been started, start recording. 1066 // Now that the file thread has been started, start recording.
1094 StartMetricsRecording(); 1067 StartMetricsRecording();
1095 #endif 1068 #endif
1096 1069
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 1070 // Create watchdog thread after creating all other threads because it will
1104 // watch the other threads and they must be running. 1071 // watch the other threads and they must be running.
1105 browser_process_->watchdog_thread(); 1072 browser_process_->watchdog_thread();
1106 1073
1107 // Do any initializating in the browser process that requires all threads 1074 // Do any initializating in the browser process that requires all threads
1108 // running. 1075 // running.
1109 browser_process_->PreMainMessageLoopRun(); 1076 browser_process_->PreMainMessageLoopRun();
1110 1077
1111 // Record last shutdown time into a histogram. 1078 // Record last shutdown time into a histogram.
1112 browser_shutdown::ReadLastShutdownInfo(); 1079 browser_shutdown::ReadLastShutdownInfo();
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
1684 chromeos::CrosSettings::Shutdown(); 1651 chromeos::CrosSettings::Shutdown();
1685 #endif 1652 #endif
1686 #endif 1653 #endif
1687 } 1654 }
1688 1655
1689 // Public members: 1656 // Public members:
1690 1657
1691 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { 1658 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) {
1692 chrome_extra_parts_.push_back(parts); 1659 chrome_extra_parts_.push_back(parts);
1693 } 1660 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698