Chromium Code Reviews| 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 <stdint.h> | 11 #include <stdint.h> |
| 12 | 12 |
| 13 #include <map> | 13 #include <map> |
| 14 #include <string> | 14 #include <string> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
| 20 #include "base/memory/scoped_vector.h" | 20 #include "base/memory/scoped_vector.h" |
| 21 #include "base/memory/weak_ptr.h" | 21 #include "base/memory/weak_ptr.h" |
| 22 #include "base/metrics/field_trial.h" | 22 #include "base/metrics/field_trial.h" |
| 23 #include "base/metrics/histogram_flattener.h" | 23 #include "base/metrics/histogram_flattener.h" |
| 24 #include "base/metrics/histogram_snapshot_manager.h" | 24 #include "base/metrics/histogram_snapshot_manager.h" |
| 25 #include "base/metrics/user_metrics.h" | 25 #include "base/metrics/user_metrics.h" |
| 26 #include "base/observer_list.h" | 26 #include "base/observer_list.h" |
| 27 #include "base/time/time.h" | 27 #include "base/time/time.h" |
| 28 #include "build/build_config.h" | 28 #include "build/build_config.h" |
| 29 #include "components/metrics/clean_exit_beacon.h" | 29 #include "components/metrics/clean_exit_beacon.h" |
| 30 #include "components/metrics/data_use_tracker.h" | |
| 30 #include "components/metrics/metrics_log.h" | 31 #include "components/metrics/metrics_log.h" |
| 31 #include "components/metrics/metrics_log_manager.h" | 32 #include "components/metrics/metrics_log_manager.h" |
| 32 #include "components/metrics/metrics_provider.h" | 33 #include "components/metrics/metrics_provider.h" |
| 33 #include "components/metrics/net/network_metrics_provider.h" | 34 #include "components/metrics/net/network_metrics_provider.h" |
| 34 #include "components/variations/synthetic_trials.h" | 35 #include "components/variations/synthetic_trials.h" |
| 35 | 36 |
| 36 class PrefService; | 37 class PrefService; |
| 37 class PrefRegistrySimple; | 38 class PrefRegistrySimple; |
| 38 | 39 |
| 39 namespace base { | 40 namespace base { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 SHUTDOWN_TIMEBOMB_ARM = 600, | 73 SHUTDOWN_TIMEBOMB_ARM = 600, |
| 73 SHUTDOWN_COMPLETE = 700, | 74 SHUTDOWN_COMPLETE = 700, |
| 74 }; | 75 }; |
| 75 | 76 |
| 76 // Creates the MetricsService with the given |state_manager|, |client|, and | 77 // Creates the MetricsService with the given |state_manager|, |client|, and |
| 77 // |local_state|. Does not take ownership of the paramaters; instead stores | 78 // |local_state|. Does not take ownership of the paramaters; instead stores |
| 78 // a weak pointer to each. Caller should ensure that the parameters are valid | 79 // a weak pointer to each. Caller should ensure that the parameters are valid |
| 79 // for the lifetime of this class. | 80 // for the lifetime of this class. |
| 80 MetricsService(MetricsStateManager* state_manager, | 81 MetricsService(MetricsStateManager* state_manager, |
| 81 MetricsServiceClient* client, | 82 MetricsServiceClient* client, |
| 82 PrefService* local_state); | 83 PrefService* local_state, |
| 84 base::Callback<void(bool*)> cellular_callback); | |
| 83 ~MetricsService() override; | 85 ~MetricsService() override; |
| 84 | 86 |
| 85 // Initializes metrics recording state. Updates various bookkeeping values in | 87 // Initializes metrics recording state. Updates various bookkeeping values in |
| 86 // prefs and sets up the scheduler. This is a separate function rather than | 88 // prefs and sets up the scheduler. This is a separate function rather than |
| 87 // being done by the constructor so that field trials could be created before | 89 // being done by the constructor so that field trials could be created before |
| 88 // this is run. | 90 // this is run. |
| 89 void InitializeMetricsRecordingState(); | 91 void InitializeMetricsRecordingState(); |
| 90 | 92 |
| 91 // Starts the metrics system, turning on recording and uploading of metrics. | 93 // Starts the metrics system, turning on recording and uploading of metrics. |
| 92 // Should be called when starting up with metrics enabled, or when metrics | 94 // Should be called when starting up with metrics enabled, or when metrics |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 // should not be called more than once. | 209 // should not be called more than once. |
| 208 void CheckForClonedInstall( | 210 void CheckForClonedInstall( |
| 209 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 211 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 210 | 212 |
| 211 // Clears the stability metrics that are saved in local state. | 213 // Clears the stability metrics that are saved in local state. |
| 212 void ClearSavedStabilityMetrics(); | 214 void ClearSavedStabilityMetrics(); |
| 213 | 215 |
| 214 // Pushes a log that has been generated by an external component. | 216 // Pushes a log that has been generated by an external component. |
| 215 void PushExternalLog(const std::string& log); | 217 void PushExternalLog(const std::string& log); |
| 216 | 218 |
| 219 base::WeakPtr<DataUseTracker> GetDataUseTracker(); | |
| 220 | |
| 217 protected: | 221 protected: |
| 218 // Exposed for testing. | 222 // Exposed for testing. |
| 219 MetricsLogManager* log_manager() { return &log_manager_; } | 223 MetricsLogManager* log_manager() { return &log_manager_; } |
| 220 | 224 |
| 221 private: | 225 private: |
| 222 friend class MetricsServiceAccessor; | 226 friend class MetricsServiceAccessor; |
| 223 | 227 |
| 224 // The MetricsService has a lifecycle that is stored as a state. | 228 // The MetricsService has a lifecycle that is stored as a state. |
| 225 // See metrics_service.cc for description of this lifecycle. | 229 // See metrics_service.cc for description of this lifecycle. |
| 226 enum State { | 230 enum State { |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 461 // Field trial groups that map to Chrome configuration states. | 465 // Field trial groups that map to Chrome configuration states. |
| 462 SyntheticTrialGroups synthetic_trial_groups_; | 466 SyntheticTrialGroups synthetic_trial_groups_; |
| 463 | 467 |
| 464 // List of observers of |synthetic_trial_groups_| changes. | 468 // List of observers of |synthetic_trial_groups_| changes. |
| 465 base::ObserverList<variations::SyntheticTrialObserver> | 469 base::ObserverList<variations::SyntheticTrialObserver> |
| 466 synthetic_trial_observer_list_; | 470 synthetic_trial_observer_list_; |
| 467 | 471 |
| 468 // Execution phase the browser is in. | 472 // Execution phase the browser is in. |
| 469 static ExecutionPhase execution_phase_; | 473 static ExecutionPhase execution_phase_; |
| 470 | 474 |
| 471 // Reduntant marker to check that we completed our shutdown, and set the | 475 // Redundant marker to check that we completed our shutdown, and set the |
| 472 // exited-cleanly bit in the prefs. | 476 // exited-cleanly bit in the prefs. |
| 473 static ShutdownCleanliness clean_shutdown_status_; | 477 static ShutdownCleanliness clean_shutdown_status_; |
| 474 | 478 |
| 479 // Returns true if current connection type is cellular and user is assigned to | |
| 480 // experimental group for enabled cellular uploads. | |
| 481 base::Callback<void(bool*)> cellular_callback_; | |
|
Alexei Svitkine (slow)
2016/03/29 16:29:10
Put these members below the friend declarations.
gayane -on leave until 09-2017
2016/03/31 01:38:24
Done.
| |
| 482 | |
| 483 scoped_ptr<DataUseTracker> data_use_tracker_; | |
| 484 | |
| 475 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); | 485 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); |
| 476 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, | 486 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, |
| 477 PermutedEntropyCacheClearedWhenLowEntropyReset); | 487 PermutedEntropyCacheClearedWhenLowEntropyReset); |
| 478 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); | 488 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); |
| 479 | 489 |
| 480 // Weak pointers factory used to post task on different threads. All weak | 490 // Weak pointers factory used to post task on different threads. All weak |
| 481 // pointers managed by this factory have the same lifetime as MetricsService. | 491 // pointers managed by this factory have the same lifetime as MetricsService. |
| 482 base::WeakPtrFactory<MetricsService> self_ptr_factory_; | 492 base::WeakPtrFactory<MetricsService> self_ptr_factory_; |
| 483 | 493 |
| 484 // Weak pointers factory used for saving state. All weak pointers managed by | 494 // Weak pointers factory used for saving state. All weak pointers managed by |
| 485 // this factory are invalidated in ScheduleNextStateSave. | 495 // this factory are invalidated in ScheduleNextStateSave. |
| 486 base::WeakPtrFactory<MetricsService> state_saver_factory_; | 496 base::WeakPtrFactory<MetricsService> state_saver_factory_; |
| 487 | 497 |
| 488 DISALLOW_COPY_AND_ASSIGN(MetricsService); | 498 DISALLOW_COPY_AND_ASSIGN(MetricsService); |
| 489 }; | 499 }; |
| 490 | 500 |
| 491 } // namespace metrics | 501 } // namespace metrics |
| 492 | 502 |
| 493 #endif // COMPONENTS_METRICS_METRICS_SERVICE_H_ | 503 #endif // COMPONENTS_METRICS_METRICS_SERVICE_H_ |
| OLD | NEW |