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 |
11 #include <map> | 11 #include <map> |
12 #include <string> | 12 #include <string> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
16 #include "base/gtest_prod_util.h" | 16 #include "base/gtest_prod_util.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/memory/scoped_vector.h" | 18 #include "base/memory/scoped_vector.h" |
19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
20 #include "base/metrics/field_trial.h" | 20 #include "base/metrics/field_trial.h" |
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/time/time.h" | 25 #include "base/time/time.h" |
25 #include "components/metrics/clean_exit_beacon.h" | 26 #include "components/metrics/clean_exit_beacon.h" |
26 #include "components/metrics/metrics_log.h" | 27 #include "components/metrics/metrics_log.h" |
27 #include "components/metrics/metrics_log_manager.h" | 28 #include "components/metrics/metrics_log_manager.h" |
28 #include "components/metrics/metrics_provider.h" | 29 #include "components/metrics/metrics_provider.h" |
29 #include "components/variations/active_field_trials.h" | 30 #include "components/variations/active_field_trials.h" |
30 | 31 |
31 class MetricsServiceAccessor; | 32 class MetricsServiceAccessor; |
32 class PrefService; | 33 class PrefService; |
33 class PrefRegistrySimple; | 34 class PrefRegistrySimple; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 friend class ::MetricsServiceAccessor; | 70 friend class ::MetricsServiceAccessor; |
70 friend class MetricsService; | 71 friend class MetricsService; |
71 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); | 72 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); |
72 | 73 |
73 // This constructor is private specifically so as to control which code is | 74 // This constructor is private specifically so as to control which code is |
74 // able to access it. New code that wishes to use it should be added as a | 75 // able to access it. New code that wishes to use it should be added as a |
75 // friend class. | 76 // friend class. |
76 SyntheticTrialGroup(uint32 trial, uint32 group); | 77 SyntheticTrialGroup(uint32 trial, uint32 group); |
77 }; | 78 }; |
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 |
79 // See metrics_service.cc for a detailed description. | 91 // See metrics_service.cc for a detailed description. |
80 class MetricsService : public base::HistogramFlattener { | 92 class MetricsService : public base::HistogramFlattener { |
81 public: | 93 public: |
82 // The execution phase of the browser. | 94 // The execution phase of the browser. |
83 enum ExecutionPhase { | 95 enum ExecutionPhase { |
84 UNINITIALIZED_PHASE = 0, | 96 UNINITIALIZED_PHASE = 0, |
85 START_METRICS_RECORDING = 100, | 97 START_METRICS_RECORDING = 100, |
86 CREATE_PROFILE = 200, | 98 CREATE_PROFILE = 200, |
87 STARTUP_TIMEBOMB_ARM = 300, | 99 STARTUP_TIMEBOMB_ARM = 300, |
88 THREAD_WATCHER_START = 400, | 100 THREAD_WATCHER_START = 400, |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 // Registers a field trial name and group to be used to annotate a UMA report | 216 // Registers a field trial name and group to be used to annotate a UMA report |
205 // with a particular Chrome configuration state. A UMA report will be | 217 // with a particular Chrome configuration state. A UMA report will be |
206 // annotated with this trial group if and only if all events in the report | 218 // annotated with this trial group if and only if all events in the report |
207 // were created after the trial is registered. Only one group name may be | 219 // were created after the trial is registered. Only one group name may be |
208 // registered at a time for a given trial_name. Only the last group name that | 220 // registered at a time for a given trial_name. Only the last group name that |
209 // is registered for a given trial name will be recorded. The values passed | 221 // is registered for a given trial name will be recorded. The values passed |
210 // in must not correspond to any real field trial in the code. | 222 // in must not correspond to any real field trial in the code. |
211 // To use this method, SyntheticTrialGroup should friend your class. | 223 // To use this method, SyntheticTrialGroup should friend your class. |
212 void RegisterSyntheticFieldTrial(const SyntheticTrialGroup& trial_group); | 224 void RegisterSyntheticFieldTrial(const SyntheticTrialGroup& trial_group); |
213 | 225 |
| 226 // Adds an observer to be notified when the synthetic trials list changes. |
| 227 void AddSyntheticTrialObserver(SyntheticTrialObserver* observer); |
| 228 |
| 229 // Removes an existing observer of synthetic trials list changes. |
| 230 void RemoveSyntheticTrialObserver(SyntheticTrialObserver* observer); |
| 231 |
214 // Register the specified |provider| to provide additional metrics into the | 232 // Register the specified |provider| to provide additional metrics into the |
215 // UMA log. Should be called during MetricsService initialization only. | 233 // UMA log. Should be called during MetricsService initialization only. |
216 void RegisterMetricsProvider(scoped_ptr<MetricsProvider> provider); | 234 void RegisterMetricsProvider(scoped_ptr<MetricsProvider> provider); |
217 | 235 |
218 // Check if this install was cloned or imaged from another machine. If a | 236 // Check if this install was cloned or imaged from another machine. If a |
219 // clone is detected, reset the client id and low entropy source. This | 237 // clone is detected, reset the client id and low entropy source. This |
220 // should not be called more than once. | 238 // should not be called more than once. |
221 void CheckForClonedInstall( | 239 void CheckForClonedInstall( |
222 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 240 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
223 | 241 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 // Records state that should be periodically saved, like uptime and | 369 // Records state that should be periodically saved, like uptime and |
352 // buffered plugin stability statistics. | 370 // buffered plugin stability statistics. |
353 void RecordCurrentState(PrefService* pref); | 371 void RecordCurrentState(PrefService* pref); |
354 | 372 |
355 // Checks whether events should currently be logged. | 373 // Checks whether events should currently be logged. |
356 bool ShouldLogEvents(); | 374 bool ShouldLogEvents(); |
357 | 375 |
358 // Sets the value of the specified path in prefs and schedules a save. | 376 // Sets the value of the specified path in prefs and schedules a save. |
359 void RecordBooleanPrefValue(const char* path, bool value); | 377 void RecordBooleanPrefValue(const char* path, bool value); |
360 | 378 |
| 379 // Notifies observers on a synthetic trial list change. |
| 380 void NotifySyntheticTrialObservers(); |
| 381 |
361 // Returns a list of synthetic field trials that were active for the entire | 382 // Returns a list of synthetic field trials that were active for the entire |
362 // duration of the current log. | 383 // duration of the current log. |
363 void GetCurrentSyntheticFieldTrials( | 384 void GetCurrentSyntheticFieldTrials( |
364 std::vector<variations::ActiveGroupId>* synthetic_trials); | 385 std::vector<variations::ActiveGroupId>* synthetic_trials); |
365 | 386 |
366 // Creates a new MetricsLog instance with the given |log_type|. | 387 // Creates a new MetricsLog instance with the given |log_type|. |
367 scoped_ptr<MetricsLog> CreateLog(MetricsLog::LogType log_type); | 388 scoped_ptr<MetricsLog> CreateLog(MetricsLog::LogType log_type); |
368 | 389 |
369 // Records the current environment (system profile) in |log|. | 390 // Records the current environment (system profile) in |log|. |
370 void RecordCurrentEnvironment(MetricsLog* log); | 391 void RecordCurrentEnvironment(MetricsLog* log); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 | 461 |
441 // Stores the time of the first call to |GetUptimes()|. | 462 // Stores the time of the first call to |GetUptimes()|. |
442 base::TimeTicks first_updated_time_; | 463 base::TimeTicks first_updated_time_; |
443 | 464 |
444 // Stores the time of the last call to |GetUptimes()|. | 465 // Stores the time of the last call to |GetUptimes()|. |
445 base::TimeTicks last_updated_time_; | 466 base::TimeTicks last_updated_time_; |
446 | 467 |
447 // Field trial groups that map to Chrome configuration states. | 468 // Field trial groups that map to Chrome configuration states. |
448 SyntheticTrialGroups synthetic_trial_groups_; | 469 SyntheticTrialGroups synthetic_trial_groups_; |
449 | 470 |
| 471 // List of observers of |synthetic_trial_groups_| changes. |
| 472 ObserverList<SyntheticTrialObserver> synthetic_trial_observer_list_; |
| 473 |
450 // Execution phase the browser is in. | 474 // Execution phase the browser is in. |
451 static ExecutionPhase execution_phase_; | 475 static ExecutionPhase execution_phase_; |
452 | 476 |
453 // Reduntant marker to check that we completed our shutdown, and set the | 477 // Reduntant marker to check that we completed our shutdown, and set the |
454 // exited-cleanly bit in the prefs. | 478 // exited-cleanly bit in the prefs. |
455 static ShutdownCleanliness clean_shutdown_status_; | 479 static ShutdownCleanliness clean_shutdown_status_; |
456 | 480 |
457 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); | 481 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); |
458 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, | 482 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, |
459 PermutedEntropyCacheClearedWhenLowEntropyReset); | 483 PermutedEntropyCacheClearedWhenLowEntropyReset); |
460 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); | 484 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); |
461 | 485 |
462 // Weak pointers factory used to post task on different threads. All weak | 486 // Weak pointers factory used to post task on different threads. All weak |
463 // pointers managed by this factory have the same lifetime as MetricsService. | 487 // pointers managed by this factory have the same lifetime as MetricsService. |
464 base::WeakPtrFactory<MetricsService> self_ptr_factory_; | 488 base::WeakPtrFactory<MetricsService> self_ptr_factory_; |
465 | 489 |
466 // Weak pointers factory used for saving state. All weak pointers managed by | 490 // Weak pointers factory used for saving state. All weak pointers managed by |
467 // this factory are invalidated in ScheduleNextStateSave. | 491 // this factory are invalidated in ScheduleNextStateSave. |
468 base::WeakPtrFactory<MetricsService> state_saver_factory_; | 492 base::WeakPtrFactory<MetricsService> state_saver_factory_; |
469 | 493 |
470 DISALLOW_COPY_AND_ASSIGN(MetricsService); | 494 DISALLOW_COPY_AND_ASSIGN(MetricsService); |
471 }; | 495 }; |
472 | 496 |
473 } // namespace metrics | 497 } // namespace metrics |
474 | 498 |
475 #endif // COMPONENTS_METRICS_METRICS_SERVICE_H_ | 499 #endif // COMPONENTS_METRICS_METRICS_SERVICE_H_ |
OLD | NEW |