OLD | NEW |
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 // This file defines a service that collects information about the user | 5 // This file defines a service that collects information about the user |
6 // experience in order to help improve future versions of the app. | 6 // experience in order to help improve future versions of the app. |
7 | 7 |
8 #ifndef COMPONENTS_METRICS_METRICS_SERVICE_H_ | 8 #ifndef COMPONENTS_METRICS_METRICS_SERVICE_H_ |
9 #define COMPONENTS_METRICS_METRICS_SERVICE_H_ | 9 #define COMPONENTS_METRICS_METRICS_SERVICE_H_ |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "base/metrics/histogram_flattener.h" | 21 #include "base/metrics/histogram_flattener.h" |
22 #include "base/metrics/histogram_snapshot_manager.h" | 22 #include "base/metrics/histogram_snapshot_manager.h" |
23 #include "base/metrics/user_metrics.h" | 23 #include "base/metrics/user_metrics.h" |
24 #include "base/observer_list.h" | 24 #include "base/observer_list.h" |
25 #include "base/time/time.h" | 25 #include "base/time/time.h" |
26 #include "components/metrics/clean_exit_beacon.h" | 26 #include "components/metrics/clean_exit_beacon.h" |
27 #include "components/metrics/metrics_log.h" | 27 #include "components/metrics/metrics_log.h" |
28 #include "components/metrics/metrics_log_manager.h" | 28 #include "components/metrics/metrics_log_manager.h" |
29 #include "components/metrics/metrics_provider.h" | 29 #include "components/metrics/metrics_provider.h" |
30 #include "components/metrics/net/network_metrics_provider.h" | 30 #include "components/metrics/net/network_metrics_provider.h" |
31 #include "components/variations/active_field_trials.h" | 31 #include "components/variations/synthetic_trials.h" |
32 | 32 |
33 class PrefService; | 33 class PrefService; |
34 class PrefRegistrySimple; | 34 class PrefRegistrySimple; |
35 | 35 |
36 namespace base { | 36 namespace base { |
37 class DictionaryValue; | 37 class DictionaryValue; |
38 class HistogramSamples; | 38 class HistogramSamples; |
39 class PrefService; | 39 class PrefService; |
40 } | 40 } |
41 | 41 |
42 namespace variations { | 42 namespace variations { |
43 struct ActiveGroupId; | 43 struct ActiveGroupId; |
44 } | 44 } |
45 | 45 |
46 namespace net { | 46 namespace net { |
47 class URLFetcher; | 47 class URLFetcher; |
48 } | 48 } |
49 | 49 |
50 namespace metrics { | 50 namespace metrics { |
51 | 51 |
52 class MetricsLogUploader; | 52 class MetricsLogUploader; |
53 class MetricsReportingScheduler; | 53 class MetricsReportingScheduler; |
54 class MetricsServiceAccessor; | 54 class MetricsServiceAccessor; |
55 class MetricsServiceClient; | 55 class MetricsServiceClient; |
56 class MetricsStateManager; | 56 class MetricsStateManager; |
57 | 57 |
58 // A Field Trial and its selected group, which represent a particular | |
59 // Chrome configuration state. For example, the trial name could map to | |
60 // a preference name, and the group name could map to a preference value. | |
61 struct SyntheticTrialGroup { | |
62 public: | |
63 ~SyntheticTrialGroup(); | |
64 | |
65 variations::ActiveGroupId id; | |
66 base::TimeTicks start_time; | |
67 | |
68 private: | |
69 // Synthetic field trial users: | |
70 friend class MetricsServiceAccessor; | |
71 friend class MetricsService; | |
72 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); | |
73 | |
74 // This constructor is private specifically so as to control which code is | |
75 // able to access it. New code that wishes to use it should be added as a | |
76 // friend class. | |
77 SyntheticTrialGroup(uint32 trial, uint32 group); | |
78 }; | |
79 | |
80 // Interface class to observe changes to synthetic trials in MetricsService. | |
81 class SyntheticTrialObserver { | |
82 public: | |
83 // Called when the list of synthetic field trial groups has changed. | |
84 virtual void OnSyntheticTrialsChanged( | |
85 const std::vector<SyntheticTrialGroup>& groups) = 0; | |
86 | |
87 protected: | |
88 virtual ~SyntheticTrialObserver() {} | |
89 }; | |
90 | |
91 // See metrics_service.cc for a detailed description. | 58 // See metrics_service.cc for a detailed description. |
92 class MetricsService : public base::HistogramFlattener { | 59 class MetricsService : public base::HistogramFlattener { |
93 public: | 60 public: |
94 // The execution phase of the browser. | 61 // The execution phase of the browser. |
95 enum ExecutionPhase { | 62 enum ExecutionPhase { |
96 UNINITIALIZED_PHASE = 0, | 63 UNINITIALIZED_PHASE = 0, |
97 START_METRICS_RECORDING = 100, | 64 START_METRICS_RECORDING = 100, |
98 CREATE_PROFILE = 200, | 65 CREATE_PROFILE = 200, |
99 STARTUP_TIMEBOMB_ARM = 300, | 66 STARTUP_TIMEBOMB_ARM = 300, |
100 THREAD_WATCHER_START = 400, | 67 THREAD_WATCHER_START = 400, |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 // This count is eventually send via UMA logs. | 176 // This count is eventually send via UMA logs. |
210 void RecordBreakpadHasDebugger(bool has_debugger); | 177 void RecordBreakpadHasDebugger(bool has_debugger); |
211 | 178 |
212 bool recording_active() const; | 179 bool recording_active() const; |
213 bool reporting_active() const; | 180 bool reporting_active() const; |
214 | 181 |
215 // Redundant test to ensure that we are notified of a clean exit. | 182 // Redundant test to ensure that we are notified of a clean exit. |
216 // This value should be true when process has completed shutdown. | 183 // This value should be true when process has completed shutdown. |
217 static bool UmaMetricsProperlyShutdown(); | 184 static bool UmaMetricsProperlyShutdown(); |
218 | 185 |
219 // Registers a field trial name and group to be used to annotate a UMA report | |
220 // with a particular Chrome configuration state. A UMA report will be | |
221 // annotated with this trial group if and only if all events in the report | |
222 // were created after the trial is registered. Only one group name may be | |
223 // registered at a time for a given trial_name. Only the last group name that | |
224 // is registered for a given trial name will be recorded. The values passed | |
225 // in must not correspond to any real field trial in the code. | |
226 // To use this method, SyntheticTrialGroup should friend your class. | |
227 void RegisterSyntheticFieldTrial(const SyntheticTrialGroup& trial_group); | |
228 | |
229 // Public accessor that returns the list of synthetic field trials. It must | 186 // Public accessor that returns the list of synthetic field trials. It must |
230 // only be used for testing. | 187 // only be used for testing. |
231 void GetCurrentSyntheticFieldTrialsForTesting( | 188 void GetCurrentSyntheticFieldTrialsForTesting( |
232 std::vector<variations::ActiveGroupId>* synthetic_trials); | 189 std::vector<variations::ActiveGroupId>* synthetic_trials); |
233 | 190 |
234 // Adds an observer to be notified when the synthetic trials list changes. | 191 // Adds an observer to be notified when the synthetic trials list changes. |
235 void AddSyntheticTrialObserver(SyntheticTrialObserver* observer); | 192 void AddSyntheticTrialObserver(variations::SyntheticTrialObserver* observer); |
236 | 193 |
237 // Removes an existing observer of synthetic trials list changes. | 194 // Removes an existing observer of synthetic trials list changes. |
238 void RemoveSyntheticTrialObserver(SyntheticTrialObserver* observer); | 195 void RemoveSyntheticTrialObserver( |
| 196 variations::SyntheticTrialObserver* observer); |
239 | 197 |
240 // Register the specified |provider| to provide additional metrics into the | 198 // Register the specified |provider| to provide additional metrics into the |
241 // UMA log. Should be called during MetricsService initialization only. | 199 // UMA log. Should be called during MetricsService initialization only. |
242 void RegisterMetricsProvider(scoped_ptr<MetricsProvider> provider); | 200 void RegisterMetricsProvider(scoped_ptr<MetricsProvider> provider); |
243 | 201 |
244 // Check if this install was cloned or imaged from another machine. If a | 202 // Check if this install was cloned or imaged from another machine. If a |
245 // clone is detected, reset the client id and low entropy source. This | 203 // clone is detected, reset the client id and low entropy source. This |
246 // should not be called more than once. | 204 // should not be called more than once. |
247 void CheckForClonedInstall( | 205 void CheckForClonedInstall( |
248 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 206 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
249 | 207 |
250 // Clears the stability metrics that are saved in local state. | 208 // Clears the stability metrics that are saved in local state. |
251 void ClearSavedStabilityMetrics(); | 209 void ClearSavedStabilityMetrics(); |
252 | 210 |
253 // Pushes a log that has been generated by an external component. | 211 // Pushes a log that has been generated by an external component. |
254 void PushExternalLog(const std::string& log); | 212 void PushExternalLog(const std::string& log); |
255 | 213 |
256 protected: | 214 protected: |
257 // Exposed for testing. | 215 // Exposed for testing. |
258 MetricsLogManager* log_manager() { return &log_manager_; } | 216 MetricsLogManager* log_manager() { return &log_manager_; } |
259 | 217 |
260 private: | 218 private: |
| 219 friend class MetricsServiceAccessor; |
| 220 |
261 // The MetricsService has a lifecycle that is stored as a state. | 221 // The MetricsService has a lifecycle that is stored as a state. |
262 // See metrics_service.cc for description of this lifecycle. | 222 // See metrics_service.cc for description of this lifecycle. |
263 enum State { | 223 enum State { |
264 INITIALIZED, // Constructor was called. | 224 INITIALIZED, // Constructor was called. |
265 INIT_TASK_SCHEDULED, // Waiting for deferred init tasks to finish. | 225 INIT_TASK_SCHEDULED, // Waiting for deferred init tasks to finish. |
266 INIT_TASK_DONE, // Waiting for timer to send initial log. | 226 INIT_TASK_DONE, // Waiting for timer to send initial log. |
267 SENDING_LOGS, // Sending logs an creating new ones when we run out. | 227 SENDING_LOGS, // Sending logs an creating new ones when we run out. |
268 }; | 228 }; |
269 | 229 |
270 enum ShutdownCleanliness { | 230 enum ShutdownCleanliness { |
271 CLEANLY_SHUTDOWN = 0xdeadbeef, | 231 CLEANLY_SHUTDOWN = 0xdeadbeef, |
272 NEED_TO_SHUTDOWN = ~CLEANLY_SHUTDOWN | 232 NEED_TO_SHUTDOWN = ~CLEANLY_SHUTDOWN |
273 }; | 233 }; |
274 | 234 |
275 // The current state of recording for the MetricsService. The state is UNSET | 235 // The current state of recording for the MetricsService. The state is UNSET |
276 // until set to something else, at which point it remains INACTIVE or ACTIVE | 236 // until set to something else, at which point it remains INACTIVE or ACTIVE |
277 // for the lifetime of the object. | 237 // for the lifetime of the object. |
278 enum RecordingState { | 238 enum RecordingState { |
279 INACTIVE, | 239 INACTIVE, |
280 ACTIVE, | 240 ACTIVE, |
281 UNSET | 241 UNSET |
282 }; | 242 }; |
283 | 243 |
284 typedef std::vector<SyntheticTrialGroup> SyntheticTrialGroups; | 244 typedef std::vector<variations::SyntheticTrialGroup> SyntheticTrialGroups; |
| 245 |
| 246 // Registers a field trial name and group to be used to annotate a UMA report |
| 247 // with a particular Chrome configuration state. A UMA report will be |
| 248 // annotated with this trial group if and only if all events in the report |
| 249 // were created after the trial is registered. Only one group name may be |
| 250 // registered at a time for a given trial_name. Only the last group name that |
| 251 // is registered for a given trial name will be recorded. The values passed |
| 252 // in must not correspond to any real field trial in the code. |
| 253 void RegisterSyntheticFieldTrial( |
| 254 const variations::SyntheticTrialGroup& trial_group); |
285 | 255 |
286 // Calls into the client to initialize some system profile metrics. | 256 // Calls into the client to initialize some system profile metrics. |
287 void StartInitTask(); | 257 void StartInitTask(); |
288 | 258 |
289 // Callback that moves the state to INIT_TASK_DONE. When this is called, the | 259 // Callback that moves the state to INIT_TASK_DONE. When this is called, the |
290 // state should be INIT_TASK_SCHEDULED. | 260 // state should be INIT_TASK_SCHEDULED. |
291 void FinishedInitTask(); | 261 void FinishedInitTask(); |
292 | 262 |
293 void OnUserAction(const std::string& action); | 263 void OnUserAction(const std::string& action); |
294 | 264 |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 // Stores the time of the first call to |GetUptimes()|. | 452 // Stores the time of the first call to |GetUptimes()|. |
483 base::TimeTicks first_updated_time_; | 453 base::TimeTicks first_updated_time_; |
484 | 454 |
485 // Stores the time of the last call to |GetUptimes()|. | 455 // Stores the time of the last call to |GetUptimes()|. |
486 base::TimeTicks last_updated_time_; | 456 base::TimeTicks last_updated_time_; |
487 | 457 |
488 // Field trial groups that map to Chrome configuration states. | 458 // Field trial groups that map to Chrome configuration states. |
489 SyntheticTrialGroups synthetic_trial_groups_; | 459 SyntheticTrialGroups synthetic_trial_groups_; |
490 | 460 |
491 // List of observers of |synthetic_trial_groups_| changes. | 461 // List of observers of |synthetic_trial_groups_| changes. |
492 base::ObserverList<SyntheticTrialObserver> synthetic_trial_observer_list_; | 462 base::ObserverList<variations::SyntheticTrialObserver> |
| 463 synthetic_trial_observer_list_; |
493 | 464 |
494 // Execution phase the browser is in. | 465 // Execution phase the browser is in. |
495 static ExecutionPhase execution_phase_; | 466 static ExecutionPhase execution_phase_; |
496 | 467 |
497 // Reduntant marker to check that we completed our shutdown, and set the | 468 // Reduntant marker to check that we completed our shutdown, and set the |
498 // exited-cleanly bit in the prefs. | 469 // exited-cleanly bit in the prefs. |
499 static ShutdownCleanliness clean_shutdown_status_; | 470 static ShutdownCleanliness clean_shutdown_status_; |
500 | 471 |
501 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); | 472 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); |
502 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, | 473 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, |
503 PermutedEntropyCacheClearedWhenLowEntropyReset); | 474 PermutedEntropyCacheClearedWhenLowEntropyReset); |
504 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); | 475 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); |
505 | 476 |
506 // Weak pointers factory used to post task on different threads. All weak | 477 // Weak pointers factory used to post task on different threads. All weak |
507 // pointers managed by this factory have the same lifetime as MetricsService. | 478 // pointers managed by this factory have the same lifetime as MetricsService. |
508 base::WeakPtrFactory<MetricsService> self_ptr_factory_; | 479 base::WeakPtrFactory<MetricsService> self_ptr_factory_; |
509 | 480 |
510 // Weak pointers factory used for saving state. All weak pointers managed by | 481 // Weak pointers factory used for saving state. All weak pointers managed by |
511 // this factory are invalidated in ScheduleNextStateSave. | 482 // this factory are invalidated in ScheduleNextStateSave. |
512 base::WeakPtrFactory<MetricsService> state_saver_factory_; | 483 base::WeakPtrFactory<MetricsService> state_saver_factory_; |
513 | 484 |
514 DISALLOW_COPY_AND_ASSIGN(MetricsService); | 485 DISALLOW_COPY_AND_ASSIGN(MetricsService); |
515 }; | 486 }; |
516 | 487 |
517 } // namespace metrics | 488 } // namespace metrics |
518 | 489 |
519 #endif // COMPONENTS_METRICS_METRICS_SERVICE_H_ | 490 #endif // COMPONENTS_METRICS_METRICS_SERVICE_H_ |
OLD | NEW |