| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/ui/webui/engagement/site_engagement_ui.h" | 5 #include "chrome/browser/ui/webui/engagement/site_engagement_ui.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/macros.h" | 9 #include "base/macros.h" |
| 8 #include "chrome/browser/engagement/site_engagement_service.h" | 10 #include "chrome/browser/engagement/site_engagement_service.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
| 11 #include "content/public/browser/web_ui.h" | 13 #include "content/public/browser/web_ui.h" |
| 12 #include "content/public/browser/web_ui_controller.h" | 14 #include "content/public/browser/web_ui_controller.h" |
| 13 #include "content/public/browser/web_ui_data_source.h" | 15 #include "content/public/browser/web_ui_data_source.h" |
| 14 #include "grit/browser_resources.h" | 16 #include "grit/browser_resources.h" |
| 15 #include "mojo/common/url_type_converters.h" | 17 #include "mojo/common/url_type_converters.h" |
| 16 #include "mojo/public/cpp/bindings/binding.h" | 18 #include "mojo/public/cpp/bindings/binding.h" |
| 17 | 19 |
| 18 namespace { | 20 namespace { |
| 19 | 21 |
| 20 // Implementation of SiteEngagementUIHandler that gets information from the | 22 // Implementation of SiteEngagementUIHandler that gets information from the |
| 21 // SiteEngagementService to provide data for the WebUI. | 23 // SiteEngagementService to provide data for the WebUI. |
| 22 class SiteEngagementUIHandlerImpl : public SiteEngagementUIHandler { | 24 class SiteEngagementUIHandlerImpl : public SiteEngagementUIHandler { |
| 23 public: | 25 public: |
| 24 // SiteEngagementUIHandlerImpl is deleted when the supplied pipe is destroyed. | 26 // SiteEngagementUIHandlerImpl is deleted when the supplied pipe is destroyed. |
| 25 SiteEngagementUIHandlerImpl( | 27 SiteEngagementUIHandlerImpl( |
| 26 Profile* profile, | 28 Profile* profile, |
| 27 mojo::InterfaceRequest<SiteEngagementUIHandler> request) | 29 mojo::InterfaceRequest<SiteEngagementUIHandler> request) |
| 28 : profile_(profile), binding_(this, request.Pass()) { | 30 : profile_(profile), binding_(this, std::move(request)) { |
| 29 DCHECK(profile_); | 31 DCHECK(profile_); |
| 30 } | 32 } |
| 31 | 33 |
| 32 ~SiteEngagementUIHandlerImpl() override {} | 34 ~SiteEngagementUIHandlerImpl() override {} |
| 33 | 35 |
| 34 // SiteEngagementUIHandler overrides: | 36 // SiteEngagementUIHandler overrides: |
| 35 void GetSiteEngagementInfo( | 37 void GetSiteEngagementInfo( |
| 36 const GetSiteEngagementInfoCallback& callback) override { | 38 const GetSiteEngagementInfoCallback& callback) override { |
| 37 mojo::Array<SiteEngagementInfoPtr> engagement_info(0); | 39 mojo::Array<SiteEngagementInfoPtr> engagement_info(0); |
| 38 | 40 |
| 39 SiteEngagementService* service = SiteEngagementService::Get(profile_); | 41 SiteEngagementService* service = SiteEngagementService::Get(profile_); |
| 40 | 42 |
| 41 for (const std::pair<GURL, double>& info : service->GetScoreMap()) { | 43 for (const std::pair<GURL, double>& info : service->GetScoreMap()) { |
| 42 SiteEngagementInfoPtr origin_info(SiteEngagementInfo::New()); | 44 SiteEngagementInfoPtr origin_info(SiteEngagementInfo::New()); |
| 43 origin_info->origin = mojo::String::From(info.first); | 45 origin_info->origin = mojo::String::From(info.first); |
| 44 origin_info->score = info.second; | 46 origin_info->score = info.second; |
| 45 engagement_info.push_back(origin_info.Pass()); | 47 engagement_info.push_back(std::move(origin_info)); |
| 46 } | 48 } |
| 47 | 49 |
| 48 callback.Run(engagement_info.Pass()); | 50 callback.Run(std::move(engagement_info)); |
| 49 } | 51 } |
| 50 | 52 |
| 51 private: | 53 private: |
| 52 // The Profile* handed to us in our constructor. | 54 // The Profile* handed to us in our constructor. |
| 53 Profile* profile_; | 55 Profile* profile_; |
| 54 | 56 |
| 55 mojo::Binding<SiteEngagementUIHandler> binding_; | 57 mojo::Binding<SiteEngagementUIHandler> binding_; |
| 56 | 58 |
| 57 DISALLOW_COPY_AND_ASSIGN(SiteEngagementUIHandlerImpl); | 59 DISALLOW_COPY_AND_ASSIGN(SiteEngagementUIHandlerImpl); |
| 58 }; | 60 }; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 78 source->SetDefaultResource(IDR_SITE_ENGAGEMENT_HTML); | 80 source->SetDefaultResource(IDR_SITE_ENGAGEMENT_HTML); |
| 79 | 81 |
| 80 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source.release()); | 82 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source.release()); |
| 81 } | 83 } |
| 82 | 84 |
| 83 SiteEngagementUI::~SiteEngagementUI() {} | 85 SiteEngagementUI::~SiteEngagementUI() {} |
| 84 | 86 |
| 85 void SiteEngagementUI::BindUIHandler( | 87 void SiteEngagementUI::BindUIHandler( |
| 86 mojo::InterfaceRequest<SiteEngagementUIHandler> request) { | 88 mojo::InterfaceRequest<SiteEngagementUIHandler> request) { |
| 87 ui_handler_.reset(new SiteEngagementUIHandlerImpl( | 89 ui_handler_.reset(new SiteEngagementUIHandlerImpl( |
| 88 Profile::FromWebUI(web_ui()), request.Pass())); | 90 Profile::FromWebUI(web_ui()), std::move(request))); |
| 89 } | 91 } |
| OLD | NEW |