| OLD | NEW |
| 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 #include "base/threading/thread_restrictions.h" | 181 #include "base/threading/thread_restrictions.h" |
| 182 #include "base/tracked_objects.h" | 182 #include "base/tracked_objects.h" |
| 183 #include "base/values.h" | 183 #include "base/values.h" |
| 184 #include "chrome/browser/browser_process.h" | 184 #include "chrome/browser/browser_process.h" |
| 185 #include "chrome/browser/chrome_notification_types.h" | 185 #include "chrome/browser/chrome_notification_types.h" |
| 186 #include "chrome/browser/io_thread.h" | 186 #include "chrome/browser/io_thread.h" |
| 187 #include "chrome/browser/memory_details.h" | 187 #include "chrome/browser/memory_details.h" |
| 188 #include "chrome/browser/metrics/compression_utils.h" | 188 #include "chrome/browser/metrics/compression_utils.h" |
| 189 #include "chrome/browser/metrics/metrics_log.h" | 189 #include "chrome/browser/metrics/metrics_log.h" |
| 190 #include "chrome/browser/metrics/metrics_state_manager.h" | 190 #include "chrome/browser/metrics/metrics_state_manager.h" |
| 191 #include "chrome/browser/metrics/omnibox_metrics_provider.h" |
| 191 #include "chrome/browser/metrics/time_ticks_experiment_win.h" | 192 #include "chrome/browser/metrics/time_ticks_experiment_win.h" |
| 192 #include "chrome/browser/metrics/tracking_synchronizer.h" | 193 #include "chrome/browser/metrics/tracking_synchronizer.h" |
| 193 #include "chrome/browser/net/http_pipelining_compatibility_client.h" | 194 #include "chrome/browser/net/http_pipelining_compatibility_client.h" |
| 194 #include "chrome/browser/net/network_stats.h" | 195 #include "chrome/browser/net/network_stats.h" |
| 195 #include "chrome/browser/omnibox/omnibox_log.h" | |
| 196 #include "chrome/browser/ui/browser_otr_state.h" | 196 #include "chrome/browser/ui/browser_otr_state.h" |
| 197 #include "chrome/common/chrome_constants.h" | 197 #include "chrome/common/chrome_constants.h" |
| 198 #include "chrome/common/chrome_switches.h" | 198 #include "chrome/common/chrome_switches.h" |
| 199 #include "chrome/common/crash_keys.h" | 199 #include "chrome/common/crash_keys.h" |
| 200 #include "chrome/common/metrics/variations/variations_util.h" | 200 #include "chrome/common/metrics/variations/variations_util.h" |
| 201 #include "chrome/common/net/test_server_locations.h" | 201 #include "chrome/common/net/test_server_locations.h" |
| 202 #include "chrome/common/pref_names.h" | 202 #include "chrome/common/pref_names.h" |
| 203 #include "chrome/common/render_messages.h" | 203 #include "chrome/common/render_messages.h" |
| 204 #include "components/metrics/metrics_log_manager.h" | 204 #include "components/metrics/metrics_log_manager.h" |
| 205 #include "components/metrics/metrics_pref_names.h" | 205 #include "components/metrics/metrics_pref_names.h" |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 idle_since_last_transmission_(false), | 470 idle_since_last_transmission_(false), |
| 471 session_id_(-1), | 471 session_id_(-1), |
| 472 next_window_id_(0), | 472 next_window_id_(0), |
| 473 self_ptr_factory_(this), | 473 self_ptr_factory_(this), |
| 474 state_saver_factory_(this), | 474 state_saver_factory_(this), |
| 475 waiting_for_asynchronous_reporting_step_(false), | 475 waiting_for_asynchronous_reporting_step_(false), |
| 476 num_async_histogram_fetches_in_progress_(0) { | 476 num_async_histogram_fetches_in_progress_(0) { |
| 477 DCHECK(IsSingleThreaded()); | 477 DCHECK(IsSingleThreaded()); |
| 478 DCHECK(state_manager_); | 478 DCHECK(state_manager_); |
| 479 | 479 |
| 480 // TODO(asvitkine): Move this out of MetricsService. |
| 481 RegisterMetricsProvider( |
| 482 scoped_ptr<metrics::MetricsProvider>(new OmniboxMetricsProvider)); |
| 483 |
| 480 BrowserChildProcessObserver::Add(this); | 484 BrowserChildProcessObserver::Add(this); |
| 481 } | 485 } |
| 482 | 486 |
| 483 MetricsService::~MetricsService() { | 487 MetricsService::~MetricsService() { |
| 484 DisableRecording(); | 488 DisableRecording(); |
| 485 | 489 |
| 486 BrowserChildProcessObserver::Remove(this); | 490 BrowserChildProcessObserver::Remove(this); |
| 487 } | 491 } |
| 488 | 492 |
| 489 void MetricsService::InitializeMetricsRecordingState() { | 493 void MetricsService::InitializeMetricsRecordingState() { |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 const content::ChildProcessData& data) { | 636 const content::ChildProcessData& data) { |
| 633 GetChildProcessStats(data).instances++; | 637 GetChildProcessStats(data).instances++; |
| 634 } | 638 } |
| 635 | 639 |
| 636 void MetricsService::Observe(int type, | 640 void MetricsService::Observe(int type, |
| 637 const content::NotificationSource& source, | 641 const content::NotificationSource& source, |
| 638 const content::NotificationDetails& details) { | 642 const content::NotificationDetails& details) { |
| 639 DCHECK(log_manager_.current_log()); | 643 DCHECK(log_manager_.current_log()); |
| 640 DCHECK(IsSingleThreaded()); | 644 DCHECK(IsSingleThreaded()); |
| 641 | 645 |
| 642 // Check for notifications related to core stability metrics, or that are | |
| 643 // just triggers to end idle mode. Anything else should be added in the later | |
| 644 // switch statement, where they take effect only if general metrics should be | |
| 645 // logged. | |
| 646 bool handled = false; | |
| 647 switch (type) { | 646 switch (type) { |
| 648 case chrome::NOTIFICATION_BROWSER_OPENED: | 647 case chrome::NOTIFICATION_BROWSER_OPENED: |
| 649 case chrome::NOTIFICATION_BROWSER_CLOSED: | 648 case chrome::NOTIFICATION_BROWSER_CLOSED: |
| 649 case chrome::NOTIFICATION_OMNIBOX_OPENED_URL: |
| 650 case chrome::NOTIFICATION_TAB_PARENTED: | 650 case chrome::NOTIFICATION_TAB_PARENTED: |
| 651 case chrome::NOTIFICATION_TAB_CLOSING: | 651 case chrome::NOTIFICATION_TAB_CLOSING: |
| 652 case content::NOTIFICATION_LOAD_STOP: | 652 case content::NOTIFICATION_LOAD_STOP: |
| 653 // These notifications are used only to break out of idle mode. | 653 // These notifications are used only to break out of idle mode. |
| 654 handled = true; | |
| 655 break; | 654 break; |
| 656 | 655 |
| 657 case content::NOTIFICATION_LOAD_START: { | 656 case content::NOTIFICATION_LOAD_START: { |
| 658 content::NavigationController* controller = | 657 content::NavigationController* controller = |
| 659 content::Source<content::NavigationController>(source).ptr(); | 658 content::Source<content::NavigationController>(source).ptr(); |
| 660 content::WebContents* web_contents = controller->GetWebContents(); | 659 content::WebContents* web_contents = controller->GetWebContents(); |
| 661 LogLoadStarted(web_contents); | 660 LogLoadStarted(web_contents); |
| 662 handled = true; | |
| 663 break; | 661 break; |
| 664 } | 662 } |
| 665 | 663 |
| 666 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { | 664 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { |
| 667 content::RenderProcessHost::RendererClosedDetails* process_details = | 665 content::RenderProcessHost::RendererClosedDetails* process_details = |
| 668 content::Details< | 666 content::Details< |
| 669 content::RenderProcessHost::RendererClosedDetails>( | 667 content::RenderProcessHost::RendererClosedDetails>( |
| 670 details).ptr(); | 668 details).ptr(); |
| 671 content::RenderProcessHost* host = | 669 content::RenderProcessHost* host = |
| 672 content::Source<content::RenderProcessHost>(source).ptr(); | 670 content::Source<content::RenderProcessHost>(source).ptr(); |
| 673 LogRendererCrash( | 671 LogRendererCrash( |
| 674 host, process_details->status, process_details->exit_code); | 672 host, process_details->status, process_details->exit_code); |
| 675 handled = true; | |
| 676 break; | 673 break; |
| 677 } | 674 } |
| 678 | 675 |
| 679 case content::NOTIFICATION_RENDER_WIDGET_HOST_HANG: | 676 case content::NOTIFICATION_RENDER_WIDGET_HOST_HANG: |
| 680 LogRendererHang(); | 677 LogRendererHang(); |
| 681 handled = true; | |
| 682 break; | 678 break; |
| 683 | 679 |
| 684 default: | 680 default: |
| 685 // Everything else is handled after the early return check below. | 681 NOTREACHED(); |
| 686 break; | 682 break; |
| 687 } | 683 } |
| 688 | 684 |
| 689 // If it wasn't one of the stability-related notifications, and event | |
| 690 // logging isn't suppressed, handle it. | |
| 691 if (!handled && ShouldLogEvents()) { | |
| 692 switch (type) { | |
| 693 case chrome::NOTIFICATION_OMNIBOX_OPENED_URL: { | |
| 694 MetricsLog* current_log = | |
| 695 static_cast<MetricsLog*>(log_manager_.current_log()); | |
| 696 DCHECK(current_log); | |
| 697 current_log->RecordOmniboxOpenedURL( | |
| 698 *content::Details<OmniboxLog>(details).ptr()); | |
| 699 break; | |
| 700 } | |
| 701 | |
| 702 default: | |
| 703 NOTREACHED(); | |
| 704 break; | |
| 705 } | |
| 706 } | |
| 707 | |
| 708 HandleIdleSinceLastTransmission(false); | 685 HandleIdleSinceLastTransmission(false); |
| 709 } | 686 } |
| 710 | 687 |
| 711 void MetricsService::HandleIdleSinceLastTransmission(bool in_idle) { | 688 void MetricsService::HandleIdleSinceLastTransmission(bool in_idle) { |
| 712 // If there wasn't a lot of action, maybe the computer was asleep, in which | 689 // If there wasn't a lot of action, maybe the computer was asleep, in which |
| 713 // case, the log transmissions should have stopped. Here we start them up | 690 // case, the log transmissions should have stopped. Here we start them up |
| 714 // again. | 691 // again. |
| 715 if (!in_idle && idle_since_last_transmission_) | 692 if (!in_idle && idle_since_last_transmission_) |
| 716 StartSchedulerIfNecessary(); | 693 StartSchedulerIfNecessary(); |
| 717 idle_since_last_transmission_ = in_idle; | 694 idle_since_last_transmission_ = in_idle; |
| (...skipping 1274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1992 if (metrics_service) | 1969 if (metrics_service) |
| 1993 metrics_service->AddObserver(observer); | 1970 metrics_service->AddObserver(observer); |
| 1994 } | 1971 } |
| 1995 | 1972 |
| 1996 void MetricsServiceHelper::RemoveMetricsServiceObserver( | 1973 void MetricsServiceHelper::RemoveMetricsServiceObserver( |
| 1997 MetricsServiceObserver* observer) { | 1974 MetricsServiceObserver* observer) { |
| 1998 MetricsService* metrics_service = g_browser_process->metrics_service(); | 1975 MetricsService* metrics_service = g_browser_process->metrics_service(); |
| 1999 if (metrics_service) | 1976 if (metrics_service) |
| 2000 metrics_service->RemoveObserver(observer); | 1977 metrics_service->RemoveObserver(observer); |
| 2001 } | 1978 } |
| OLD | NEW |