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

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

Issue 12039079: content: convert user action notification to observer usage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 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 | Annotate | Revision Log
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 //------------------------------------------------------------------------------ 5 //------------------------------------------------------------------------------
6 // Description of the life cycle of a instance of MetricsService. 6 // Description of the life cycle of a instance of MetricsService.
7 // 7 //
8 // OVERVIEW 8 // OVERVIEW
9 // 9 //
10 // A MetricsService instance is typically created at application startup. It 10 // A MetricsService instance is typically created at application startup. It
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 if (recording_active_) 622 if (recording_active_)
623 return; 623 return;
624 recording_active_ = true; 624 recording_active_ = true;
625 625
626 ForceClientIdCreation(); 626 ForceClientIdCreation();
627 child_process_logging::SetClientId(client_id_); 627 child_process_logging::SetClientId(client_id_);
628 if (!log_manager_.current_log()) 628 if (!log_manager_.current_log())
629 OpenNewLog(); 629 OpenNewLog();
630 630
631 SetUpNotifications(&registrar_, this); 631 SetUpNotifications(&registrar_, this);
632 content::RemoveActionCallback(action_callback_);
633 action_callback_ = base::Bind(&MetricsService::OnUserAction,
634 base::Unretained(this));
635 content::AddActionCallback(action_callback_);
632 } 636 }
633 637
634 void MetricsService::DisableRecording() { 638 void MetricsService::DisableRecording() {
635 DCHECK(IsSingleThreaded()); 639 DCHECK(IsSingleThreaded());
636 640
637 if (!recording_active_) 641 if (!recording_active_)
638 return; 642 return;
639 recording_active_ = false; 643 recording_active_ = false;
640 644
645 content::RemoveActionCallback(action_callback_);
641 registrar_.RemoveAll(); 646 registrar_.RemoveAll();
642 PushPendingLogsToPersistentStorage(); 647 PushPendingLogsToPersistentStorage();
643 DCHECK(!log_manager_.has_staged_log()); 648 DCHECK(!log_manager_.has_staged_log());
644 } 649 }
645 650
646 bool MetricsService::recording_active() const { 651 bool MetricsService::recording_active() const {
647 DCHECK(IsSingleThreaded()); 652 DCHECK(IsSingleThreaded());
648 return recording_active_; 653 return recording_active_;
649 } 654 }
650 655
651 bool MetricsService::reporting_active() const { 656 bool MetricsService::reporting_active() const {
652 DCHECK(IsSingleThreaded()); 657 DCHECK(IsSingleThreaded());
653 return reporting_active_; 658 return reporting_active_;
654 } 659 }
655 660
656 // static 661 // static
657 void MetricsService::SetUpNotifications( 662 void MetricsService::SetUpNotifications(
658 content::NotificationRegistrar* registrar, 663 content::NotificationRegistrar* registrar,
659 content::NotificationObserver* observer) { 664 content::NotificationObserver* observer) {
660 registrar->Add(observer, chrome::NOTIFICATION_BROWSER_OPENED, 665 registrar->Add(observer, chrome::NOTIFICATION_BROWSER_OPENED,
661 content::NotificationService::AllBrowserContextsAndSources()); 666 content::NotificationService::AllBrowserContextsAndSources());
662 registrar->Add(observer, chrome::NOTIFICATION_BROWSER_CLOSED, 667 registrar->Add(observer, chrome::NOTIFICATION_BROWSER_CLOSED,
663 content::NotificationService::AllSources()); 668 content::NotificationService::AllSources());
664 registrar->Add(observer, content::NOTIFICATION_USER_ACTION,
665 content::NotificationService::AllSources());
666 registrar->Add(observer, chrome::NOTIFICATION_TAB_PARENTED, 669 registrar->Add(observer, chrome::NOTIFICATION_TAB_PARENTED,
667 content::NotificationService::AllSources()); 670 content::NotificationService::AllSources());
668 registrar->Add(observer, chrome::NOTIFICATION_TAB_CLOSING, 671 registrar->Add(observer, chrome::NOTIFICATION_TAB_CLOSING,
669 content::NotificationService::AllSources()); 672 content::NotificationService::AllSources());
670 registrar->Add(observer, content::NOTIFICATION_LOAD_START, 673 registrar->Add(observer, content::NOTIFICATION_LOAD_START,
671 content::NotificationService::AllSources()); 674 content::NotificationService::AllSources());
672 registrar->Add(observer, content::NOTIFICATION_LOAD_STOP, 675 registrar->Add(observer, content::NOTIFICATION_LOAD_STOP,
673 content::NotificationService::AllSources()); 676 content::NotificationService::AllSources());
674 registrar->Add(observer, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 677 registrar->Add(observer, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
675 content::NotificationService::AllSources()); 678 content::NotificationService::AllSources());
(...skipping 10 matching lines...) Expand all
686 registrar->Add(observer, chrome::NOTIFICATION_OMNIBOX_OPENED_URL, 689 registrar->Add(observer, chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
687 content::NotificationService::AllSources()); 690 content::NotificationService::AllSources());
688 } 691 }
689 692
690 void MetricsService::Observe(int type, 693 void MetricsService::Observe(int type,
691 const content::NotificationSource& source, 694 const content::NotificationSource& source,
692 const content::NotificationDetails& details) { 695 const content::NotificationDetails& details) {
693 DCHECK(log_manager_.current_log()); 696 DCHECK(log_manager_.current_log());
694 DCHECK(IsSingleThreaded()); 697 DCHECK(IsSingleThreaded());
695 698
696 if (!CanLogNotification(type, source, details)) 699 if (!CanLogNotification())
697 return; 700 return;
698 701
699 switch (type) { 702 switch (type) {
700 case content::NOTIFICATION_USER_ACTION:
701 log_manager_.current_log()->RecordUserAction(
702 *content::Details<const char*>(details).ptr());
703 break;
704
705 case chrome::NOTIFICATION_BROWSER_OPENED: 703 case chrome::NOTIFICATION_BROWSER_OPENED:
706 case chrome::NOTIFICATION_BROWSER_CLOSED: { 704 case chrome::NOTIFICATION_BROWSER_CLOSED: {
707 Browser* browser = content::Source<Browser>(source).ptr(); 705 Browser* browser = content::Source<Browser>(source).ptr();
708 LogWindowOrTabChange(type, reinterpret_cast<uintptr_t>(browser)); 706 LogWindowOrTabChange(type, reinterpret_cast<uintptr_t>(browser));
709 break; 707 break;
710 } 708 }
711 709
712 case chrome::NOTIFICATION_TAB_PARENTED: { 710 case chrome::NOTIFICATION_TAB_PARENTED: {
713 content::WebContents* web_contents = 711 content::WebContents* web_contents =
714 content::Source<content::WebContents>(source).ptr(); 712 content::Source<content::WebContents>(source).ptr();
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); 1026 DCHECK_EQ(INIT_TASK_SCHEDULED, state_);
1029 1027
1030 google_update_metrics_ = google_update_metrics; 1028 google_update_metrics_ = google_update_metrics;
1031 1029
1032 // Start the next part of the init task: fetching performance data. This will 1030 // Start the next part of the init task: fetching performance data. This will
1033 // call into |FinishedReceivingProfilerData()| when the task completes. 1031 // call into |FinishedReceivingProfilerData()| when the task completes.
1034 chrome_browser_metrics::TrackingSynchronizer::FetchProfilerDataAsynchronously( 1032 chrome_browser_metrics::TrackingSynchronizer::FetchProfilerDataAsynchronously(
1035 self_ptr_factory_.GetWeakPtr()); 1033 self_ptr_factory_.GetWeakPtr());
1036 } 1034 }
1037 1035
1036 void MetricsService::OnUserAction(const std::string& action) {
1037 if (!CanLogNotification())
1038 return;
1039
1040 log_manager_.current_log()->RecordUserAction(action.c_str());
1041 HandleIdleSinceLastTransmission(false);
1042 }
1043
1038 void MetricsService::ReceivedProfilerData( 1044 void MetricsService::ReceivedProfilerData(
1039 const tracked_objects::ProcessDataSnapshot& process_data, 1045 const tracked_objects::ProcessDataSnapshot& process_data,
1040 content::ProcessType process_type) { 1046 content::ProcessType process_type) {
1041 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); 1047 DCHECK_EQ(INIT_TASK_SCHEDULED, state_);
1042 1048
1043 // Upon the first callback, create the initial log so that we can immediately 1049 // Upon the first callback, create the initial log so that we can immediately
1044 // save the profiler data. 1050 // save the profiler data.
1045 if (!initial_log_.get()) 1051 if (!initial_log_.get())
1046 initial_log_.reset(new MetricsLog(client_id_, session_id_)); 1052 initial_log_.reset(new MetricsLog(client_id_, session_id_));
1047 1053
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after
1885 stats.process_crashes); 1891 stats.process_crashes);
1886 plugin_dict->SetInteger(prefs::kStabilityPluginInstances, 1892 plugin_dict->SetInteger(prefs::kStabilityPluginInstances,
1887 stats.instances); 1893 stats.instances);
1888 plugin_dict->SetInteger(prefs::kStabilityPluginLoadingErrors, 1894 plugin_dict->SetInteger(prefs::kStabilityPluginLoadingErrors,
1889 stats.loading_errors); 1895 stats.loading_errors);
1890 plugins->Append(plugin_dict); 1896 plugins->Append(plugin_dict);
1891 } 1897 }
1892 child_process_stats_buffer_.clear(); 1898 child_process_stats_buffer_.clear();
1893 } 1899 }
1894 1900
1895 bool MetricsService::CanLogNotification( 1901 bool MetricsService::CanLogNotification() {
1896 int type,
1897 const content::NotificationSource& source,
1898 const content::NotificationDetails& details) {
1899 // We simply don't log anything to UMA if there is a single incognito 1902 // We simply don't log anything to UMA if there is a single incognito
1900 // session visible. The problem is that we always notify using the orginal 1903 // session visible. The problem is that we always notify using the orginal
1901 // profile in order to simplify notification processing. 1904 // profile in order to simplify notification processing.
1902 return !chrome::IsOffTheRecordSessionActive(); 1905 return !chrome::IsOffTheRecordSessionActive();
1903 } 1906 }
1904 1907
1905 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { 1908 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) {
1906 DCHECK(IsSingleThreaded()); 1909 DCHECK(IsSingleThreaded());
1907 1910
1908 PrefService* pref = g_browser_process->local_state(); 1911 PrefService* pref = g_browser_process->local_state();
(...skipping 30 matching lines...) Expand all
1939 if (local_state) { 1942 if (local_state) {
1940 const PrefService::Preference* uma_pref = 1943 const PrefService::Preference* uma_pref =
1941 local_state->FindPreference(prefs::kMetricsReportingEnabled); 1944 local_state->FindPreference(prefs::kMetricsReportingEnabled);
1942 if (uma_pref) { 1945 if (uma_pref) {
1943 bool success = uma_pref->GetValue()->GetAsBoolean(&result); 1946 bool success = uma_pref->GetValue()->GetAsBoolean(&result);
1944 DCHECK(success); 1947 DCHECK(success);
1945 } 1948 }
1946 } 1949 }
1947 return result; 1950 return result;
1948 } 1951 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/metrics_service.h ('k') | chrome/browser/ui/webui/user_actions/user_actions_ui_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698