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

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: callbacks 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 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 if (recording_active_) 629 if (recording_active_)
630 return; 630 return;
631 recording_active_ = true; 631 recording_active_ = true;
632 632
633 ForceClientIdCreation(); 633 ForceClientIdCreation();
634 child_process_logging::SetClientId(client_id_); 634 child_process_logging::SetClientId(client_id_);
635 if (!log_manager_.current_log()) 635 if (!log_manager_.current_log())
636 OpenNewLog(); 636 OpenNewLog();
637 637
638 SetUpNotifications(&registrar_, this); 638 SetUpNotifications(&registrar_, this);
639 content::AddActionCallback(base::Bind(&MetricsService::OnUserAction,
640 base::Unretained(this)));
639 } 641 }
640 642
641 void MetricsService::DisableRecording() { 643 void MetricsService::DisableRecording() {
642 DCHECK(IsSingleThreaded()); 644 DCHECK(IsSingleThreaded());
643 645
644 if (!recording_active_) 646 if (!recording_active_)
645 return; 647 return;
646 recording_active_ = false; 648 recording_active_ = false;
647 649
650 content::RemoveActionCallback(base::Bind(&MetricsService::OnUserAction,
651 base::Unretained(this)));
648 registrar_.RemoveAll(); 652 registrar_.RemoveAll();
649 PushPendingLogsToPersistentStorage(); 653 PushPendingLogsToPersistentStorage();
650 DCHECK(!log_manager_.has_staged_log()); 654 DCHECK(!log_manager_.has_staged_log());
651 } 655 }
652 656
653 bool MetricsService::recording_active() const { 657 bool MetricsService::recording_active() const {
654 DCHECK(IsSingleThreaded()); 658 DCHECK(IsSingleThreaded());
655 return recording_active_; 659 return recording_active_;
656 } 660 }
657 661
658 bool MetricsService::reporting_active() const { 662 bool MetricsService::reporting_active() const {
659 DCHECK(IsSingleThreaded()); 663 DCHECK(IsSingleThreaded());
660 return reporting_active_; 664 return reporting_active_;
661 } 665 }
662 666
663 // static 667 // static
664 void MetricsService::SetUpNotifications( 668 void MetricsService::SetUpNotifications(
665 content::NotificationRegistrar* registrar, 669 content::NotificationRegistrar* registrar,
666 content::NotificationObserver* observer) { 670 content::NotificationObserver* observer) {
667 registrar->Add(observer, chrome::NOTIFICATION_BROWSER_OPENED, 671 registrar->Add(observer, chrome::NOTIFICATION_BROWSER_OPENED,
668 content::NotificationService::AllBrowserContextsAndSources()); 672 content::NotificationService::AllBrowserContextsAndSources());
669 registrar->Add(observer, chrome::NOTIFICATION_BROWSER_CLOSED, 673 registrar->Add(observer, chrome::NOTIFICATION_BROWSER_CLOSED,
670 content::NotificationService::AllSources()); 674 content::NotificationService::AllSources());
671 registrar->Add(observer, content::NOTIFICATION_USER_ACTION,
672 content::NotificationService::AllSources());
673 registrar->Add(observer, chrome::NOTIFICATION_TAB_PARENTED, 675 registrar->Add(observer, chrome::NOTIFICATION_TAB_PARENTED,
674 content::NotificationService::AllSources()); 676 content::NotificationService::AllSources());
675 registrar->Add(observer, chrome::NOTIFICATION_TAB_CLOSING, 677 registrar->Add(observer, chrome::NOTIFICATION_TAB_CLOSING,
676 content::NotificationService::AllSources()); 678 content::NotificationService::AllSources());
677 registrar->Add(observer, content::NOTIFICATION_LOAD_START, 679 registrar->Add(observer, content::NOTIFICATION_LOAD_START,
678 content::NotificationService::AllSources()); 680 content::NotificationService::AllSources());
679 registrar->Add(observer, content::NOTIFICATION_LOAD_STOP, 681 registrar->Add(observer, content::NOTIFICATION_LOAD_STOP,
680 content::NotificationService::AllSources()); 682 content::NotificationService::AllSources());
681 registrar->Add(observer, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 683 registrar->Add(observer, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
682 content::NotificationService::AllSources()); 684 content::NotificationService::AllSources());
(...skipping 12 matching lines...) Expand all
695 registrar->Add(observer, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, 697 registrar->Add(observer, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED,
696 content::NotificationService::AllBrowserContextsAndSources()); 698 content::NotificationService::AllBrowserContextsAndSources());
697 } 699 }
698 700
699 void MetricsService::Observe(int type, 701 void MetricsService::Observe(int type,
700 const content::NotificationSource& source, 702 const content::NotificationSource& source,
701 const content::NotificationDetails& details) { 703 const content::NotificationDetails& details) {
702 DCHECK(log_manager_.current_log()); 704 DCHECK(log_manager_.current_log());
703 DCHECK(IsSingleThreaded()); 705 DCHECK(IsSingleThreaded());
704 706
705 if (!CanLogNotification(type, source, details)) 707 if (!CanLogNotification())
706 return; 708 return;
707 709
708 switch (type) { 710 switch (type) {
709 case content::NOTIFICATION_USER_ACTION:
710 log_manager_.current_log()->RecordUserAction(
711 *content::Details<const char*>(details).ptr());
712 break;
713
714 case chrome::NOTIFICATION_BROWSER_OPENED: 711 case chrome::NOTIFICATION_BROWSER_OPENED:
715 case chrome::NOTIFICATION_BROWSER_CLOSED: { 712 case chrome::NOTIFICATION_BROWSER_CLOSED: {
716 Browser* browser = content::Source<Browser>(source).ptr(); 713 Browser* browser = content::Source<Browser>(source).ptr();
717 LogWindowOrTabChange(type, reinterpret_cast<uintptr_t>(browser)); 714 LogWindowOrTabChange(type, reinterpret_cast<uintptr_t>(browser));
718 break; 715 break;
719 } 716 }
720 717
721 case chrome::NOTIFICATION_TAB_PARENTED: { 718 case chrome::NOTIFICATION_TAB_PARENTED: {
722 content::WebContents* web_contents = 719 content::WebContents* web_contents =
723 content::Source<content::WebContents>(source).ptr(); 720 content::Source<content::WebContents>(source).ptr();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 break; 781 break;
785 } 782 }
786 default: 783 default:
787 NOTREACHED(); 784 NOTREACHED();
788 break; 785 break;
789 } 786 }
790 787
791 HandleIdleSinceLastTransmission(false); 788 HandleIdleSinceLastTransmission(false);
792 } 789 }
793 790
791 void MetricsService::OnUserAction(const std::string& action) {
792 if (!CanLogNotification())
793 return;
794
795 log_manager_.current_log()->RecordUserAction(action.c_str());
796 HandleIdleSinceLastTransmission(false);
797 }
798
794 void MetricsService::HandleIdleSinceLastTransmission(bool in_idle) { 799 void MetricsService::HandleIdleSinceLastTransmission(bool in_idle) {
795 // If there wasn't a lot of action, maybe the computer was asleep, in which 800 // If there wasn't a lot of action, maybe the computer was asleep, in which
796 // case, the log transmissions should have stopped. Here we start them up 801 // case, the log transmissions should have stopped. Here we start them up
797 // again. 802 // again.
798 if (!in_idle && idle_since_last_transmission_) 803 if (!in_idle && idle_since_last_transmission_)
799 StartSchedulerIfNecessary(); 804 StartSchedulerIfNecessary();
800 idle_since_last_transmission_ = in_idle; 805 idle_since_last_transmission_ = in_idle;
801 } 806 }
802 807
803 void MetricsService::RecordStartOfSessionEnd() { 808 void MetricsService::RecordStartOfSessionEnd() {
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1938 stats.process_crashes); 1943 stats.process_crashes);
1939 plugin_dict->SetInteger(prefs::kStabilityPluginInstances, 1944 plugin_dict->SetInteger(prefs::kStabilityPluginInstances,
1940 stats.instances); 1945 stats.instances);
1941 plugin_dict->SetInteger(prefs::kStabilityPluginLoadingErrors, 1946 plugin_dict->SetInteger(prefs::kStabilityPluginLoadingErrors,
1942 stats.loading_errors); 1947 stats.loading_errors);
1943 plugins->Append(plugin_dict); 1948 plugins->Append(plugin_dict);
1944 } 1949 }
1945 child_process_stats_buffer_.clear(); 1950 child_process_stats_buffer_.clear();
1946 } 1951 }
1947 1952
1948 bool MetricsService::CanLogNotification( 1953 bool MetricsService::CanLogNotification() {
1949 int type,
1950 const content::NotificationSource& source,
1951 const content::NotificationDetails& details) {
1952 // We simply don't log anything to UMA if there is a single incognito 1954 // We simply don't log anything to UMA if there is a single incognito
1953 // session visible. The problem is that we always notify using the orginal 1955 // session visible. The problem is that we always notify using the orginal
1954 // profile in order to simplify notification processing. 1956 // profile in order to simplify notification processing.
1955 return !chrome::IsOffTheRecordSessionActive(); 1957 return !chrome::IsOffTheRecordSessionActive();
1956 } 1958 }
1957 1959
1958 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { 1960 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) {
1959 DCHECK(IsSingleThreaded()); 1961 DCHECK(IsSingleThreaded());
1960 1962
1961 PrefService* pref = g_browser_process->local_state(); 1963 PrefService* pref = g_browser_process->local_state();
(...skipping 30 matching lines...) Expand all
1992 if (local_state) { 1994 if (local_state) {
1993 const PrefService::Preference* uma_pref = 1995 const PrefService::Preference* uma_pref =
1994 local_state->FindPreference(prefs::kMetricsReportingEnabled); 1996 local_state->FindPreference(prefs::kMetricsReportingEnabled);
1995 if (uma_pref) { 1997 if (uma_pref) {
1996 bool success = uma_pref->GetValue()->GetAsBoolean(&result); 1998 bool success = uma_pref->GetValue()->GetAsBoolean(&result);
1997 DCHECK(success); 1999 DCHECK(success);
1998 } 2000 }
1999 } 2001 }
2000 return result; 2002 return result;
2001 } 2003 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698