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_service.h" | 5 #include "chrome/browser/metrics/metrics_service.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 // take between 1-15ms per the documented resolution of base::TimeTicks. | 117 // take between 1-15ms per the documented resolution of base::TimeTicks. |
118 void WaitUntilTimeChanges(const base::TimeTicks& value) { | 118 void WaitUntilTimeChanges(const base::TimeTicks& value) { |
119 while (base::TimeTicks::Now() == value) { | 119 while (base::TimeTicks::Now() == value) { |
120 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); | 120 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 // Returns true if there is a synthetic trial in the given vector that matches | 124 // Returns true if there is a synthetic trial in the given vector that matches |
125 // the given trial name and trial group; returns false otherwise. | 125 // the given trial name and trial group; returns false otherwise. |
126 bool HasSyntheticTrial( | 126 bool HasSyntheticTrial( |
127 const std::vector<chrome_variations::ActiveGroupId>& synthetic_trials, | 127 const std::vector<variations::ActiveGroupId>& synthetic_trials, |
128 const std::string& trial_name, | 128 const std::string& trial_name, |
129 const std::string& trial_group) { | 129 const std::string& trial_group) { |
130 uint32 trial_name_hash = metrics::HashName(trial_name); | 130 uint32 trial_name_hash = metrics::HashName(trial_name); |
131 uint32 trial_group_hash = metrics::HashName(trial_group); | 131 uint32 trial_group_hash = metrics::HashName(trial_group); |
132 for (std::vector<chrome_variations::ActiveGroupId>::const_iterator it = | 132 for (std::vector<variations::ActiveGroupId>::const_iterator it = |
133 synthetic_trials.begin(); | 133 synthetic_trials.begin(); |
134 it != synthetic_trials.end(); ++it) { | 134 it != synthetic_trials.end(); ++it) { |
135 if ((*it).name == trial_name_hash && (*it).group == trial_group_hash) | 135 if ((*it).name == trial_name_hash && (*it).group == trial_group_hash) |
136 return true; | 136 return true; |
137 } | 137 } |
138 return false; | 138 return false; |
139 } | 139 } |
140 | 140 |
141 private: | 141 private: |
142 content::TestBrowserThreadBundle thread_bundle_; | 142 content::TestBrowserThreadBundle thread_bundle_; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 EnableMetricsReporting(); | 188 EnableMetricsReporting(); |
189 GetLocalState()->ClearPref(prefs::kStabilityExitedCleanly); | 189 GetLocalState()->ClearPref(prefs::kStabilityExitedCleanly); |
190 | 190 |
191 // Set up prefs to simulate restarting after a crash. | 191 // Set up prefs to simulate restarting after a crash. |
192 | 192 |
193 // Save an existing system profile to prefs, to correspond to what would be | 193 // Save an existing system profile to prefs, to correspond to what would be |
194 // saved from a previous session. | 194 // saved from a previous session. |
195 TestMetricsLog log("client", 1); | 195 TestMetricsLog log("client", 1); |
196 log.RecordEnvironment(std::vector<content::WebPluginInfo>(), | 196 log.RecordEnvironment(std::vector<content::WebPluginInfo>(), |
197 GoogleUpdateMetrics(), | 197 GoogleUpdateMetrics(), |
198 std::vector<chrome_variations::ActiveGroupId>()); | 198 std::vector<variations::ActiveGroupId>()); |
199 | 199 |
200 // Record stability build time and version from previous session, so that | 200 // Record stability build time and version from previous session, so that |
201 // stability metrics (including exited cleanly flag) won't be cleared. | 201 // stability metrics (including exited cleanly flag) won't be cleared. |
202 GetLocalState()->SetInt64(prefs::kStabilityStatsBuildTime, | 202 GetLocalState()->SetInt64(prefs::kStabilityStatsBuildTime, |
203 MetricsLog::GetBuildTime()); | 203 MetricsLog::GetBuildTime()); |
204 GetLocalState()->SetString(prefs::kStabilityStatsVersion, | 204 GetLocalState()->SetString(prefs::kStabilityStatsVersion, |
205 MetricsLog::GetVersionString()); | 205 MetricsLog::GetVersionString()); |
206 | 206 |
207 GetLocalState()->SetBoolean(prefs::kStabilityExitedCleanly, false); | 207 GetLocalState()->SetBoolean(prefs::kStabilityExitedCleanly, false); |
208 | 208 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 // Ensure that time has advanced by at least a tick before proceeding. | 247 // Ensure that time has advanced by at least a tick before proceeding. |
248 WaitUntilTimeChanges(base::TimeTicks::Now()); | 248 WaitUntilTimeChanges(base::TimeTicks::Now()); |
249 | 249 |
250 service.log_manager_.BeginLoggingWithLog( | 250 service.log_manager_.BeginLoggingWithLog( |
251 new MetricsLog("clientID", 1, MetricsLog::INITIAL_STABILITY_LOG)); | 251 new MetricsLog("clientID", 1, MetricsLog::INITIAL_STABILITY_LOG)); |
252 // Save the time when the log was started (it's okay for this to be greater | 252 // Save the time when the log was started (it's okay for this to be greater |
253 // than the time recorded by the above call since it's used to ensure the | 253 // than the time recorded by the above call since it's used to ensure the |
254 // value changes). | 254 // value changes). |
255 const base::TimeTicks begin_log_time = base::TimeTicks::Now(); | 255 const base::TimeTicks begin_log_time = base::TimeTicks::Now(); |
256 | 256 |
257 std::vector<chrome_variations::ActiveGroupId> synthetic_trials; | 257 std::vector<variations::ActiveGroupId> synthetic_trials; |
258 service.GetCurrentSyntheticFieldTrials(&synthetic_trials); | 258 service.GetCurrentSyntheticFieldTrials(&synthetic_trials); |
259 EXPECT_EQ(2U, synthetic_trials.size()); | 259 EXPECT_EQ(2U, synthetic_trials.size()); |
260 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial1", "Group1")); | 260 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial1", "Group1")); |
261 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial2", "Group2")); | 261 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial2", "Group2")); |
262 | 262 |
263 // Ensure that time has advanced by at least a tick before proceeding. | 263 // Ensure that time has advanced by at least a tick before proceeding. |
264 WaitUntilTimeChanges(begin_log_time); | 264 WaitUntilTimeChanges(begin_log_time); |
265 | 265 |
266 // Change the group for the first trial after the log started. | 266 // Change the group for the first trial after the log started. |
267 SyntheticTrialGroup trial3(metrics::HashName("TestTrial1"), | 267 SyntheticTrialGroup trial3(metrics::HashName("TestTrial1"), |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 | 354 |
355 service.RemoveObserver(&observer1); | 355 service.RemoveObserver(&observer1); |
356 | 356 |
357 service.OpenNewLog(); | 357 service.OpenNewLog(); |
358 EXPECT_EQ(2, observer1.observed()); | 358 EXPECT_EQ(2, observer1.observed()); |
359 EXPECT_EQ(2, observer2.observed()); | 359 EXPECT_EQ(2, observer2.observed()); |
360 service.log_manager_.FinishCurrentLog(); | 360 service.log_manager_.FinishCurrentLog(); |
361 | 361 |
362 service.RemoveObserver(&observer2); | 362 service.RemoveObserver(&observer2); |
363 } | 363 } |
OLD | NEW |