OLD | NEW |
---|---|
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> |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 | 45 |
46 // "Active" files may be open by one or more other processes and updated | 46 // "Active" files may be open by one or more other processes and updated |
47 // at any time with new samples or new histograms. Such files may also be | 47 // at any time with new samples or new histograms. Such files may also be |
48 // inactive for any period of time only to be opened again and have new | 48 // inactive for any period of time only to be opened again and have new |
49 // data written to them. The file should probably never be deleted because | 49 // data written to them. The file should probably never be deleted because |
50 // there would be no guarantee that the data has been reported. | 50 // there would be no guarantee that the data has been reported. |
51 // TODO(bcwhite): Enable when read/write mem-mapped files are supported. | 51 // TODO(bcwhite): Enable when read/write mem-mapped files are supported. |
52 //FILE_HISTOGRAMS_ACTIVE, | 52 //FILE_HISTOGRAMS_ACTIVE, |
53 }; | 53 }; |
54 | 54 |
55 enum FileAssociation { | |
56 // Associates the metrics in the file with the current run of the browser. | |
57 // The reporting will take place as part of the normal logging of | |
58 // histograms. | |
59 ASSOCIATE_CURRENT_RUN, | |
60 | |
61 // Associates the metrics in the file with the previous run of the browesr. | |
62 // The reporting will take place as part of the "stability" histograms. | |
63 // This is important when metrics are dumped as part of a crash of the | |
64 // previous run. This can only be used with FILE_HISTOGRAMS_ATOMIC. | |
65 ASSOCIATE_PREVIOUS_RUN, | |
66 }; | |
67 | |
55 FileMetricsProvider(const scoped_refptr<base::TaskRunner>& task_runner, | 68 FileMetricsProvider(const scoped_refptr<base::TaskRunner>& task_runner, |
56 PrefService* local_state); | 69 PrefService* local_state); |
57 ~FileMetricsProvider() override; | 70 ~FileMetricsProvider() override; |
58 | 71 |
59 // Indicates a file to be monitored and how the file is used. Because some | 72 // Indicates a file to be monitored and how the file is used. Because some |
60 // metadata may persist across process restarts, preferences entries are | 73 // metadata may persist across process restarts, preferences entries are |
61 // used based on the |prefs_key| name. Call RegisterPrefs() with the same | 74 // used based on the |prefs_key| name. Call RegisterPrefs() with the same |
62 // name to create the necessary keys in advance. Set |prefs_key| empty | 75 // name to create the necessary keys in advance. Set |prefs_key| empty |
63 // if no persistence is required. | 76 // if no persistence is required. |
64 void RegisterFile(const base::FilePath& path, | 77 void RegisterFile(const base::FilePath& path, |
65 FileType type, | 78 FileType type, |
79 FileAssociation file_association, | |
66 const base::StringPiece prefs_key); | 80 const base::StringPiece prefs_key); |
67 | 81 |
68 // Registers all necessary preferences for maintaining persistent state | 82 // Registers all necessary preferences for maintaining persistent state |
69 // about a monitored file across process restarts. The |prefs_key| is | 83 // about a monitored file across process restarts. The |prefs_key| is |
70 // typically the filename. | 84 // typically the filename. |
71 static void RegisterPrefs(PrefRegistrySimple* prefs, | 85 static void RegisterPrefs(PrefRegistrySimple* prefs, |
72 const base::StringPiece prefs_key); | 86 const base::StringPiece prefs_key); |
73 | 87 |
74 private: | 88 private: |
75 friend class FileMetricsProviderTest; | 89 friend class FileMetricsProviderTest; |
76 FRIEND_TEST_ALL_PREFIXES(FileMetricsProviderTest, AccessMetrics); | 90 FRIEND_TEST_ALL_PREFIXES(FileMetricsProviderTest, AccessMetrics); |
91 FRIEND_TEST_ALL_PREFIXES(FileMetricsProviderTest, AccessStabilityMetrics); | |
77 | 92 |
78 // The different results that can occur accessing a file. | 93 // The different results that can occur accessing a file. |
79 enum AccessResult { | 94 enum AccessResult { |
80 // File was successfully mapped. | 95 // File was successfully mapped. |
81 ACCESS_RESULT_SUCCESS, | 96 ACCESS_RESULT_SUCCESS, |
82 | 97 |
83 // File does not exist. | 98 // File does not exist. |
84 ACCESS_RESULT_DOESNT_EXIST, | 99 ACCESS_RESULT_DOESNT_EXIST, |
85 | 100 |
86 // File exists but not modified since last read. | 101 // File exists but not modified since last read. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 | 139 |
125 // Takes a list of files checked by an external task and determines what | 140 // Takes a list of files checked by an external task and determines what |
126 // to do with each. | 141 // to do with each. |
127 void RecordFilesChecked(FileInfoList* checked); | 142 void RecordFilesChecked(FileInfoList* checked); |
128 | 143 |
129 // Updates the persistent state information to show a file as being read. | 144 // Updates the persistent state information to show a file as being read. |
130 void RecordFileAsSeen(FileInfo* file); | 145 void RecordFileAsSeen(FileInfo* file); |
131 | 146 |
132 // metrics::MetricsDataProvider: | 147 // metrics::MetricsDataProvider: |
133 void OnDidCreateMetricsLog() override; | 148 void OnDidCreateMetricsLog() override; |
149 bool HasInitialStabilityMetrics() override; | |
134 void RecordHistogramSnapshots( | 150 void RecordHistogramSnapshots( |
135 base::HistogramSnapshotManager* snapshot_manager) override; | 151 base::HistogramSnapshotManager* snapshot_manager) override; |
152 void RecordStabilityHistogramSnapshots( | |
153 base::HistogramSnapshotManager* snapshot_manager) override; | |
136 | 154 |
137 // A task-runner capable of performing I/O. | 155 // A task-runner capable of performing I/O. |
138 scoped_refptr<base::TaskRunner> task_runner_; | 156 scoped_refptr<base::TaskRunner> task_runner_; |
139 | 157 |
140 // A list of files not currently active that need to be checked for changes. | 158 // A list of files not currently active that need to be checked for changes. |
141 FileInfoList files_to_check_; | 159 FileInfoList files_to_check_; |
142 | 160 |
143 // A list of files that have data to be read and reported. | 161 // A list of files that have data to be read and reported. |
144 FileInfoList files_to_read_; | 162 FileInfoList files_to_read_; |
145 | 163 |
164 // A list of files for a previous run. These are held separately because | |
165 // they are not subject to the periodic background checking that handles | |
166 // metrics for the current run. | |
167 FileInfoList files_for_previous_; | |
Ilya Sherman
2016/05/04 06:48:08
nit: s/for_previous/for_previous_runs
bcwhite
2016/05/04 14:12:51
Done.
| |
168 | |
146 // The preferences-service used to store persistent state about files. | 169 // The preferences-service used to store persistent state about files. |
147 PrefService* pref_service_; | 170 PrefService* pref_service_; |
148 | 171 |
149 base::ThreadChecker thread_checker_; | 172 base::ThreadChecker thread_checker_; |
150 base::WeakPtrFactory<FileMetricsProvider> weak_factory_; | 173 base::WeakPtrFactory<FileMetricsProvider> weak_factory_; |
151 | 174 |
152 DISALLOW_COPY_AND_ASSIGN(FileMetricsProvider); | 175 DISALLOW_COPY_AND_ASSIGN(FileMetricsProvider); |
153 }; | 176 }; |
154 | 177 |
155 } // namespace metrics | 178 } // namespace metrics |
156 | 179 |
157 #endif // COMPONENTS_METRICS_FILE_METRICS_PROVIDER_H_ | 180 #endif // COMPONENTS_METRICS_FILE_METRICS_PROVIDER_H_ |
OLD | NEW |