Chromium Code Reviews| 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 <math.h> | |
|
Dan Beam
2016/03/11 22:46:36
https://chromium-cpp.appspot.com/ mentions <cmath>
calamity
2016/03/14 05:38:30
Fixed.
| |
| 7 #include <utility> | 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/macros.h" | 10 #include "base/macros.h" |
| 10 #include "chrome/browser/engagement/site_engagement_service.h" | 11 #include "chrome/browser/engagement/site_engagement_service.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
| 13 #include "content/public/browser/web_ui.h" | 14 #include "content/public/browser/web_ui.h" |
| 14 #include "content/public/browser/web_ui_controller.h" | 15 #include "content/public/browser/web_ui_controller.h" |
| 15 #include "content/public/browser/web_ui_data_source.h" | 16 #include "content/public/browser/web_ui_data_source.h" |
| 16 #include "grit/browser_resources.h" | 17 #include "grit/browser_resources.h" |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 47 engagement_info.push_back(std::move(origin_info)); | 48 engagement_info.push_back(std::move(origin_info)); |
| 48 } | 49 } |
| 49 | 50 |
| 50 callback.Run(std::move(engagement_info)); | 51 callback.Run(std::move(engagement_info)); |
| 51 } | 52 } |
| 52 | 53 |
| 53 void SetSiteEngagementScoreForOrigin(const mojo::String& origin, | 54 void SetSiteEngagementScoreForOrigin(const mojo::String& origin, |
| 54 double score) override { | 55 double score) override { |
| 55 GURL origin_gurl(origin.get()); | 56 GURL origin_gurl(origin.get()); |
| 56 if (!origin_gurl.is_valid() || score < 0 || | 57 if (!origin_gurl.is_valid() || score < 0 || |
| 57 score > SiteEngagementScore::kMaxPoints) { | 58 score > SiteEngagementScore::kMaxPoints || isnan(score)) { |
| 58 return; | 59 return; |
| 59 } | 60 } |
| 60 | 61 |
| 61 SiteEngagementService* service = SiteEngagementService::Get(profile_); | 62 SiteEngagementService* service = SiteEngagementService::Get(profile_); |
| 62 service->ResetScoreForURL(origin_gurl, score); | 63 service->ResetScoreForURL(origin_gurl, score); |
| 63 } | 64 } |
| 64 | 65 |
| 65 private: | 66 private: |
| 66 // The Profile* handed to us in our constructor. | 67 // The Profile* handed to us in our constructor. |
| 67 Profile* profile_; | 68 Profile* profile_; |
| 68 | 69 |
| 69 mojo::Binding<SiteEngagementUIHandler> binding_; | 70 mojo::Binding<SiteEngagementUIHandler> binding_; |
| 70 | 71 |
| 71 DISALLOW_COPY_AND_ASSIGN(SiteEngagementUIHandlerImpl); | 72 DISALLOW_COPY_AND_ASSIGN(SiteEngagementUIHandlerImpl); |
| 72 }; | 73 }; |
| 73 | 74 |
| 74 } // namespace | 75 } // namespace |
| 75 | 76 |
| 76 SiteEngagementUI::SiteEngagementUI(content::WebUI* web_ui) | 77 SiteEngagementUI::SiteEngagementUI(content::WebUI* web_ui) |
| 77 : MojoWebUIController<SiteEngagementUIHandler>(web_ui) { | 78 : MojoWebUIController<SiteEngagementUIHandler>(web_ui) { |
| 78 // Set up the chrome://site-engagement/ source. | 79 // Set up the chrome://site-engagement/ source. |
| 79 scoped_ptr<content::WebUIDataSource> source( | 80 scoped_ptr<content::WebUIDataSource> source( |
| 80 content::WebUIDataSource::Create(chrome::kChromeUISiteEngagementHost)); | 81 content::WebUIDataSource::Create(chrome::kChromeUISiteEngagementHost)); |
| 81 source->AddResourcePath("engagement_table.html", | |
| 82 IDR_SITE_ENGAGEMENT_ENGAGEMENT_TABLE_HTML); | |
| 83 source->AddResourcePath("engagement_table.css", | |
| 84 IDR_SITE_ENGAGEMENT_ENGAGEMENT_TABLE_CSS); | |
| 85 source->AddResourcePath("engagement_table.js", | |
| 86 IDR_SITE_ENGAGEMENT_ENGAGEMENT_TABLE_JS); | |
| 87 source->AddResourcePath("site_engagement.js", IDR_SITE_ENGAGEMENT_JS); | 82 source->AddResourcePath("site_engagement.js", IDR_SITE_ENGAGEMENT_JS); |
| 88 source->AddResourcePath( | 83 source->AddResourcePath( |
| 89 "chrome/browser/ui/webui/engagement/site_engagement.mojom", | 84 "chrome/browser/ui/webui/engagement/site_engagement.mojom", |
| 90 IDR_SITE_ENGAGEMENT_MOJO_JS); | 85 IDR_SITE_ENGAGEMENT_MOJO_JS); |
| 91 source->SetDefaultResource(IDR_SITE_ENGAGEMENT_HTML); | 86 source->SetDefaultResource(IDR_SITE_ENGAGEMENT_HTML); |
| 92 | 87 |
| 93 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source.release()); | 88 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source.release()); |
| 94 } | 89 } |
| 95 | 90 |
| 96 SiteEngagementUI::~SiteEngagementUI() {} | 91 SiteEngagementUI::~SiteEngagementUI() {} |
| 97 | 92 |
| 98 void SiteEngagementUI::BindUIHandler( | 93 void SiteEngagementUI::BindUIHandler( |
| 99 mojo::InterfaceRequest<SiteEngagementUIHandler> request) { | 94 mojo::InterfaceRequest<SiteEngagementUIHandler> request) { |
| 100 ui_handler_.reset(new SiteEngagementUIHandlerImpl( | 95 ui_handler_.reset(new SiteEngagementUIHandlerImpl( |
| 101 Profile::FromWebUI(web_ui()), std::move(request))); | 96 Profile::FromWebUI(web_ui()), std::move(request))); |
| 102 } | 97 } |
| OLD | NEW |