| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "ios/chrome/browser/ui/webui/history/metrics_handler.h" | 5 #include "ios/chrome/browser/ui/webui/history/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.h" | 10 #include "base/metrics/histogram.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 "ios/public/provider/web/web_ui_ios.h" | 14 #include "ios/public/provider/web/web_ui_ios.h" |
| 14 #include "ios/web/public/user_metrics.h" | |
| 15 | 15 |
| 16 using base::ListValue; | 16 using base::ListValue; |
| 17 using base::UserMetricsAction; | 17 using base::UserMetricsAction; |
| 18 | 18 |
| 19 MetricsHandler::MetricsHandler() {} | 19 MetricsHandler::MetricsHandler() {} |
| 20 MetricsHandler::~MetricsHandler() {} | 20 MetricsHandler::~MetricsHandler() {} |
| 21 | 21 |
| 22 void MetricsHandler::RegisterMessages() { | 22 void MetricsHandler::RegisterMessages() { |
| 23 web_ui()->RegisterMessageCallback( | 23 web_ui()->RegisterMessageCallback( |
| 24 "metricsHandler:recordAction", | 24 "metricsHandler:recordAction", |
| 25 base::Bind(&MetricsHandler::HandleRecordAction, base::Unretained(this))); | 25 base::Bind(&MetricsHandler::HandleRecordAction, base::Unretained(this))); |
| 26 web_ui()->RegisterMessageCallback( | 26 web_ui()->RegisterMessageCallback( |
| 27 "metricsHandler:recordInHistogram", | 27 "metricsHandler:recordInHistogram", |
| 28 base::Bind(&MetricsHandler::HandleRecordInHistogram, | 28 base::Bind(&MetricsHandler::HandleRecordInHistogram, |
| 29 base::Unretained(this))); | 29 base::Unretained(this))); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void MetricsHandler::HandleRecordAction(const base::ListValue* args) { | 32 void MetricsHandler::HandleRecordAction(const base::ListValue* args) { |
| 33 std::string string_action = base::UTF16ToUTF8(ExtractStringValue(args)); | 33 std::string string_action = base::UTF16ToUTF8(ExtractStringValue(args)); |
| 34 web::RecordComputedAction(string_action); | 34 base::RecordComputedAction(string_action); |
| 35 } | 35 } |
| 36 | 36 |
| 37 void MetricsHandler::HandleRecordInHistogram(const base::ListValue* args) { | 37 void MetricsHandler::HandleRecordInHistogram(const base::ListValue* args) { |
| 38 std::string histogram_name; | 38 std::string histogram_name; |
| 39 double value; | 39 double value; |
| 40 double boundary_value; | 40 double boundary_value; |
| 41 if (!args->GetString(0, &histogram_name) || !args->GetDouble(1, &value) || | 41 if (!args->GetString(0, &histogram_name) || !args->GetDouble(1, &value) || |
| 42 !args->GetDouble(2, &boundary_value)) { | 42 !args->GetDouble(2, &boundary_value)) { |
| 43 NOTREACHED(); | 43 NOTREACHED(); |
| 44 return; | 44 return; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 57 bucket_count /= 10; | 57 bucket_count /= 10; |
| 58 } | 58 } |
| 59 | 59 |
| 60 // As |histogram_name| may change between calls, the UMA_HISTOGRAM_ENUMERATION | 60 // As |histogram_name| may change between calls, the UMA_HISTOGRAM_ENUMERATION |
| 61 // macro cannot be used here. | 61 // macro cannot be used here. |
| 62 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( | 62 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( |
| 63 histogram_name, 1, int_boundary_value, bucket_count + 1, | 63 histogram_name, 1, int_boundary_value, bucket_count + 1, |
| 64 base::HistogramBase::kUmaTargetedHistogramFlag); | 64 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 65 counter->Add(int_value); | 65 counter->Add(int_value); |
| 66 } | 66 } |
| OLD | NEW |