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/engagement/important_sites_util.h" | 5 #include "chrome/browser/engagement/important_sites_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 return CROSSED_DURABLE; | 130 return CROSSED_DURABLE; |
131 else if (engagement) | 131 else if (engagement) |
132 return CROSSED_ENGAGEMENT; | 132 return CROSSED_ENGAGEMENT; |
133 return CROSSED_REASON_UNKNOWN; | 133 return CROSSED_REASON_UNKNOWN; |
134 } | 134 } |
135 | 135 |
136 void MaybePopulateImportantInfoForReason( | 136 void MaybePopulateImportantInfoForReason( |
137 const GURL& origin, | 137 const GURL& origin, |
138 std::set<GURL>* visited_origins, | 138 std::set<GURL>* visited_origins, |
139 ImportantReason reason, | 139 ImportantReason reason, |
140 base::hash_map<std::string, ImportantDomainInfo>* output) { | 140 std::map<std::string, ImportantDomainInfo>* output) { |
141 if (!origin.is_valid() || !visited_origins->insert(origin).second) | 141 if (!origin.is_valid() || !visited_origins->insert(origin).second) |
142 return; | 142 return; |
143 std::string registerable_domain = | 143 std::string registerable_domain = |
144 ImportantSitesUtil::GetRegisterableDomainOrIP(origin); | 144 ImportantSitesUtil::GetRegisterableDomainOrIP(origin); |
145 ImportantDomainInfo& info = (*output)[registerable_domain]; | 145 ImportantDomainInfo& info = (*output)[registerable_domain]; |
146 info.reason_bitfield |= 1 << reason; | 146 info.reason_bitfield |= 1 << reason; |
147 if (info.example_origin.is_empty()) { | 147 if (info.example_origin.is_empty()) { |
148 info.registerable_domain = registerable_domain; | 148 info.registerable_domain = registerable_domain; |
149 info.example_origin = origin; | 149 info.example_origin = origin; |
150 } | 150 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 if (ShouldSuppressItem(dict.get())) | 220 if (ShouldSuppressItem(dict.get())) |
221 ignoring_domains.insert(origin.host()); | 221 ignoring_domains.insert(origin.host()); |
222 } | 222 } |
223 return ignoring_domains; | 223 return ignoring_domains; |
224 } | 224 } |
225 | 225 |
226 void PopulateInfoMapWithSiteEngagement( | 226 void PopulateInfoMapWithSiteEngagement( |
227 Profile* profile, | 227 Profile* profile, |
228 blink::mojom::EngagementLevel minimum_engagement, | 228 blink::mojom::EngagementLevel minimum_engagement, |
229 std::map<GURL, double>* engagement_map, | 229 std::map<GURL, double>* engagement_map, |
230 base::hash_map<std::string, ImportantDomainInfo>* output) { | 230 std::map<std::string, ImportantDomainInfo>* output) { |
231 SiteEngagementService* service = SiteEngagementService::Get(profile); | 231 SiteEngagementService* service = SiteEngagementService::Get(profile); |
232 *engagement_map = service->GetScoreMap(); | 232 *engagement_map = service->GetScoreMap(); |
233 // We can have multiple origins for a single domain, so we record the one | 233 // We can have multiple origins for a single domain, so we record the one |
234 // with the highest engagement score. | 234 // with the highest engagement score. |
235 for (const auto& url_engagement_pair : *engagement_map) { | 235 for (const auto& url_engagement_pair : *engagement_map) { |
236 if (!service->IsEngagementAtLeast(url_engagement_pair.first, | 236 if (!service->IsEngagementAtLeast(url_engagement_pair.first, |
237 minimum_engagement)) { | 237 minimum_engagement)) { |
238 continue; | 238 continue; |
239 } | 239 } |
240 std::string registerable_domain = | 240 std::string registerable_domain = |
241 ImportantSitesUtil::GetRegisterableDomainOrIP( | 241 ImportantSitesUtil::GetRegisterableDomainOrIP( |
242 url_engagement_pair.first); | 242 url_engagement_pair.first); |
243 ImportantDomainInfo& info = (*output)[registerable_domain]; | 243 ImportantDomainInfo& info = (*output)[registerable_domain]; |
244 if (url_engagement_pair.second > info.engagement_score) { | 244 if (url_engagement_pair.second > info.engagement_score) { |
245 info.registerable_domain = registerable_domain; | 245 info.registerable_domain = registerable_domain; |
246 info.engagement_score = url_engagement_pair.second; | 246 info.engagement_score = url_engagement_pair.second; |
247 info.example_origin = url_engagement_pair.first; | 247 info.example_origin = url_engagement_pair.first; |
248 info.reason_bitfield |= 1 << ImportantReason::ENGAGEMENT; | 248 info.reason_bitfield |= 1 << ImportantReason::ENGAGEMENT; |
249 } | 249 } |
250 } | 250 } |
251 } | 251 } |
252 | 252 |
253 void PopulateInfoMapWithContentTypeAllowed( | 253 void PopulateInfoMapWithContentTypeAllowed( |
254 Profile* profile, | 254 Profile* profile, |
255 ContentSettingsType content_type, | 255 ContentSettingsType content_type, |
256 ImportantReason reason, | 256 ImportantReason reason, |
257 base::hash_map<std::string, ImportantDomainInfo>* output) { | 257 std::map<std::string, ImportantDomainInfo>* output) { |
258 // Grab our content settings list. | 258 // Grab our content settings list. |
259 ContentSettingsForOneType content_settings_list; | 259 ContentSettingsForOneType content_settings_list; |
260 HostContentSettingsMapFactory::GetForProfile(profile)->GetSettingsForOneType( | 260 HostContentSettingsMapFactory::GetForProfile(profile)->GetSettingsForOneType( |
261 content_type, content_settings::ResourceIdentifier(), | 261 content_type, content_settings::ResourceIdentifier(), |
262 &content_settings_list); | 262 &content_settings_list); |
263 // Extract a set of urls, using the primary pattern. We don't handle | 263 // Extract a set of urls, using the primary pattern. We don't handle |
264 // wildcard patterns. | 264 // wildcard patterns. |
265 std::set<GURL> content_origins; | 265 std::set<GURL> content_origins; |
266 for (const ContentSettingPatternSource& site : content_settings_list) { | 266 for (const ContentSettingPatternSource& site : content_settings_list) { |
267 if (site.setting != CONTENT_SETTING_ALLOW) | 267 if (site.setting != CONTENT_SETTING_ALLOW) |
268 continue; | 268 continue; |
269 MaybePopulateImportantInfoForReason(GURL(site.primary_pattern.ToString()), | 269 MaybePopulateImportantInfoForReason(GURL(site.primary_pattern.ToString()), |
270 &content_origins, reason, output); | 270 &content_origins, reason, output); |
271 } | 271 } |
272 } | 272 } |
273 | 273 |
274 void PopulateInfoMapWithBookmarks( | 274 void PopulateInfoMapWithBookmarks( |
275 Profile* profile, | 275 Profile* profile, |
276 const std::map<GURL, double>& engagement_map, | 276 const std::map<GURL, double>& engagement_map, |
277 base::hash_map<std::string, ImportantDomainInfo>* output) { | 277 std::map<std::string, ImportantDomainInfo>* output) { |
278 SiteEngagementService* service = SiteEngagementService::Get(profile); | 278 SiteEngagementService* service = SiteEngagementService::Get(profile); |
279 BookmarkModel* model = | 279 BookmarkModel* model = |
280 BookmarkModelFactory::GetForBrowserContextIfExists(profile); | 280 BookmarkModelFactory::GetForBrowserContextIfExists(profile); |
281 if (!model) | 281 if (!model) |
282 return; | 282 return; |
283 std::vector<BookmarkModel::URLAndTitle> untrimmed_bookmarks; | 283 std::vector<BookmarkModel::URLAndTitle> untrimmed_bookmarks; |
284 model->GetBookmarks(&untrimmed_bookmarks); | 284 model->GetBookmarks(&untrimmed_bookmarks); |
285 | 285 |
286 // Process the bookmarks and optionally trim them if we have too many. | 286 // Process the bookmarks and optionally trim them if we have too many. |
287 std::vector<BookmarkModel::URLAndTitle> result_bookmarks; | 287 std::vector<BookmarkModel::URLAndTitle> result_bookmarks; |
(...skipping 26 matching lines...) Expand all Loading... |
314 | 314 |
315 std::set<GURL> content_origins; | 315 std::set<GURL> content_origins; |
316 for (const BookmarkModel::URLAndTitle& bookmark : result_bookmarks) { | 316 for (const BookmarkModel::URLAndTitle& bookmark : result_bookmarks) { |
317 MaybePopulateImportantInfoForReason(bookmark.url, &content_origins, | 317 MaybePopulateImportantInfoForReason(bookmark.url, &content_origins, |
318 ImportantReason::BOOKMARKS, output); | 318 ImportantReason::BOOKMARKS, output); |
319 } | 319 } |
320 } | 320 } |
321 | 321 |
322 void PopulateInfoMapWithHomeScreen( | 322 void PopulateInfoMapWithHomeScreen( |
323 Profile* profile, | 323 Profile* profile, |
324 base::hash_map<std::string, ImportantDomainInfo>* output) { | 324 std::map<std::string, ImportantDomainInfo>* output) { |
325 ContentSettingsForOneType content_settings_list; | 325 ContentSettingsForOneType content_settings_list; |
326 HostContentSettingsMapFactory::GetForProfile(profile)->GetSettingsForOneType( | 326 HostContentSettingsMapFactory::GetForProfile(profile)->GetSettingsForOneType( |
327 CONTENT_SETTINGS_TYPE_APP_BANNER, content_settings::ResourceIdentifier(), | 327 CONTENT_SETTINGS_TYPE_APP_BANNER, content_settings::ResourceIdentifier(), |
328 &content_settings_list); | 328 &content_settings_list); |
329 // Extract a set of urls, using the primary pattern. We don't handle | 329 // Extract a set of urls, using the primary pattern. We don't handle |
330 // wildcard patterns. | 330 // wildcard patterns. |
331 std::set<GURL> content_origins; | 331 std::set<GURL> content_origins; |
332 base::Time now = base::Time::Now(); | 332 base::Time now = base::Time::Now(); |
333 for (const ContentSettingPatternSource& site : content_settings_list) { | 333 for (const ContentSettingPatternSource& site : content_settings_list) { |
334 GURL origin(site.primary_pattern.ToString()); | 334 GURL origin(site.primary_pattern.ToString()); |
(...skipping 28 matching lines...) Expand all Loading... |
363 } | 363 } |
364 | 364 |
365 void ImportantSitesUtil::RegisterProfilePrefs( | 365 void ImportantSitesUtil::RegisterProfilePrefs( |
366 user_prefs::PrefRegistrySyncable* registry) { | 366 user_prefs::PrefRegistrySyncable* registry) { |
367 registry->RegisterDictionaryPref(prefs::kImportantSitesDialogHistory); | 367 registry->RegisterDictionaryPref(prefs::kImportantSitesDialogHistory); |
368 } | 368 } |
369 | 369 |
370 std::vector<ImportantDomainInfo> | 370 std::vector<ImportantDomainInfo> |
371 ImportantSitesUtil::GetImportantRegisterableDomains(Profile* profile, | 371 ImportantSitesUtil::GetImportantRegisterableDomains(Profile* profile, |
372 size_t max_results) { | 372 size_t max_results) { |
373 base::hash_map<std::string, ImportantDomainInfo> important_info; | 373 std::map<std::string, ImportantDomainInfo> important_info; |
374 std::map<GURL, double> engagement_map; | 374 std::map<GURL, double> engagement_map; |
375 | 375 |
376 PopulateInfoMapWithSiteEngagement( | 376 PopulateInfoMapWithSiteEngagement( |
377 profile, blink::mojom::EngagementLevel::MEDIUM, &engagement_map, | 377 profile, blink::mojom::EngagementLevel::MEDIUM, &engagement_map, |
378 &important_info); | 378 &important_info); |
379 | 379 |
380 PopulateInfoMapWithContentTypeAllowed( | 380 PopulateInfoMapWithContentTypeAllowed( |
381 profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 381 profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
382 ImportantReason::NOTIFICATIONS, &important_info); | 382 ImportantReason::NOTIFICATIONS, &important_info); |
383 | 383 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 const GURL& origin) { | 486 const GURL& origin) { |
487 SiteEngagementScore::SetParamValuesForTesting(); | 487 SiteEngagementScore::SetParamValuesForTesting(); |
488 // First get data from site engagement. | 488 // First get data from site engagement. |
489 SiteEngagementService* site_engagement_service = | 489 SiteEngagementService* site_engagement_service = |
490 SiteEngagementService::Get(profile); | 490 SiteEngagementService::Get(profile); |
491 site_engagement_service->ResetBaseScoreForURL( | 491 site_engagement_service->ResetBaseScoreForURL( |
492 origin, SiteEngagementScore::GetMediumEngagementBoundary()); | 492 origin, SiteEngagementScore::GetMediumEngagementBoundary()); |
493 DCHECK(site_engagement_service->IsEngagementAtLeast( | 493 DCHECK(site_engagement_service->IsEngagementAtLeast( |
494 origin, blink::mojom::EngagementLevel::MEDIUM)); | 494 origin, blink::mojom::EngagementLevel::MEDIUM)); |
495 } | 495 } |
OLD | NEW |