Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/android/preferences/important_sites_util.h" | 5 #include "chrome/browser/android/preferences/important_sites_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/metrics/histogram_macros.h" | |
| 11 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 12 #include "chrome/browser/engagement/site_engagement_score.h" | 13 #include "chrome/browser/engagement/site_engagement_score.h" |
| 13 #include "chrome/browser/engagement/site_engagement_service.h" | 14 #include "chrome/browser/engagement/site_engagement_service.h" |
| 14 #include "components/content_settings/core/browser/host_content_settings_map.h" | 15 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 15 #include "components/content_settings/core/common/content_settings.h" | 16 #include "components/content_settings/core/common/content_settings.h" |
| 16 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 17 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 17 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 22 enum ReasonStatTypes { | |
| 23 DURABLE = 0, | |
| 24 NOTIFICATIONS, | |
| 25 ENGAGEMENT, | |
| 26 NOTIFICATIONS_AND_ENGAGEMENT, | |
| 27 DURABLE_AND_ENGAGEMENT, | |
| 28 NOTIFICATIONS_AND_DURABLE, | |
| 29 NOTIFICATIONS_AND_DURABLE_AND_ENGAGEMENT, | |
| 30 REASON_BOUNDARY | |
| 31 }; | |
| 32 | |
| 33 struct ImportantReason { | |
| 34 bool engagement = false; | |
| 35 bool notifications = false; | |
| 36 bool durable = false; | |
| 37 }; | |
| 38 | |
| 21 std::vector<std::pair<GURL, double>> GetSortedTopEngagementOrigins( | 39 std::vector<std::pair<GURL, double>> GetSortedTopEngagementOrigins( |
| 22 const SiteEngagementService* site_engagement_service, | 40 const SiteEngagementService* site_engagement_service, |
| 23 const std::map<GURL, double>& engagement_map, | 41 const std::map<GURL, double>& engagement_map, |
| 24 SiteEngagementService::EngagementLevel minimum_engagement) { | 42 SiteEngagementService::EngagementLevel minimum_engagement) { |
| 25 std::vector<std::pair<GURL, double>> top_ranking_origins; | 43 std::vector<std::pair<GURL, double>> top_ranking_origins; |
| 26 for (const auto& url_engagement_pair : engagement_map) { | 44 for (const auto& url_engagement_pair : engagement_map) { |
| 27 if (!site_engagement_service->IsEngagementAtLeast(url_engagement_pair.first, | 45 if (!site_engagement_service->IsEngagementAtLeast(url_engagement_pair.first, |
| 28 minimum_engagement)) { | 46 minimum_engagement)) { |
| 29 continue; | 47 continue; |
| 30 } | 48 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 std::vector<std::string> final_list; | 144 std::vector<std::string> final_list; |
| 127 // We start with notifications. | 145 // We start with notifications. |
| 128 FillTopRegisterableDomains(sorted_notification_origins, max_results, | 146 FillTopRegisterableDomains(sorted_notification_origins, max_results, |
| 129 &final_list, optional_example_origins); | 147 &final_list, optional_example_origins); |
| 130 // And now we fill the rest with high engagement sites. | 148 // And now we fill the rest with high engagement sites. |
| 131 FillTopRegisterableDomains(sorted_engagement_origins, max_results, | 149 FillTopRegisterableDomains(sorted_engagement_origins, max_results, |
| 132 &final_list, optional_example_origins); | 150 &final_list, optional_example_origins); |
| 133 return final_list; | 151 return final_list; |
| 134 } | 152 } |
| 135 | 153 |
| 154 void ImportantSitesUtil::RecordMetricsForBlacklistedSites( | |
| 155 Profile* profile, std::vector<std::string> blacklisted_sites) { | |
| 156 SiteEngagementService* site_engagement_service = | |
| 157 SiteEngagementService::Get(profile); | |
| 158 | |
| 159 std::map<std::string, ImportantReason> reason_map; | |
| 160 | |
| 161 std::map<GURL, double> engagement_map = | |
| 162 site_engagement_service->GetScoreMap(); | |
| 163 | |
| 164 // Site engagement. | |
| 165 for (const auto& url_score_pair : engagement_map) { | |
| 166 if (url_score_pair.second < | |
| 167 SiteEngagementScore::GetMediumEngagementBoundary()) { | |
| 168 continue; | |
| 169 } | |
| 170 const std::string& host = url_score_pair.first.host(); | |
| 171 for (const std::string& blacklisted_site : blacklisted_sites) { | |
| 172 if (host.find(blacklisted_site) != host.end()) { | |
| 173 reason_map[blacklisted_site].engagement |= true; | |
| 174 break; | |
| 175 } | |
| 176 } | |
| 177 } | |
| 178 | |
| 179 // Durable. | |
| 180 ContentSettingsForOneType content_settings_list; | |
| 181 HostContentSettingsMapFactory::GetForProfile(profile)->GetSettingsForOneType( | |
| 182 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, | |
| 183 content_settings::ResourceIdentifier(), &content_settings_list); | |
| 184 for (const ContentSettingPatternSource& site : content_settings_list) { | |
| 185 if (site.setting != CONTENT_SETTING_ALLOW) | |
| 186 continue; | |
| 187 GURL origin(site.primary_pattern.ToString()); | |
| 188 if (!origin.is_valid()) | |
| 189 continue; | |
| 190 const std::string& host = origin.host(); | |
| 191 for (const std::string& blacklisted_site : blacklisted_sites) { | |
| 192 if (host.find(blacklisted_site) != host.end()) { | |
| 193 reason_map[blacklisted_site].durable |= true; | |
| 194 break; | |
| 195 } | |
| 196 } | |
| 197 } | |
| 198 | |
| 199 // Notifications. | |
| 200 ContentSettingsForOneType content_settings_list; | |
| 201 HostContentSettingsMapFactory::GetForProfile(profile)->GetSettingsForOneType( | |
| 202 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
| 203 content_settings::ResourceIdentifier(), &content_settings_list); | |
| 204 for (const ContentSettingPatternSource& site : content_settings_list) { | |
| 205 if (site.setting != CONTENT_SETTING_ALLOW) | |
| 206 continue; | |
| 207 GURL origin(site.primary_pattern.ToString()); | |
| 208 if (!origin.is_valid()) | |
| 209 continue; | |
| 210 const std::string& host = origin.host(); | |
| 211 for (const std::string& blacklisted_site : blacklisted_sites) { | |
|
Ted C
2016/06/29 16:14:54
would it not be possible to just gather the conten
dmurph
2016/06/29 19:20:59
The main issue here is that we don't have GURLs to
Ted C
2016/06/29 19:44:19
Hmm...that is unfortunate. We actually have all o
dmurph
2016/06/29 21:59:26
Unfortunately this seems really complicated, we wo
Ted C
2016/06/29 23:53:48
I think the bitmask would be the most reasonable a
| |
| 212 if (host.find(blacklisted_site) != host.end()) { | |
| 213 reason_map[blacklisted_site].notifications |= true; | |
| 214 break; | |
| 215 } | |
| 216 } | |
| 217 } | |
| 218 | |
| 219 for (const auto& reason_pair : reason_map) { | |
| 220 const ImportantReason& reason = reason_pair.second; | |
| 221 if (reason.notifications && reason.durable && reason.engagement) { | |
| 222 UMA_HISTOGRAM_ENUMERATION("Storage.BlacklistedImportantSites.Reason", | |
|
Ted C
2016/06/29 16:14:54
i'm slightly worried that this won't scale as we a
dmurph
2016/06/29 19:20:59
Initially, we want all of this data to determine w
Ted C
2016/06/29 19:44:19
Ack...no comment needed
| |
| 223 NOTIFICATIONS_AND_DURABLE_AND_ENGAGEMENT, | |
| 224 REASON_BOUNDARY); | |
| 225 } else if (reason.notifications && reason.durable) { | |
| 226 UMA_HISTOGRAM_ENUMERATION("Storage.BlacklistedImportantSites.Reason", | |
| 227 NOTIFICATIONS_AND_DURABLE, REASON_BOUNDARY); | |
| 228 } else if (reason.notifications && reason.engagement) { | |
| 229 UMA_HISTOGRAM_ENUMERATION("Storage.BlacklistedImportantSites.Reason", | |
| 230 NOTIFICATIONS_AND_ENGAGEMENT, REASON_BOUNDARY); | |
| 231 } else if (reason.durable && reason.engagement) { | |
| 232 UMA_HISTOGRAM_ENUMERATION("Storage.BlacklistedImportantSites.Reason", | |
| 233 DURABLE_AND_ENGAGEMENT, REASON_BOUNDARY); | |
| 234 } else if (reason.notifications) { | |
| 235 UMA_HISTOGRAM_ENUMERATION("Storage.BlacklistedImportantSites.Reason", | |
| 236 NOTIFICATIONS, REASON_BOUNDARY); | |
| 237 } else if (reason.durable) { | |
| 238 UMA_HISTOGRAM_ENUMERATION("Storage.BlacklistedImportantSites.Reason", | |
| 239 DURABLE, REASON_BOUNDARY); | |
| 240 } else if (reason.engagement) { | |
| 241 UMA_HISTOGRAM_ENUMERATION("Storage.BlacklistedImportantSites.Reason", | |
| 242 ENGAGEMENT, REASON_BOUNDARY); | |
| 243 } | |
| 244 } | |
| 245 } | |
| 246 | |
| 136 void ImportantSitesUtil::MarkOriginAsImportantForTesting(Profile* profile, | 247 void ImportantSitesUtil::MarkOriginAsImportantForTesting(Profile* profile, |
| 137 const GURL& origin) { | 248 const GURL& origin) { |
| 138 // First get data from site engagement. | 249 // First get data from site engagement. |
| 139 SiteEngagementService* site_engagement_service = | 250 SiteEngagementService* site_engagement_service = |
| 140 SiteEngagementService::Get(profile); | 251 SiteEngagementService::Get(profile); |
| 141 site_engagement_service->ResetScoreForURL( | 252 site_engagement_service->ResetScoreForURL( |
| 142 origin, SiteEngagementScore::GetMediumEngagementBoundary()); | 253 origin, SiteEngagementScore::GetMediumEngagementBoundary()); |
| 143 DCHECK(site_engagement_service->IsEngagementAtLeast( | 254 DCHECK(site_engagement_service->IsEngagementAtLeast( |
| 144 origin, SiteEngagementService::ENGAGEMENT_LEVEL_MEDIUM)); | 255 origin, SiteEngagementService::ENGAGEMENT_LEVEL_MEDIUM)); |
| 145 } | 256 } |
| OLD | NEW |