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 { | |
Mark P
2016/07/06 19:10:42
Insert standard warning here.
dmurph
2016/07/07 00:20:36
Done.
| |
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, | |
156 std::vector<std::string> blacklisted_sites) { | |
157 SiteEngagementService* site_engagement_service = | |
158 SiteEngagementService::Get(profile); | |
159 | |
160 std::map<std::string, ImportantReason> reason_map; | |
161 | |
162 std::map<GURL, double> engagement_map = | |
163 site_engagement_service->GetScoreMap(); | |
164 | |
165 // Site engagement. | |
166 for (const auto& url_score_pair : engagement_map) { | |
167 if (url_score_pair.second < | |
168 SiteEngagementScore::GetMediumEngagementBoundary()) { | |
169 continue; | |
170 } | |
171 const std::string& host = url_score_pair.first.host(); | |
172 for (const std::string& blacklisted_site : blacklisted_sites) { | |
173 if (host.find(blacklisted_site) != std::string::npos) { | |
174 reason_map[blacklisted_site].engagement |= true; | |
175 break; | |
176 } | |
177 } | |
178 } | |
179 | |
180 // Durable. | |
181 ContentSettingsForOneType content_settings_list; | |
182 HostContentSettingsMapFactory::GetForProfile(profile)->GetSettingsForOneType( | |
183 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, | |
184 content_settings::ResourceIdentifier(), &content_settings_list); | |
185 for (const ContentSettingPatternSource& site : content_settings_list) { | |
186 if (site.setting != CONTENT_SETTING_ALLOW) | |
187 continue; | |
188 GURL origin(site.primary_pattern.ToString()); | |
189 if (!origin.is_valid()) | |
190 continue; | |
191 const std::string& host = origin.host(); | |
192 for (const std::string& blacklisted_site : blacklisted_sites) { | |
193 if (host.find(blacklisted_site) != std::string::npos) { | |
194 reason_map[blacklisted_site].durable |= true; | |
195 break; | |
196 } | |
197 } | |
198 } | |
199 | |
200 // Notifications. | |
201 content_settings_list.clear(); | |
202 HostContentSettingsMapFactory::GetForProfile(profile)->GetSettingsForOneType( | |
203 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
204 content_settings::ResourceIdentifier(), &content_settings_list); | |
205 for (const ContentSettingPatternSource& site : content_settings_list) { | |
206 if (site.setting != CONTENT_SETTING_ALLOW) | |
207 continue; | |
208 GURL origin(site.primary_pattern.ToString()); | |
209 if (!origin.is_valid()) | |
210 continue; | |
211 const std::string& host = origin.host(); | |
212 for (const std::string& blacklisted_site : blacklisted_sites) { | |
213 if (host.find(blacklisted_site) != std::string::npos) { | |
214 reason_map[blacklisted_site].notifications |= true; | |
215 break; | |
216 } | |
217 } | |
218 } | |
219 | |
220 // Note: we don't plan on adding new metrics here, this is just for the finch | |
221 // experiment to give us initial data on what signals actually mattered. | |
222 for (const auto& reason_pair : reason_map) { | |
223 const ImportantReason& reason = reason_pair.second; | |
224 if (reason.notifications && reason.durable && reason.engagement) { | |
225 UMA_HISTOGRAM_ENUMERATION("Storage.BlacklistedImportantSites.Reason", | |
226 NOTIFICATIONS_AND_DURABLE_AND_ENGAGEMENT, | |
227 REASON_BOUNDARY); | |
228 } else if (reason.notifications && reason.durable) { | |
229 UMA_HISTOGRAM_ENUMERATION("Storage.BlacklistedImportantSites.Reason", | |
230 NOTIFICATIONS_AND_DURABLE, REASON_BOUNDARY); | |
231 } else if (reason.notifications && reason.engagement) { | |
232 UMA_HISTOGRAM_ENUMERATION("Storage.BlacklistedImportantSites.Reason", | |
233 NOTIFICATIONS_AND_ENGAGEMENT, REASON_BOUNDARY); | |
234 } else if (reason.durable && reason.engagement) { | |
235 UMA_HISTOGRAM_ENUMERATION("Storage.BlacklistedImportantSites.Reason", | |
236 DURABLE_AND_ENGAGEMENT, REASON_BOUNDARY); | |
237 } else if (reason.notifications) { | |
238 UMA_HISTOGRAM_ENUMERATION("Storage.BlacklistedImportantSites.Reason", | |
239 NOTIFICATIONS, REASON_BOUNDARY); | |
240 } else if (reason.durable) { | |
241 UMA_HISTOGRAM_ENUMERATION("Storage.BlacklistedImportantSites.Reason", | |
242 DURABLE, REASON_BOUNDARY); | |
243 } else if (reason.engagement) { | |
244 UMA_HISTOGRAM_ENUMERATION("Storage.BlacklistedImportantSites.Reason", | |
245 ENGAGEMENT, REASON_BOUNDARY); | |
246 } | |
Mark P
2016/07/06 19:10:42
Why is none of the above not a possibility?
dmurph
2016/07/07 00:20:36
Added. It shouldn't occur (as we only use the abov
| |
247 } | |
248 } | |
249 | |
136 void ImportantSitesUtil::MarkOriginAsImportantForTesting(Profile* profile, | 250 void ImportantSitesUtil::MarkOriginAsImportantForTesting(Profile* profile, |
137 const GURL& origin) { | 251 const GURL& origin) { |
138 // First get data from site engagement. | 252 // First get data from site engagement. |
139 SiteEngagementService* site_engagement_service = | 253 SiteEngagementService* site_engagement_service = |
140 SiteEngagementService::Get(profile); | 254 SiteEngagementService::Get(profile); |
141 site_engagement_service->ResetScoreForURL( | 255 site_engagement_service->ResetScoreForURL( |
142 origin, SiteEngagementScore::GetMediumEngagementBoundary()); | 256 origin, SiteEngagementScore::GetMediumEngagementBoundary()); |
143 DCHECK(site_engagement_service->IsEngagementAtLeast( | 257 DCHECK(site_engagement_service->IsEngagementAtLeast( |
144 origin, SiteEngagementService::ENGAGEMENT_LEVEL_MEDIUM)); | 258 origin, SiteEngagementService::ENGAGEMENT_LEVEL_MEDIUM)); |
145 } | 259 } |
OLD | NEW |