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

Side by Side Diff: chrome/browser/metrics/metrics_service.h

Issue 253203002: Log operator code histogram on new metric log (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@api_move
Patch Set: addressed more comments. Created 6 years, 7 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 (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
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/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
19 #include "base/metrics/field_trial.h" 19 #include "base/metrics/field_trial.h"
20 #include "base/metrics/user_metrics.h" 20 #include "base/metrics/user_metrics.h"
21 #include "base/observer_list.h"
21 #include "base/process/kill.h" 22 #include "base/process/kill.h"
22 #include "base/time/time.h" 23 #include "base/time/time.h"
23 #include "chrome/browser/metrics/metrics_log.h" 24 #include "chrome/browser/metrics/metrics_log.h"
25 #include "chrome/browser/metrics/metrics_service_observer.h"
24 #include "chrome/browser/metrics/tracking_synchronizer_observer.h" 26 #include "chrome/browser/metrics/tracking_synchronizer_observer.h"
25 #include "chrome/common/metrics/metrics_service_base.h" 27 #include "chrome/common/metrics/metrics_service_base.h"
26 #include "chrome/installer/util/google_update_settings.h" 28 #include "chrome/installer/util/google_update_settings.h"
27 #include "content/public/browser/browser_child_process_observer.h" 29 #include "content/public/browser/browser_child_process_observer.h"
28 #include "content/public/browser/notification_observer.h" 30 #include "content/public/browser/notification_observer.h"
29 #include "content/public/browser/notification_registrar.h" 31 #include "content/public/browser/notification_registrar.h"
30 #include "content/public/browser/user_metrics.h" 32 #include "content/public/browser/user_metrics.h"
31 #include "net/url_request/url_fetcher_delegate.h" 33 #include "net/url_request/url_fetcher_delegate.h"
32 34
33 #if defined(OS_ANDROID) 35 #if defined(OS_ANDROID)
34 #include "chrome/browser/android/activity_type_ids.h" 36 #include "chrome/browser/android/activity_type_ids.h"
35 #elif defined(OS_CHROMEOS) 37 #elif defined(OS_CHROMEOS)
36 #include "chrome/browser/chromeos/external_metrics.h" 38 #include "chrome/browser/chromeos/external_metrics.h"
37 #endif 39 #endif
38 40
41 class ChromeBrowserMetricsServiceObserver;
39 class MetricsReportingScheduler; 42 class MetricsReportingScheduler;
40 class PrefService; 43 class PrefService;
41 class PrefRegistrySimple; 44 class PrefRegistrySimple;
42 class Profile; 45 class Profile;
43 class TemplateURLService; 46 class TemplateURLService;
44 47
45 namespace { 48 namespace {
46 class CrashesDOMHandler; 49 class CrashesDOMHandler;
47 class FlashDOMHandler; 50 class FlashDOMHandler;
48 } 51 }
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 357
355 // If in_idle is true, sets idle_since_last_transmission to true. 358 // If in_idle is true, sets idle_since_last_transmission to true.
356 // If in_idle is false and idle_since_last_transmission_ is true, sets 359 // If in_idle is false and idle_since_last_transmission_ is true, sets
357 // idle_since_last_transmission to false and starts the timer (provided 360 // idle_since_last_transmission to false and starts the timer (provided
358 // starting the timer is permitted). 361 // starting the timer is permitted).
359 void HandleIdleSinceLastTransmission(bool in_idle); 362 void HandleIdleSinceLastTransmission(bool in_idle);
360 363
361 // Set up client ID, session ID, etc. 364 // Set up client ID, session ID, etc.
362 void InitializeMetricsState(); 365 void InitializeMetricsState();
363 366
367 // Registers/unregsiters |observer| to receive MetricsLog notifications.
bengr 2014/05/07 16:03:58 unregisters
bolian 2014/05/07 18:11:44 Done.
368 void AddObserver(MetricsServiceObserver* observer);
369 void RemoveObserver(MetricsServiceObserver* observer);
370 void NotifyOnDidCreateMetricsLog();
371
364 // Schedule the next save of LocalState information. This is called 372 // Schedule the next save of LocalState information. This is called
365 // automatically by the task that performs each save to schedule the next one. 373 // automatically by the task that performs each save to schedule the next one.
366 void ScheduleNextStateSave(); 374 void ScheduleNextStateSave();
367 375
368 // Save the LocalState information immediately. This should not be called by 376 // Save the LocalState information immediately. This should not be called by
369 // anybody other than the scheduler to avoid doing too many writes. When you 377 // anybody other than the scheduler to avoid doing too many writes. When you
370 // make a change, call ScheduleNextStateSave() instead. 378 // make a change, call ScheduleNextStateSave() instead.
371 void SaveLocalState(); 379 void SaveLocalState();
372 380
373 // Opens a new log for recording user experience metrics. 381 // Opens a new log for recording user experience metrics.
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 // Execution phase the browser is in. 583 // Execution phase the browser is in.
576 static ExecutionPhase execution_phase_; 584 static ExecutionPhase execution_phase_;
577 585
578 // Reduntant marker to check that we completed our shutdown, and set the 586 // Reduntant marker to check that we completed our shutdown, and set the
579 // exited-cleanly bit in the prefs. 587 // exited-cleanly bit in the prefs.
580 static ShutdownCleanliness clean_shutdown_status_; 588 static ShutdownCleanliness clean_shutdown_status_;
581 589
582 // Field trial groups that map to Chrome configuration states. 590 // Field trial groups that map to Chrome configuration states.
583 SyntheticTrialGroups synthetic_trial_groups_; 591 SyntheticTrialGroups synthetic_trial_groups_;
584 592
593 ObserverList<MetricsServiceObserver> observers_;
594 // Confirms single-threaded access to observers_ in debug builds.
595 base::ThreadChecker thread_checker_;
596
597 friend class MetricsServiceHelper;
598
585 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); 599 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess);
586 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, 600 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest,
587 PermutedEntropyCacheClearedWhenLowEntropyReset); 601 PermutedEntropyCacheClearedWhenLowEntropyReset);
588 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); 602 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial);
603 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsServiceObserver);
589 604
590 DISALLOW_COPY_AND_ASSIGN(MetricsService); 605 DISALLOW_COPY_AND_ASSIGN(MetricsService);
591 }; 606 };
592 607
593 // This class limits and documents access to the IsMetricsReportingEnabled() and 608 // This class limits and documents access to metrics service helper methods.
594 // IsCrashReportingEnabled() methods. Since these methods are private, each user 609 // Since these methods are private, each user has to be explicitly declared
595 // has to be explicitly declared as a 'friend' below. 610 // as a 'friend' below.
596 class MetricsServiceHelper { 611 class MetricsServiceHelper {
597 private: 612 private:
598 friend bool prerender::IsOmniboxEnabled(Profile* profile); 613 friend bool prerender::IsOmniboxEnabled(Profile* profile);
614 friend class ::ChromeBrowserMetricsServiceObserver;
599 friend class ChromeRenderMessageFilter; 615 friend class ChromeRenderMessageFilter;
600 friend class ::CrashesDOMHandler; 616 friend class ::CrashesDOMHandler;
601 friend class extensions::ExtensionDownloader; 617 friend class extensions::ExtensionDownloader;
602 friend class extensions::ManifestFetchData; 618 friend class extensions::ManifestFetchData;
603 friend class extensions::MetricsPrivateGetIsCrashReportingEnabledFunction; 619 friend class extensions::MetricsPrivateGetIsCrashReportingEnabledFunction;
604 friend class ::FlashDOMHandler; 620 friend class ::FlashDOMHandler;
605 friend class system_logs::ChromeInternalLogSource; 621 friend class system_logs::ChromeInternalLogSource;
606 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsReportingEnabled); 622 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsReportingEnabled);
607 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CrashReportingEnabled); 623 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CrashReportingEnabled);
608 624
609 // Returns true if prefs::kMetricsReportingEnabled is set. 625 // Returns true if prefs::kMetricsReportingEnabled is set.
610 // TODO(asvitkine): Consolidate the method in MetricsStateManager. 626 // TODO(asvitkine): Consolidate the method in MetricsStateManager.
611 // TODO(asvitkine): This function does not report the correct value on 627 // TODO(asvitkine): This function does not report the correct value on
612 // Android and ChromeOS, see http://crbug.com/362192. 628 // Android and ChromeOS, see http://crbug.com/362192.
613 static bool IsMetricsReportingEnabled(); 629 static bool IsMetricsReportingEnabled();
614 630
615 // Returns true if crash reporting is enabled. This is set at the platform 631 // Returns true if crash reporting is enabled. This is set at the platform
616 // level for Android and ChromeOS, and otherwise is the same as 632 // level for Android and ChromeOS, and otherwise is the same as
617 // IsMetricsReportingEnabled for desktop Chrome. 633 // IsMetricsReportingEnabled for desktop Chrome.
618 static bool IsCrashReportingEnabled(); 634 static bool IsCrashReportingEnabled();
619 635
636 // Registers/Unregsiters |observer| to receive MetricsLog notifications
bengr 2014/05/07 16:03:58 unregisters
bolian 2014/05/07 18:11:44 Done.
637 // from metric service.
bengr 2014/05/07 16:03:58 from the metrics service.
bolian 2014/05/07 18:11:44 Done.
638 static void AddMetricsServiceObserver(MetricsServiceObserver* observer);
639 static void RemoveMetricsServiceObserver(MetricsServiceObserver* observer);
640
620 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper); 641 DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper);
621 }; 642 };
622 643
623 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_ 644 #endif // CHROME_BROWSER_METRICS_METRICS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698