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

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

Issue 287193005: [Metrics] Move non-idle notifications from MetricsService to ChromeMetricsServiceClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: break! 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 | 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 is 10 // A MetricsService instance is typically created at application startup. It is
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 594
595 bool MetricsService::reporting_active() const { 595 bool MetricsService::reporting_active() const {
596 DCHECK(IsSingleThreaded()); 596 DCHECK(IsSingleThreaded());
597 return reporting_active_; 597 return reporting_active_;
598 } 598 }
599 599
600 // static 600 // static
601 void MetricsService::SetUpNotifications( 601 void MetricsService::SetUpNotifications(
602 content::NotificationRegistrar* registrar, 602 content::NotificationRegistrar* registrar,
603 content::NotificationObserver* observer) { 603 content::NotificationObserver* observer) {
604 registrar->Add(observer, chrome::NOTIFICATION_BROWSER_OPENED,
605 content::NotificationService::AllBrowserContextsAndSources());
606 registrar->Add(observer, chrome::NOTIFICATION_BROWSER_CLOSED,
607 content::NotificationService::AllSources());
608 registrar->Add(observer, chrome::NOTIFICATION_TAB_PARENTED,
609 content::NotificationService::AllSources());
610 registrar->Add(observer, chrome::NOTIFICATION_TAB_CLOSING,
611 content::NotificationService::AllSources());
612 registrar->Add(observer, content::NOTIFICATION_LOAD_START, 604 registrar->Add(observer, content::NOTIFICATION_LOAD_START,
613 content::NotificationService::AllSources()); 605 content::NotificationService::AllSources());
614 registrar->Add(observer, content::NOTIFICATION_LOAD_STOP,
615 content::NotificationService::AllSources());
616 registrar->Add(observer, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 606 registrar->Add(observer, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
617 content::NotificationService::AllSources()); 607 content::NotificationService::AllSources());
618 registrar->Add(observer, content::NOTIFICATION_RENDER_WIDGET_HOST_HANG, 608 registrar->Add(observer, content::NOTIFICATION_RENDER_WIDGET_HOST_HANG,
619 content::NotificationService::AllSources()); 609 content::NotificationService::AllSources());
620 registrar->Add(observer, chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
621 content::NotificationService::AllSources());
622 } 610 }
623 611
624 void MetricsService::BrowserChildProcessHostConnected( 612 void MetricsService::BrowserChildProcessHostConnected(
625 const content::ChildProcessData& data) { 613 const content::ChildProcessData& data) {
626 GetChildProcessStats(data).process_launches++; 614 GetChildProcessStats(data).process_launches++;
627 } 615 }
628 616
629 void MetricsService::BrowserChildProcessCrashed( 617 void MetricsService::BrowserChildProcessCrashed(
630 const content::ChildProcessData& data) { 618 const content::ChildProcessData& data) {
631 GetChildProcessStats(data).process_crashes++; 619 GetChildProcessStats(data).process_crashes++;
632 // Exclude plugin crashes from the count below because we report them via 620 // Exclude plugin crashes from the count below because we report them via
633 // a separate UMA metric. 621 // a separate UMA metric.
634 if (!IsPluginProcess(data.process_type)) 622 if (!IsPluginProcess(data.process_type))
635 IncrementPrefValue(prefs::kStabilityChildProcessCrashCount); 623 IncrementPrefValue(prefs::kStabilityChildProcessCrashCount);
636 } 624 }
637 625
638 void MetricsService::BrowserChildProcessInstanceCreated( 626 void MetricsService::BrowserChildProcessInstanceCreated(
639 const content::ChildProcessData& data) { 627 const content::ChildProcessData& data) {
640 GetChildProcessStats(data).instances++; 628 GetChildProcessStats(data).instances++;
641 } 629 }
642 630
643 void MetricsService::Observe(int type, 631 void MetricsService::Observe(int type,
644 const content::NotificationSource& source, 632 const content::NotificationSource& source,
645 const content::NotificationDetails& details) { 633 const content::NotificationDetails& details) {
646 DCHECK(log_manager_.current_log()); 634 DCHECK(log_manager_.current_log());
647 DCHECK(IsSingleThreaded()); 635 DCHECK(IsSingleThreaded());
648 636
649 switch (type) { 637 switch (type) {
650 case chrome::NOTIFICATION_BROWSER_OPENED:
651 case chrome::NOTIFICATION_BROWSER_CLOSED:
652 case chrome::NOTIFICATION_OMNIBOX_OPENED_URL:
653 case chrome::NOTIFICATION_TAB_PARENTED:
654 case chrome::NOTIFICATION_TAB_CLOSING:
655 case content::NOTIFICATION_LOAD_STOP:
656 // These notifications are used only to break out of idle mode.
657 break;
658
659 case content::NOTIFICATION_LOAD_START: { 638 case content::NOTIFICATION_LOAD_START: {
660 content::NavigationController* controller = 639 content::NavigationController* controller =
661 content::Source<content::NavigationController>(source).ptr(); 640 content::Source<content::NavigationController>(source).ptr();
662 content::WebContents* web_contents = controller->GetWebContents(); 641 content::WebContents* web_contents = controller->GetWebContents();
663 LogLoadStarted(web_contents); 642 LogLoadStarted(web_contents);
664 break; 643 break;
665 } 644 }
666 645
667 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { 646 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: {
668 content::RenderProcessHost::RendererClosedDetails* process_details = 647 content::RenderProcessHost::RendererClosedDetails* process_details =
669 content::Details< 648 content::Details<
670 content::RenderProcessHost::RendererClosedDetails>( 649 content::RenderProcessHost::RendererClosedDetails>(
671 details).ptr(); 650 details).ptr();
672 content::RenderProcessHost* host = 651 content::RenderProcessHost* host =
673 content::Source<content::RenderProcessHost>(source).ptr(); 652 content::Source<content::RenderProcessHost>(source).ptr();
674 LogRendererCrash( 653 LogRendererCrash(
675 host, process_details->status, process_details->exit_code); 654 host, process_details->status, process_details->exit_code);
676 break; 655 break;
677 } 656 }
678 657
679 case content::NOTIFICATION_RENDER_WIDGET_HOST_HANG: 658 case content::NOTIFICATION_RENDER_WIDGET_HOST_HANG:
680 LogRendererHang(); 659 LogRendererHang();
681 break; 660 break;
682 661
683 default: 662 default:
684 NOTREACHED(); 663 NOTREACHED();
685 break;
686 } 664 }
687
688 HandleIdleSinceLastTransmission(false);
689 } 665 }
690 666
691 void MetricsService::HandleIdleSinceLastTransmission(bool in_idle) { 667 void MetricsService::HandleIdleSinceLastTransmission(bool in_idle) {
692 // If there wasn't a lot of action, maybe the computer was asleep, in which 668 // If there wasn't a lot of action, maybe the computer was asleep, in which
693 // case, the log transmissions should have stopped. Here we start them up 669 // case, the log transmissions should have stopped. Here we start them up
694 // again. 670 // again.
695 if (!in_idle && idle_since_last_transmission_) 671 if (!in_idle && idle_since_last_transmission_)
696 StartSchedulerIfNecessary(); 672 StartSchedulerIfNecessary();
697 idle_since_last_transmission_ = in_idle; 673 idle_since_last_transmission_ = in_idle;
698 } 674 }
699 675
676 void MetricsService::OnApplicationNotIdle() {
677 if (recording_active_)
678 HandleIdleSinceLastTransmission(false);
679 }
680
700 void MetricsService::RecordStartOfSessionEnd() { 681 void MetricsService::RecordStartOfSessionEnd() {
701 LogCleanShutdown(); 682 LogCleanShutdown();
702 RecordBooleanPrefValue(prefs::kStabilitySessionEndCompleted, false); 683 RecordBooleanPrefValue(prefs::kStabilitySessionEndCompleted, false);
703 } 684 }
704 685
705 void MetricsService::RecordCompletedSessionEnd() { 686 void MetricsService::RecordCompletedSessionEnd() {
706 LogCleanShutdown(); 687 LogCleanShutdown();
707 RecordBooleanPrefValue(prefs::kStabilitySessionEndCompleted, true); 688 RecordBooleanPrefValue(prefs::kStabilitySessionEndCompleted, true);
708 } 689 }
709 690
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
1209 } 1190 }
1210 } 1191 }
1211 1192
1212 void MetricsService::StartScheduledUpload() { 1193 void MetricsService::StartScheduledUpload() {
1213 // If we're getting no notifications, then the log won't have much in it, and 1194 // If we're getting no notifications, then the log won't have much in it, and
1214 // it's possible the computer is about to go to sleep, so don't upload and 1195 // it's possible the computer is about to go to sleep, so don't upload and
1215 // stop the scheduler. 1196 // stop the scheduler.
1216 // If recording has been turned off, the scheduler doesn't need to run. 1197 // If recording has been turned off, the scheduler doesn't need to run.
1217 // If reporting is off, proceed if the initial log hasn't been created, since 1198 // If reporting is off, proceed if the initial log hasn't been created, since
1218 // that has to happen in order for logs to be cut and stored when persisting. 1199 // that has to happen in order for logs to be cut and stored when persisting.
1219 // TODO(stuartmorgan): Call Stop() on the schedule when reporting and/or 1200 // TODO(stuartmorgan): Call Stop() on the scheduler when reporting and/or
1220 // recording are turned off instead of letting it fire and then aborting. 1201 // recording are turned off instead of letting it fire and then aborting.
1221 if (idle_since_last_transmission_ || 1202 if (idle_since_last_transmission_ ||
1222 !recording_active() || 1203 !recording_active() ||
1223 (!reporting_active() && state_ >= SENDING_INITIAL_STABILITY_LOG)) { 1204 (!reporting_active() && state_ >= SENDING_INITIAL_STABILITY_LOG)) {
1224 scheduler_->Stop(); 1205 scheduler_->Stop();
1225 scheduler_->UploadCancelled(); 1206 scheduler_->UploadCancelled();
1226 return; 1207 return;
1227 } 1208 }
1228 1209
1229 // If the callback was to upload an old log, but there no longer is one, 1210 // If the callback was to upload an old log, but there no longer is one,
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
1972 if (metrics_service) 1953 if (metrics_service)
1973 metrics_service->AddObserver(observer); 1954 metrics_service->AddObserver(observer);
1974 } 1955 }
1975 1956
1976 void MetricsServiceHelper::RemoveMetricsServiceObserver( 1957 void MetricsServiceHelper::RemoveMetricsServiceObserver(
1977 MetricsServiceObserver* observer) { 1958 MetricsServiceObserver* observer) {
1978 MetricsService* metrics_service = g_browser_process->metrics_service(); 1959 MetricsService* metrics_service = g_browser_process->metrics_service();
1979 if (metrics_service) 1960 if (metrics_service)
1980 metrics_service->RemoveObserver(observer); 1961 metrics_service->RemoveObserver(observer);
1981 } 1962 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/metrics_service.h ('k') | chrome/browser/metrics/metrics_services_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698