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/engagement/site_engagement_service.h" | 5 #include "chrome/browser/engagement/site_engagement_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 } | 132 } |
| 133 | 133 |
| 134 blink::mojom::EngagementLevel | 134 blink::mojom::EngagementLevel |
| 135 SiteEngagementService::GetEngagementLevel(const GURL& url) const { | 135 SiteEngagementService::GetEngagementLevel(const GURL& url) const { |
| 136 if (IsLastEngagementStale()) | 136 if (IsLastEngagementStale()) |
| 137 CleanupEngagementScores(true); | 137 CleanupEngagementScores(true); |
| 138 | 138 |
| 139 return CreateEngagementScore(url).GetEngagementLevel(); | 139 return CreateEngagementScore(url).GetEngagementLevel(); |
| 140 } | 140 } |
| 141 | 141 |
| 142 std::map<GURL, double> SiteEngagementService::GetScoreMap() const { | 142 std::vector<mojom::SiteEngagementDetails> |
| 143 SiteEngagementService::GetScoreDetails() const { | |
| 143 HostContentSettingsMap* settings_map = | 144 HostContentSettingsMap* settings_map = |
| 144 HostContentSettingsMapFactory::GetForProfile(profile_); | 145 HostContentSettingsMapFactory::GetForProfile(profile_); |
| 145 std::unique_ptr<ContentSettingsForOneType> engagement_settings = | 146 std::unique_ptr<ContentSettingsForOneType> engagement_settings = |
| 146 GetEngagementContentSettings(settings_map); | 147 GetEngagementContentSettings(settings_map); |
| 147 | 148 |
| 148 std::map<GURL, double> score_map; | 149 std::vector<mojom::SiteEngagementDetails> scores; |
| 150 scores.reserve(engagement_settings->size()); | |
| 149 for (const auto& site : *engagement_settings) { | 151 for (const auto& site : *engagement_settings) { |
|
dominickn
2017/04/06 01:47:16
A nuance here is that sites with only a notificati
Wez
2017/04/08 01:52:53
IIUC correctly what you're saying is basically:
s
dominickn
2017/04/10 00:58:11
This is what I had in mind (slight difference to y
Wez
2017/04/10 03:45:28
That makes sense; what I've actually done in the l
dominickn
2017/04/10 04:41:26
It's done using content::PostAfterStartupTask, so
Wez
2017/04/10 21:18:09
Acknowledged.
| |
| 150 GURL origin(site.primary_pattern.ToString()); | 152 GURL origin(site.primary_pattern.ToString()); |
| 151 if (!origin.is_valid()) | 153 if (!origin.is_valid()) |
| 152 continue; | 154 continue; |
| 155 scores.push_back(GetScoreDetails(origin)); | |
| 156 } | |
| 153 | 157 |
| 154 score_map[origin] = GetScore(origin); | 158 return scores; |
| 159 } | |
| 160 | |
| 161 std::map<GURL, double> SiteEngagementService::GetScoreMap() const { | |
| 162 std::vector<mojom::SiteEngagementDetails> scores = GetScoreDetails(); | |
| 163 | |
| 164 std::map<GURL, double> score_map; | |
| 165 for (const auto& info : scores) { | |
| 166 score_map[info.origin] = info.score; | |
|
Wez
2017/04/08 01:52:53
Note to self; this also leads to loads of memory c
dominickn
2017/04/10 00:58:11
Even better: we should be able to remove this meth
Wez
2017/04/10 03:45:28
Acknowledged.
| |
| 155 } | 167 } |
| 156 | 168 |
| 157 return score_map; | 169 return score_map; |
| 158 } | 170 } |
| 159 | 171 |
| 160 void SiteEngagementService::HandleNotificationInteraction(const GURL& url) { | 172 void SiteEngagementService::HandleNotificationInteraction(const GURL& url) { |
| 161 if (!ShouldRecordEngagement(url)) | 173 if (!ShouldRecordEngagement(url)) |
| 162 return; | 174 return; |
| 163 | 175 |
| 164 SiteEngagementMetrics::RecordEngagement( | 176 SiteEngagementMetrics::RecordEngagement( |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 SiteEngagementService::Helper* helper) { | 249 SiteEngagementService::Helper* helper) { |
| 238 helpers_.insert(helper); | 250 helpers_.insert(helper); |
| 239 } | 251 } |
| 240 | 252 |
| 241 void SiteEngagementService::HelperDeleted( | 253 void SiteEngagementService::HelperDeleted( |
| 242 SiteEngagementService::Helper* helper) { | 254 SiteEngagementService::Helper* helper) { |
| 243 helpers_.erase(helper); | 255 helpers_.erase(helper); |
| 244 } | 256 } |
| 245 | 257 |
| 246 double SiteEngagementService::GetScore(const GURL& url) const { | 258 double SiteEngagementService::GetScore(const GURL& url) const { |
| 259 return GetScoreDetails(url).score; | |
| 260 } | |
| 261 | |
| 262 mojom::SiteEngagementDetails SiteEngagementService::GetScoreDetails( | |
|
Wez
2017/04/08 01:52:53
Note to self: This clashes with GetScoreDetails()
Wez
2017/04/10 03:45:28
Renamed the two in the latest patch.
| |
| 263 const GURL& url) const { | |
| 247 // Ensure that if engagement is stale, we clean things up before fetching the | 264 // Ensure that if engagement is stale, we clean things up before fetching the |
| 248 // score. | 265 // score. |
| 249 if (IsLastEngagementStale()) | 266 if (IsLastEngagementStale()) |
| 250 CleanupEngagementScores(true); | 267 CleanupEngagementScores(true); |
| 251 | 268 |
| 252 return CreateEngagementScore(url).GetScore(); | 269 return CreateEngagementScore(url).GetDetails(); |
| 253 } | 270 } |
| 254 | 271 |
| 255 double SiteEngagementService::GetTotalEngagementPoints() const { | 272 double SiteEngagementService::GetTotalEngagementPoints() const { |
| 256 std::map<GURL, double> score_map = GetScoreMap(); | 273 std::map<GURL, double> score_map = GetScoreMap(); |
| 257 | 274 |
| 258 double total_score = 0; | 275 double total_score = 0; |
| 259 for (const auto& value : score_map) | 276 for (const auto& value : score_map) |
| 260 total_score += value.second; | 277 total_score += value.second; |
| 261 | 278 |
| 262 return total_score; | 279 return total_score; |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 667 if (!engagement_score.last_shortcut_launch_time().is_null() && | 684 if (!engagement_score.last_shortcut_launch_time().is_null() && |
| 668 engagement_score.last_shortcut_launch_time() > last_visit) { | 685 engagement_score.last_shortcut_launch_time() > last_visit) { |
| 669 engagement_score.set_last_shortcut_launch_time(last_visit); | 686 engagement_score.set_last_shortcut_launch_time(last_visit); |
| 670 } | 687 } |
| 671 | 688 |
| 672 engagement_score.Commit(); | 689 engagement_score.Commit(); |
| 673 } | 690 } |
| 674 | 691 |
| 675 SetLastEngagementTime(now); | 692 SetLastEngagementTime(now); |
| 676 } | 693 } |
| OLD | NEW |