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

Side by Side Diff: components/metrics/file_metrics_provider.h

Issue 2965753002: [Cleanup] Migrate the FileMetricsProvider to use the Task Scheduler. (Closed)
Patch Set: 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
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 #ifndef COMPONENTS_METRICS_FILE_METRICS_PROVIDER_H_ 5 #ifndef COMPONENTS_METRICS_FILE_METRICS_PROVIDER_H_
6 #define COMPONENTS_METRICS_FILE_METRICS_PROVIDER_H_ 6 #define COMPONENTS_METRICS_FILE_METRICS_PROVIDER_H_
7 7
8 #include <list> 8 #include <list>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/metrics/statistics_recorder.h" 16 #include "base/metrics/statistics_recorder.h"
17 #include "base/threading/thread_checker.h" 17 #include "base/sequence_checker.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "components/metrics/metrics_provider.h" 19 #include "components/metrics/metrics_provider.h"
20 20
21 class PrefRegistrySimple; 21 class PrefRegistrySimple;
22 class PrefService; 22 class PrefService;
23 23
24 namespace base { 24 namespace base {
25 class TaskRunner; 25 class TaskRunner;
26 } 26 }
27 27
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 ASSOCIATE_INTERNAL_PROFILE, 88 ASSOCIATE_INTERNAL_PROFILE,
89 89
90 // Like above but fall back to ASSOCIATE_PREVIOUS_RUN if there is no 90 // Like above but fall back to ASSOCIATE_PREVIOUS_RUN if there is no
91 // embedded profile. This has a small cost during startup as that is 91 // embedded profile. This has a small cost during startup as that is
92 // when previous-run metrics are sent so the file has be checked at 92 // when previous-run metrics are sent so the file has be checked at
93 // that time even though actual transfer will be delayed if an 93 // that time even though actual transfer will be delayed if an
94 // embedded profile is found. 94 // embedded profile is found.
95 ASSOCIATE_INTERNAL_PROFILE_OR_PREVIOUS_RUN, 95 ASSOCIATE_INTERNAL_PROFILE_OR_PREVIOUS_RUN,
96 }; 96 };
97 97
98 FileMetricsProvider(const scoped_refptr<base::TaskRunner>& task_runner, 98 explicit FileMetricsProvider(PrefService* local_state);
99 PrefService* local_state);
100 ~FileMetricsProvider() override; 99 ~FileMetricsProvider() override;
101 100
102 // Indicates a file or directory to be monitored and how the file or files 101 // Indicates a file or directory to be monitored and how the file or files
103 // within that directory are used. Because some metadata may need to persist 102 // within that directory are used. Because some metadata may need to persist
104 // across process restarts, preferences entries are used based on the 103 // across process restarts, preferences entries are used based on the
105 // |prefs_key| name. Call RegisterPrefs() with the same name to create the 104 // |prefs_key| name. Call RegisterPrefs() with the same name to create the
106 // necessary keys in advance. Set |prefs_key| empty (nullptr will work) if 105 // necessary keys in advance. Set |prefs_key| empty (nullptr will work) if
107 // no persistence is required. ACTIVE files shouldn't have a pref key as 106 // no persistence is required. ACTIVE files shouldn't have a pref key as
108 // they update internal state about what has been previously sent. 107 // they update internal state about what has been previously sent.
109 void RegisterSource(const base::FilePath& path, 108 void RegisterSource(const base::FilePath& path,
110 SourceType type, 109 SourceType type,
111 SourceAssociation source_association, 110 SourceAssociation source_association,
112 const base::StringPiece prefs_key); 111 const base::StringPiece prefs_key);
113 112
114 // Registers all necessary preferences for maintaining persistent state 113 // Registers all necessary preferences for maintaining persistent state
115 // about a monitored file across process restarts. The |prefs_key| is 114 // about a monitored file across process restarts. The |prefs_key| is
116 // typically the filename. 115 // typically the filename.
117 static void RegisterPrefs(PrefRegistrySimple* prefs, 116 static void RegisterPrefs(PrefRegistrySimple* prefs,
118 const base::StringPiece prefs_key); 117 const base::StringPiece prefs_key);
119 118
119 // Sets the task runner to use for testing.
120 static void SetTaskRunnerForTesting(
121 const scoped_refptr<base::TaskRunner>& task_runner);
122
120 private: 123 private:
121 friend class FileMetricsProviderTest; 124 friend class FileMetricsProviderTest;
122 125
123 // The different results that can occur accessing a file. 126 // The different results that can occur accessing a file.
124 enum AccessResult { 127 enum AccessResult {
125 // File was successfully mapped. 128 // File was successfully mapped.
126 ACCESS_RESULT_SUCCESS, 129 ACCESS_RESULT_SUCCESS,
127 130
128 // File does not exist. 131 // File does not exist.
129 ACCESS_RESULT_DOESNT_EXIST, 132 ACCESS_RESULT_DOESNT_EXIST,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 SourceInfoList sources_with_profile_; 219 SourceInfoList sources_with_profile_;
217 220
218 // A list of sources for a previous run. These are held separately because 221 // A list of sources for a previous run. These are held separately because
219 // they are not subject to the periodic background checking that handles 222 // they are not subject to the periodic background checking that handles
220 // metrics for the current run. 223 // metrics for the current run.
221 SourceInfoList sources_for_previous_run_; 224 SourceInfoList sources_for_previous_run_;
222 225
223 // The preferences-service used to store persistent state about sources. 226 // The preferences-service used to store persistent state about sources.
224 PrefService* pref_service_; 227 PrefService* pref_service_;
225 228
226 base::ThreadChecker thread_checker_; 229 SEQUENCE_CHECKER(sequence_checker_);
227 base::WeakPtrFactory<FileMetricsProvider> weak_factory_; 230 base::WeakPtrFactory<FileMetricsProvider> weak_factory_;
228 231
229 DISALLOW_COPY_AND_ASSIGN(FileMetricsProvider); 232 DISALLOW_COPY_AND_ASSIGN(FileMetricsProvider);
230 }; 233 };
231 234
232 } // namespace metrics 235 } // namespace metrics
233 236
234 #endif // COMPONENTS_METRICS_FILE_METRICS_PROVIDER_H_ 237 #endif // COMPONENTS_METRICS_FILE_METRICS_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698