OLD | NEW |
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 23 matching lines...) Expand all Loading... |
34 #include "content/public/common/webplugininfo.h" | 34 #include "content/public/common/webplugininfo.h" |
35 #include "content/public/test/test_browser_thread_bundle.h" | 35 #include "content/public/test/test_browser_thread_bundle.h" |
36 #include "content/public/test/test_utils.h" | 36 #include "content/public/test/test_utils.h" |
37 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
38 #include "ui/gfx/size.h" | 38 #include "ui/gfx/size.h" |
39 #include "url/gurl.h" | 39 #include "url/gurl.h" |
40 | 40 |
41 #if defined(OS_CHROMEOS) | 41 #if defined(OS_CHROMEOS) |
42 #include "chrome/browser/chromeos/login/fake_user_manager.h" | 42 #include "chrome/browser/chromeos/login/fake_user_manager.h" |
43 #include "chrome/browser/chromeos/login/user_manager.h" | 43 #include "chrome/browser/chromeos/login/user_manager.h" |
| 44 #include "chrome/browser/metrics/metrics_log_chromeos.h" |
44 #endif // OS_CHROMEOS | 45 #endif // OS_CHROMEOS |
45 | 46 |
46 using base::TimeDelta; | 47 using base::TimeDelta; |
47 using metrics::ProfilerEventProto; | 48 using metrics::ProfilerEventProto; |
48 using tracked_objects::ProcessDataSnapshot; | 49 using tracked_objects::ProcessDataSnapshot; |
49 using tracked_objects::TaskSnapshot; | 50 using tracked_objects::TaskSnapshot; |
50 | 51 |
51 namespace { | 52 namespace { |
52 | 53 |
53 const char kClientId[] = "bogus client ID"; | 54 const char kClientId[] = "bogus client ID"; |
(...skipping 28 matching lines...) Expand all Loading... |
82 base::UTF8ToUTF16(version), | 83 base::UTF8ToUTF16(version), |
83 base::string16()); | 84 base::string16()); |
84 if (is_pepper) | 85 if (is_pepper) |
85 plugin.type = content::WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS; | 86 plugin.type = content::WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS; |
86 else | 87 else |
87 plugin.type = content::WebPluginInfo::PLUGIN_TYPE_NPAPI; | 88 plugin.type = content::WebPluginInfo::PLUGIN_TYPE_NPAPI; |
88 return plugin; | 89 return plugin; |
89 } | 90 } |
90 #endif // defined(ENABLE_PLUGINS) | 91 #endif // defined(ENABLE_PLUGINS) |
91 | 92 |
| 93 #if defined(OS_CHROMEOS) |
| 94 class TestMetricsLogChromeOS : public MetricsLogChromeOS { |
| 95 public: |
| 96 explicit TestMetricsLogChromeOS( |
| 97 metrics::ChromeUserMetricsExtension* uma_proto) |
| 98 : MetricsLogChromeOS(uma_proto) { |
| 99 } |
| 100 |
| 101 protected: |
| 102 // Don't touch bluetooth information, as it won't be correctly initialized. |
| 103 virtual void WriteBluetoothProto() 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())); |
| 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())); |
| 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 Loading... |
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 Loading... |
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 |
OLD | NEW |