| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_stability_metrics_provider.h" | 5 #include "blimp/engine/app/blimp_stability_metrics_provider.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/metrics/sparse_histogram.h" | 11 #include "base/metrics/sparse_histogram.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | |
| 14 #include "content/public/browser/child_process_data.h" | 13 #include "content/public/browser/child_process_data.h" |
| 15 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
| 15 #include "content/public/browser/notification_types.h" |
| 16 #include "content/public/browser/render_process_host.h" | 16 #include "content/public/browser/render_process_host.h" |
| 17 | 17 |
| 18 #if defined(ENABLE_EXTENSIONS) | 18 BlimpStabilityMetricsProvider::BlimpStabilityMetricsProvider( |
| 19 #include "extensions/browser/process_map.h" | |
| 20 #endif | |
| 21 | |
| 22 #if defined(ENABLE_PLUGINS) | |
| 23 #include "chrome/browser/metrics/plugin_metrics_provider.h" | |
| 24 #endif | |
| 25 | |
| 26 #if defined(OS_WIN) | |
| 27 #include <windows.h> // Needed for STATUS_* codes | |
| 28 #include "chrome/common/metrics_constants_util_win.h" | |
| 29 #endif | |
| 30 | |
| 31 ChromeStabilityMetricsProvider::ChromeStabilityMetricsProvider( | |
| 32 PrefService* local_state) | 19 PrefService* local_state) |
| 33 : helper_(local_state) { | 20 : helper_(local_state) { |
| 34 BrowserChildProcessObserver::Add(this); | 21 BrowserChildProcessObserver::Add(this); |
| 35 } | 22 } |
| 36 | 23 |
| 37 ChromeStabilityMetricsProvider::~ChromeStabilityMetricsProvider() { | 24 BlimpStabilityMetricsProvider::~BlimpStabilityMetricsProvider() { |
| 38 BrowserChildProcessObserver::Remove(this); | 25 BrowserChildProcessObserver::Remove(this); |
| 39 } | 26 } |
| 40 | 27 |
| 41 void ChromeStabilityMetricsProvider::OnRecordingEnabled() { | 28 void BlimpStabilityMetricsProvider::OnRecordingEnabled() { |
| 42 registrar_.Add(this, | 29 registrar_.Add(this, |
| 43 content::NOTIFICATION_LOAD_START, | 30 content::NOTIFICATION_LOAD_START, |
| 44 content::NotificationService::AllSources()); | 31 content::NotificationService::AllSources()); |
| 45 registrar_.Add(this, | 32 registrar_.Add(this, |
| 46 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 33 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| 47 content::NotificationService::AllSources()); | 34 content::NotificationService::AllSources()); |
| 48 registrar_.Add(this, | 35 registrar_.Add(this, |
| 49 content::NOTIFICATION_RENDER_WIDGET_HOST_HANG, | 36 content::NOTIFICATION_RENDER_WIDGET_HOST_HANG, |
| 50 content::NotificationService::AllSources()); | 37 content::NotificationService::AllSources()); |
| 51 } | 38 } |
| 52 | 39 |
| 53 void ChromeStabilityMetricsProvider::OnRecordingDisabled() { | 40 void BlimpStabilityMetricsProvider::OnRecordingDisabled() { |
| 54 registrar_.RemoveAll(); | 41 registrar_.RemoveAll(); |
| 55 } | 42 } |
| 56 | 43 |
| 57 void ChromeStabilityMetricsProvider::ProvideStabilityMetrics( | 44 void BlimpStabilityMetricsProvider::ProvideStabilityMetrics( |
| 58 metrics::SystemProfileProto* system_profile_proto) { | 45 metrics::SystemProfileProto* system_profile_proto) { |
| 59 helper_.ProvideStabilityMetrics(system_profile_proto); | 46 helper_.ProvideStabilityMetrics(system_profile_proto); |
| 60 } | 47 } |
| 61 | 48 |
| 62 void ChromeStabilityMetricsProvider::ClearSavedStabilityMetrics() { | 49 void BlimpStabilityMetricsProvider::ClearSavedStabilityMetrics() { |
| 63 helper_.ClearSavedStabilityMetrics(); | 50 helper_.ClearSavedStabilityMetrics(); |
| 64 } | 51 } |
| 65 | 52 |
| 66 void ChromeStabilityMetricsProvider::Observe( | 53 void BlimpStabilityMetricsProvider::Observe( |
| 67 int type, | 54 int type, |
| 68 const content::NotificationSource& source, | 55 const content::NotificationSource& source, |
| 69 const content::NotificationDetails& details) { | 56 const content::NotificationDetails& details) { |
| 70 switch (type) { | 57 switch (type) { |
| 71 case content::NOTIFICATION_LOAD_START: { | 58 case content::NOTIFICATION_LOAD_START: { |
| 72 helper_.LogLoadStarted(); | 59 helper_.LogLoadStarted(); |
| 73 break; | 60 break; |
| 74 } | 61 } |
| 75 | 62 |
| 76 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { | 63 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { |
| 77 content::RenderProcessHost::RendererClosedDetails* process_details = | 64 content::RenderProcessHost::RendererClosedDetails* process_details = |
| 78 content::Details<content::RenderProcessHost::RendererClosedDetails>( | 65 content::Details<content::RenderProcessHost::RendererClosedDetails>( |
| 79 details).ptr(); | 66 details).ptr(); |
| 80 bool was_extension_process = false; | 67 bool was_extension_process = false; |
| 81 #if defined(ENABLE_EXTENSIONS) | |
| 82 content::RenderProcessHost* host = | |
| 83 content::Source<content::RenderProcessHost>(source).ptr(); | |
| 84 if (extensions::ProcessMap::Get(host->GetBrowserContext()) | |
| 85 ->Contains(host->GetID())) { | |
| 86 was_extension_process = true; | |
| 87 } | |
| 88 #endif | |
| 89 helper_.LogRendererCrash(was_extension_process, process_details->status, | 68 helper_.LogRendererCrash(was_extension_process, process_details->status, |
| 90 process_details->exit_code); | 69 process_details->exit_code); |
| 91 break; | 70 break; |
| 92 } | 71 } |
| 93 | 72 |
| 94 case content::NOTIFICATION_RENDER_WIDGET_HOST_HANG: | 73 case content::NOTIFICATION_RENDER_WIDGET_HOST_HANG: |
| 95 helper_.LogRendererHang(); | 74 helper_.LogRendererHang(); |
| 96 break; | 75 break; |
| 97 | 76 |
| 98 default: | 77 default: |
| 99 NOTREACHED(); | 78 NOTREACHED(); |
| 100 break; | 79 break; |
| 101 } | 80 } |
| 102 } | 81 } |
| 103 | 82 |
| 104 void ChromeStabilityMetricsProvider::BrowserChildProcessCrashed( | 83 void BlimpStabilityMetricsProvider::BrowserChildProcessCrashed( |
| 105 const content::ChildProcessData& data, | 84 const content::ChildProcessData& data, |
| 106 int exit_code) { | 85 int exit_code) { |
| 107 #if defined(ENABLE_PLUGINS) | |
| 108 // Exclude plugin crashes from the count below because we report them via | |
| 109 // a separate UMA metric. | |
| 110 if (PluginMetricsProvider::IsPluginProcess(data.process_type)) | |
| 111 return; | |
| 112 #endif | |
| 113 | |
| 114 helper_.BrowserChildProcessCrashed(); | 86 helper_.BrowserChildProcessCrashed(); |
| 115 } | 87 } |
| OLD | NEW |