| 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 <map> | 11 #include <map> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 16 #include "base/gtest_prod_util.h" | 16 #include "base/gtest_prod_util.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/memory/scoped_vector.h" | 18 #include "base/memory/scoped_vector.h" |
| 19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
| 20 #include "base/metrics/field_trial.h" | 20 #include "base/metrics/field_trial.h" |
| 21 #include "base/metrics/histogram_flattener.h" | 21 #include "base/metrics/histogram_flattener.h" |
| 22 #include "base/metrics/histogram_snapshot_manager.h" | 22 #include "base/metrics/histogram_snapshot_manager.h" |
| 23 #include "base/metrics/user_metrics.h" | 23 #include "base/metrics/user_metrics.h" |
| 24 #include "base/observer_list.h" | |
| 25 #include "base/strings/string16.h" | |
| 26 #include "base/threading/thread_checker.h" | |
| 27 #include "base/time/time.h" | 24 #include "base/time/time.h" |
| 28 #include "components/metrics/metrics_log.h" | 25 #include "components/metrics/metrics_log.h" |
| 29 #include "components/metrics/metrics_log_manager.h" | 26 #include "components/metrics/metrics_log_manager.h" |
| 30 #include "components/metrics/metrics_provider.h" | 27 #include "components/metrics/metrics_provider.h" |
| 31 #include "components/metrics/metrics_service_observer.h" | |
| 32 #include "components/variations/active_field_trials.h" | 28 #include "components/variations/active_field_trials.h" |
| 33 | 29 |
| 34 class MetricsServiceAccessor; | 30 class MetricsServiceAccessor; |
| 35 class PrefService; | 31 class PrefService; |
| 36 class PrefRegistrySimple; | 32 class PrefRegistrySimple; |
| 37 | 33 |
| 38 namespace base { | 34 namespace base { |
| 39 class DictionaryValue; | 35 class DictionaryValue; |
| 40 class HistogramSamples; | 36 class HistogramSamples; |
| 41 class MessageLoopProxy; | 37 class MessageLoopProxy; |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 | 272 |
| 277 // If in_idle is true, sets idle_since_last_transmission to true. | 273 // If in_idle is true, sets idle_since_last_transmission to true. |
| 278 // If in_idle is false and idle_since_last_transmission_ is true, sets | 274 // If in_idle is false and idle_since_last_transmission_ is true, sets |
| 279 // idle_since_last_transmission to false and starts the timer (provided | 275 // idle_since_last_transmission to false and starts the timer (provided |
| 280 // starting the timer is permitted). | 276 // starting the timer is permitted). |
| 281 void HandleIdleSinceLastTransmission(bool in_idle); | 277 void HandleIdleSinceLastTransmission(bool in_idle); |
| 282 | 278 |
| 283 // Set up client ID, session ID, etc. | 279 // Set up client ID, session ID, etc. |
| 284 void InitializeMetricsState(); | 280 void InitializeMetricsState(); |
| 285 | 281 |
| 286 // Registers/unregisters |observer| to receive MetricsLog notifications. | 282 // Notifies providers when a new metrics log is created. |
| 287 void AddObserver(MetricsServiceObserver* observer); | |
| 288 void RemoveObserver(MetricsServiceObserver* observer); | |
| 289 void NotifyOnDidCreateMetricsLog(); | 283 void NotifyOnDidCreateMetricsLog(); |
| 290 | 284 |
| 291 // Schedule the next save of LocalState information. This is called | 285 // Schedule the next save of LocalState information. This is called |
| 292 // automatically by the task that performs each save to schedule the next one. | 286 // automatically by the task that performs each save to schedule the next one. |
| 293 void ScheduleNextStateSave(); | 287 void ScheduleNextStateSave(); |
| 294 | 288 |
| 295 // Save the LocalState information immediately. This should not be called by | 289 // Save the LocalState information immediately. This should not be called by |
| 296 // anybody other than the scheduler to avoid doing too many writes. When you | 290 // anybody other than the scheduler to avoid doing too many writes. When you |
| 297 // make a change, call ScheduleNextStateSave() instead. | 291 // make a change, call ScheduleNextStateSave() instead. |
| 298 void SaveLocalState(); | 292 void SaveLocalState(); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 | 433 |
| 440 // The scheduler for determining when uploads should happen. | 434 // The scheduler for determining when uploads should happen. |
| 441 scoped_ptr<MetricsReportingScheduler> scheduler_; | 435 scoped_ptr<MetricsReportingScheduler> scheduler_; |
| 442 | 436 |
| 443 // Stores the time of the first call to |GetUptimes()|. | 437 // Stores the time of the first call to |GetUptimes()|. |
| 444 base::TimeTicks first_updated_time_; | 438 base::TimeTicks first_updated_time_; |
| 445 | 439 |
| 446 // Stores the time of the last call to |GetUptimes()|. | 440 // Stores the time of the last call to |GetUptimes()|. |
| 447 base::TimeTicks last_updated_time_; | 441 base::TimeTicks last_updated_time_; |
| 448 | 442 |
| 443 // Field trial groups that map to Chrome configuration states. |
| 444 SyntheticTrialGroups synthetic_trial_groups_; |
| 445 |
| 449 // Execution phase the browser is in. | 446 // Execution phase the browser is in. |
| 450 static ExecutionPhase execution_phase_; | 447 static ExecutionPhase execution_phase_; |
| 451 | 448 |
| 452 // Reduntant marker to check that we completed our shutdown, and set the | 449 // Reduntant marker to check that we completed our shutdown, and set the |
| 453 // exited-cleanly bit in the prefs. | 450 // exited-cleanly bit in the prefs. |
| 454 static ShutdownCleanliness clean_shutdown_status_; | 451 static ShutdownCleanliness clean_shutdown_status_; |
| 455 | 452 |
| 456 // Field trial groups that map to Chrome configuration states. | |
| 457 SyntheticTrialGroups synthetic_trial_groups_; | |
| 458 | |
| 459 ObserverList<MetricsServiceObserver> observers_; | |
| 460 | |
| 461 // Confirms single-threaded access to |observers_| in debug builds. | |
| 462 base::ThreadChecker thread_checker_; | |
| 463 | |
| 464 friend class ::MetricsServiceAccessor; | 453 friend class ::MetricsServiceAccessor; |
| 465 | 454 |
| 466 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); | 455 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); |
| 467 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsServiceObserver); | |
| 468 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, | 456 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, |
| 469 PermutedEntropyCacheClearedWhenLowEntropyReset); | 457 PermutedEntropyCacheClearedWhenLowEntropyReset); |
| 470 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); | 458 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); |
| 471 | 459 |
| 472 DISALLOW_COPY_AND_ASSIGN(MetricsService); | 460 DISALLOW_COPY_AND_ASSIGN(MetricsService); |
| 473 }; | 461 }; |
| 474 | 462 |
| 475 } // namespace metrics | 463 } // namespace metrics |
| 476 | 464 |
| 477 #endif // COMPONENTS_METRICS_METRICS_SERVICE_H_ | 465 #endif // COMPONENTS_METRICS_METRICS_SERVICE_H_ |
| OLD | NEW |