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

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

Issue 2965753002: [Cleanup] Migrate the FileMetricsProvider to use the Task Scheduler. (Closed)
Patch Set: Change DCHECK syntax Created 3 years, 5 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/file_metrics_provider.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/file_metrics_provider.h" 5 #include "components/metrics/file_metrics_provider.h"
6 6
7 #include <functional> 7 #include <functional>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/files/memory_mapped_file.h" 10 #include "base/files/memory_mapped_file.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 80
81 FileMetricsProviderTest() 81 FileMetricsProviderTest()
82 : create_large_files_(GetParam()), 82 : create_large_files_(GetParam()),
83 task_runner_(new base::TestSimpleTaskRunner()), 83 task_runner_(new base::TestSimpleTaskRunner()),
84 thread_task_runner_handle_(task_runner_), 84 thread_task_runner_handle_(task_runner_),
85 statistics_recorder_( 85 statistics_recorder_(
86 base::StatisticsRecorder::CreateTemporaryForTesting()), 86 base::StatisticsRecorder::CreateTemporaryForTesting()),
87 prefs_(new TestingPrefServiceSimple) { 87 prefs_(new TestingPrefServiceSimple) {
88 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); 88 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
89 FileMetricsProvider::RegisterPrefs(prefs_->registry(), kMetricsName); 89 FileMetricsProvider::RegisterPrefs(prefs_->registry(), kMetricsName);
90 FileMetricsProvider::SetTaskRunnerForTesting(task_runner_);
90 } 91 }
91 92
92 ~FileMetricsProviderTest() override { 93 ~FileMetricsProviderTest() override {
93 // Clear out any final remaining tasks. 94 // Clear out any final remaining tasks.
94 task_runner_->RunUntilIdle(); 95 task_runner_->RunUntilIdle();
95 // If a global histogram allocator exists at this point then it likely 96 // If a global histogram allocator exists at this point then it likely
96 // acquired histograms that will continue to point to the released 97 // acquired histograms that will continue to point to the released
97 // memory and potentially cause use-after-free memory corruption. 98 // memory and potentially cause use-after-free memory corruption.
98 DCHECK(!base::GlobalHistogramAllocator::Get()); 99 DCHECK(!base::GlobalHistogramAllocator::Get());
99 } 100 }
100 101
101 TestingPrefServiceSimple* prefs() { return prefs_.get(); } 102 TestingPrefServiceSimple* prefs() { return prefs_.get(); }
102 base::FilePath temp_dir() { return temp_dir_.GetPath(); } 103 base::FilePath temp_dir() { return temp_dir_.GetPath(); }
103 base::FilePath metrics_file() { 104 base::FilePath metrics_file() {
104 return temp_dir_.GetPath().AppendASCII(kMetricsFilename); 105 return temp_dir_.GetPath().AppendASCII(kMetricsFilename);
105 } 106 }
106 107
107 FileMetricsProvider* provider() { 108 FileMetricsProvider* provider() {
108 if (!provider_) 109 if (!provider_)
109 provider_.reset(new FileMetricsProvider(task_runner_, prefs())); 110 provider_.reset(new FileMetricsProvider(prefs()));
110 return provider_.get(); 111 return provider_.get();
111 } 112 }
112 113
113 void OnDidCreateMetricsLog() { 114 void OnDidCreateMetricsLog() {
114 provider()->OnDidCreateMetricsLog(); 115 provider()->OnDidCreateMetricsLog();
115 } 116 }
116 117
117 bool HasInitialStabilityMetrics() { 118 bool HasInitialStabilityMetrics() {
118 return provider()->HasInitialStabilityMetrics(); 119 return provider()->HasInitialStabilityMetrics();
119 } 120 }
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 } 646 }
646 EXPECT_FALSE(ProvideIndependentMetrics(&profile, &snapshot_manager)); 647 EXPECT_FALSE(ProvideIndependentMetrics(&profile, &snapshot_manager));
647 648
648 OnDidCreateMetricsLog(); 649 OnDidCreateMetricsLog();
649 RunTasks(); 650 RunTasks();
650 for (const auto& file_name : file_names) 651 for (const auto& file_name : file_names)
651 EXPECT_FALSE(base::PathExists(file_name)); 652 EXPECT_FALSE(base::PathExists(file_name));
652 } 653 }
653 654
654 } // namespace metrics 655 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/file_metrics_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698