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

Side by Side Diff: chrome/browser/metrics/chrome_metrics_service_client.cc

Issue 2653693004: UKM Sync Observer (Closed)
Patch Set: Complex state Created 3 years, 10 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 #include "chrome/browser/metrics/chrome_metrics_service_client.h" 5 #include "chrome/browser/metrics/chrome_metrics_service_client.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 23 matching lines...) Expand all
34 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" 34 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
35 #include "chrome/browser/metrics/chrome_stability_metrics_provider.h" 35 #include "chrome/browser/metrics/chrome_stability_metrics_provider.h"
36 #include "chrome/browser/metrics/https_engagement_metrics_provider.h" 36 #include "chrome/browser/metrics/https_engagement_metrics_provider.h"
37 #include "chrome/browser/metrics/metrics_reporting_state.h" 37 #include "chrome/browser/metrics/metrics_reporting_state.h"
38 #include "chrome/browser/metrics/network_quality_estimator_provider_impl.h" 38 #include "chrome/browser/metrics/network_quality_estimator_provider_impl.h"
39 #include "chrome/browser/metrics/sampling_metrics_provider.h" 39 #include "chrome/browser/metrics/sampling_metrics_provider.h"
40 #include "chrome/browser/metrics/subprocess_metrics_provider.h" 40 #include "chrome/browser/metrics/subprocess_metrics_provider.h"
41 #include "chrome/browser/profiles/profile_manager.h" 41 #include "chrome/browser/profiles/profile_manager.h"
42 #include "chrome/browser/safe_browsing/certificate_reporting_metrics_provider.h" 42 #include "chrome/browser/safe_browsing/certificate_reporting_metrics_provider.h"
43 #include "chrome/browser/sync/chrome_sync_client.h" 43 #include "chrome/browser/sync/chrome_sync_client.h"
44 #include "chrome/browser/sync/profile_sync_service_factory.h"
44 #include "chrome/browser/ui/browser_otr_state.h" 45 #include "chrome/browser/ui/browser_otr_state.h"
45 #include "chrome/common/channel_info.h" 46 #include "chrome/common/channel_info.h"
46 #include "chrome/common/chrome_paths.h" 47 #include "chrome/common/chrome_paths.h"
47 #include "chrome/common/chrome_paths_internal.h" 48 #include "chrome/common/chrome_paths_internal.h"
48 #include "chrome/common/chrome_switches.h" 49 #include "chrome/common/chrome_switches.h"
49 #include "chrome/common/crash_keys.h" 50 #include "chrome/common/crash_keys.h"
50 #include "chrome/common/features.h" 51 #include "chrome/common/features.h"
51 #include "chrome/common/pref_names.h" 52 #include "chrome/common/pref_names.h"
52 #include "chrome/installer/util/util_constants.h" 53 #include "chrome/installer/util/util_constants.h"
54 #include "components/browser_sync/profile_sync_service.h"
53 #include "components/browser_watcher/stability_debugging.h" 55 #include "components/browser_watcher/stability_debugging.h"
54 #include "components/history/core/browser/history_service.h" 56 #include "components/history/core/browser/history_service.h"
55 #include "components/metrics/call_stack_profile_metrics_provider.h" 57 #include "components/metrics/call_stack_profile_metrics_provider.h"
56 #include "components/metrics/drive_metrics_provider.h" 58 #include "components/metrics/drive_metrics_provider.h"
57 #include "components/metrics/file_metrics_provider.h" 59 #include "components/metrics/file_metrics_provider.h"
58 #include "components/metrics/gpu/gpu_metrics_provider.h" 60 #include "components/metrics/gpu/gpu_metrics_provider.h"
59 #include "components/metrics/metrics_pref_names.h" 61 #include "components/metrics/metrics_pref_names.h"
60 #include "components/metrics/metrics_reporting_default_state.h" 62 #include "components/metrics/metrics_reporting_default_state.h"
61 #include "components/metrics/metrics_service.h" 63 #include "components/metrics/metrics_service.h"
62 #include "components/metrics/metrics_service_client.h" 64 #include "components/metrics/metrics_service_client.h"
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 omnibox_url_opened_subscription_ = 890 omnibox_url_opened_subscription_ =
889 OmniboxEventGlobalTracker::GetInstance()->RegisterCallback( 891 OmniboxEventGlobalTracker::GetInstance()->RegisterCallback(
890 base::Bind(&ChromeMetricsServiceClient::OnURLOpenedFromOmnibox, 892 base::Bind(&ChromeMetricsServiceClient::OnURLOpenedFromOmnibox,
891 base::Unretained(this))); 893 base::Unretained(this)));
892 894
893 // Observe history deletions for all profiles. 895 // Observe history deletions for all profiles.
894 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, 896 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED,
895 content::NotificationService::AllBrowserContextsAndSources()); 897 content::NotificationService::AllBrowserContextsAndSources());
896 for (Profile* profile : 898 for (Profile* profile :
897 g_browser_process->profile_manager()->GetLoadedProfiles()) { 899 g_browser_process->profile_manager()->GetLoadedProfiles()) {
898 RegisterForHistoryDeletions(profile); 900 RegisterForProfileEvents(profile);
899 } 901 }
900 } 902 }
901 903
902 void ChromeMetricsServiceClient::RegisterForHistoryDeletions(Profile* profile) { 904 void ChromeMetricsServiceClient::RegisterForProfileEvents(Profile* profile) {
903 history::HistoryService* history_service = 905 history::HistoryService* history_service =
904 HistoryServiceFactory::GetForProfile(profile, 906 HistoryServiceFactory::GetForProfile(profile,
905 ServiceAccessType::IMPLICIT_ACCESS); 907 ServiceAccessType::IMPLICIT_ACCESS);
906 ObserveServiceForDeletions(history_service); 908 ObserveServiceForDeletions(history_service);
909 browser_sync::ProfileSyncService* sync =
910 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile);
911 if (sync)
912 ObserveServiceForSyncDisables(static_cast<syncer::SyncService*>(sync));
907 } 913 }
908 914
909 void ChromeMetricsServiceClient::Observe( 915 void ChromeMetricsServiceClient::Observe(
910 int type, 916 int type,
911 const content::NotificationSource& source, 917 const content::NotificationSource& source,
912 const content::NotificationDetails& details) { 918 const content::NotificationDetails& details) {
913 DCHECK(thread_checker_.CalledOnValidThread()); 919 DCHECK(thread_checker_.CalledOnValidThread());
914 920
915 switch (type) { 921 switch (type) {
916 case chrome::NOTIFICATION_BROWSER_OPENED: 922 case chrome::NOTIFICATION_BROWSER_OPENED:
917 case chrome::NOTIFICATION_BROWSER_CLOSED: 923 case chrome::NOTIFICATION_BROWSER_CLOSED:
918 case chrome::NOTIFICATION_TAB_PARENTED: 924 case chrome::NOTIFICATION_TAB_PARENTED:
919 case chrome::NOTIFICATION_TAB_CLOSING: 925 case chrome::NOTIFICATION_TAB_CLOSING:
920 case content::NOTIFICATION_LOAD_STOP: 926 case content::NOTIFICATION_LOAD_STOP:
921 case content::NOTIFICATION_LOAD_START: 927 case content::NOTIFICATION_LOAD_START:
922 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: 928 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED:
923 case content::NOTIFICATION_RENDER_WIDGET_HOST_HANG: 929 case content::NOTIFICATION_RENDER_WIDGET_HOST_HANG:
924 metrics_service_->OnApplicationNotIdle(); 930 metrics_service_->OnApplicationNotIdle();
925 break; 931 break;
926 932
927 case chrome::NOTIFICATION_PROFILE_ADDED: 933 case chrome::NOTIFICATION_PROFILE_ADDED:
928 RegisterForHistoryDeletions(content::Source<Profile>(source).ptr()); 934 RegisterForProfileEvents(content::Source<Profile>(source).ptr());
929 break; 935 break;
930 936
931 default: 937 default:
932 NOTREACHED(); 938 NOTREACHED();
933 } 939 }
934 } 940 }
935 941
936 void ChromeMetricsServiceClient::OnURLOpenedFromOmnibox(OmniboxLog* log) { 942 void ChromeMetricsServiceClient::OnURLOpenedFromOmnibox(OmniboxLog* log) {
937 metrics_service_->OnApplicationNotIdle(); 943 metrics_service_->OnApplicationNotIdle();
938 } 944 }
939 945
940 bool ChromeMetricsServiceClient::IsUMACellularUploadLogicEnabled() { 946 bool ChromeMetricsServiceClient::IsUMACellularUploadLogicEnabled() {
941 return metrics::IsCellularLogicEnabled(); 947 return metrics::IsCellularLogicEnabled();
942 } 948 }
943 949
944 void ChromeMetricsServiceClient::OnHistoryDeleted() { 950 void ChromeMetricsServiceClient::OnHistoryDeleted() {
945 if (ukm_service_) 951 if (ukm_service_)
946 ukm_service_->Purge(); 952 ukm_service_->Purge();
947 } 953 }
954
955 void ChromeMetricsServiceClient::OnSyncPrefsChanged(bool must_purge) {
956 if (!ukm_service_)
957 return;
958 if (must_purge) {
959 ukm_service_->Purge();
960 ukm_service_->ResetClientId();
961 }
962 // Signal service manager to enable/disable UKM based on new state.
963 UpdateRunningServices();
964 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698