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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 | |
85 // Creates the MetricsService as above with given |cellular_callback| | |
Alexei Svitkine (slow)
2016/03/31 20:00:40
Instead of having a callback as a ctor param, can'
gayane -on leave until 09-2017
2016/03/31 21:55:10
I think we tried to do this once and I think metri
Alexei Svitkine (slow)
2016/03/31 22:18:02
I think it should work. MetricsService already dep
| |
86 MetricsService(MetricsStateManager* state_manager, | |
87 MetricsServiceClient* client, | |
88 PrefService* local_state, | |
89 base::Callback<void(bool*)> cellular_callback); | |
83 ~MetricsService() override; | 90 ~MetricsService() override; |
84 | 91 |
85 // Initializes metrics recording state. Updates various bookkeeping values in | 92 // Initializes metrics recording state. Updates various bookkeeping values in |
86 // prefs and sets up the scheduler. This is a separate function rather than | 93 // 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 | 94 // being done by the constructor so that field trials could be created before |
88 // this is run. | 95 // this is run. |
89 void InitializeMetricsRecordingState(); | 96 void InitializeMetricsRecordingState(); |
90 | 97 |
91 // Starts the metrics system, turning on recording and uploading of metrics. | 98 // Starts the metrics system, turning on recording and uploading of metrics. |
92 // Should be called when starting up with metrics enabled, or when metrics | 99 // 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. | 214 // should not be called more than once. |
208 void CheckForClonedInstall( | 215 void CheckForClonedInstall( |
209 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 216 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
210 | 217 |
211 // Clears the stability metrics that are saved in local state. | 218 // Clears the stability metrics that are saved in local state. |
212 void ClearSavedStabilityMetrics(); | 219 void ClearSavedStabilityMetrics(); |
213 | 220 |
214 // Pushes a log that has been generated by an external component. | 221 // Pushes a log that has been generated by an external component. |
215 void PushExternalLog(const std::string& log); | 222 void PushExternalLog(const std::string& log); |
216 | 223 |
224 // Returns a callback to data use pref updating function attached to | |
225 // |data_use_tracker| weak pointer. Should be called on UI thread. | |
Alexei Svitkine (slow)
2016/03/31 20:00:40
This description reads like implementation detail.
gayane -on leave until 09-2017
2016/03/31 21:55:10
Done.
| |
226 UpdateUsagePrefCallbackType GetDataUseForwardingCallback(); | |
227 | |
217 protected: | 228 protected: |
218 // Exposed for testing. | 229 // Exposed for testing. |
219 MetricsLogManager* log_manager() { return &log_manager_; } | 230 MetricsLogManager* log_manager() { return &log_manager_; } |
220 | 231 |
221 private: | 232 private: |
222 friend class MetricsServiceAccessor; | 233 friend class MetricsServiceAccessor; |
223 | 234 |
224 // The MetricsService has a lifecycle that is stored as a state. | 235 // The MetricsService has a lifecycle that is stored as a state. |
225 // See metrics_service.cc for description of this lifecycle. | 236 // See metrics_service.cc for description of this lifecycle. |
226 enum State { | 237 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. | 472 // Field trial groups that map to Chrome configuration states. |
462 SyntheticTrialGroups synthetic_trial_groups_; | 473 SyntheticTrialGroups synthetic_trial_groups_; |
463 | 474 |
464 // List of observers of |synthetic_trial_groups_| changes. | 475 // List of observers of |synthetic_trial_groups_| changes. |
465 base::ObserverList<variations::SyntheticTrialObserver> | 476 base::ObserverList<variations::SyntheticTrialObserver> |
466 synthetic_trial_observer_list_; | 477 synthetic_trial_observer_list_; |
467 | 478 |
468 // Execution phase the browser is in. | 479 // Execution phase the browser is in. |
469 static ExecutionPhase execution_phase_; | 480 static ExecutionPhase execution_phase_; |
470 | 481 |
471 // Reduntant marker to check that we completed our shutdown, and set the | 482 // Redundant marker to check that we completed our shutdown, and set the |
472 // exited-cleanly bit in the prefs. | 483 // exited-cleanly bit in the prefs. |
473 static ShutdownCleanliness clean_shutdown_status_; | 484 static ShutdownCleanliness clean_shutdown_status_; |
474 | 485 |
475 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); | 486 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); |
476 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, | 487 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, |
477 PermutedEntropyCacheClearedWhenLowEntropyReset); | 488 PermutedEntropyCacheClearedWhenLowEntropyReset); |
478 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); | 489 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); |
479 | 490 |
491 // Assigns true to output param if current connection type is cellular and | |
492 // user is assigned to experimental group for enabled cellular uploads. | |
493 base::Callback<void(bool*)> cellular_callback_; | |
494 | |
495 // Pointer used for obtaining data use pref updater callback on above layers. | |
496 scoped_ptr<DataUseTracker> data_use_tracker_; | |
497 | |
480 // Weak pointers factory used to post task on different threads. All weak | 498 // Weak pointers factory used to post task on different threads. All weak |
481 // pointers managed by this factory have the same lifetime as MetricsService. | 499 // pointers managed by this factory have the same lifetime as MetricsService. |
482 base::WeakPtrFactory<MetricsService> self_ptr_factory_; | 500 base::WeakPtrFactory<MetricsService> self_ptr_factory_; |
483 | 501 |
484 // Weak pointers factory used for saving state. All weak pointers managed by | 502 // Weak pointers factory used for saving state. All weak pointers managed by |
485 // this factory are invalidated in ScheduleNextStateSave. | 503 // this factory are invalidated in ScheduleNextStateSave. |
486 base::WeakPtrFactory<MetricsService> state_saver_factory_; | 504 base::WeakPtrFactory<MetricsService> state_saver_factory_; |
487 | 505 |
488 DISALLOW_COPY_AND_ASSIGN(MetricsService); | 506 DISALLOW_COPY_AND_ASSIGN(MetricsService); |
489 }; | 507 }; |
490 | 508 |
491 } // namespace metrics | 509 } // namespace metrics |
492 | 510 |
493 #endif // COMPONENTS_METRICS_METRICS_SERVICE_H_ | 511 #endif // COMPONENTS_METRICS_METRICS_SERVICE_H_ |
OLD | NEW |