| 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 #include "chrome/browser/ui/webui/metrics_handler.h" | 5 #include "chrome/browser/ui/webui/metrics_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/metrics/user_metrics.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 14 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 15 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
| 15 #include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h" | 16 #include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h" |
| 16 #include "chrome/common/search/ntp_logging_events.h" | 17 #include "chrome/common/search/ntp_logging_events.h" |
| 17 #include "content/public/browser/user_metrics.h" | |
| 18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 19 #include "content/public/browser/web_ui.h" | 19 #include "content/public/browser/web_ui.h" |
| 20 | 20 |
| 21 using base::ListValue; | 21 using base::ListValue; |
| 22 using base::UserMetricsAction; | 22 using base::UserMetricsAction; |
| 23 using content::WebContents; | 23 using content::WebContents; |
| 24 | 24 |
| 25 MetricsHandler::MetricsHandler() {} | 25 MetricsHandler::MetricsHandler() {} |
| 26 MetricsHandler::~MetricsHandler() {} | 26 MetricsHandler::~MetricsHandler() {} |
| 27 | 27 |
| 28 void MetricsHandler::RegisterMessages() { | 28 void MetricsHandler::RegisterMessages() { |
| 29 web_ui()->RegisterMessageCallback( | 29 web_ui()->RegisterMessageCallback( |
| 30 "metricsHandler:recordAction", | 30 "metricsHandler:recordAction", |
| 31 base::Bind(&MetricsHandler::HandleRecordAction, base::Unretained(this))); | 31 base::Bind(&MetricsHandler::HandleRecordAction, base::Unretained(this))); |
| 32 web_ui()->RegisterMessageCallback( | 32 web_ui()->RegisterMessageCallback( |
| 33 "metricsHandler:recordInHistogram", | 33 "metricsHandler:recordInHistogram", |
| 34 base::Bind(&MetricsHandler::HandleRecordInHistogram, | 34 base::Bind(&MetricsHandler::HandleRecordInHistogram, |
| 35 base::Unretained(this))); | 35 base::Unretained(this))); |
| 36 web_ui()->RegisterMessageCallback( | 36 web_ui()->RegisterMessageCallback( |
| 37 "metricsHandler:recordTime", | 37 "metricsHandler:recordTime", |
| 38 base::Bind(&MetricsHandler::HandleRecordTime, base::Unretained(this))); | 38 base::Bind(&MetricsHandler::HandleRecordTime, base::Unretained(this))); |
| 39 web_ui()->RegisterMessageCallback( | 39 web_ui()->RegisterMessageCallback( |
| 40 "metricsHandler:logEventTime", | 40 "metricsHandler:logEventTime", |
| 41 base::Bind(&MetricsHandler::HandleLogEventTime, base::Unretained(this))); | 41 base::Bind(&MetricsHandler::HandleLogEventTime, base::Unretained(this))); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void MetricsHandler::HandleRecordAction(const base::ListValue* args) { | 44 void MetricsHandler::HandleRecordAction(const base::ListValue* args) { |
| 45 std::string string_action = base::UTF16ToUTF8(ExtractStringValue(args)); | 45 std::string string_action = base::UTF16ToUTF8(ExtractStringValue(args)); |
| 46 content::RecordComputedAction(string_action); | 46 base::RecordComputedAction(string_action); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void MetricsHandler::HandleRecordInHistogram(const base::ListValue* args) { | 49 void MetricsHandler::HandleRecordInHistogram(const base::ListValue* args) { |
| 50 std::string histogram_name; | 50 std::string histogram_name; |
| 51 double value; | 51 double value; |
| 52 double boundary_value; | 52 double boundary_value; |
| 53 if (!args->GetString(0, &histogram_name) || | 53 if (!args->GetString(0, &histogram_name) || |
| 54 !args->GetDouble(1, &value) || | 54 !args->GetDouble(1, &value) || |
| 55 !args->GetDouble(2, &boundary_value)) { | 55 !args->GetDouble(2, &boundary_value)) { |
| 56 NOTREACHED(); | 56 NOTREACHED(); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration); | 119 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration); |
| 120 } else if (event_name == "Tab.NewTabOnload") { | 120 } else if (event_name == "Tab.NewTabOnload") { |
| 121 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration); | 121 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration); |
| 122 // The new tab page has finished loading; reset it. | 122 // The new tab page has finished loading; reset it. |
| 123 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(tab); | 123 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(tab); |
| 124 core_tab_helper->set_new_tab_start_time(base::TimeTicks()); | 124 core_tab_helper->set_new_tab_start_time(base::TimeTicks()); |
| 125 } else { | 125 } else { |
| 126 NOTREACHED(); | 126 NOTREACHED(); |
| 127 } | 127 } |
| 128 } | 128 } |
| OLD | NEW |