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

Side by Side Diff: chrome/browser/engagement/site_engagement_service.cc

Issue 1207383006: Add GetTotalEngagementPoints to SiteEngagementService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months 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 unified diff | Download patch
OLDNEW
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/engagement/site_engagement_service.h" 5 #include "chrome/browser/engagement/site_engagement_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 14 matching lines...) Expand all
25 25
26 // Delta within which to consider internal time values equal. Internal time 26 // Delta within which to consider internal time values equal. Internal time
27 // values are in microseconds, so this delta comes out at one second. 27 // values are in microseconds, so this delta comes out at one second.
28 const double kTimeDelta = 1000000; 28 const double kTimeDelta = 1000000;
29 29
30 bool DoublesConsideredDifferent(double value1, double value2, double delta) { 30 bool DoublesConsideredDifferent(double value1, double value2, double delta) {
31 double abs_difference = fabs(value1 - value2); 31 double abs_difference = fabs(value1 - value2);
32 return abs_difference > delta; 32 return abs_difference > delta;
33 } 33 }
34 34
35 scoped_ptr<base::DictionaryValue> GetOriginDict( 35 scoped_ptr<base::DictionaryValue> GetOriginDict(
raymes 2015/07/01 05:33:09 How about we rename this GetScoreDict or GetScoreD
calamity 2015/07/06 01:51:06 Done.
36 HostContentSettingsMap* settings, 36 HostContentSettingsMap* settings,
37 const GURL& origin_url) { 37 const GURL& origin_url) {
38 if (!settings) 38 if (!settings)
39 return scoped_ptr<base::DictionaryValue>(); 39 return scoped_ptr<base::DictionaryValue>();
40 40
41 scoped_ptr<base::Value> value = settings->GetWebsiteSetting( 41 scoped_ptr<base::Value> value = settings->GetWebsiteSetting(
42 origin_url, origin_url, CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, 42 origin_url, origin_url, CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT,
43 std::string(), NULL); 43 std::string(), NULL);
44 if (!value.get()) 44 if (!value.get())
45 return make_scoped_ptr(new base::DictionaryValue()); 45 return make_scoped_ptr(new base::DictionaryValue());
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 } 185 }
186 186
187 int SiteEngagementService::GetScore(const GURL& url) { 187 int SiteEngagementService::GetScore(const GURL& url) {
188 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); 188 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap();
189 scoped_ptr<base::DictionaryValue> settings = GetOriginDict(settings_map, url); 189 scoped_ptr<base::DictionaryValue> settings = GetOriginDict(settings_map, url);
190 SiteEngagementScore score(&clock_, *settings); 190 SiteEngagementScore score(&clock_, *settings);
191 191
192 return score.Score(); 192 return score.Score();
193 } 193 }
194 194
195 int SiteEngagementService::GetTotalEngagementPoints() {
196 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap();
197 ContentSettingsForOneType engagement_settings;
198 settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT,
199 std::string(), &engagement_settings);
200 int total_score = 0;
201 for (auto it : engagement_settings) {
raymes 2015/07/01 05:33:08 perhaps for (auto site : engagement_settings) Al
calamity 2015/07/06 01:51:06 Done.
202 scoped_ptr<base::DictionaryValue> settings =
203 GetOriginDict(settings_map, GURL(it.primary_pattern.ToString()));
raymes 2015/07/01 05:33:09 I guess we should technically check that the GURL
calamity 2015/07/06 01:51:06 Done.
204 SiteEngagementScore score(&clock_, *settings);
205 total_score += score.Score();
206 }
207 return total_score;
208 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698