| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/uma_browsing_activity_observer.h" |
| 6 |
| 7 #include "base/metrics/histogram.h" |
| 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/browser_list.h" |
| 10 #include "chrome/browser/ui/browser_window.h" |
| 11 #include "chrome/common/chrome_notification_types.h" |
| 12 #include "content/public/browser/navigation_details.h" |
| 13 #include "content/public/browser/notification_service.h" |
| 14 #include "content/public/browser/render_process_host.h" |
| 15 |
| 16 namespace chrome { |
| 17 namespace { |
| 18 |
| 19 UMABrowsingActivityObserver* g_instance = NULL; |
| 20 |
| 21 } // namespace |
| 22 |
| 23 // static |
| 24 void UMABrowsingActivityObserver::Init() { |
| 25 DCHECK(!g_instance); |
| 26 DCHECK(BrowserList::empty()); // Must be created before any Browsers are. |
| 27 g_instance = new UMABrowsingActivityObserver; |
| 28 } |
| 29 |
| 30 UMABrowsingActivityObserver::UMABrowsingActivityObserver() { |
| 31 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 32 content::NotificationService::AllSources()); |
| 33 registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING, |
| 34 content::NotificationService::AllSources()); |
| 35 } |
| 36 |
| 37 UMABrowsingActivityObserver::~UMABrowsingActivityObserver() { |
| 38 } |
| 39 |
| 40 void UMABrowsingActivityObserver::Observe( |
| 41 int type, |
| 42 const content::NotificationSource& source, |
| 43 const content::NotificationDetails& details) { |
| 44 if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { |
| 45 const content::LoadCommittedDetails& load = |
| 46 *content::Details<content::LoadCommittedDetails>(details).ptr(); |
| 47 if (!load.is_navigation_to_different_page()) |
| 48 return; // Don't log for subframes or other trivial types. |
| 49 |
| 50 LogRenderProcessHostCount(); |
| 51 LogBrowserTabCount(); |
| 52 } else if (type == content::NOTIFICATION_APP_TERMINATING) { |
| 53 delete g_instance; |
| 54 g_instance = NULL; |
| 55 } |
| 56 } |
| 57 |
| 58 void UMABrowsingActivityObserver::LogRenderProcessHostCount() const { |
| 59 int hosts_count = 0; |
| 60 for (content::RenderProcessHost::iterator i( |
| 61 content::RenderProcessHost::AllHostsIterator()); |
| 62 !i.IsAtEnd(); i.Advance()) |
| 63 ++hosts_count; |
| 64 UMA_HISTOGRAM_CUSTOM_COUNTS("MPArch.RPHCountPerLoad", hosts_count, |
| 65 1, 50, 50); |
| 66 } |
| 67 |
| 68 void UMABrowsingActivityObserver::LogBrowserTabCount() const { |
| 69 int tab_count = 0; |
| 70 for (BrowserList::const_iterator browser_iterator = BrowserList::begin(); |
| 71 browser_iterator != BrowserList::end(); browser_iterator++) { |
| 72 // Record how many tabs each window has open. |
| 73 Browser* browser = (*browser_iterator); |
| 74 UMA_HISTOGRAM_CUSTOM_COUNTS("Tabs.TabCountPerWindow", |
| 75 browser->tab_count(), 1, 200, 50); |
| 76 tab_count += browser->tab_count(); |
| 77 |
| 78 if (browser->window()->IsActive()) { |
| 79 // Record how many tabs the active window has open. |
| 80 UMA_HISTOGRAM_CUSTOM_COUNTS("Tabs.TabCountActiveWindow", |
| 81 browser->tab_count(), 1, 200, 50); |
| 82 } |
| 83 } |
| 84 // Record how many tabs total are open (across all windows). |
| 85 UMA_HISTOGRAM_CUSTOM_COUNTS("Tabs.TabCountPerLoad", tab_count, 1, 200, 50); |
| 86 } |
| 87 |
| 88 } // namespace chrome |
| OLD | NEW |