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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 class SyntheticTrialObserver { | 81 class SyntheticTrialObserver { |
82 public: | 82 public: |
83 // Called when the list of synthetic field trial groups has changed. | 83 // Called when the list of synthetic field trial groups has changed. |
84 virtual void OnSyntheticTrialsChanged( | 84 virtual void OnSyntheticTrialsChanged( |
85 const std::vector<SyntheticTrialGroup>& groups) = 0; | 85 const std::vector<SyntheticTrialGroup>& groups) = 0; |
86 | 86 |
87 protected: | 87 protected: |
88 virtual ~SyntheticTrialObserver() {} | 88 virtual ~SyntheticTrialObserver() {} |
89 }; | 89 }; |
90 | 90 |
| 91 // Interface for observing whenever the MetricsService is started or stopped. |
| 92 class MetricsServiceObserver { |
| 93 public: |
| 94 virtual void OnMetricsServiceStart() = 0; |
| 95 virtual void OnMetricsServiceStop() = 0; |
| 96 |
| 97 protected: |
| 98 virtual ~MetricsServiceObserver() {} |
| 99 }; |
| 100 |
91 // See metrics_service.cc for a detailed description. | 101 // See metrics_service.cc for a detailed description. |
92 class MetricsService : public base::HistogramFlattener { | 102 class MetricsService : public base::HistogramFlattener { |
93 public: | 103 public: |
94 // The execution phase of the browser. | 104 // The execution phase of the browser. |
95 enum ExecutionPhase { | 105 enum ExecutionPhase { |
96 UNINITIALIZED_PHASE = 0, | 106 UNINITIALIZED_PHASE = 0, |
97 START_METRICS_RECORDING = 100, | 107 START_METRICS_RECORDING = 100, |
98 CREATE_PROFILE = 200, | 108 CREATE_PROFILE = 200, |
99 STARTUP_TIMEBOMB_ARM = 300, | 109 STARTUP_TIMEBOMB_ARM = 300, |
100 THREAD_WATCHER_START = 400, | 110 THREAD_WATCHER_START = 400, |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 // in must not correspond to any real field trial in the code. | 235 // in must not correspond to any real field trial in the code. |
226 // To use this method, SyntheticTrialGroup should friend your class. | 236 // To use this method, SyntheticTrialGroup should friend your class. |
227 void RegisterSyntheticFieldTrial(const SyntheticTrialGroup& trial_group); | 237 void RegisterSyntheticFieldTrial(const SyntheticTrialGroup& trial_group); |
228 | 238 |
229 // Adds an observer to be notified when the synthetic trials list changes. | 239 // Adds an observer to be notified when the synthetic trials list changes. |
230 void AddSyntheticTrialObserver(SyntheticTrialObserver* observer); | 240 void AddSyntheticTrialObserver(SyntheticTrialObserver* observer); |
231 | 241 |
232 // Removes an existing observer of synthetic trials list changes. | 242 // Removes an existing observer of synthetic trials list changes. |
233 void RemoveSyntheticTrialObserver(SyntheticTrialObserver* observer); | 243 void RemoveSyntheticTrialObserver(SyntheticTrialObserver* observer); |
234 | 244 |
| 245 // Add / remove observers interested in watching the MetricsService start and |
| 246 // stop events. |
| 247 void AddObserver(MetricsServiceObserver* observer); |
| 248 void RemoveObserver(MetricsServiceObserver* observer); |
| 249 |
235 // Register the specified |provider| to provide additional metrics into the | 250 // Register the specified |provider| to provide additional metrics into the |
236 // UMA log. Should be called during MetricsService initialization only. | 251 // UMA log. Should be called during MetricsService initialization only. |
237 void RegisterMetricsProvider(scoped_ptr<MetricsProvider> provider); | 252 void RegisterMetricsProvider(scoped_ptr<MetricsProvider> provider); |
238 | 253 |
239 // Check if this install was cloned or imaged from another machine. If a | 254 // Check if this install was cloned or imaged from another machine. If a |
240 // clone is detected, reset the client id and low entropy source. This | 255 // clone is detected, reset the client id and low entropy source. This |
241 // should not be called more than once. | 256 // should not be called more than once. |
242 void CheckForClonedInstall( | 257 void CheckForClonedInstall( |
243 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 258 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
244 | 259 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 | 494 |
480 // Stores the time of the last call to |GetUptimes()|. | 495 // Stores the time of the last call to |GetUptimes()|. |
481 base::TimeTicks last_updated_time_; | 496 base::TimeTicks last_updated_time_; |
482 | 497 |
483 // Field trial groups that map to Chrome configuration states. | 498 // Field trial groups that map to Chrome configuration states. |
484 SyntheticTrialGroups synthetic_trial_groups_; | 499 SyntheticTrialGroups synthetic_trial_groups_; |
485 | 500 |
486 // List of observers of |synthetic_trial_groups_| changes. | 501 // List of observers of |synthetic_trial_groups_| changes. |
487 base::ObserverList<SyntheticTrialObserver> synthetic_trial_observer_list_; | 502 base::ObserverList<SyntheticTrialObserver> synthetic_trial_observer_list_; |
488 | 503 |
| 504 // List of observers interested in watching the MetricsService start and stop |
| 505 // events. |
| 506 base::ObserverList<MetricsServiceObserver> metrics_service_observer_list_; |
| 507 |
489 // Execution phase the browser is in. | 508 // Execution phase the browser is in. |
490 static ExecutionPhase execution_phase_; | 509 static ExecutionPhase execution_phase_; |
491 | 510 |
492 // Reduntant marker to check that we completed our shutdown, and set the | 511 // Reduntant marker to check that we completed our shutdown, and set the |
493 // exited-cleanly bit in the prefs. | 512 // exited-cleanly bit in the prefs. |
494 static ShutdownCleanliness clean_shutdown_status_; | 513 static ShutdownCleanliness clean_shutdown_status_; |
495 | 514 |
496 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); | 515 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); |
497 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, | 516 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, |
498 PermutedEntropyCacheClearedWhenLowEntropyReset); | 517 PermutedEntropyCacheClearedWhenLowEntropyReset); |
499 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); | 518 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); |
500 | 519 |
501 // Weak pointers factory used to post task on different threads. All weak | 520 // Weak pointers factory used to post task on different threads. All weak |
502 // pointers managed by this factory have the same lifetime as MetricsService. | 521 // pointers managed by this factory have the same lifetime as MetricsService. |
503 base::WeakPtrFactory<MetricsService> self_ptr_factory_; | 522 base::WeakPtrFactory<MetricsService> self_ptr_factory_; |
504 | 523 |
505 // Weak pointers factory used for saving state. All weak pointers managed by | 524 // Weak pointers factory used for saving state. All weak pointers managed by |
506 // this factory are invalidated in ScheduleNextStateSave. | 525 // this factory are invalidated in ScheduleNextStateSave. |
507 base::WeakPtrFactory<MetricsService> state_saver_factory_; | 526 base::WeakPtrFactory<MetricsService> state_saver_factory_; |
508 | 527 |
509 DISALLOW_COPY_AND_ASSIGN(MetricsService); | 528 DISALLOW_COPY_AND_ASSIGN(MetricsService); |
510 }; | 529 }; |
511 | 530 |
512 } // namespace metrics | 531 } // namespace metrics |
513 | 532 |
514 #endif // COMPONENTS_METRICS_METRICS_SERVICE_H_ | 533 #endif // COMPONENTS_METRICS_METRICS_SERVICE_H_ |
OLD | NEW |