navigation_metrics_recorder.cc revision 8bcbed890bc3ce4d7a057a8f32cab53fa534672e
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/tab_contents/navigation_metrics_recorder.h" 6 7#include "base/metrics/histogram.h" 8#include "content/public/browser/navigation_details.h" 9#include "content/public/browser/navigation_entry.h" 10#include "content/public/browser/render_view_host.h" 11#include "content/public/browser/render_widget_host_view.h" 12 13#if defined(OS_WIN) 14#include "base/win/windows_version.h" 15#include "chrome/browser/metro_utils/metro_chrome_win.h" 16#endif 17 18DEFINE_WEB_CONTENTS_USER_DATA_KEY(NavigationMetricsRecorder); 19 20namespace { 21 22enum Scheme { 23 SCHEME_UNKNOWN, 24 SCHEME_HTTP, 25 SCHEME_HTTPS, 26 SCHEME_FILE, 27 SCHEME_FTP, 28 SCHEME_DATA, 29 SCHEME_JAVASCRIPT, 30 SCHEME_ABOUT, 31 SCHEME_CHROME, 32 SCHEME_MAX, 33}; 34 35static const char* kSchemeNames[] = { 36 "unknown", 37 "http", 38 "https", 39 "file", 40 "ftp", 41 "data", 42 "javascript", 43 "about", 44 "chrome", 45 "max", 46}; 47 48COMPILE_ASSERT(arraysize(kSchemeNames) == SCHEME_MAX + 1, 49 NavigationMetricsRecorder_name_count_mismatch); 50 51void RecordMainFrameNavigation(const content::LoadCommittedDetails& details) { 52 GURL url = details.entry->GetVirtualURL(); 53 Scheme scheme = SCHEME_UNKNOWN; 54 for (int i = 1; i < SCHEME_MAX; ++i) { 55 if (url.SchemeIs(kSchemeNames[i])) { 56 scheme = static_cast<Scheme>(i); 57 break; 58 } 59 } 60 UMA_HISTOGRAM_ENUMERATION( 61 "Navigation.MainFrameScheme", scheme, SCHEME_MAX); 62} 63 64} // namespace 65 66NavigationMetricsRecorder::NavigationMetricsRecorder( 67 content::WebContents* web_contents) 68 : content::WebContentsObserver(web_contents) { 69} 70 71NavigationMetricsRecorder::~NavigationMetricsRecorder() { 72} 73 74void NavigationMetricsRecorder::DidNavigateMainFrame( 75 const content::LoadCommittedDetails& details, 76 const content::FrameNavigateParams& params) { 77 RecordMainFrameNavigation(details); 78} 79 80void NavigationMetricsRecorder::DidStartLoading( 81 content::RenderViewHost* render_view_host) { 82#if defined(OS_WIN) && defined(USE_ASH) 83 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { 84 gfx::NativeView view = render_view_host->GetView()->GetNativeView(); 85 if (view) { 86 chrome::HostDesktopType desktop = 87 chrome::GetHostDesktopTypeForNativeView(view); 88 UMA_HISTOGRAM_ENUMERATION("Win8.PageLoad", 89 chrome::GetWin8Environment(desktop), 90 chrome::WIN_8_ENVIRONMENT_MAX); 91 } 92 } 93#endif 94} 95 96 97