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

Side by Side Diff: ios/chrome/browser/ui/webui/history/metrics_handler.cc

Issue 2494853003: Remove some unused history resources on iOS (Closed)
Patch Set: add back URL constants Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « ios/chrome/browser/ui/webui/history/metrics_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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 "ios/chrome/browser/ui/webui/history/metrics_handler.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/logging.h"
10 #include "base/metrics/histogram.h"
11 #include "base/metrics/user_metrics.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "base/values.h"
14 #include "ios/web/public/webui/web_ui_ios.h"
15
16 using base::ListValue;
17 using base::UserMetricsAction;
18
19 MetricsHandler::MetricsHandler() {}
20 MetricsHandler::~MetricsHandler() {}
21
22 void MetricsHandler::RegisterMessages() {
23 web_ui()->RegisterMessageCallback(
24 "metricsHandler:recordAction",
25 base::Bind(&MetricsHandler::HandleRecordAction, base::Unretained(this)));
26 web_ui()->RegisterMessageCallback(
27 "metricsHandler:recordInHistogram",
28 base::Bind(&MetricsHandler::HandleRecordInHistogram,
29 base::Unretained(this)));
30 }
31
32 void MetricsHandler::HandleRecordAction(const base::ListValue* args) {
33 std::string string_action = base::UTF16ToUTF8(ExtractStringValue(args));
34 base::RecordComputedAction(string_action);
35 }
36
37 void MetricsHandler::HandleRecordInHistogram(const base::ListValue* args) {
38 std::string histogram_name;
39 double value;
40 double boundary_value;
41 if (!args->GetString(0, &histogram_name) || !args->GetDouble(1, &value) ||
42 !args->GetDouble(2, &boundary_value)) {
43 NOTREACHED();
44 return;
45 }
46
47 int int_value = static_cast<int>(value);
48 int int_boundary_value = static_cast<int>(boundary_value);
49 if (int_boundary_value >= 4000 || int_value > int_boundary_value ||
50 int_value < 0) {
51 NOTREACHED();
52 return;
53 }
54
55 int bucket_count = int_boundary_value;
56 while (bucket_count >= 100) {
57 bucket_count /= 10;
58 }
59
60 // As |histogram_name| may change between calls, the UMA_HISTOGRAM_ENUMERATION
61 // macro cannot be used here.
62 base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
63 histogram_name, 1, int_boundary_value, bucket_count + 1,
64 base::HistogramBase::kUmaTargetedHistogramFlag);
65 counter->Add(int_value);
66 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/webui/history/metrics_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698