Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1206)

Unified Diff: chrome/browser/ui/webui/ntp/new_tab_ui.cc

Issue 8052028: NTP: Clean up of MetricsHandler class and namespacing chrome.send messages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tried to remove dependencies of metricshandler, most still necessary in NewTabUI Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/ntp/new_tab_ui.cc
diff --git a/chrome/browser/ui/webui/ntp/new_tab_ui.cc b/chrome/browser/ui/webui/ntp/new_tab_ui.cc
index 2ad0c41aa41c1ead7242ab332aea7337c67fbfe6..6b3a8e1e22a4662f065efde2df196d4b4b63c862 100644
--- a/chrome/browser/ui/webui/ntp/new_tab_ui.cc
+++ b/chrome/browser/ui/webui/ntp/new_tab_ui.cc
@@ -17,7 +17,6 @@
#include "base/threading/thread.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/defaults.h"
-#include "chrome/browser/metrics/metric_event_duration_details.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/session_types.h"
@@ -29,6 +28,7 @@
#include "chrome/browser/ui/webui/ntp/bookmarks_handler.h"
#include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h"
#include "chrome/browser/ui/webui/ntp/foreign_session_handler.h"
+#include "chrome/browser/ui/webui/ntp/metrics_handler.h"
#include "chrome/browser/ui/webui/ntp/most_visited_handler.h"
#include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h"
#include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h"
@@ -55,12 +55,6 @@
namespace {
-// The number of recent bookmarks we show.
-const int kRecentBookmarks = 9;
-
-// The number of search URLs to show.
-const int kSearchURLs = 3;
-
// The amount of time there must be no painting for us to consider painting
// finished. Observed times are in the ~1200ms range on Windows.
const int kTimeoutMs = 2000;
@@ -70,119 +64,6 @@ const int kTimeoutMs = 2000;
const char kRTLHtmlTextDirection[] = "rtl";
const char kDefaultHtmlTextDirection[] = "ltr";
-///////////////////////////////////////////////////////////////////////////////
-// MetricsHandler
-
-// Let the page contents record UMA actions. Only use when you can't do it from
-// C++. For example, we currently use it to let the NTP log the postion of the
-// Most Visited or Bookmark the user clicked on, as we don't get that
-// information through RequestOpenURL. You will need to update the metrics
-// dashboard with the action names you use, as our processor won't catch that
-// information (treat it as RecordComputedMetrics)
-class MetricsHandler : public WebUIMessageHandler {
- public:
- MetricsHandler() {}
- virtual ~MetricsHandler() {}
-
- // WebUIMessageHandler implementation.
- virtual void RegisterMessages() OVERRIDE;
-
- // Callback which records a user action.
- void HandleRecordAction(const ListValue* args);
-
- // Callback which records into a histogram. |args| contains the histogram
- // name, the value to record, and the maximum allowed value, which can be at
- // most 4000. The histogram will use at most 100 buckets, one for each 1,
- // 10, or 100 different values, depending on the maximum value.
- void HandleRecordInHistogram(const ListValue* args);
-
- // Callback for the "logEventTime" message.
- void HandleLogEventTime(const ListValue* args);
-
- private:
-
- DISALLOW_COPY_AND_ASSIGN(MetricsHandler);
-};
-
-void MetricsHandler::RegisterMessages() {
- web_ui_->RegisterMessageCallback("recordAction",
- NewCallback(this, &MetricsHandler::HandleRecordAction));
- web_ui_->RegisterMessageCallback("recordInHistogram",
- NewCallback(this, &MetricsHandler::HandleRecordInHistogram));
-
- web_ui_->RegisterMessageCallback("logEventTime",
- NewCallback(this, &MetricsHandler::HandleLogEventTime));
-}
-
-void MetricsHandler::HandleRecordAction(const ListValue* args) {
- std::string string_action = UTF16ToUTF8(ExtractStringValue(args));
- UserMetrics::RecordComputedAction(string_action);
-}
-
-void MetricsHandler::HandleRecordInHistogram(const ListValue* args) {
- std::string histogram_name;
- double value;
- double boundary_value;
- if (!args->GetString(0, &histogram_name) ||
- !args->GetDouble(1, &value) ||
- !args->GetDouble(2, &boundary_value)) {
- NOTREACHED();
- return;
- }
-
- int int_value = static_cast<int>(value);
- int int_boundary_value = static_cast<int>(boundary_value);
- if (int_boundary_value >= 4000 ||
- int_value > int_boundary_value ||
- int_value < 0) {
- NOTREACHED();
- return;
- }
-
- int bucket_count = int_boundary_value;
- while (bucket_count >= 100) {
- bucket_count /= 10;
- }
-
- // As |histogram_name| may change between calls, the UMA_HISTOGRAM_ENUMERATION
- // macro cannot be used here.
- base::Histogram* counter =
- base::LinearHistogram::FactoryGet(
- histogram_name, 1, int_boundary_value, bucket_count + 1,
- base::Histogram::kUmaTargetedHistogramFlag);
- counter->Add(int_value);
-}
-
-void MetricsHandler::HandleLogEventTime(const ListValue* args) {
- std::string event_name = UTF16ToUTF8(ExtractStringValue(args));
- TabContents* tab = web_ui_->tab_contents();
-
- // Not all new tab pages get timed. In those cases, we don't have a
- // new_tab_start_time_.
- if (tab->new_tab_start_time().is_null())
- return;
-
- base::TimeDelta duration = base::TimeTicks::Now() - tab->new_tab_start_time();
- MetricEventDurationDetails details(event_name,
- static_cast<int>(duration.InMilliseconds()));
-
- if (event_name == "Tab.NewTabScriptStart") {
- UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
- } else if (event_name == "Tab.NewTabDOMContentLoaded") {
- UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
- } else if (event_name == "Tab.NewTabOnload") {
- UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
- // The new tab page has finished loading; reset it.
- tab->set_new_tab_start_time(base::TimeTicks());
- } else {
- NOTREACHED();
- }
- NotificationService::current()->Notify(
- chrome::NOTIFICATION_METRIC_EVENT_DURATION,
- Source<TabContents>(tab),
- Details<MetricEventDurationDetails>(&details));
-}
-
} // namespace
///////////////////////////////////////////////////////////////////////////////

Powered by Google App Engine
This is Rietveld 408576698