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

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

Issue 2687393004: Gather stability prefs into managing objects. (Closed)
Patch Set: Incorporate Feedback Created 3 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
« no previous file with comments | « components/metrics/metrics_service.cc ('k') | components/metrics/stability_metrics_provider.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> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/metrics/metrics_hashes.h" 15 #include "base/metrics/metrics_hashes.h"
16 #include "base/metrics/statistics_recorder.h" 16 #include "base/metrics/statistics_recorder.h"
17 #include "base/metrics/user_metrics.h" 17 #include "base/metrics/user_metrics.h"
18 #include "base/test/scoped_feature_list.h" 18 #include "base/test/scoped_feature_list.h"
19 #include "base/test/test_simple_task_runner.h" 19 #include "base/test/test_simple_task_runner.h"
20 #include "base/threading/platform_thread.h" 20 #include "base/threading/platform_thread.h"
21 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
22 #include "components/metrics/client_info.h" 22 #include "components/metrics/client_info.h"
23 #include "components/metrics/environment_recorder.h"
23 #include "components/metrics/metrics_log.h" 24 #include "components/metrics/metrics_log.h"
24 #include "components/metrics/metrics_pref_names.h" 25 #include "components/metrics/metrics_pref_names.h"
25 #include "components/metrics/metrics_state_manager.h" 26 #include "components/metrics/metrics_state_manager.h"
26 #include "components/metrics/metrics_upload_scheduler.h" 27 #include "components/metrics/metrics_upload_scheduler.h"
27 #include "components/metrics/test_enabled_state_provider.h" 28 #include "components/metrics/test_enabled_state_provider.h"
28 #include "components/metrics/test_metrics_provider.h" 29 #include "components/metrics/test_metrics_provider.h"
29 #include "components/metrics/test_metrics_service_client.h" 30 #include "components/metrics/test_metrics_service_client.h"
30 #include "components/prefs/testing_pref_service.h" 31 #include "components/prefs/testing_pref_service.h"
31 #include "components/variations/metrics_util.h" 32 #include "components/variations/metrics_util.h"
32 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 206
206 // Save an existing system profile to prefs, to correspond to what would be 207 // Save an existing system profile to prefs, to correspond to what would be
207 // saved from a previous session. 208 // saved from a previous session.
208 TestMetricsServiceClient client; 209 TestMetricsServiceClient client;
209 TestMetricsLog log("client", 1, &client, GetLocalState()); 210 TestMetricsLog log("client", 1, &client, GetLocalState());
210 log.RecordEnvironment(std::vector<std::unique_ptr<MetricsProvider>>(), 211 log.RecordEnvironment(std::vector<std::unique_ptr<MetricsProvider>>(),
211 std::vector<variations::ActiveGroupId>(), 0, 0); 212 std::vector<variations::ActiveGroupId>(), 0, 0);
212 213
213 // Record stability build time and version from previous session, so that 214 // Record stability build time and version from previous session, so that
214 // stability metrics (including exited cleanly flag) won't be cleared. 215 // stability metrics (including exited cleanly flag) won't be cleared.
215 GetLocalState()->SetInt64(prefs::kStabilityStatsBuildTime, 216 EnvironmentRecorder(GetLocalState())
216 MetricsLog::GetBuildTime()); 217 .SetBuildtimeAndVersion(MetricsLog::GetBuildTime(),
217 GetLocalState()->SetString(prefs::kStabilityStatsVersion, 218 client.GetVersionString());
218 client.GetVersionString());
219 219
220 // Set the clean exit flag, as that will otherwise cause a stabilty 220 // Set the clean exit flag, as that will otherwise cause a stabilty
221 // log to be produced, irrespective provider requests. 221 // log to be produced, irrespective provider requests.
222 GetLocalState()->SetBoolean(prefs::kStabilityExitedCleanly, true); 222 GetLocalState()->SetBoolean(prefs::kStabilityExitedCleanly, true);
223 223
224 TestMetricsService service( 224 TestMetricsService service(
225 GetMetricsStateManager(), &client, GetLocalState()); 225 GetMetricsStateManager(), &client, GetLocalState());
226 // Add a metrics provider that requests a stability log. 226 // Add a metrics provider that requests a stability log.
227 TestMetricsProvider* test_provider = new TestMetricsProvider(); 227 TestMetricsProvider* test_provider = new TestMetricsProvider();
228 test_provider->set_has_initial_stability_metrics(true); 228 test_provider->set_has_initial_stability_metrics(true);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 277
278 // Save an existing system profile to prefs, to correspond to what would be 278 // Save an existing system profile to prefs, to correspond to what would be
279 // saved from a previous session. 279 // saved from a previous session.
280 TestMetricsServiceClient client; 280 TestMetricsServiceClient client;
281 TestMetricsLog log("client", 1, &client, GetLocalState()); 281 TestMetricsLog log("client", 1, &client, GetLocalState());
282 log.RecordEnvironment(std::vector<std::unique_ptr<MetricsProvider>>(), 282 log.RecordEnvironment(std::vector<std::unique_ptr<MetricsProvider>>(),
283 std::vector<variations::ActiveGroupId>(), 0, 0); 283 std::vector<variations::ActiveGroupId>(), 0, 0);
284 284
285 // Record stability build time and version from previous session, so that 285 // Record stability build time and version from previous session, so that
286 // stability metrics (including exited cleanly flag) won't be cleared. 286 // stability metrics (including exited cleanly flag) won't be cleared.
287 GetLocalState()->SetInt64(prefs::kStabilityStatsBuildTime, 287 EnvironmentRecorder(GetLocalState())
288 MetricsLog::GetBuildTime()); 288 .SetBuildtimeAndVersion(MetricsLog::GetBuildTime(),
289 GetLocalState()->SetString(prefs::kStabilityStatsVersion, 289 client.GetVersionString());
290 client.GetVersionString());
291 290
292 GetLocalState()->SetBoolean(prefs::kStabilityExitedCleanly, false); 291 GetLocalState()->SetBoolean(prefs::kStabilityExitedCleanly, false);
293 292
294 TestMetricsService service( 293 TestMetricsService service(
295 GetMetricsStateManager(), &client, GetLocalState()); 294 GetMetricsStateManager(), &client, GetLocalState());
296 // Add a provider. 295 // Add a provider.
297 TestMetricsProvider* test_provider = new TestMetricsProvider(); 296 TestMetricsProvider* test_provider = new TestMetricsProvider();
298 service.RegisterMetricsProvider( 297 service.RegisterMetricsProvider(
299 std::unique_ptr<MetricsProvider>(test_provider)); 298 std::unique_ptr<MetricsProvider>(test_provider));
300 service.InitializeMetricsRecordingState(); 299 service.InitializeMetricsRecordingState();
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 client.uploader()->CompleteUpload(200); 547 client.uploader()->CompleteUpload(200);
549 EXPECT_FALSE(client.uploader()->is_uploading()); 548 EXPECT_FALSE(client.uploader()->is_uploading());
550 EXPECT_EQ(1U, task_runner_->NumPendingTasks()); 549 EXPECT_EQ(1U, task_runner_->NumPendingTasks());
551 // Upload should start. 550 // Upload should start.
552 task_runner_->RunPendingTasks(); 551 task_runner_->RunPendingTasks();
553 EXPECT_TRUE(client.uploader()->is_uploading()); 552 EXPECT_TRUE(client.uploader()->is_uploading());
554 EXPECT_EQ(0U, task_runner_->NumPendingTasks()); 553 EXPECT_EQ(0U, task_runner_->NumPendingTasks());
555 } 554 }
556 555
557 } // namespace metrics 556 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/metrics_service.cc ('k') | components/metrics/stability_metrics_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698