| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 // Associates the metrics in the file with the current run of the browser. | 73 // Associates the metrics in the file with the current run of the browser. |
| 74 // The reporting will take place as part of the normal logging of | 74 // The reporting will take place as part of the normal logging of |
| 75 // histograms. | 75 // histograms. |
| 76 ASSOCIATE_CURRENT_RUN, | 76 ASSOCIATE_CURRENT_RUN, |
| 77 | 77 |
| 78 // Associates the metrics in the file with the previous run of the browesr. | 78 // Associates the metrics in the file with the previous run of the browesr. |
| 79 // The reporting will take place as part of the "stability" histograms. | 79 // The reporting will take place as part of the "stability" histograms. |
| 80 // This is important when metrics are dumped as part of a crash of the | 80 // This is important when metrics are dumped as part of a crash of the |
| 81 // previous run. This can only be used with FILE_HISTOGRAMS_ATOMIC. | 81 // previous run. This can only be used with FILE_HISTOGRAMS_ATOMIC. |
| 82 ASSOCIATE_PREVIOUS_RUN, | 82 ASSOCIATE_PREVIOUS_RUN, |
| 83 |
| 84 // Associates the metrics in the file with the a profile embedded in the |
| 85 // same file. The reporting will take place at a convenient time after |
| 86 // startup when the browser is otherwise idle. If there is no embedded |
| 87 // system profile, these metrics will be lost. |
| 88 ASSOCIATE_INTERNAL_PROFILE, |
| 89 |
| 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 |
| 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 |
| 94 // embedded profile is found. |
| 95 ASSOCIATE_INTERNAL_PROFILE_OR_PREVIOUS_RUN, |
| 83 }; | 96 }; |
| 84 | 97 |
| 85 FileMetricsProvider(const scoped_refptr<base::TaskRunner>& task_runner, | 98 FileMetricsProvider(const scoped_refptr<base::TaskRunner>& task_runner, |
| 86 PrefService* local_state); | 99 PrefService* local_state); |
| 87 ~FileMetricsProvider() override; | 100 ~FileMetricsProvider() override; |
| 88 | 101 |
| 89 // Indicates a file or directory to be monitored and how the file or files | 102 // Indicates a file or directory to be monitored and how the file or files |
| 90 // within that directory are used. Because some metadata may need to persist | 103 // within that directory are used. Because some metadata may need to persist |
| 91 // across process restarts, preferences entries are used based on the | 104 // across process restarts, preferences entries are used based on the |
| 92 // |prefs_key| name. Call RegisterPrefs() with the same name to create the | 105 // |prefs_key| name. Call RegisterPrefs() with the same name to create the |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 // inside the .cc file. | 153 // inside the .cc file. |
| 141 struct SourceInfo; | 154 struct SourceInfo; |
| 142 using SourceInfoList = std::list<std::unique_ptr<SourceInfo>>; | 155 using SourceInfoList = std::list<std::unique_ptr<SourceInfo>>; |
| 143 | 156 |
| 144 // Looks for the next file to read within a directory. Returns true if a | 157 // Looks for the next file to read within a directory. Returns true if a |
| 145 // file was found. This is part of CheckAndMapNewMetricSourcesOnTaskRunner | 158 // file was found. This is part of CheckAndMapNewMetricSourcesOnTaskRunner |
| 146 // and so runs on an thread capable of I/O. The |source| structure will | 159 // and so runs on an thread capable of I/O. The |source| structure will |
| 147 // be internally updated to indicate the next file to be read. | 160 // be internally updated to indicate the next file to be read. |
| 148 static bool LocateNextFileInDirectory(SourceInfo* source); | 161 static bool LocateNextFileInDirectory(SourceInfo* source); |
| 149 | 162 |
| 163 // Handles the completion of a source. |
| 164 static void FinishedWithSource(SourceInfo* source, AccessResult result); |
| 165 |
| 150 // Checks a list of sources (on a task-runner allowed to do I/O) and merge | 166 // Checks a list of sources (on a task-runner allowed to do I/O) and merge |
| 151 // any data found within them. | 167 // any data found within them. |
| 152 static void CheckAndMergeMetricSourcesOnTaskRunner(SourceInfoList* sources); | 168 static void CheckAndMergeMetricSourcesOnTaskRunner(SourceInfoList* sources); |
| 153 | 169 |
| 154 // Checks a single source and maps it into memory. | 170 // Checks a single source and maps it into memory. |
| 155 static AccessResult CheckAndMapMetricSource(SourceInfo* source); | 171 static AccessResult CheckAndMapMetricSource(SourceInfo* source); |
| 156 | 172 |
| 157 // Merges all of the histograms from a |source| to the StatisticsRecorder. | 173 // Merges all of the histograms from a |source| to the StatisticsRecorder. |
| 158 static void MergeHistogramDeltasFromSource(SourceInfo* source); | 174 static void MergeHistogramDeltasFromSource(SourceInfo* source); |
| 159 | 175 |
| 160 // Records all histograms from a given source via a snapshot-manager. | 176 // Records all histograms from a given source via a snapshot-manager. |
| 161 static void RecordHistogramSnapshotsFromSource( | 177 static void RecordHistogramSnapshotsFromSource( |
| 162 base::HistogramSnapshotManager* snapshot_manager, | 178 base::HistogramSnapshotManager* snapshot_manager, |
| 163 SourceInfo* source); | 179 SourceInfo* source); |
| 164 | 180 |
| 165 // Creates a task to check all monitored sources for updates. | 181 // Creates a task to check all monitored sources for updates. |
| 166 void ScheduleSourcesCheck(); | 182 void ScheduleSourcesCheck(); |
| 167 | 183 |
| 168 // Takes a list of sources checked by an external task and determines what | 184 // Takes a list of sources checked by an external task and determines what |
| 169 // to do with each. | 185 // to do with each. |
| 170 void RecordSourcesChecked(SourceInfoList* checked); | 186 void RecordSourcesChecked(SourceInfoList* checked); |
| 171 | 187 |
| 172 // Schedules the deletion of a file in the background using the task-runner. | 188 // Schedules the deletion of a file in the background using the task-runner. |
| 173 void DeleteFileAsync(const base::FilePath& path); | 189 void DeleteFileAsync(const base::FilePath& path); |
| 174 | 190 |
| 175 // Updates the persistent state information to show a source as being read. | 191 // Updates the persistent state information to show a source as being read. |
| 176 void RecordSourceAsRead(SourceInfo* source); | 192 void RecordSourceAsRead(SourceInfo* source); |
| 177 | 193 |
| 178 // metrics::MetricsDataProvider: | 194 // metrics::MetricsProvider: |
| 179 void OnDidCreateMetricsLog() override; | 195 void OnDidCreateMetricsLog() override; |
| 196 bool ProvideIndependentMetrics( |
| 197 SystemProfileProto* system_profile_proto, |
| 198 base::HistogramSnapshotManager* snapshot_manager) override; |
| 180 bool HasInitialStabilityMetrics() override; | 199 bool HasInitialStabilityMetrics() override; |
| 181 void RecordInitialHistogramSnapshots( | 200 void RecordInitialHistogramSnapshots( |
| 182 base::HistogramSnapshotManager* snapshot_manager) override; | 201 base::HistogramSnapshotManager* snapshot_manager) override; |
| 183 | 202 |
| 184 // base::StatisticsRecorder::HistogramProvider: | 203 // base::StatisticsRecorder::HistogramProvider: |
| 185 void MergeHistogramDeltas() override; | 204 void MergeHistogramDeltas() override; |
| 186 | 205 |
| 187 // A task-runner capable of performing I/O. | 206 // A task-runner capable of performing I/O. |
| 188 scoped_refptr<base::TaskRunner> task_runner_; | 207 scoped_refptr<base::TaskRunner> task_runner_; |
| 189 | 208 |
| 190 // A list of sources not currently active that need to be checked for changes. | 209 // A list of sources not currently active that need to be checked for changes. |
| 191 SourceInfoList sources_to_check_; | 210 SourceInfoList sources_to_check_; |
| 192 | 211 |
| 193 // A list of currently active sources to be merged when required. | 212 // A list of currently active sources to be merged when required. |
| 194 SourceInfoList sources_mapped_; | 213 SourceInfoList sources_mapped_; |
| 195 | 214 |
| 215 // A list of currently active sources to be merged when required. |
| 216 SourceInfoList sources_with_profile_; |
| 217 |
| 196 // A list of sources for a previous run. These are held separately because | 218 // A list of sources for a previous run. These are held separately because |
| 197 // they are not subject to the periodic background checking that handles | 219 // they are not subject to the periodic background checking that handles |
| 198 // metrics for the current run. | 220 // metrics for the current run. |
| 199 SourceInfoList sources_for_previous_run_; | 221 SourceInfoList sources_for_previous_run_; |
| 200 | 222 |
| 201 // The preferences-service used to store persistent state about sources. | 223 // The preferences-service used to store persistent state about sources. |
| 202 PrefService* pref_service_; | 224 PrefService* pref_service_; |
| 203 | 225 |
| 204 base::ThreadChecker thread_checker_; | 226 base::ThreadChecker thread_checker_; |
| 205 base::WeakPtrFactory<FileMetricsProvider> weak_factory_; | 227 base::WeakPtrFactory<FileMetricsProvider> weak_factory_; |
| 206 | 228 |
| 207 DISALLOW_COPY_AND_ASSIGN(FileMetricsProvider); | 229 DISALLOW_COPY_AND_ASSIGN(FileMetricsProvider); |
| 208 }; | 230 }; |
| 209 | 231 |
| 210 } // namespace metrics | 232 } // namespace metrics |
| 211 | 233 |
| 212 #endif // COMPONENTS_METRICS_FILE_METRICS_PROVIDER_H_ | 234 #endif // COMPONENTS_METRICS_FILE_METRICS_PROVIDER_H_ |
| OLD | NEW |