Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/metrics/renderer_uptime_metrics_provider.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "chrome/browser/metrics/renderer_uptime_tracker.h" | |
| 10 #include "content/public/browser/notification_service.h" | |
| 11 #include "content/public/browser/notification_types.h" | |
| 12 #include "content/public/browser/render_process_host.h" | |
| 13 #include "extensions/features/features.h" | |
| 14 | |
| 15 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 16 #include "extensions/browser/process_map.h" | |
| 17 #endif | |
| 18 | |
| 19 RendererUptimeMetricsProvider::RendererUptimeMetricsProvider() {} | |
| 20 | |
| 21 void RendererUptimeMetricsProvider::OnRecordingEnabled() { | |
| 22 if (!RendererUptimeTracker::IsInitialized()) | |
| 23 RendererUptimeTracker::Initialize(); | |
| 24 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, | |
|
Alexei Svitkine (slow)
2017/02/28 16:13:11
It's strange to use a provider class if you're not
keishi
2017/03/01 08:09:54
Done. Removed metric provider class.
FYI: Maybe i
Alexei Svitkine (slow)
2017/03/01 15:50:18
Thanks for pointing that out. I filed crbug.com/69
| |
| 25 content::NotificationService::AllSources()); | |
| 26 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | |
| 27 content::NotificationService::AllSources()); | |
| 28 } | |
| 29 | |
| 30 void RendererUptimeMetricsProvider::OnRecordingDisabled() { | |
| 31 registrar_.RemoveAll(); | |
| 32 } | |
| 33 | |
| 34 void RendererUptimeMetricsProvider::Observe( | |
| 35 int type, | |
| 36 const content::NotificationSource& source, | |
| 37 const content::NotificationDetails& details) { | |
| 38 switch (type) { | |
| 39 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: { | |
| 40 content::RenderProcessHost* host = | |
| 41 content::Source<content::RenderProcessHost>(source).ptr(); | |
| 42 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 43 if (extensions::ProcessMap::Get(host->GetBrowserContext()) | |
| 44 ->Contains(host->GetID())) { | |
| 45 break; | |
| 46 } | |
| 47 #endif | |
| 48 RendererUptimeTracker::Get()->OnRendererStarted(host->GetID()); | |
| 49 break; | |
| 50 } | |
| 51 | |
| 52 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { | |
| 53 content::RenderProcessHost* host = | |
| 54 content::Source<content::RenderProcessHost>(source).ptr(); | |
| 55 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 56 if (extensions::ProcessMap::Get(host->GetBrowserContext()) | |
| 57 ->Contains(host->GetID())) { | |
| 58 break; | |
| 59 } | |
| 60 #endif | |
| 61 RendererUptimeTracker::Get()->OnRendererTerminated(host->GetID()); | |
| 62 break; | |
| 63 } | |
| 64 | |
| 65 default: | |
| 66 NOTREACHED(); | |
| 67 break; | |
| 68 } | |
| 69 } | |
| OLD | NEW |