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

Side by Side Diff: chrome/browser/android/preferences/important_sites_util.cc

Issue 2110463004: [ImportantStorage] Blacklisted reason metrics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed domain empty check Created 4 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 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 // Do not change the values here, as they are used for UMA histograms.
23 enum ReasonStatTypes {
24 DURABLE = 0,
25 NOTIFICATIONS,
26 ENGAGEMENT,
27 NOTIFICATIONS_AND_ENGAGEMENT,
28 DURABLE_AND_ENGAGEMENT,
29 NOTIFICATIONS_AND_DURABLE,
30 NOTIFICATIONS_AND_DURABLE_AND_ENGAGEMENT,
31 REASON_UNKNOWN,
32 REASON_BOUNDARY
33 };
34
35 struct ImportantReason {
36 bool engagement = false;
37 bool notifications = false;
38 bool durable = false;
39 };
40
21 std::vector<std::pair<GURL, double>> GetSortedTopEngagementOrigins( 41 std::vector<std::pair<GURL, double>> GetSortedTopEngagementOrigins(
22 const SiteEngagementService* site_engagement_service, 42 const SiteEngagementService* site_engagement_service,
23 const std::map<GURL, double>& engagement_map, 43 const std::map<GURL, double>& engagement_map,
24 SiteEngagementService::EngagementLevel minimum_engagement) { 44 SiteEngagementService::EngagementLevel minimum_engagement) {
25 std::vector<std::pair<GURL, double>> top_ranking_origins; 45 std::vector<std::pair<GURL, double>> top_ranking_origins;
26 for (const auto& url_engagement_pair : engagement_map) { 46 for (const auto& url_engagement_pair : engagement_map) {
27 if (!site_engagement_service->IsEngagementAtLeast(url_engagement_pair.first, 47 if (!site_engagement_service->IsEngagementAtLeast(url_engagement_pair.first,
28 minimum_engagement)) { 48 minimum_engagement)) {
29 continue; 49 continue;
30 } 50 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 std::vector<std::string> final_list; 146 std::vector<std::string> final_list;
127 // We start with notifications. 147 // We start with notifications.
128 FillTopRegisterableDomains(sorted_notification_origins, max_results, 148 FillTopRegisterableDomains(sorted_notification_origins, max_results,
129 &final_list, optional_example_origins); 149 &final_list, optional_example_origins);
130 // And now we fill the rest with high engagement sites. 150 // And now we fill the rest with high engagement sites.
131 FillTopRegisterableDomains(sorted_engagement_origins, max_results, 151 FillTopRegisterableDomains(sorted_engagement_origins, max_results,
132 &final_list, optional_example_origins); 152 &final_list, optional_example_origins);
133 return final_list; 153 return final_list;
134 } 154 }
135 155
156 void ImportantSitesUtil::RecordMetricsForBlacklistedSites(
157 Profile* profile,
158 std::vector<std::string> blacklisted_sites) {
159 SiteEngagementService* site_engagement_service =
160 SiteEngagementService::Get(profile);
161
162 std::map<std::string, ImportantReason> reason_map;
163
164 std::map<GURL, double> engagement_map =
165 site_engagement_service->GetScoreMap();
166
167 // Site engagement.
168 for (const auto& url_score_pair : engagement_map) {
169 if (url_score_pair.second <
170 SiteEngagementScore::GetMediumEngagementBoundary()) {
171 continue;
172 }
173 const std::string& host = url_score_pair.first.host();
174 for (const std::string& blacklisted_site : blacklisted_sites) {
175 if (host.find(blacklisted_site) != std::string::npos) {
176 reason_map[blacklisted_site].engagement |= true;
177 break;
178 }
179 }
180 }
181
182 // Durable.
183 ContentSettingsForOneType content_settings_list;
184 HostContentSettingsMapFactory::GetForProfile(profile)->GetSettingsForOneType(
185 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE,
186 content_settings::ResourceIdentifier(), &content_settings_list);
187 for (const ContentSettingPatternSource& site : content_settings_list) {
188 if (site.setting != CONTENT_SETTING_ALLOW)
189 continue;
190 GURL origin(site.primary_pattern.ToString());
191 if (!origin.is_valid())
192 continue;
193 const std::string& host = origin.host();
194 for (const std::string& blacklisted_site : blacklisted_sites) {
195 if (host.find(blacklisted_site) != std::string::npos) {
196 reason_map[blacklisted_site].durable |= true;
197 break;
198 }
199 }
200 }
201
202 // Notifications.
203 content_settings_list.clear();
204 HostContentSettingsMapFactory::GetForProfile(profile)->GetSettingsForOneType(
205 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
206 content_settings::ResourceIdentifier(), &content_settings_list);
207 for (const ContentSettingPatternSource& site : content_settings_list) {
208 if (site.setting != CONTENT_SETTING_ALLOW)
209 continue;
210 GURL origin(site.primary_pattern.ToString());
211 if (!origin.is_valid())
212 continue;
213 const std::string& host = origin.host();
214 for (const std::string& blacklisted_site : blacklisted_sites) {
215 if (host.find(blacklisted_site) != std::string::npos) {
216 reason_map[blacklisted_site].notifications |= true;
217 break;
218 }
219 }
220 }
221
222 // Note: we don't plan on adding new metrics here, this is just for the finch
223 // experiment to give us initial data on what signals actually mattered.
224 for (const auto& reason_pair : reason_map) {
225 const ImportantReason& reason = reason_pair.second;
226 if (reason.notifications && reason.durable && reason.engagement) {
227 UMA_HISTOGRAM_ENUMERATION("Storage.BlacklistedImportantSites.Reason",
228 NOTIFICATIONS_AND_DURABLE_AND_ENGAGEMENT,
229 REASON_BOUNDARY);
230 } else if (reason.notifications && reason.durable) {
231 UMA_HISTOGRAM_ENUMERATION("Storage.BlacklistedImportantSites.Reason",
232 NOTIFICATIONS_AND_DURABLE, REASON_BOUNDARY);
233 } else if (reason.notifications && reason.engagement) {
234 UMA_HISTOGRAM_ENUMERATION("Storage.BlacklistedImportantSites.Reason",
235 NOTIFICATIONS_AND_ENGAGEMENT, REASON_BOUNDARY);
236 } else if (reason.durable && reason.engagement) {
237 UMA_HISTOGRAM_ENUMERATION("Storage.BlacklistedImportantSites.Reason",
238 DURABLE_AND_ENGAGEMENT, REASON_BOUNDARY);
239 } else if (reason.notifications) {
240 UMA_HISTOGRAM_ENUMERATION("Storage.BlacklistedImportantSites.Reason",
241 NOTIFICATIONS, REASON_BOUNDARY);
242 } else if (reason.durable) {
243 UMA_HISTOGRAM_ENUMERATION("Storage.BlacklistedImportantSites.Reason",
244 DURABLE, REASON_BOUNDARY);
245 } else if (reason.engagement) {
246 UMA_HISTOGRAM_ENUMERATION("Storage.BlacklistedImportantSites.Reason",
247 ENGAGEMENT, REASON_BOUNDARY);
248 } else {
249 UMA_HISTOGRAM_ENUMERATION("Storage.BlacklistedImportantSites.Reason",
250 REASON_UNKNOWN, REASON_BOUNDARY);
251
252 }
253 }
254 }
255
136 void ImportantSitesUtil::MarkOriginAsImportantForTesting(Profile* profile, 256 void ImportantSitesUtil::MarkOriginAsImportantForTesting(Profile* profile,
137 const GURL& origin) { 257 const GURL& origin) {
138 // First get data from site engagement. 258 // First get data from site engagement.
139 SiteEngagementService* site_engagement_service = 259 SiteEngagementService* site_engagement_service =
140 SiteEngagementService::Get(profile); 260 SiteEngagementService::Get(profile);
141 site_engagement_service->ResetScoreForURL( 261 site_engagement_service->ResetScoreForURL(
142 origin, SiteEngagementScore::GetMediumEngagementBoundary()); 262 origin, SiteEngagementScore::GetMediumEngagementBoundary());
143 DCHECK(site_engagement_service->IsEngagementAtLeast( 263 DCHECK(site_engagement_service->IsEngagementAtLeast(
144 origin, SiteEngagementService::ENGAGEMENT_LEVEL_MEDIUM)); 264 origin, SiteEngagementService::ENGAGEMENT_LEVEL_MEDIUM));
145 } 265 }
OLDNEW
« no previous file with comments | « chrome/browser/android/preferences/important_sites_util.h ('k') | chrome/browser/android/preferences/pref_service_bridge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698