| 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> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "chrome/browser/banners/app_banner_settings_helper.h" | 19 #include "chrome/browser/banners/app_banner_settings_helper.h" |
| 20 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 20 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 21 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 21 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 22 #include "chrome/browser/engagement/site_engagement_score.h" | 22 #include "chrome/browser/engagement/site_engagement_score.h" |
| 23 #include "chrome/browser/engagement/site_engagement_service.h" | 23 #include "chrome/browser/engagement/site_engagement_service.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 26 #include "components/bookmarks/browser/bookmark_model.h" | 26 #include "components/bookmarks/browser/bookmark_model.h" |
| 27 #include "components/content_settings/core/browser/host_content_settings_map.h" | 27 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 28 #include "components/content_settings/core/common/content_settings.h" | 28 #include "components/content_settings/core/common/content_settings.h" |
| 29 #include "components/content_settings/core/common/content_settings_utils.h" |
| 29 #include "components/pref_registry/pref_registry_syncable.h" | 30 #include "components/pref_registry/pref_registry_syncable.h" |
| 30 #include "components/prefs/pref_service.h" | 31 #include "components/prefs/pref_service.h" |
| 31 #include "components/prefs/scoped_user_pref_update.h" | 32 #include "components/prefs/scoped_user_pref_update.h" |
| 32 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 33 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 33 #include "third_party/WebKit/public/platform/site_engagement.mojom.h" | 34 #include "third_party/WebKit/public/platform/site_engagement.mojom.h" |
| 34 #include "url/gurl.h" | 35 #include "url/gurl.h" |
| 35 #include "url/url_util.h" | 36 #include "url/url_util.h" |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 using bookmarks::BookmarkModel; | 39 using bookmarks::BookmarkModel; |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 base::hash_map<std::string, ImportantDomainInfo>* output) { | 258 base::hash_map<std::string, ImportantDomainInfo>* output) { |
| 258 // Grab our content settings list. | 259 // Grab our content settings list. |
| 259 ContentSettingsForOneType content_settings_list; | 260 ContentSettingsForOneType content_settings_list; |
| 260 HostContentSettingsMapFactory::GetForProfile(profile)->GetSettingsForOneType( | 261 HostContentSettingsMapFactory::GetForProfile(profile)->GetSettingsForOneType( |
| 261 content_type, content_settings::ResourceIdentifier(), | 262 content_type, content_settings::ResourceIdentifier(), |
| 262 &content_settings_list); | 263 &content_settings_list); |
| 263 // Extract a set of urls, using the primary pattern. We don't handle | 264 // Extract a set of urls, using the primary pattern. We don't handle |
| 264 // wildcard patterns. | 265 // wildcard patterns. |
| 265 std::set<GURL> content_origins; | 266 std::set<GURL> content_origins; |
| 266 for (const ContentSettingPatternSource& site : content_settings_list) { | 267 for (const ContentSettingPatternSource& site : content_settings_list) { |
| 267 if (site.setting != CONTENT_SETTING_ALLOW) | 268 if (content_settings::ValueToContentSetting(site.setting_value.get()) != |
| 269 CONTENT_SETTING_ALLOW) { |
| 268 continue; | 270 continue; |
| 271 } |
| 269 MaybePopulateImportantInfoForReason(GURL(site.primary_pattern.ToString()), | 272 MaybePopulateImportantInfoForReason(GURL(site.primary_pattern.ToString()), |
| 270 &content_origins, reason, output); | 273 &content_origins, reason, output); |
| 271 } | 274 } |
| 272 } | 275 } |
| 273 | 276 |
| 274 void PopulateInfoMapWithBookmarks( | 277 void PopulateInfoMapWithBookmarks( |
| 275 Profile* profile, | 278 Profile* profile, |
| 276 const std::map<GURL, double>& engagement_map, | 279 const std::map<GURL, double>& engagement_map, |
| 277 base::hash_map<std::string, ImportantDomainInfo>* output) { | 280 base::hash_map<std::string, ImportantDomainInfo>* output) { |
| 278 SiteEngagementService* service = SiteEngagementService::Get(profile); | 281 SiteEngagementService* service = SiteEngagementService::Get(profile); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 const GURL& origin) { | 489 const GURL& origin) { |
| 487 SiteEngagementScore::SetParamValuesForTesting(); | 490 SiteEngagementScore::SetParamValuesForTesting(); |
| 488 // First get data from site engagement. | 491 // First get data from site engagement. |
| 489 SiteEngagementService* site_engagement_service = | 492 SiteEngagementService* site_engagement_service = |
| 490 SiteEngagementService::Get(profile); | 493 SiteEngagementService::Get(profile); |
| 491 site_engagement_service->ResetBaseScoreForURL( | 494 site_engagement_service->ResetBaseScoreForURL( |
| 492 origin, SiteEngagementScore::GetMediumEngagementBoundary()); | 495 origin, SiteEngagementScore::GetMediumEngagementBoundary()); |
| 493 DCHECK(site_engagement_service->IsEngagementAtLeast( | 496 DCHECK(site_engagement_service->IsEngagementAtLeast( |
| 494 origin, blink::mojom::EngagementLevel::MEDIUM)); | 497 origin, blink::mojom::EngagementLevel::MEDIUM)); |
| 495 } | 498 } |
| OLD | NEW |