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

Unified Diff: ios/chrome/browser/ui/webui/physical_web_ui.cc

Issue 2571853003: Move PW message handler logic to components (Closed)
Patch Set: Restore url_constants.h include Created 4 years 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: ios/chrome/browser/ui/webui/physical_web_ui.cc
diff --git a/ios/chrome/browser/ui/webui/physical_web_ui.cc b/ios/chrome/browser/ui/webui/physical_web_ui.cc
index b7423277307c5f04a07695de39dd688c07256095..4969305c105b0ba6a06a26f08ce355f8d35b4462 100644
--- a/ios/chrome/browser/ui/webui/physical_web_ui.cc
+++ b/ios/chrome/browser/ui/webui/physical_web_ui.cc
@@ -4,11 +4,8 @@
#include "ios/chrome/browser/ui/webui/physical_web_ui.h"
-#include "base/bind.h"
#include "base/macros.h"
-#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
-#include "base/values.h"
#include "components/grit/components_resources.h"
#include "components/physical_web/data_source/physical_web_data_source.h"
#include "components/physical_web/webui/physical_web_ui_constants.h"
@@ -22,9 +19,6 @@
namespace {
-// Maximum value for the "selected position" histogram.
-const int kSelectedPositionMaxValue = 50;
-
web::WebUIIOSDataSource* CreatePhysicalWebUIDataSource() {
web::WebUIIOSDataSource* html_source =
web::WebUIIOSDataSource::Create(kChromeUIPhysicalWebHost);
@@ -49,73 +43,31 @@ web::WebUIIOSDataSource* CreatePhysicalWebUIDataSource() {
////////////////////////////////////////////////////////////////////////////////
// The handler for Javascript messages for the chrome:physical-web page.
-class PhysicalWebDOMHandler : public web::WebUIIOSMessageHandler {
+class PhysicalWebDOMHandler
+ : public web::WebUIIOSMessageHandler,
+ public physical_web_ui::PhysicalWebBaseMessageHandler {
mattreynolds 2016/12/13 22:40:13 Multiple inheritance is allowed only when all supe
cco3 2016/12/21 18:06:58 Done.
public:
PhysicalWebDOMHandler() {}
~PhysicalWebDOMHandler() override {}
- void RegisterMessages() override;
-
- void HandleRequestNearbyURLs(const base::ListValue* args);
- void HandlePhysicalWebItemClicked(const base::ListValue* args);
+ void RegisterMessages() override { RegisterMessagesImpl(); }
private:
- DISALLOW_COPY_AND_ASSIGN(PhysicalWebDOMHandler);
-};
-
-void PhysicalWebDOMHandler::RegisterMessages() {
- web_ui()->RegisterMessageCallback(
- physical_web_ui::kRequestNearbyUrls,
- base::Bind(&PhysicalWebDOMHandler::HandleRequestNearbyURLs,
- base::Unretained(this)));
- web_ui()->RegisterMessageCallback(
- physical_web_ui::kPhysicalWebItemClicked,
- base::Bind(&PhysicalWebDOMHandler::HandlePhysicalWebItemClicked,
- base::Unretained(this)));
-}
-
-void PhysicalWebDOMHandler::HandleRequestNearbyURLs(
- const base::ListValue* args) {
- base::DictionaryValue results;
-
- std::unique_ptr<base::ListValue> metadata =
- GetApplicationContext()->GetPhysicalWebDataSource()->GetMetadata();
-
- // Add item indices. When an item is selected, the index of the selected item
- // is recorded in a UMA histogram.
- for (size_t i = 0; i < metadata->GetSize(); i++) {
- base::DictionaryValue* metadata_item = NULL;
- metadata->GetDictionary(i, &metadata_item);
- metadata_item->SetInteger(physical_web_ui::kIndex, i);
+ void RegisterMessageCallback(
+ const std::string& message,
+ const content::WebUI::MessageCallback& callback) override {
+ web_ui()->RegisterMessageCallback(message, callback);
}
-
- results.Set(physical_web_ui::kMetadata, metadata.release());
-
- // Pass the list of Physical Web URL metadata to the WebUI. A jstemplate will
- // create a list view with an item for each URL.
- web_ui()->CallJavascriptFunction(physical_web_ui::kReturnNearbyUrls, results);
-}
-
-void PhysicalWebDOMHandler::HandlePhysicalWebItemClicked(
- const base::ListValue* args) {
- int index;
- if (!args->GetInteger(0, &index)) {
- DLOG(ERROR) << "Invalid selection index";
- return;
+ void CallJavaScriptFunction(const std::string& function,
+ const base::Value& arg) override {
+ web_ui()->CallJavascriptFunctionUnsafe(function, arg);
mattreynolds 2016/12/13 22:40:13 Why does this need to call the Unsafe version?
cco3 2016/12/21 18:06:58 Done.
}
-
- // Record the index of the selected item. The index must be strictly less than
- // the maximum enumeration value.
- if (index > kSelectedPositionMaxValue) {
- index = kSelectedPositionMaxValue;
+ physical_web::PhysicalWebDataSource* GetPhysicalWebDataSource() override {
+ return GetApplicationContext()->GetPhysicalWebDataSource();
}
- UMA_HISTOGRAM_EXACT_LINEAR("PhysicalWeb.WebUI.ListViewUrlPosition", index,
- kSelectedPositionMaxValue);
- // Count the number of selections.
- base::RecordAction(
- base::UserMetricsAction("PhysicalWeb.WebUI.ListViewUrlSelected"));
-}
+ DISALLOW_COPY_AND_ASSIGN(PhysicalWebDOMHandler);
+};
} // namespace

Powered by Google App Engine
This is Rietveld 408576698