OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ | 8 #ifndef CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ |
9 #define CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ | 9 #define CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ |
10 | 10 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 } | 63 } |
64 | 64 |
65 namespace extensions { | 65 namespace extensions { |
66 class ExtensionDownloader; | 66 class ExtensionDownloader; |
67 class ManifestFetchData; | 67 class ManifestFetchData; |
68 class MetricsPrivateGetIsCrashReportingEnabledFunction; | 68 class MetricsPrivateGetIsCrashReportingEnabledFunction; |
69 } | 69 } |
70 | 70 |
71 namespace metrics { | 71 namespace metrics { |
72 class ClonedInstallDetector; | 72 class ClonedInstallDetector; |
73 class MetricsStateManager; | |
73 } | 74 } |
74 | 75 |
75 namespace net { | 76 namespace net { |
76 class URLFetcher; | 77 class URLFetcher; |
77 } | 78 } |
78 | 79 |
79 namespace prerender { | 80 namespace prerender { |
80 bool IsOmniboxEnabled(Profile* profile); | 81 bool IsOmniboxEnabled(Profile* profile); |
81 } | 82 } |
82 | 83 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 }; | 134 }; |
134 | 135 |
135 MetricsService(); | 136 MetricsService(); |
136 virtual ~MetricsService(); | 137 virtual ~MetricsService(); |
137 | 138 |
138 // Initializes metrics recording state. Updates various bookkeeping values in | 139 // Initializes metrics recording state. Updates various bookkeeping values in |
139 // prefs and sets up the scheduler. This is a separate function rather than | 140 // prefs and sets up the scheduler. This is a separate function rather than |
140 // being done by the constructor so that field trials could be created before | 141 // being done by the constructor so that field trials could be created before |
141 // this is run. Takes |reporting_state| parameter which specifies whether UMA | 142 // this is run. Takes |reporting_state| parameter which specifies whether UMA |
142 // is enabled. | 143 // is enabled. |
143 void InitializeMetricsRecordingState(ReportingState reporting_state); | 144 void InitializeMetricsRecordingState(); |
144 | 145 |
145 // Starts the metrics system, turning on recording and uploading of metrics. | 146 // Starts the metrics system, turning on recording and uploading of metrics. |
146 // Should be called when starting up with metrics enabled, or when metrics | 147 // Should be called when starting up with metrics enabled, or when metrics |
147 // are turned on. | 148 // are turned on. |
148 void Start(); | 149 void Start(); |
149 | 150 |
151 // If metrics reporting is enabled, starts the metrics service. Returns | |
152 // whether the metrics service was started. | |
153 bool StartIfMetricsReportingEnabled(); | |
154 | |
150 // Starts the metrics system in a special test-only mode. Metrics won't ever | 155 // Starts the metrics system in a special test-only mode. Metrics won't ever |
151 // be uploaded or persisted in this mode, but metrics will be recorded in | 156 // be uploaded or persisted in this mode, but metrics will be recorded in |
152 // memory. | 157 // memory. |
153 void StartRecordingForTests(); | 158 void StartRecordingForTests(); |
154 | 159 |
155 // Shuts down the metrics system. Should be called at shutdown, or if metrics | 160 // Shuts down the metrics system. Should be called at shutdown, or if metrics |
156 // are turned off. | 161 // are turned off. |
157 void Stop(); | 162 void Stop(); |
158 | 163 |
159 // Enable/disable transmission of accumulated logs and crash reports (dumps). | 164 // Enable/disable transmission of accumulated logs and crash reports (dumps). |
160 // Calling Start() automatically enables reporting, but sending is | 165 // Calling Start() automatically enables reporting, but sending is |
161 // asyncronous so this can be called immediately after Start() to prevent | 166 // asyncronous so this can be called immediately after Start() to prevent |
162 // any uploading. | 167 // any uploading. |
163 void EnableReporting(); | 168 void EnableReporting(); |
164 void DisableReporting(); | 169 void DisableReporting(); |
165 | 170 |
166 // Returns the client ID for this client, or the empty string if metrics | 171 // Returns the client ID for this client, or the empty string if metrics |
167 // recording is not currently running. | 172 // recording is not currently running. |
168 std::string GetClientId(); | 173 std::string GetClientId(); |
169 | 174 |
170 // Returns the preferred entropy provider used to seed persistent activities | 175 // Returns the preferred entropy provider used to seed persistent activities |
jwd
2014/05/01 15:51:14
Update comment.
Alexei Svitkine (slow)
2014/05/01 18:01:45
Done.
| |
171 // based on whether or not metrics reporting will be permitted on this client. | 176 // based on whether or not metrics reporting will be permitted on this client. |
172 // The caller must determine if metrics reporting will be enabled for this | 177 // The caller must determine if metrics reporting will be enabled for this |
173 // client and pass that state in as |reporting_will_be_enabled|. | 178 // client and pass that state in as |reporting_will_be_enabled|. |
174 // | 179 // |
175 // If |reporting_will_be_enabled| is true, this method returns an entropy | 180 // If |reporting_will_be_enabled| is true, this method returns an entropy |
176 // provider that has a high source of entropy, partially based on the client | 181 // provider that has a high source of entropy, partially based on the client |
177 // ID. Otherwise, an entropy provider that is based on a low entropy source | 182 // ID. Otherwise, an entropy provider that is based on a low entropy source |
178 // is returned. | 183 // is returned. |
179 // | 184 // |
180 // Note that this reporting state can not be checked by reporting_active() | 185 // Note that this reporting state can not be checked by reporting_active() |
181 // because this method may need to be called before the MetricsService needs | 186 // because this method may need to be called before the MetricsService needs |
182 // to be started. | 187 // to be started. |
183 scoped_ptr<const base::FieldTrial::EntropyProvider> CreateEntropyProvider( | 188 scoped_ptr<const base::FieldTrial::EntropyProvider> CreateEntropyProvider(); |
184 ReportingState reporting_state); | |
185 | 189 |
186 // Force the client ID to be generated. This is useful in case it's needed | 190 // Force the client ID to be generated. This is useful in case it's needed |
187 // before recording. | 191 // before recording. |
188 void ForceClientIdCreation(); | 192 void ForceClientIdCreation(); |
jwd
2014/05/01 15:51:14
Is this still needed in the metrics service?
Alexei Svitkine (slow)
2014/05/01 18:01:45
No, it's not. Good catch!
| |
189 | 193 |
190 // At startup, prefs needs to be called with a list of all the pref names and | 194 // At startup, prefs needs to be called with a list of all the pref names and |
191 // types we'll be using. | 195 // types we'll be using. |
192 static void RegisterPrefs(PrefRegistrySimple* registry); | 196 static void RegisterPrefs(PrefRegistrySimple* registry); |
193 #if defined(OS_ANDROID) | 197 #if defined(OS_ANDROID) |
194 static void RegisterPrefsAndroid(PrefRegistrySimple* registry); | 198 static void RegisterPrefsAndroid(PrefRegistrySimple* registry); |
195 #endif // defined(OS_ANDROID) | 199 #endif // defined(OS_ANDROID) |
196 | 200 |
197 // Set up notifications which indicate that a user is performing work. This is | 201 // Set up notifications which indicate that a user is performing work. This is |
198 // useful to allow some features to sleep, until the machine becomes active, | 202 // useful to allow some features to sleep, until the machine becomes active, |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
361 // Get the amount of uptime since this process started and since the last | 365 // Get the amount of uptime since this process started and since the last |
362 // call to this function. Also updates the cumulative uptime metric (stored | 366 // call to this function. Also updates the cumulative uptime metric (stored |
363 // as a pref) for uninstall. Uptimes are measured using TimeTicks, which | 367 // as a pref) for uninstall. Uptimes are measured using TimeTicks, which |
364 // guarantees that it is monotonic and does not jump if the user changes | 368 // guarantees that it is monotonic and does not jump if the user changes |
365 // his/her clock. The TimeTicks implementation also makes the clock not | 369 // his/her clock. The TimeTicks implementation also makes the clock not |
366 // count time the computer is suspended. | 370 // count time the computer is suspended. |
367 void GetUptimes(PrefService* pref, | 371 void GetUptimes(PrefService* pref, |
368 base::TimeDelta* incremental_uptime, | 372 base::TimeDelta* incremental_uptime, |
369 base::TimeDelta* uptime); | 373 base::TimeDelta* uptime); |
370 | 374 |
371 // Reset the client id and low entropy source if the kMetricsResetMetricIDs | |
372 // pref is true. | |
373 void ResetMetricsIDsIfNecessary(); | |
374 | |
375 // Returns the low entropy source for this client. This is a random value | |
376 // that is non-identifying amongst browser clients. This method will | |
377 // generate the entropy source value if it has not been called before. | |
378 int GetLowEntropySource(); | |
379 | |
380 // Returns the first entropy source that was returned by this service since | |
381 // start up, or NONE if neither was returned yet. This is exposed for testing | |
382 // only. | |
383 EntropySourceReturned entropy_source_returned() const { | |
384 return entropy_source_returned_; | |
385 } | |
386 | |
387 // Turns recording on or off. | 375 // Turns recording on or off. |
388 // DisableRecording() also forces a persistent save of logging state (if | 376 // DisableRecording() also forces a persistent save of logging state (if |
389 // anything has been recorded, or transmitted). | 377 // anything has been recorded, or transmitted). |
390 void EnableRecording(); | 378 void EnableRecording(); |
391 void DisableRecording(); | 379 void DisableRecording(); |
392 | 380 |
393 // If in_idle is true, sets idle_since_last_transmission to true. | 381 // If in_idle is true, sets idle_since_last_transmission to true. |
394 // If in_idle is false and idle_since_last_transmission_ is true, sets | 382 // If in_idle is false and idle_since_last_transmission_ is true, sets |
395 // idle_since_last_transmission to false and starts the timer (provided | 383 // idle_since_last_transmission to false and starts the timer (provided |
396 // starting the timer is permitted). | 384 // starting the timer is permitted). |
397 void HandleIdleSinceLastTransmission(bool in_idle); | 385 void HandleIdleSinceLastTransmission(bool in_idle); |
398 | 386 |
399 // Set up client ID, session ID, etc. | 387 // Set up client ID, session ID, etc. |
400 void InitializeMetricsState(ReportingState reporting_state); | 388 void InitializeMetricsState(); |
401 | |
402 // Generates a new client ID to use to identify self to metrics server. | |
403 static std::string GenerateClientID(); | |
404 | 389 |
405 // Schedule the next save of LocalState information. This is called | 390 // Schedule the next save of LocalState information. This is called |
406 // automatically by the task that performs each save to schedule the next one. | 391 // automatically by the task that performs each save to schedule the next one. |
407 void ScheduleNextStateSave(); | 392 void ScheduleNextStateSave(); |
408 | 393 |
409 // Save the LocalState information immediately. This should not be called by | 394 // Save the LocalState information immediately. This should not be called by |
410 // anybody other than the scheduler to avoid doing too many writes. When you | 395 // anybody other than the scheduler to avoid doing too many writes. When you |
411 // make a change, call ScheduleNextStateSave() instead. | 396 // make a change, call ScheduleNextStateSave() instead. |
412 void SaveLocalState(); | 397 void SaveLocalState(); |
413 | 398 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
505 | 490 |
506 // Returns true if process of type |type| should be counted as a plugin | 491 // Returns true if process of type |type| should be counted as a plugin |
507 // process, and false otherwise. | 492 // process, and false otherwise. |
508 static bool IsPluginProcess(int process_type); | 493 static bool IsPluginProcess(int process_type); |
509 | 494 |
510 // Returns a list of synthetic field trials that were active for the entire | 495 // Returns a list of synthetic field trials that were active for the entire |
511 // duration of the current log. | 496 // duration of the current log. |
512 void GetCurrentSyntheticFieldTrials( | 497 void GetCurrentSyntheticFieldTrials( |
513 std::vector<chrome_variations::ActiveGroupId>* synthetic_trials); | 498 std::vector<chrome_variations::ActiveGroupId>* synthetic_trials); |
514 | 499 |
500 scoped_ptr<metrics::MetricsStateManager> state_manager_; | |
501 | |
515 base::ActionCallback action_callback_; | 502 base::ActionCallback action_callback_; |
516 | 503 |
517 content::NotificationRegistrar registrar_; | 504 content::NotificationRegistrar registrar_; |
518 | 505 |
519 // Set to true when |ResetMetricsIDsIfNecessary| is called for the first time. | 506 // Set to true when |ResetMetricsIDsIfNecessary| is called for the first time. |
520 // This prevents multiple resets within the same Chrome session. | 507 // This prevents multiple resets within the same Chrome session. |
521 bool metrics_ids_reset_check_performed_; | 508 bool metrics_ids_reset_check_performed_; |
522 | 509 |
523 // Indicate whether recording and reporting are currently happening. | 510 // Indicate whether recording and reporting are currently happening. |
524 // These should not be set directly, but by calling SetRecording and | 511 // These should not be set directly, but by calling SetRecording and |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
556 | 543 |
557 // The outstanding transmission appears as a URL Fetch operation. | 544 // The outstanding transmission appears as a URL Fetch operation. |
558 scoped_ptr<net::URLFetcher> current_fetch_; | 545 scoped_ptr<net::URLFetcher> current_fetch_; |
559 | 546 |
560 // The TCP/UDP echo server to collect network connectivity stats. | 547 // The TCP/UDP echo server to collect network connectivity stats. |
561 std::string network_stats_server_; | 548 std::string network_stats_server_; |
562 | 549 |
563 // The HTTP pipelining test server. | 550 // The HTTP pipelining test server. |
564 std::string http_pipelining_test_server_; | 551 std::string http_pipelining_test_server_; |
565 | 552 |
566 // The identifier that's sent to the server with the log reports. | |
567 std::string client_id_; | |
568 | |
569 // The non-identifying low entropy source value. | |
570 int low_entropy_source_; | |
571 | |
572 // Whether the MetricsService object has received any notifications since | 553 // Whether the MetricsService object has received any notifications since |
573 // the last time a transmission was sent. | 554 // the last time a transmission was sent. |
574 bool idle_since_last_transmission_; | 555 bool idle_since_last_transmission_; |
575 | 556 |
576 // A number that identifies the how many times the app has been launched. | 557 // A number that identifies the how many times the app has been launched. |
577 int session_id_; | 558 int session_id_; |
578 | 559 |
579 // Maps WebContentses (corresponding to tabs) or Browsers (corresponding to | 560 // Maps WebContentses (corresponding to tabs) or Browsers (corresponding to |
580 // Windows) to a unique integer that we will use to identify them. | 561 // Windows) to a unique integer that we will use to identify them. |
581 // |next_window_id_| is used to track which IDs we have used so far. | 562 // |next_window_id_| is used to track which IDs we have used so far. |
(...skipping 20 matching lines...) Expand all Loading... | |
602 bool waiting_for_asynchronous_reporting_step_; | 583 bool waiting_for_asynchronous_reporting_step_; |
603 | 584 |
604 // Number of async histogram fetch requests in progress. | 585 // Number of async histogram fetch requests in progress. |
605 int num_async_histogram_fetches_in_progress_; | 586 int num_async_histogram_fetches_in_progress_; |
606 | 587 |
607 #if defined(OS_CHROMEOS) | 588 #if defined(OS_CHROMEOS) |
608 // The external metric service is used to log ChromeOS UMA events. | 589 // The external metric service is used to log ChromeOS UMA events. |
609 scoped_refptr<chromeos::ExternalMetrics> external_metrics_; | 590 scoped_refptr<chromeos::ExternalMetrics> external_metrics_; |
610 #endif | 591 #endif |
611 | 592 |
612 // The last entropy source returned by this service, used for testing. | |
613 EntropySourceReturned entropy_source_returned_; | |
614 | |
615 // Stores the time of the first call to |GetUptimes()|. | 593 // Stores the time of the first call to |GetUptimes()|. |
616 base::TimeTicks first_updated_time_; | 594 base::TimeTicks first_updated_time_; |
617 | 595 |
618 // Stores the time of the last call to |GetUptimes()|. | 596 // Stores the time of the last call to |GetUptimes()|. |
619 base::TimeTicks last_updated_time_; | 597 base::TimeTicks last_updated_time_; |
620 | 598 |
621 // Execution phase the browser is in. | 599 // Execution phase the browser is in. |
622 static ExecutionPhase execution_phase_; | 600 static ExecutionPhase execution_phase_; |
623 | 601 |
624 // Reduntant marker to check that we completed our shutdown, and set the | 602 // Reduntant marker to check that we completed our shutdown, and set the |
625 // exited-cleanly bit in the prefs. | 603 // exited-cleanly bit in the prefs. |
626 static ShutdownCleanliness clean_shutdown_status_; | 604 static ShutdownCleanliness clean_shutdown_status_; |
627 | 605 |
628 // Field trial groups that map to Chrome configuration states. | 606 // Field trial groups that map to Chrome configuration states. |
629 SyntheticTrialGroups synthetic_trial_groups_; | 607 SyntheticTrialGroups synthetic_trial_groups_; |
630 | 608 |
631 scoped_ptr<metrics::ClonedInstallDetector> cloned_install_detector_; | |
632 | |
633 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdCorrectlyFormatted); | |
634 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); | 609 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); |
635 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, LowEntropySource0NotReset); | |
636 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, | 610 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, |
637 PermutedEntropyCacheClearedWhenLowEntropyReset); | 611 PermutedEntropyCacheClearedWhenLowEntropyReset); |
638 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); | 612 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); |
639 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ResetMetricsIDs); | |
640 FRIEND_TEST_ALL_PREFIXES(MetricsServiceBrowserTest, | |
641 CheckLowEntropySourceUsed); | |
642 FRIEND_TEST_ALL_PREFIXES(MetricsServiceReportingTest, | |
643 CheckHighEntropySourceUsed); | |
644 | 613 |
645 DISALLOW_COPY_AND_ASSIGN(MetricsService); | 614 DISALLOW_COPY_AND_ASSIGN(MetricsService); |
646 }; | 615 }; |
647 | 616 |
648 // This class limits and documents access to the IsMetricsReportingEnabled() and | 617 // This class limits and documents access to the IsMetricsReportingEnabled() and |
649 // IsCrashReportingEnabled() methods. Since these methods are private, each user | 618 // IsCrashReportingEnabled() methods. Since these methods are private, each user |
650 // has to be explicitly declared as a 'friend' below. | 619 // has to be explicitly declared as a 'friend' below. |
651 class MetricsServiceHelper { | 620 class MetricsServiceHelper { |
652 private: | 621 private: |
653 friend bool prerender::IsOmniboxEnabled(Profile* profile); | 622 friend bool prerender::IsOmniboxEnabled(Profile* profile); |
(...skipping 12 matching lines...) Expand all Loading... | |
666 | 635 |
667 // Returns true if crash reporting is enabled. This is set at the platform | 636 // Returns true if crash reporting is enabled. This is set at the platform |
668 // level for Android and ChromeOS, and otherwise is the same as | 637 // level for Android and ChromeOS, and otherwise is the same as |
669 // IsMetricsReportingEnabled for desktop Chrome. | 638 // IsMetricsReportingEnabled for desktop Chrome. |
670 static bool IsCrashReportingEnabled(); | 639 static bool IsCrashReportingEnabled(); |
671 | 640 |
672 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper); | 641 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper); |
673 }; | 642 }; |
674 | 643 |
675 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ | 644 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ |
OLD | NEW |