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

Side by Side Diff: chrome/browser/metrics/metrics_log_unittest.cc

Issue 146913005: Factor ChromeOS specific code out of MetricsLog. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address asvitkine's comments. Created 6 years, 10 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/metrics/metrics_log.h" 5 #include "chrome/browser/metrics/metrics_log.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 base::UTF8ToUTF16(version), 82 base::UTF8ToUTF16(version),
83 base::string16()); 83 base::string16());
84 if (is_pepper) 84 if (is_pepper)
85 plugin.type = content::WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS; 85 plugin.type = content::WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS;
86 else 86 else
87 plugin.type = content::WebPluginInfo::PLUGIN_TYPE_NPAPI; 87 plugin.type = content::WebPluginInfo::PLUGIN_TYPE_NPAPI;
88 return plugin; 88 return plugin;
89 } 89 }
90 #endif // defined(ENABLE_PLUGINS) 90 #endif // defined(ENABLE_PLUGINS)
91 91
92 #if defined(OS_CHROMEOS)
93 class TestMetricsLogChromeOS : public MetricsLogChromeOS {
94 public:
95 explicit TestMetricsLogChromeOS(
96 metrics::SystemProfileProto* system_profile)
97 : MetricsLogChromeOS(system_profile) {
98 }
99
100 protected:
101 // Don't touch bluetooth information, as it won't be correctly initialized.
102 virtual void WriteBluetoothProto(
103 metrics::SystemProfileProto::Hardware* hardware) OVERRIDE {
104 }
105 };
106 #endif // OS_CHROMEOS
107
92 class TestMetricsLog : public MetricsLog { 108 class TestMetricsLog : public MetricsLog {
93 public: 109 public:
94 TestMetricsLog(const std::string& client_id, int session_id) 110 TestMetricsLog(const std::string& client_id, int session_id)
95 : MetricsLog(client_id, session_id), 111 : MetricsLog(client_id, session_id),
96 prefs_(&scoped_prefs_), 112 prefs_(&scoped_prefs_),
97 brand_for_testing_(kBrandForTesting) { 113 brand_for_testing_(kBrandForTesting) {
114 #if defined(OS_CHROMEOS)
115 metrics_log_chromeos_.reset(new TestMetricsLogChromeOS(
116 MetricsLog::uma_proto()->mutable_system_profile()));
117 #endif // OS_CHROMEOS
98 chrome::RegisterLocalState(scoped_prefs_.registry()); 118 chrome::RegisterLocalState(scoped_prefs_.registry());
99 InitPrefs(); 119 InitPrefs();
100 } 120 }
101 // Creates a TestMetricsLog that will use |prefs| as the fake local state. 121 // Creates a TestMetricsLog that will use |prefs| as the fake local state.
102 // Useful for tests that need to re-use the local state prefs between logs. 122 // Useful for tests that need to re-use the local state prefs between logs.
103 TestMetricsLog(const std::string& client_id, 123 TestMetricsLog(const std::string& client_id,
104 int session_id, 124 int session_id,
105 TestingPrefServiceSimple* prefs) 125 TestingPrefServiceSimple* prefs)
106 : MetricsLog(client_id, session_id), 126 : MetricsLog(client_id, session_id),
107 prefs_(prefs), 127 prefs_(prefs),
108 brand_for_testing_(kBrandForTesting) { 128 brand_for_testing_(kBrandForTesting) {
129 #if defined(OS_CHROMEOS)
130 metrics_log_chromeos_.reset(new TestMetricsLogChromeOS(
131 MetricsLog::uma_proto()->mutable_system_profile()));
132 #endif // OS_CHROMEOS
109 InitPrefs(); 133 InitPrefs();
110 } 134 }
111 virtual ~TestMetricsLog() {} 135 virtual ~TestMetricsLog() {}
112 136
113 virtual PrefService* GetPrefService() OVERRIDE { 137 virtual PrefService* GetPrefService() OVERRIDE {
114 return prefs_; 138 return prefs_;
115 } 139 }
116 140
117 const metrics::ChromeUserMetricsExtension& uma_proto() const { 141 const metrics::ChromeUserMetricsExtension& uma_proto() const {
118 return *MetricsLog::uma_proto(); 142 return *MetricsLog::uma_proto();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 } 174 }
151 175
152 virtual float GetScreenDeviceScaleFactor() const OVERRIDE { 176 virtual float GetScreenDeviceScaleFactor() const OVERRIDE {
153 return kScreenScaleFactor; 177 return kScreenScaleFactor;
154 } 178 }
155 179
156 virtual int GetScreenCount() const OVERRIDE { 180 virtual int GetScreenCount() const OVERRIDE {
157 return kScreenCount; 181 return kScreenCount;
158 } 182 }
159 183
160 virtual void WriteBluetoothProto(
161 metrics::SystemProfileProto::Hardware* hardware) OVERRIDE {
162 }
163
164 // Scoped PrefsService, which may not be used if |prefs_ != &scoped_prefs|. 184 // Scoped PrefsService, which may not be used if |prefs_ != &scoped_prefs|.
165 TestingPrefServiceSimple scoped_prefs_; 185 TestingPrefServiceSimple scoped_prefs_;
166 // Weak pointer to the PrefsService used by this log. 186 // Weak pointer to the PrefsService used by this log.
167 TestingPrefServiceSimple* prefs_; 187 TestingPrefServiceSimple* prefs_;
168 188
169 google_util::BrandForTesting brand_for_testing_; 189 google_util::BrandForTesting brand_for_testing_;
170 190
171 DISALLOW_COPY_AND_ASSIGN(TestMetricsLog); 191 DISALLOW_COPY_AND_ASSIGN(TestMetricsLog);
172 }; 192 };
173 193
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 TestMetricsLog log(kClientId, kSessionId); 591 TestMetricsLog log(kClientId, kSessionId);
572 EXPECT_EQ(1u, log.system_profile().multi_profile_user_count()); 592 EXPECT_EQ(1u, log.system_profile().multi_profile_user_count());
573 593
574 user_manager->LoginUser(user2); 594 user_manager->LoginUser(user2);
575 std::vector<chrome_variations::ActiveGroupId> synthetic_trials; 595 std::vector<chrome_variations::ActiveGroupId> synthetic_trials;
576 log.RecordEnvironment(std::vector<content::WebPluginInfo>(), 596 log.RecordEnvironment(std::vector<content::WebPluginInfo>(),
577 GoogleUpdateMetrics(), synthetic_trials); 597 GoogleUpdateMetrics(), synthetic_trials);
578 EXPECT_EQ(0u, log.system_profile().multi_profile_user_count()); 598 EXPECT_EQ(0u, log.system_profile().multi_profile_user_count());
579 } 599 }
580 #endif // OS_CHROMEOS 600 #endif // OS_CHROMEOS
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698