Chromium Code Reviews| 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..97f7e38dff072665cd49452d6e38789a30d57127 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); |
| @@ -42,6 +36,32 @@ web::WebUIIOSDataSource* CreatePhysicalWebUIDataSource() { |
| return html_source; |
| } |
| +class MessageHandlerImpl : |
|
Eugene But (OOO till 7-30)
2016/12/22 16:09:22
What is the reason for creating this class here? I
Eugene But (OOO till 7-30)
2016/12/22 19:04:47
Please add comment to this class.
cco3
2016/12/22 20:14:45
Done.
cco3
2016/12/22 20:14:45
Acknowledged.
|
| + public physical_web_ui::PhysicalWebBaseMessageHandler { |
| + public: |
| + MessageHandlerImpl(WebUIIOS* web_ui) { |
|
Eugene But (OOO till 7-30)
2016/12/22 19:04:47
explicit
cco3
2016/12/22 20:14:45
Done.
|
| + web_ui_ = web_ui; |
|
Eugene But (OOO till 7-30)
2016/12/22 19:04:47
Please use initialization list.
cco3
2016/12/22 20:14:45
Done.
|
| + } |
| + ~MessageHandlerImpl() override {} |
| + |
| + private |
|
Eugene But (OOO till 7-30)
2016/12/22 19:04:47
private:
cco3
2016/12/22 20:14:45
Done.
|
| + void RegisterMessageCallback( |
| + const std::string& message, |
| + const content::WebUI::MessageCallback& callback) override { |
| + web_ui_->RegisterMessageCallback(message, callback); |
| + } |
| + void CallJavaScriptFunction(const std::string& function, |
| + const base::Value& arg) override { |
| + web_ui_->CallJavascriptFunction(function, arg); |
| + } |
| + physical_web::PhysicalWebDataSource* GetPhysicalWebDataSource() override { |
| + return GetApplicationContext()->GetPhysicalWebDataSource(); |
| + } |
| + |
| + WebUIIOS* web_ui_; |
| + DISALLOW_COPY_AND_ASSIGN(MessageHandlerImpl); |
| +} |
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| // |
| // PhysicalWebDOMHandler |
| @@ -50,73 +70,17 @@ web::WebUIIOSDataSource* CreatePhysicalWebUIDataSource() { |
| // The handler for Javascript messages for the chrome:physical-web page. |
| class PhysicalWebDOMHandler : public web::WebUIIOSMessageHandler { |
|
Eugene But (OOO till 7-30)
2016/12/22 19:04:47
s/{/,
cco3
2016/12/22 20:14:45
Done.
|
| + public physical_web_ui::PhysicalWebBaseMessageHandler { |
| public: |
| - PhysicalWebDOMHandler() {} |
| + PhysicalWebDOMHandler() : impl(web_ui()) {} |
|
Eugene But (OOO till 7-30)
2016/12/22 19:04:47
You need an ivar for impl
cco3
2016/12/22 20:14:45
Done.
|
| ~PhysicalWebDOMHandler() override {} |
| - void RegisterMessages() override; |
| - |
| - void HandleRequestNearbyURLs(const base::ListValue* args); |
| - void HandlePhysicalWebItemClicked(const base::ListValue* args); |
| + void RegisterMessages() override { impl.RegisterMessages(); } |
| 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); |
| - } |
| - |
| - 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; |
| - } |
| - |
| - // Record the index of the selected item. The index must be strictly less than |
| - // the maximum enumeration value. |
| - if (index > kSelectedPositionMaxValue) { |
| - index = kSelectedPositionMaxValue; |
| - } |
| - UMA_HISTOGRAM_EXACT_LINEAR("PhysicalWeb.WebUI.ListViewUrlPosition", index, |
| - kSelectedPositionMaxValue); |
| - |
| - // Count the number of selections. |
| - base::RecordAction( |
| - base::UserMetricsAction("PhysicalWeb.WebUI.ListViewUrlSelected")); |
| -} |
| - |
| } // namespace |
| //////////////////////////////////////////////////////////////////////////////// |