Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "components/physical_web/webui/physical_web_base_message_handler.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/metrics/histogram_macros.h" | |
| 9 #include "base/metrics/user_metrics.h" | |
| 10 #include "components/physical_web/data_source/physical_web_data_source.h" | |
| 11 #include "components/physical_web/webui/physical_web_ui_constants.h" | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 // Maximum value for the "selected position" histogram. | |
| 16 const int kSelectedPositionMaxValue = 50; | |
| 17 | |
| 18 } // namespace | |
| 19 | |
| 20 namespace physical_web_ui { | |
| 21 | |
| 22 PhysicalWebBaseMessageHandler::PhysicalWebBaseMessageHandler() {} | |
| 23 | |
| 24 PhysicalWebBaseMessageHandler::~PhysicalWebBaseMessageHandler() = default; | |
| 25 | |
| 26 void PhysicalWebBaseMessageHandler::RegisterMessagesImpl() { | |
| 27 RegisterMessageCallback( | |
| 28 kRequestNearbyUrls, | |
| 29 base::Bind(&PhysicalWebBaseMessageHandler::HandleRequestNearbyURLs, | |
|
mattreynolds
2016/12/13 22:40:13
src/docs/callback.md suggests we should use base::
cco3
2016/12/21 18:06:58
Done.
| |
| 30 base::Unretained(this))); | |
| 31 RegisterMessageCallback(kPhysicalWebItemClicked, | |
| 32 base::Bind(&PhysicalWebBaseMessageHandler::HandlePhysicalWebItemClicked, | |
| 33 base::Unretained(this))); | |
| 34 } | |
| 35 | |
| 36 void PhysicalWebBaseMessageHandler::HandleRequestNearbyURLs( | |
| 37 const base::ListValue* args) { | |
| 38 base::DictionaryValue results; | |
| 39 | |
| 40 std::unique_ptr<base::ListValue> metadata = | |
| 41 GetPhysicalWebDataSource()->GetMetadata(); | |
| 42 | |
| 43 // Add item indices. When an item is selected, the index of the selected item | |
| 44 // is recorded in a UMA histogram. | |
| 45 for (size_t i = 0; i < metadata->GetSize(); i++) { | |
| 46 base::DictionaryValue* metadata_item = NULL; | |
| 47 metadata->GetDictionary(i, &metadata_item); | |
| 48 metadata_item->SetInteger(physical_web_ui::kIndex, i); | |
| 49 } | |
| 50 | |
| 51 results.Set(physical_web_ui::kMetadata, metadata.release()); | |
| 52 | |
| 53 // Pass the list of Physical Web URL metadata to the WebUI. A jstemplate will | |
| 54 // create a list view with an item for each URL. | |
| 55 CallJavaScriptFunction(physical_web_ui::kReturnNearbyUrls, results); | |
| 56 } | |
| 57 | |
| 58 void PhysicalWebBaseMessageHandler::HandlePhysicalWebItemClicked( | |
| 59 const base::ListValue* args) { | |
| 60 int index; | |
| 61 if (!args->GetInteger(0, &index)) { | |
| 62 DLOG(ERROR) << "Invalid selection index"; | |
| 63 return; | |
| 64 } | |
| 65 | |
| 66 // Record the index of the selected item. The index must be strictly less than | |
| 67 // the maximum enumeration value. | |
| 68 if (index > kSelectedPositionMaxValue) { | |
|
mattreynolds
2016/12/13 22:40:13
Turns out this is incorrect, UMA_HISTOGRAM_EXACT_L
cco3
2016/12/21 18:06:58
Done.
| |
| 69 index = kSelectedPositionMaxValue; | |
| 70 } | |
| 71 UMA_HISTOGRAM_EXACT_LINEAR("PhysicalWeb.WebUI.ListViewUrlPosition", index, | |
| 72 kSelectedPositionMaxValue); | |
|
mattreynolds
2016/12/13 22:40:13
Let's remove the kSelectedPositionMaxValue constan
cco3
2016/12/21 18:06:58
Done.
| |
| 73 | |
| 74 // Count the number of selections. | |
| 75 base::RecordAction( | |
| 76 base::UserMetricsAction("PhysicalWeb.WebUI.ListViewUrlSelected")); | |
| 77 } | |
| 78 | |
| 79 } // namespace physical_web_ui | |
| OLD | NEW |