OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/renderer/translate/translate_helper_metrics.h" | 5 #include "chrome/renderer/translate/translate_helper_metrics.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/metrics/histogram_samples.h" | 10 #include "base/metrics/histogram_samples.h" |
11 #include "base/metrics/statistics_recorder.h" | 11 #include "base/metrics/statistics_recorder.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "testing/platform_test.h" | 13 #include "testing/platform_test.h" |
14 | 14 |
15 using base::HistogramBase; | 15 using base::HistogramBase; |
16 using base::HistogramSamples; | 16 using base::HistogramSamples; |
17 using base::SampleCountIterator; | 17 using base::SampleCountIterator; |
18 using base::StatisticsRecorder; | 18 using base::StatisticsRecorder; |
19 using base::TimeTicks; | 19 using base::TimeTicks; |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 const int kTrue = 1; | 23 const int kTrue = 1; |
24 const int kFalse = 0; | 24 const int kFalse = 0; |
25 | 25 |
26 class MetricsRecorder { | 26 class MetricsRecorder { |
27 public: | 27 public: |
28 explicit MetricsRecorder(const char* key) | 28 explicit MetricsRecorder(const char* key) : key_(key) { |
29 : key_(key), | |
30 base_samples_(NULL), | |
31 samples_(NULL) { | |
32 StatisticsRecorder::Initialize(); | 29 StatisticsRecorder::Initialize(); |
33 | 30 |
34 HistogramBase* histogram = StatisticsRecorder::FindHistogram(key_); | 31 HistogramBase* histogram = StatisticsRecorder::FindHistogram(key_); |
35 if (histogram) | 32 if (histogram) |
36 base_samples_ = histogram->SnapshotSamples(); | 33 base_samples_ = histogram->SnapshotSamples(); |
37 } | 34 } |
38 | 35 |
39 void CheckLanguage(TranslateHelperMetrics::MetricsNameIndex index, | 36 void CheckLanguage(TranslateHelperMetrics::MetricsNameIndex index, |
40 int expected_not_provided, | 37 int expected_not_provided, |
41 int expected_valid, | 38 int expected_valid, |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 TranslateHelperMetrics::UMA_LANGUAGE_DETECTION)); | 278 TranslateHelperMetrics::UMA_LANGUAGE_DETECTION)); |
282 recorder.CheckTotalCount(0); | 279 recorder.CheckTotalCount(0); |
283 TimeTicks begin = TimeTicks::Now(); | 280 TimeTicks begin = TimeTicks::Now(); |
284 TimeTicks end = begin + base::TimeDelta::FromMicroseconds(9009); | 281 TimeTicks end = begin + base::TimeDelta::FromMicroseconds(9009); |
285 TranslateHelperMetrics::ReportLanguageDetectionTime(begin, end); | 282 TranslateHelperMetrics::ReportLanguageDetectionTime(begin, end); |
286 recorder.CheckValueInLogs(9.009); | 283 recorder.CheckValueInLogs(9.009); |
287 recorder.CheckTotalCount(1); | 284 recorder.CheckTotalCount(1); |
288 } | 285 } |
289 | 286 |
290 #endif // defined(ENABLE_LANGUAGE_DETECTION) | 287 #endif // defined(ENABLE_LANGUAGE_DETECTION) |
OLD | NEW |