Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: components/metrics/metrics_service.h

Issue 502173002: Move more metrics classes to metrics namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unit test compile. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 13 matching lines...) Expand all
24 #include "base/observer_list.h" 24 #include "base/observer_list.h"
25 #include "base/strings/string16.h" 25 #include "base/strings/string16.h"
26 #include "base/threading/thread_checker.h" 26 #include "base/threading/thread_checker.h"
27 #include "base/time/time.h" 27 #include "base/time/time.h"
28 #include "components/metrics/metrics_log.h" 28 #include "components/metrics/metrics_log.h"
29 #include "components/metrics/metrics_log_manager.h" 29 #include "components/metrics/metrics_log_manager.h"
30 #include "components/metrics/metrics_provider.h" 30 #include "components/metrics/metrics_provider.h"
31 #include "components/metrics/metrics_service_observer.h" 31 #include "components/metrics/metrics_service_observer.h"
32 #include "components/variations/active_field_trials.h" 32 #include "components/variations/active_field_trials.h"
33 33
34 class MetricsReportingScheduler; 34 class MetricsServiceAccessor;
35 class PrefService; 35 class PrefService;
36 class PrefRegistrySimple; 36 class PrefRegistrySimple;
37 37
38 namespace base { 38 namespace base {
39 class DictionaryValue; 39 class DictionaryValue;
40 class HistogramSamples; 40 class HistogramSamples;
41 class MessageLoopProxy; 41 class MessageLoopProxy;
42 class PrefService; 42 class PrefService;
43 } 43 }
44 44
45 namespace variations { 45 namespace variations {
46 struct ActiveGroupId; 46 struct ActiveGroupId;
47 } 47 }
48 48
49 namespace metrics {
50 class MetricsLogUploader;
51 class MetricsServiceClient;
52 class MetricsStateManager;
53 }
54
55 namespace net { 49 namespace net {
56 class URLFetcher; 50 class URLFetcher;
57 } 51 }
58 52
53 namespace metrics {
54
55 class MetricsLogUploader;
56 class MetricsReportingScheduler;
57 class MetricsServiceClient;
58 class MetricsStateManager;
59
59 // A Field Trial and its selected group, which represent a particular 60 // A Field Trial and its selected group, which represent a particular
60 // Chrome configuration state. For example, the trial name could map to 61 // Chrome configuration state. For example, the trial name could map to
61 // a preference name, and the group name could map to a preference value. 62 // a preference name, and the group name could map to a preference value.
62 struct SyntheticTrialGroup { 63 struct SyntheticTrialGroup {
63 public: 64 public:
64 ~SyntheticTrialGroup(); 65 ~SyntheticTrialGroup();
65 66
66 variations::ActiveGroupId id; 67 variations::ActiveGroupId id;
67 base::TimeTicks start_time; 68 base::TimeTicks start_time;
68 69
69 private: 70 private:
70 // Synthetic field trial users: 71 // Synthetic field trial users:
71 friend class MetricsServiceAccessor; 72 friend class ::MetricsServiceAccessor;
72 friend class MetricsService; 73 friend class MetricsService;
73 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); 74 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial);
74 75
75 // This constructor is private specifically so as to control which code is 76 // This constructor is private specifically so as to control which code is
76 // able to access it. New code that wishes to use it should be added as a 77 // able to access it. New code that wishes to use it should be added as a
77 // friend class. 78 // friend class.
78 SyntheticTrialGroup(uint32 trial, uint32 group); 79 SyntheticTrialGroup(uint32 trial, uint32 group);
79 }; 80 };
80 81
81 // See metrics_service.cc for a detailed description. 82 // See metrics_service.cc for a detailed description.
82 class MetricsService : public base::HistogramFlattener { 83 class MetricsService : public base::HistogramFlattener {
83 public: 84 public:
84 // The execution phase of the browser. 85 // The execution phase of the browser.
85 enum ExecutionPhase { 86 enum ExecutionPhase {
86 UNINITIALIZED_PHASE = 0, 87 UNINITIALIZED_PHASE = 0,
87 START_METRICS_RECORDING = 100, 88 START_METRICS_RECORDING = 100,
88 CREATE_PROFILE = 200, 89 CREATE_PROFILE = 200,
89 STARTUP_TIMEBOMB_ARM = 300, 90 STARTUP_TIMEBOMB_ARM = 300,
90 THREAD_WATCHER_START = 400, 91 THREAD_WATCHER_START = 400,
91 MAIN_MESSAGE_LOOP_RUN = 500, 92 MAIN_MESSAGE_LOOP_RUN = 500,
92 SHUTDOWN_TIMEBOMB_ARM = 600, 93 SHUTDOWN_TIMEBOMB_ARM = 600,
93 SHUTDOWN_COMPLETE = 700, 94 SHUTDOWN_COMPLETE = 700,
94 }; 95 };
95 96
96 // Creates the MetricsService with the given |state_manager|, |client|, and 97 // Creates the MetricsService with the given |state_manager|, |client|, and
97 // |local_state|. Does not take ownership of the paramaters; instead stores 98 // |local_state|. Does not take ownership of the paramaters; instead stores
98 // a weak pointer to each. Caller should ensure that the parameters are valid 99 // a weak pointer to each. Caller should ensure that the parameters are valid
99 // for the lifetime of this class. 100 // for the lifetime of this class.
100 MetricsService(metrics::MetricsStateManager* state_manager, 101 MetricsService(MetricsStateManager* state_manager,
101 metrics::MetricsServiceClient* client, 102 MetricsServiceClient* client,
102 PrefService* local_state); 103 PrefService* local_state);
103 virtual ~MetricsService(); 104 virtual ~MetricsService();
104 105
105 // Initializes metrics recording state. Updates various bookkeeping values in 106 // Initializes metrics recording state. Updates various bookkeeping values in
106 // prefs and sets up the scheduler. This is a separate function rather than 107 // prefs and sets up the scheduler. This is a separate function rather than
107 // being done by the constructor so that field trials could be created before 108 // being done by the constructor so that field trials could be created before
108 // this is run. 109 // this is run.
109 void InitializeMetricsRecordingState(); 110 void InitializeMetricsRecordingState();
110 111
111 // Starts the metrics system, turning on recording and uploading of metrics. 112 // Starts the metrics system, turning on recording and uploading of metrics.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 // annotated with this trial group if and only if all events in the report 209 // annotated with this trial group if and only if all events in the report
209 // were created after the trial is registered. Only one group name may be 210 // were created after the trial is registered. Only one group name may be
210 // registered at a time for a given trial_name. Only the last group name that 211 // registered at a time for a given trial_name. Only the last group name that
211 // is registered for a given trial name will be recorded. The values passed 212 // is registered for a given trial name will be recorded. The values passed
212 // in must not correspond to any real field trial in the code. 213 // in must not correspond to any real field trial in the code.
213 // To use this method, SyntheticTrialGroup should friend your class. 214 // To use this method, SyntheticTrialGroup should friend your class.
214 void RegisterSyntheticFieldTrial(const SyntheticTrialGroup& trial_group); 215 void RegisterSyntheticFieldTrial(const SyntheticTrialGroup& trial_group);
215 216
216 // Register the specified |provider| to provide additional metrics into the 217 // Register the specified |provider| to provide additional metrics into the
217 // UMA log. Should be called during MetricsService initialization only. 218 // UMA log. Should be called during MetricsService initialization only.
218 void RegisterMetricsProvider(scoped_ptr<metrics::MetricsProvider> provider); 219 void RegisterMetricsProvider(scoped_ptr<MetricsProvider> provider);
219 220
220 // Check if this install was cloned or imaged from another machine. If a 221 // Check if this install was cloned or imaged from another machine. If a
221 // clone is detected, reset the client id and low entropy source. This 222 // clone is detected, reset the client id and low entropy source. This
222 // should not be called more than once. 223 // should not be called more than once.
223 void CheckForClonedInstall( 224 void CheckForClonedInstall(
224 scoped_refptr<base::SingleThreadTaskRunner> task_runner); 225 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
225 226
226 protected: 227 protected:
227 // Exposed for testing. 228 // Exposed for testing.
228 metrics::MetricsLogManager* log_manager() { return &log_manager_; } 229 MetricsLogManager* log_manager() { return &log_manager_; }
229 230
230 private: 231 private:
231 // The MetricsService has a lifecycle that is stored as a state. 232 // The MetricsService has a lifecycle that is stored as a state.
232 // See metrics_service.cc for description of this lifecycle. 233 // See metrics_service.cc for description of this lifecycle.
233 enum State { 234 enum State {
234 INITIALIZED, // Constructor was called. 235 INITIALIZED, // Constructor was called.
235 INIT_TASK_SCHEDULED, // Waiting for deferred init tasks to 236 INIT_TASK_SCHEDULED, // Waiting for deferred init tasks to
236 // complete. 237 // complete.
237 INIT_TASK_DONE, // Waiting for timer to send initial log. 238 INIT_TASK_DONE, // Waiting for timer to send initial log.
238 SENDING_INITIAL_STABILITY_LOG, // Initial stability log being sent. 239 SENDING_INITIAL_STABILITY_LOG, // Initial stability log being sent.
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 367
367 // Record complete list of histograms into the current log. 368 // Record complete list of histograms into the current log.
368 // Called when we close a log. 369 // Called when we close a log.
369 void RecordCurrentHistograms(); 370 void RecordCurrentHistograms();
370 371
371 // Record complete list of stability histograms into the current log, 372 // Record complete list of stability histograms into the current log,
372 // i.e., histograms with the |kUmaStabilityHistogramFlag| flag set. 373 // i.e., histograms with the |kUmaStabilityHistogramFlag| flag set.
373 void RecordCurrentStabilityHistograms(); 374 void RecordCurrentStabilityHistograms();
374 375
375 // Manager for the various in-flight logs. 376 // Manager for the various in-flight logs.
376 metrics::MetricsLogManager log_manager_; 377 MetricsLogManager log_manager_;
377 378
378 // |histogram_snapshot_manager_| prepares histogram deltas for transmission. 379 // |histogram_snapshot_manager_| prepares histogram deltas for transmission.
379 base::HistogramSnapshotManager histogram_snapshot_manager_; 380 base::HistogramSnapshotManager histogram_snapshot_manager_;
380 381
381 // Used to manage various metrics reporting state prefs, such as client id, 382 // Used to manage various metrics reporting state prefs, such as client id,
382 // low entropy source and whether metrics reporting is enabled. Weak pointer. 383 // low entropy source and whether metrics reporting is enabled. Weak pointer.
383 metrics::MetricsStateManager* const state_manager_; 384 MetricsStateManager* const state_manager_;
384 385
385 // Used to interact with the embedder. Weak pointer; must outlive |this| 386 // Used to interact with the embedder. Weak pointer; must outlive |this|
386 // instance. 387 // instance.
387 metrics::MetricsServiceClient* const client_; 388 MetricsServiceClient* const client_;
388 389
389 // Registered metrics providers. 390 // Registered metrics providers.
390 ScopedVector<metrics::MetricsProvider> metrics_providers_; 391 ScopedVector<MetricsProvider> metrics_providers_;
391 392
392 PrefService* local_state_; 393 PrefService* local_state_;
393 394
394 base::ActionCallback action_callback_; 395 base::ActionCallback action_callback_;
395 396
396 // Indicate whether recording and reporting are currently happening. 397 // Indicate whether recording and reporting are currently happening.
397 // These should not be set directly, but by calling SetRecording and 398 // These should not be set directly, but by calling SetRecording and
398 // SetReporting. 399 // SetReporting.
399 bool recording_active_; 400 bool recording_active_;
400 bool reporting_active_; 401 bool reporting_active_;
401 402
402 // Indicate whether test mode is enabled, where the initial log should never 403 // Indicate whether test mode is enabled, where the initial log should never
403 // be cut, and logs are neither persisted nor uploaded. 404 // be cut, and logs are neither persisted nor uploaded.
404 bool test_mode_active_; 405 bool test_mode_active_;
405 406
406 // The progression of states made by the browser are recorded in the following 407 // The progression of states made by the browser are recorded in the following
407 // state. 408 // state.
408 State state_; 409 State state_;
409 410
410 // Whether the initial stability log has been recorded during startup. 411 // Whether the initial stability log has been recorded during startup.
411 bool has_initial_stability_log_; 412 bool has_initial_stability_log_;
412 413
413 // The initial metrics log, used to record startup metrics (histograms and 414 // The initial metrics log, used to record startup metrics (histograms and
414 // profiler data). Note that if a crash occurred in the previous session, an 415 // profiler data). Note that if a crash occurred in the previous session, an
415 // initial stability log may be sent before this. 416 // initial stability log may be sent before this.
416 scoped_ptr<MetricsLog> initial_metrics_log_; 417 scoped_ptr<MetricsLog> initial_metrics_log_;
417 418
418 // Instance of the helper class for uploading logs. 419 // Instance of the helper class for uploading logs.
419 scoped_ptr<metrics::MetricsLogUploader> log_uploader_; 420 scoped_ptr<MetricsLogUploader> log_uploader_;
420 421
421 // Whether there is a current log upload in progress. 422 // Whether there is a current log upload in progress.
422 bool log_upload_in_progress_; 423 bool log_upload_in_progress_;
423 424
424 // Whether the MetricsService object has received any notifications since 425 // Whether the MetricsService object has received any notifications since
425 // the last time a transmission was sent. 426 // the last time a transmission was sent.
426 bool idle_since_last_transmission_; 427 bool idle_since_last_transmission_;
427 428
428 // A number that identifies the how many times the app has been launched. 429 // A number that identifies the how many times the app has been launched.
429 int session_id_; 430 int session_id_;
(...skipping 23 matching lines...) Expand all
453 static ShutdownCleanliness clean_shutdown_status_; 454 static ShutdownCleanliness clean_shutdown_status_;
454 455
455 // Field trial groups that map to Chrome configuration states. 456 // Field trial groups that map to Chrome configuration states.
456 SyntheticTrialGroups synthetic_trial_groups_; 457 SyntheticTrialGroups synthetic_trial_groups_;
457 458
458 ObserverList<MetricsServiceObserver> observers_; 459 ObserverList<MetricsServiceObserver> observers_;
459 460
460 // Confirms single-threaded access to |observers_| in debug builds. 461 // Confirms single-threaded access to |observers_| in debug builds.
461 base::ThreadChecker thread_checker_; 462 base::ThreadChecker thread_checker_;
462 463
463 friend class MetricsServiceAccessor; 464 friend class ::MetricsServiceAccessor;
464 465
465 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); 466 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess);
466 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsServiceObserver); 467 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsServiceObserver);
467 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, 468 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest,
468 PermutedEntropyCacheClearedWhenLowEntropyReset); 469 PermutedEntropyCacheClearedWhenLowEntropyReset);
469 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); 470 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial);
470 471
471 DISALLOW_COPY_AND_ASSIGN(MetricsService); 472 DISALLOW_COPY_AND_ASSIGN(MetricsService);
472 }; 473 };
473 474
475 } // namespace metrics
476
474 #endif // COMPONENTS_METRICS_METRICS_SERVICE_H_ 477 #endif // COMPONENTS_METRICS_METRICS_SERVICE_H_
OLDNEW
« no previous file with comments | « components/metrics/metrics_reporting_scheduler_unittest.cc ('k') | components/metrics/metrics_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698