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

Side by Side Diff: components/metrics/metrics_service_unittest.cc

Issue 1548113002: Switch to standard integer types in components/, part 2 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gn Created 4 years, 12 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
« no previous file with comments | « components/metrics/metrics_service_client.h ('k') | components/metrics/metrics_state_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/metrics/metrics_service.h" 5 #include "components/metrics/metrics_service.h"
6 6
7 #include <stdint.h>
8
7 #include <string> 9 #include <string>
8 10
9 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
12 #include "base/metrics/metrics_hashes.h" 15 #include "base/metrics/metrics_hashes.h"
13 #include "base/metrics/statistics_recorder.h" 16 #include "base/metrics/statistics_recorder.h"
14 #include "base/prefs/testing_pref_service.h" 17 #include "base/prefs/testing_pref_service.h"
15 #include "base/threading/platform_thread.h" 18 #include "base/threading/platform_thread.h"
16 #include "components/compression/compression_utils.h" 19 #include "components/compression/compression_utils.h"
17 #include "components/metrics/client_info.h" 20 #include "components/metrics/client_info.h"
18 #include "components/metrics/metrics_log.h" 21 #include "components/metrics/metrics_log.h"
19 #include "components/metrics/metrics_pref_names.h" 22 #include "components/metrics/metrics_pref_names.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); 104 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1));
102 } 105 }
103 } 106 }
104 107
105 // Returns true if there is a synthetic trial in the given vector that matches 108 // Returns true if there is a synthetic trial in the given vector that matches
106 // the given trial name and trial group; returns false otherwise. 109 // the given trial name and trial group; returns false otherwise.
107 bool HasSyntheticTrial( 110 bool HasSyntheticTrial(
108 const std::vector<variations::ActiveGroupId>& synthetic_trials, 111 const std::vector<variations::ActiveGroupId>& synthetic_trials,
109 const std::string& trial_name, 112 const std::string& trial_name,
110 const std::string& trial_group) { 113 const std::string& trial_group) {
111 uint32 trial_name_hash = HashName(trial_name); 114 uint32_t trial_name_hash = HashName(trial_name);
112 uint32 trial_group_hash = HashName(trial_group); 115 uint32_t trial_group_hash = HashName(trial_group);
113 for (const variations::ActiveGroupId& trial : synthetic_trials) { 116 for (const variations::ActiveGroupId& trial : synthetic_trials) {
114 if (trial.name == trial_name_hash && trial.group == trial_group_hash) 117 if (trial.name == trial_name_hash && trial.group == trial_group_hash)
115 return true; 118 return true;
116 } 119 }
117 return false; 120 return false;
118 } 121 }
119 122
120 // Finds a histogram with the specified |name_hash| in |histograms|. 123 // Finds a histogram with the specified |name_hash| in |histograms|.
121 const base::HistogramBase* FindHistogram( 124 const base::HistogramBase* FindHistogram(
122 const base::StatisticsRecorder::Histograms& histograms, 125 const base::StatisticsRecorder::Histograms& histograms,
123 uint64 name_hash) { 126 uint64_t name_hash) {
124 for (const base::HistogramBase* histogram : histograms) { 127 for (const base::HistogramBase* histogram : histograms) {
125 if (name_hash == base::HashMetricName(histogram->histogram_name())) 128 if (name_hash == base::HashMetricName(histogram->histogram_name()))
126 return histogram; 129 return histogram;
127 } 130 }
128 return nullptr; 131 return nullptr;
129 } 132 }
130 133
131 // Checks whether |uma_log| contains any histograms that are not flagged 134 // Checks whether |uma_log| contains any histograms that are not flagged
132 // with kUmaStabilityHistogramFlag. Stability logs should only contain such 135 // with kUmaStabilityHistogramFlag. Stability logs should only contain such
133 // histograms. 136 // histograms.
134 void CheckForNonStabilityHistograms( 137 void CheckForNonStabilityHistograms(
135 const ChromeUserMetricsExtension& uma_log) { 138 const ChromeUserMetricsExtension& uma_log) {
136 const int kStabilityFlags = base::HistogramBase::kUmaStabilityHistogramFlag; 139 const int kStabilityFlags = base::HistogramBase::kUmaStabilityHistogramFlag;
137 base::StatisticsRecorder::Histograms histograms; 140 base::StatisticsRecorder::Histograms histograms;
138 base::StatisticsRecorder::GetHistograms(&histograms); 141 base::StatisticsRecorder::GetHistograms(&histograms);
139 for (int i = 0; i < uma_log.histogram_event_size(); ++i) { 142 for (int i = 0; i < uma_log.histogram_event_size(); ++i) {
140 const uint64 hash = uma_log.histogram_event(i).name_hash(); 143 const uint64_t hash = uma_log.histogram_event(i).name_hash();
141 144
142 const base::HistogramBase* histogram = FindHistogram(histograms, hash); 145 const base::HistogramBase* histogram = FindHistogram(histograms, hash);
143 EXPECT_TRUE(histogram) << hash; 146 EXPECT_TRUE(histogram) << hash;
144 147
145 EXPECT_EQ(kStabilityFlags, histogram->flags() & kStabilityFlags) << hash; 148 EXPECT_EQ(kStabilityFlags, histogram->flags() & kStabilityFlags) << hash;
146 } 149 }
147 } 150 }
148 151
149 private: 152 private:
150 bool is_metrics_reporting_enabled() const { 153 bool is_metrics_reporting_enabled() const {
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 TestMetricsProvider* test_provider = new TestMetricsProvider(); 391 TestMetricsProvider* test_provider = new TestMetricsProvider();
389 service.RegisterMetricsProvider(scoped_ptr<MetricsProvider>(test_provider)); 392 service.RegisterMetricsProvider(scoped_ptr<MetricsProvider>(test_provider));
390 393
391 service.InitializeMetricsRecordingState(); 394 service.InitializeMetricsRecordingState();
392 service.Stop(); 395 service.Stop();
393 396
394 EXPECT_TRUE(test_provider->on_recording_disabled_called()); 397 EXPECT_TRUE(test_provider->on_recording_disabled_called());
395 } 398 }
396 399
397 } // namespace metrics 400 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/metrics_service_client.h ('k') | components/metrics/metrics_state_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698