diff options
author | benwells <benwells@chromium.org> | 2015-06-25 18:25:57 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-26 01:26:38 +0000 |
commit | cb74965e5aab713293d9ba6dffa1b87ab1da872e (patch) | |
tree | bbb80792b16e478929d05a8d92afcd1b1865f6f4 | |
parent | da8ec4a1a7d36de6f0ad1c34739f2f15a750be2a (diff) | |
download | chromium_src-cb74965e5aab713293d9ba6dffa1b87ab1da872e.zip chromium_src-cb74965e5aab713293d9ba6dffa1b87ab1da872e.tar.gz chromium_src-cb74965e5aab713293d9ba6dffa1b87ab1da872e.tar.bz2 |
Store site engagement values in a new content settings type.
The are currently not persisted anywhere.
BUG=464234
Review URL: https://codereview.chromium.org/1187113002
Cr-Commit-Position: refs/heads/master@{#336312}
19 files changed, 274 insertions, 76 deletions
diff --git a/chrome/browser/browsing_data/browsing_data_remover.cc b/chrome/browser/browsing_data/browsing_data_remover.cc index 4e4a99c..482f48a 100644 --- a/chrome/browser/browsing_data/browsing_data_remover.cc +++ b/chrome/browser/browsing_data/browsing_data_remover.cc @@ -550,9 +550,11 @@ void BrowsingDataRemover::RemoveImpl(int remove_mask, } #endif - if (remove_mask & REMOVE_APP_BANNER_DATA || remove_mask & REMOVE_HISTORY) { + if (remove_mask & REMOVE_SITE_USAGE_DATA || remove_mask & REMOVE_HISTORY) { profile_->GetHostContentSettingsMap()->ClearSettingsForOneType( CONTENT_SETTINGS_TYPE_APP_BANNER); + profile_->GetHostContentSettingsMap()->ClearSettingsForOneType( + CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT); } if (remove_mask & REMOVE_PASSWORDS) { diff --git a/chrome/browser/browsing_data/browsing_data_remover.h b/chrome/browser/browsing_data/browsing_data_remover.h index 1186ef65..b75e4a0 100644 --- a/chrome/browser/browsing_data/browsing_data_remover.h +++ b/chrome/browser/browsing_data/browsing_data_remover.h @@ -75,7 +75,7 @@ class BrowsingDataRemover REMOVE_CHANNEL_IDS = 1 << 12, REMOVE_CONTENT_LICENSES = 1 << 13, REMOVE_SERVICE_WORKERS = 1 << 14, - REMOVE_APP_BANNER_DATA = 1 << 15, + REMOVE_SITE_USAGE_DATA = 1 << 15, // REMOVE_NOCHECKS intentionally does not check if the Profile's prohibited // from deleting history or downloads. REMOVE_NOCHECKS = 1 << 16, @@ -92,8 +92,8 @@ class BrowsingDataRemover REMOVE_PLUGIN_DATA | REMOVE_SERVICE_WORKERS | REMOVE_WEBSQL | - REMOVE_APP_BANNER_DATA | - REMOVE_CHANNEL_IDS, + REMOVE_CHANNEL_IDS | + REMOVE_SITE_USAGE_DATA, // Includes all the available remove options. Meant to be used by clients // that wish to wipe as much data as possible from a Profile, to make it diff --git a/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc b/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc index 6386a75..de9b1a7 100644 --- a/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc +++ b/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc @@ -483,12 +483,17 @@ TEST_F(PrefProviderTest, SyncingOldToNew) { base::DictionaryValue* exceptions = new base::DictionaryValue(); base::DictionaryValue* plugin_resources = new base::DictionaryValue(); - // Add exceptions for images and app banner. + // Add exceptions for images and app banner which did not need to be migrated. exceptions->SetIntegerWithoutPathExpansion( GetTypeName(CONTENT_SETTINGS_TYPE_IMAGES), CONTENT_SETTING_ALLOW); exceptions->SetIntegerWithoutPathExpansion( GetTypeName(CONTENT_SETTINGS_TYPE_APP_BANNER), CONTENT_SETTING_ALLOW); + // Add exceptions for new content settings types added after the migration. + exceptions->SetIntegerWithoutPathExpansion( + GetTypeName(CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT), + CONTENT_SETTING_ALLOW); + // Add a regular exception for plugins, then one with a resource identifier. exceptions->SetIntegerWithoutPathExpansion( GetTypeName(CONTENT_SETTINGS_TYPE_PLUGINS), CONTENT_SETTING_ALLOW); @@ -763,7 +768,7 @@ TEST_F(PrefProviderTest, IncognitoInheritsValueMap) { // Non-OTR provider, Non-OTR iterator has one setting (pattern 1). { - scoped_ptr<RuleIterator> it (normal_provider.GetRuleIterator( + scoped_ptr<RuleIterator> it(normal_provider.GetRuleIterator( CONTENT_SETTINGS_TYPE_IMAGES, std::string(), false)); EXPECT_TRUE(it->HasNext()); EXPECT_EQ(pattern_1, it->Next().primary_pattern); diff --git a/chrome/browser/engagement/site_engagement_service.cc b/chrome/browser/engagement/site_engagement_service.cc index abe96bb..2885fbf 100644 --- a/chrome/browser/engagement/site_engagement_service.cc +++ b/chrome/browser/engagement/site_engagement_service.cc @@ -9,23 +9,67 @@ #include "base/command_line.h" #include "base/time/clock.h" +#include "base/values.h" #include "chrome/browser/engagement/site_engagement_helper.h" #include "chrome/browser/engagement/site_engagement_service_factory.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/chrome_switches.h" +#include "components/content_settings/core/browser/host_content_settings_map.h" +#include "components/content_settings/core/common/content_settings_pattern.h" #include "url/gurl.h" +namespace { + +// Delta within which to consider scores equal. +const double kScoreDelta = 0.001; + +// Delta within which to consider internal time values equal. Internal time +// values are in microseconds, so this delta comes out at one second. +const double kTimeDelta = 1000000; + +bool DoublesConsideredDifferent(double value1, double value2, double delta) { + double abs_difference = fabs(value1 - value2); + return abs_difference > delta; +} + +scoped_ptr<base::DictionaryValue> GetOriginDict( + HostContentSettingsMap* settings, + const GURL& origin_url) { + if (!settings) + return scoped_ptr<base::DictionaryValue>(); + + scoped_ptr<base::Value> value = settings->GetWebsiteSetting( + origin_url, origin_url, CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, + std::string(), NULL); + if (!value.get()) + return make_scoped_ptr(new base::DictionaryValue()); + + if (!value->IsType(base::Value::TYPE_DICTIONARY)) + return make_scoped_ptr(new base::DictionaryValue()); + + return make_scoped_ptr(static_cast<base::DictionaryValue*>(value.release())); +} + +} // namespace + +const char* SiteEngagementScore::kRawScoreKey = "rawScore"; +const char* SiteEngagementScore::kPointsAddedTodayKey = "pointsAddedToday"; +const char* SiteEngagementScore::kLastEngagementTimeKey = "lastEngagementTime"; + const double SiteEngagementScore::kMaxPoints = 100; const double SiteEngagementScore::kMaxPointsPerDay = 5; const double SiteEngagementScore::kNavigationPoints = 1; const int SiteEngagementScore::kDecayPeriodInDays = 7; const double SiteEngagementScore::kDecayPoints = 5; -SiteEngagementScore::SiteEngagementScore() : SiteEngagementScore(nullptr) { -} - -SiteEngagementScore::SiteEngagementScore(base::Clock* clock) - : clock_(clock), raw_score_(0), added_today_(0), last_engagement_() { +SiteEngagementScore::SiteEngagementScore(base::Clock* clock, + const base::DictionaryValue& settings) + : SiteEngagementScore(clock) { + settings.GetDouble(kRawScoreKey, &raw_score_); + settings.GetDouble(kPointsAddedTodayKey, &points_added_today_); + double internal_time; + if (settings.GetDouble(kLastEngagementTimeKey, &internal_time)) + last_engagement_time_ = base::Time::FromInternalValue(internal_time); } SiteEngagementScore::~SiteEngagementScore() { @@ -40,28 +84,62 @@ void SiteEngagementScore::AddPoints(double points) { // since the last update. raw_score_ = DecayedScore(); - base::Time now = Now(); - if (!last_engagement_.is_null() && - now.LocalMidnight() != last_engagement_.LocalMidnight()) { - added_today_ = 0; + base::Time now = clock_->Now(); + if (!last_engagement_time_.is_null() && + now.LocalMidnight() != last_engagement_time_.LocalMidnight()) { + points_added_today_ = 0; } double to_add = - std::min(kMaxPoints - raw_score_, kMaxPointsPerDay - added_today_); + std::min(kMaxPoints - raw_score_, kMaxPointsPerDay - points_added_today_); to_add = std::min(to_add, points); - added_today_ += to_add; + points_added_today_ += to_add; raw_score_ += to_add; - last_engagement_ = now; + last_engagement_time_ = now; } +bool SiteEngagementScore::UpdateSettings(base::DictionaryValue* settings) { + double raw_score_orig = 0; + double points_added_today_orig = 0; + double last_engagement_time_internal_orig = 0; + + settings->GetDouble(kRawScoreKey, &raw_score_orig); + settings->GetDouble(kPointsAddedTodayKey, &points_added_today_orig); + settings->GetDouble(kLastEngagementTimeKey, + &last_engagement_time_internal_orig); + bool changed = + DoublesConsideredDifferent(raw_score_orig, raw_score_, kScoreDelta) || + DoublesConsideredDifferent(points_added_today_orig, points_added_today_, + kScoreDelta) || + DoublesConsideredDifferent(last_engagement_time_internal_orig, + last_engagement_time_.ToInternalValue(), + kTimeDelta); + + if (!changed) + return false; + + settings->SetDouble(kRawScoreKey, raw_score_); + settings->SetDouble(kPointsAddedTodayKey, points_added_today_); + settings->SetDouble(kLastEngagementTimeKey, + last_engagement_time_.ToInternalValue()); + + return true; +} + +SiteEngagementScore::SiteEngagementScore(base::Clock* clock) + : clock_(clock), + raw_score_(0), + points_added_today_(0), + last_engagement_time_() {} + double SiteEngagementScore::DecayedScore() const { // Note that users can change their clock, so from this system's perspective // time can go backwards. If that does happen and the system detects that the // current day is earlier than the last engagement, no decay (or growth) is // applied. - int days_since_engagement = (Now() - last_engagement_).InDays(); + int days_since_engagement = (clock_->Now() - last_engagement_time_).InDays(); if (days_since_engagement < 0) return raw_score_; @@ -70,13 +148,6 @@ double SiteEngagementScore::DecayedScore() const { return std::max(0.0, decayed_score); } -base::Time SiteEngagementScore::Now() const { - if (clock_) - return clock_->Now(); - - return base::Time::Now(); -} - // static SiteEngagementService* SiteEngagementService::Get(Profile* profile) { return SiteEngagementServiceFactory::GetForProfile(profile); @@ -96,11 +167,28 @@ SiteEngagementService::~SiteEngagementService() { } void SiteEngagementService::HandleNavigation(const GURL& url) { - GURL origin = url.GetOrigin(); - scores_[origin].AddPoints(SiteEngagementScore::kNavigationPoints); + HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); + scoped_ptr<base::DictionaryValue> settings = GetOriginDict(settings_map, url); + SiteEngagementScore score(&clock_, *settings); + + score.AddPoints(SiteEngagementScore::kNavigationPoints); + if (score.UpdateSettings(settings.get())) { + ContentSettingsPattern pattern( + ContentSettingsPattern::FromURLNoWildcard(url)); + if (!pattern.IsValid()) + return; + + settings_map->SetWebsiteSetting(pattern, ContentSettingsPattern::Wildcard(), + CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, + std::string(), settings.release()); + } } int SiteEngagementService::GetScore(const GURL& url) { - return scores_[url.GetOrigin()].Score(); + HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); + scoped_ptr<base::DictionaryValue> settings = GetOriginDict(settings_map, url); + SiteEngagementScore score(&clock_, *settings); + + return score.Score(); } diff --git a/chrome/browser/engagement/site_engagement_service.h b/chrome/browser/engagement/site_engagement_service.h index 957dd9f..1eaa430 100644 --- a/chrome/browser/engagement/site_engagement_service.h +++ b/chrome/browser/engagement/site_engagement_service.h @@ -5,16 +5,15 @@ #ifndef CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_ #define CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_ -#include <map> - #include "base/gtest_prod_util.h" #include "base/macros.h" #include "base/memory/scoped_ptr.h" +#include "base/time/default_clock.h" #include "base/time/time.h" #include "components/keyed_service/core/keyed_service.h" namespace base { -class Clock; +class DictionaryValue; } class GURL; @@ -22,6 +21,11 @@ class Profile; class SiteEngagementScore { public: + // Keys used in the content settings dictionary. + static const char* kRawScoreKey; + static const char* kPointsAddedTodayKey; + static const char* kLastEngagementTimeKey; + // The maximum number of points that are allowed. static const double kMaxPoints; @@ -38,13 +42,20 @@ class SiteEngagementScore { // How much the score decays after every kDecayPeriodInDays. static const double kDecayPoints; - SiteEngagementScore(); + // The SiteEngagementService does not take ownership of |clock|. It is the + // responsibility of the caller to make sure |clock| outlives this + // SiteEngagementScore. + SiteEngagementScore(base::Clock* clock, + const base::DictionaryValue& settings); ~SiteEngagementScore(); double Score() const; - void AddPoints(double points); + // Updates the content settings dictionary |settings| with the current score + // fields. Returns true if |settings| changed, otherwise return false. + bool UpdateSettings(base::DictionaryValue* settings); + private: friend class SiteEngagementScoreTest; @@ -54,12 +65,8 @@ class SiteEngagementScore { // Determine the score, accounting for any decay. double DecayedScore() const; - // Gets the current time. Uses |clock_| if not null, otherwise just uses - // Time::Now(). - base::Time Now() const; - - // The clock used to vend times. Only used in tests, where it enables time - // travelling! Owned by any tests which use it. + // The clock used to vend times. Enables time travelling in tests. Owned by + // the SiteEngagementService. base::Clock* clock_; // |raw_score_| is the score before any decay is applied. @@ -67,12 +74,14 @@ class SiteEngagementScore { // The points added 'today' are tracked to avoid adding more than // kMaxPointsPerDay on any one day. 'Today' is defined in local time. - double added_today_; + double points_added_today_; // The last time the score was updated for engagement. Used in conjunction - // with |added_today_| to avoid adding more than kMaxPointsPerDay on any one - // day. - base::Time last_engagement_; + // with |points_added_today_| to avoid adding more than kMaxPointsPerDay on + // any one day. + base::Time last_engagement_time_; + + DISALLOW_COPY_AND_ASSIGN(SiteEngagementScore); }; // Stores and retrieves the engagement score of an origin. @@ -105,8 +114,8 @@ class SiteEngagementService : public KeyedService { private: Profile* profile_; - // Temporary non-persistent score database for testing. - std::map<GURL, SiteEngagementScore> scores_; + // The clock used to vend times. + base::DefaultClock clock_; DISALLOW_COPY_AND_ASSIGN(SiteEngagementService); }; diff --git a/chrome/browser/engagement/site_engagement_service_unittest.cc b/chrome/browser/engagement/site_engagement_service_unittest.cc index 7a6e4e4..0bc9543 100644 --- a/chrome/browser/engagement/site_engagement_service_unittest.cc +++ b/chrome/browser/engagement/site_engagement_service_unittest.cc @@ -4,6 +4,7 @@ #include "base/command_line.h" #include "base/test/simple_test_clock.h" +#include "base/values.h" #include "chrome/browser/engagement/site_engagement_helper.h" #include "chrome/browser/engagement/site_engagement_service.h" #include "chrome/browser/engagement/site_engagement_service_factory.h" @@ -42,6 +43,47 @@ class SiteEngagementScoreTest : public testing::Test { SiteEngagementScoreTest() : score_(&test_clock_) {} protected: + void VerifyScore(const SiteEngagementScore& score, + double expected_raw_score, + double expected_points_added_today, + base::Time expected_last_engagement_time) { + EXPECT_EQ(expected_raw_score, score.raw_score_); + EXPECT_EQ(expected_points_added_today, score.points_added_today_); + EXPECT_EQ(expected_last_engagement_time, score.last_engagement_time_); + } + + void UpdateScore(SiteEngagementScore* score, + double raw_score, + double points_added_today, + base::Time last_engagement_time) { + score->raw_score_ = raw_score; + score->points_added_today_ = points_added_today; + score->last_engagement_time_ = last_engagement_time; + } + + void TestScoreInitializesAndUpdates( + base::DictionaryValue* settings_dict, + double expected_raw_score, + double expected_points_added_today, + base::Time expected_last_engagement_time) { + SiteEngagementScore initial_score(&test_clock_, *settings_dict); + VerifyScore(initial_score, expected_raw_score, expected_points_added_today, + expected_last_engagement_time); + + // Updating the settings dict should return false, as the score shouldn't + // have changed at this point. + EXPECT_FALSE(initial_score.UpdateSettings(settings_dict)); + + // Update the score to new values and verify it updates the settings dict + // correctly. + base::Time different_day = + GetReferenceTime() + base::TimeDelta::FromDays(1); + UpdateScore(&initial_score, 5, 10, different_day); + EXPECT_TRUE(initial_score.UpdateSettings(settings_dict)); + SiteEngagementScore updated_score(&test_clock_, *settings_dict); + VerifyScore(updated_score, 5, 10, different_day); + } + base::SimpleTestClock test_clock_; SiteEngagementScore score_; }; @@ -238,6 +280,34 @@ TEST_F(SiteEngagementScoreTest, GoBackInTime) { EXPECT_EQ(2 * SiteEngagementScore::kMaxPointsPerDay, score_.Score()); } +// Test that scores are read / written correctly from / to empty settings +// dictionaries. +TEST_F(SiteEngagementScoreTest, EmptyDictionary) { + base::DictionaryValue dict; + TestScoreInitializesAndUpdates(&dict, 0, 0, base::Time()); +} + +// Test that scores are read / written correctly from / to partially empty +// settings dictionaries. +TEST_F(SiteEngagementScoreTest, PartiallyEmptyDictionary) { + base::DictionaryValue dict; + dict.SetDouble(SiteEngagementScore::kPointsAddedTodayKey, 2); + + TestScoreInitializesAndUpdates(&dict, 0, 2, base::Time()); +} + +// Test that scores are read / written correctly from / to populated settings +// dictionaries. +TEST_F(SiteEngagementScoreTest, PopulatedDictionary) { + base::DictionaryValue dict; + dict.SetDouble(SiteEngagementScore::kRawScoreKey, 1); + dict.SetDouble(SiteEngagementScore::kPointsAddedTodayKey, 2); + dict.SetDouble(SiteEngagementScore::kLastEngagementTimeKey, + GetReferenceTime().ToInternalValue()); + + TestScoreInitializesAndUpdates(&dict, 1, 2, GetReferenceTime()); +} + using SiteEngagementServiceTest = BrowserWithTestWindowTest; // Tests that the Site Engagement service is hooked up properly to navigations diff --git a/chrome/browser/extensions/api/browsing_data/browsing_data_test.cc b/chrome/browser/extensions/api/browsing_data/browsing_data_test.cc index 291f2a0..d4ccdcd 100644 --- a/chrome/browser/extensions/api/browsing_data/browsing_data_test.cc +++ b/chrome/browser/extensions/api/browsing_data/browsing_data_test.cc @@ -318,7 +318,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, RemoveBrowsingDataAll) { BrowsingDataRemover::REMOVE_PASSWORDS) & // TODO(benwells): implement clearing of site usage data via the browsing // data API. https://crbug.com/500801. - ~BrowsingDataRemover::REMOVE_APP_BANNER_DATA & + ~BrowsingDataRemover::REMOVE_SITE_USAGE_DATA & // We can't remove plugin data inside a test profile. ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask()); } @@ -495,7 +495,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionSimple) { // Test cookie and app data settings. IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionSiteData) { int site_data_no_usage = BrowsingDataRemover::REMOVE_SITE_DATA & - ~BrowsingDataRemover::REMOVE_APP_BANNER_DATA; + ~BrowsingDataRemover::REMOVE_SITE_USAGE_DATA; int site_data_no_plugins = site_data_no_usage & ~BrowsingDataRemover::REMOVE_PLUGIN_DATA; @@ -521,7 +521,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionSiteData) { // Test an arbitrary assortment of settings. IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionAssorted) { int site_data_no_plugins = BrowsingDataRemover::REMOVE_SITE_DATA & - ~BrowsingDataRemover::REMOVE_APP_BANNER_DATA & + ~BrowsingDataRemover::REMOVE_SITE_USAGE_DATA & ~BrowsingDataRemover::REMOVE_PLUGIN_DATA; SetPrefsAndVerifySettings( diff --git a/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.mm b/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.mm index e934d903..aba7d53 100644 --- a/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.mm +++ b/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.mm @@ -286,6 +286,7 @@ class ContentSettingBubbleWebContentsObserverBridge case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING: case CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS: case CONTENT_SETTINGS_TYPE_APP_BANNER: + case CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT: NOTREACHED(); } if ((self = [super initWithWindowNibPath:nibPath diff --git a/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa_unittest.mm b/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa_unittest.mm index 2d31814..f7f278b 100644 --- a/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa_unittest.mm +++ b/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa_unittest.mm @@ -114,7 +114,8 @@ TEST_F(ContentSettingBubbleControllerTest, Init) { i == CONTENT_SETTINGS_TYPE_MIDI_SYSEX || i == CONTENT_SETTINGS_TYPE_PUSH_MESSAGING || i == CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS || - i == CONTENT_SETTINGS_TYPE_APP_BANNER) { + i == CONTENT_SETTINGS_TYPE_APP_BANNER || + i == CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT) { // These types have no bubble. continue; } diff --git a/chrome/browser/ui/webui/options/content_settings_handler.cc b/chrome/browser/ui/webui/options/content_settings_handler.cc index 3fd9b0e..48aaf4c 100644 --- a/chrome/browser/ui/webui/options/content_settings_handler.cc +++ b/chrome/browser/ui/webui/options/content_settings_handler.cc @@ -777,6 +777,11 @@ void ContentSettingsHandler::UpdateExceptionsViewFromModel( // track whether app banners should be shown or not, and is not a user // visible content setting. break; + case CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT: + // The content settings type CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT is used + // to track engagement with various origins, and is not a user visible + // content setting. + break; default: UpdateExceptionsViewFromHostContentSettingsMap(type); break; @@ -800,6 +805,7 @@ void ContentSettingsHandler::UpdateOTRExceptionsViewFromModel( case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: case CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS: case CONTENT_SETTINGS_TYPE_APP_BANNER: + case CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT: break; default: UpdateExceptionsViewFromOTRHostContentSettingsMap(type); diff --git a/components/content_settings/core/browser/content_settings_default_provider.cc b/components/content_settings/core/browser/content_settings_default_provider.cc index 587e892..45a9fd6 100644 --- a/components/content_settings/core/browser/content_settings_default_provider.cc +++ b/components/content_settings/core/browser/content_settings_default_provider.cc @@ -36,9 +36,8 @@ struct DefaultContentSettingInfo { const ContentSetting default_value; }; -// The corresponding preference, default value and syncability for each -// default content setting. This array must be kept in sync with the enum -// |ContentSettingsType|. +// The corresponding preference and default value for each default content +// setting. This array must be kept in sync with the enum |ContentSettingsType|. const DefaultContentSettingInfo kDefaultSettings[] = { {prefs::kDefaultCookiesSetting, CONTENT_SETTING_ALLOW}, {prefs::kDefaultImagesSetting, CONTENT_SETTING_ALLOW}, @@ -65,7 +64,8 @@ const DefaultContentSettingInfo kDefaultSettings[] = { #elif defined(OS_ANDROID) || defined(OS_CHROMEOS) {prefs::kDefaultProtectedMediaIdentifierSetting, CONTENT_SETTING_ASK}, #endif - {prefs::kDefaultAppBannerSetting, CONTENT_SETTING_DEFAULT} + {prefs::kDefaultAppBannerSetting, CONTENT_SETTING_DEFAULT}, + {prefs::kDefaultSiteEngagementSetting, CONTENT_SETTING_DEFAULT}, }; static_assert(arraysize(kDefaultSettings) == CONTENT_SETTINGS_NUM_TYPES, "kDefaultSettings should have CONTENT_SETTINGS_NUM_TYPES " diff --git a/components/content_settings/core/browser/content_settings_policy_provider.cc b/components/content_settings/core/browser/content_settings_policy_provider.cc index 6be1a81..7b3faee 100644 --- a/components/content_settings/core/browser/content_settings_policy_provider.cc +++ b/components/content_settings/core/browser/content_settings_policy_provider.cc @@ -28,25 +28,26 @@ const char* kPrefToManageType[] = { prefs::kManagedDefaultPopupsSetting, prefs::kManagedDefaultGeolocationSetting, prefs::kManagedDefaultNotificationsSetting, - NULL, // No policy for default value of content type auto-select-certificate - NULL, // No policy for default value of fullscreen requests - NULL, // No policy for default value of mouse lock requests - NULL, // No policy for default value of mixed script blocking - NULL, // The MEDIASTREAM setting is deprecated + nullptr, // No policy for default value of auto select certificate + nullptr, // No policy for default value of fullscreen requests + nullptr, // No policy for default value of mouse lock requests + nullptr, // No policy for default value of mixed script blocking + nullptr, // The MEDIASTREAM setting is deprecated prefs::kManagedDefaultMediaStreamSetting, prefs::kManagedDefaultMediaStreamSetting, - NULL, // No policy for default value of protocol handlers - NULL, // No policy for default value of PPAPI broker - NULL, // No policy for default value of multiple automatic downloads - NULL, // No policy for default value of MIDI system exclusive requests - NULL, // No policy for default value of push messaging requests - NULL, // No policy for default value of SSL certificate decisions + nullptr, // No policy for default value of protocol handlers + nullptr, // No policy for default value of PPAPI broker + nullptr, // No policy for default value of multiple automatic downloads + nullptr, // No policy for default value of MIDI system exclusive requests + nullptr, // No policy for default value of push messaging requests + nullptr, // No policy for default value of SSL certificate decisions #if defined(OS_WIN) - NULL, // No policy for default value of "switch to desktop" + nullptr, // No policy for default value of "switch to desktop" #elif defined(OS_ANDROID) || defined(OS_CHROMEOS) - NULL, // No policy for default value of protected media identifier + nullptr, // No policy for default value of protected media identifier #endif - NULL, // No policy for default value of app banners + nullptr, // No policy for default value of app banners + nullptr, // No policy for default value of site engagement }; static_assert(arraysize(kPrefToManageType) == CONTENT_SETTINGS_NUM_TYPES, "kPrefToManageType should have CONTENT_SETTINGS_NUM_TYPES " @@ -226,7 +227,7 @@ void PolicyProvider::GetContentSettingsFromPreferences( DCHECK(pref); DCHECK(pref->IsManaged()); - const base::ListValue* pattern_str_list = NULL; + const base::ListValue* pattern_str_list = nullptr; if (!pref->GetValue()->GetAsList(&pattern_str_list)) { NOTREACHED(); return; @@ -275,7 +276,7 @@ void PolicyProvider::GetAutoSelectCertificateSettingsFromPreferences( DCHECK(pref); DCHECK(pref->IsManaged()); - const base::ListValue* pattern_filter_str_list = NULL; + const base::ListValue* pattern_filter_str_list = nullptr; if (!pref->GetValue()->GetAsList(&pattern_filter_str_list)) { NOTREACHED(); return; @@ -318,7 +319,7 @@ void PolicyProvider::GetAutoSelectCertificateSettingsFromPreferences( std::string pattern_str; bool pattern_read = pattern_filter_pair->GetStringWithoutPathExpansion( "pattern", &pattern_str); - base::DictionaryValue* cert_filter = NULL; + base::DictionaryValue* cert_filter = nullptr; pattern_filter_pair->GetDictionaryWithoutPathExpansion("filter", &cert_filter); if (!pattern_read || !cert_filter) { @@ -348,7 +349,7 @@ void PolicyProvider::GetAutoSelectCertificateSettingsFromPreferences( void PolicyProvider::ReadManagedDefaultSettings() { for (size_t type = 0; type < arraysize(kPrefToManageType); ++type) { - if (kPrefToManageType[type] == NULL) { + if (kPrefToManageType[type] == nullptr) { continue; } UpdateManagedDefaultSetting(ContentSettingsType(type)); @@ -413,7 +414,7 @@ void PolicyProvider::ShutdownOnUIThread() { if (!prefs_) return; pref_change_registrar_.RemoveAll(); - prefs_ = NULL; + prefs_ = nullptr; } void PolicyProvider::OnPreferenceChanged(const std::string& name) { diff --git a/components/content_settings/core/browser/content_settings_pref_provider.cc b/components/content_settings/core/browser/content_settings_pref_provider.cc index 8f8d8d3..118cabf 100644 --- a/components/content_settings/core/browser/content_settings_pref_provider.cc +++ b/components/content_settings/core/browser/content_settings_pref_provider.cc @@ -93,7 +93,8 @@ const char* kContentSettingsExceptionsPrefs[] = { #elif defined(OS_ANDROID) || defined(OS_CHROMEOS) prefs::kContentSettingsProtectedMediaIdentifierPatternPairs, #endif - prefs::kContentSettingsAppBannerPatternPairs + prefs::kContentSettingsAppBannerPatternPairs, + prefs::kContentSettingsSiteEngagementPatternPairs, }; static_assert(arraysize(kContentSettingsExceptionsPrefs) == CONTENT_SETTINGS_NUM_TYPES, diff --git a/components/content_settings/core/browser/content_settings_utils.cc b/components/content_settings/core/browser/content_settings_utils.cc index eed02d9..fc4b47a 100644 --- a/components/content_settings/core/browser/content_settings_utils.cc +++ b/components/content_settings/core/browser/content_settings_utils.cc @@ -50,6 +50,7 @@ const char* kTypeNames[] = { "protected-media-identifier", #endif "app-banner", + "site-engagement", }; static_assert(arraysize(kTypeNames) == CONTENT_SETTINGS_NUM_TYPES, "kTypeNames should have CONTENT_SETTINGS_NUM_TYPES elements"); diff --git a/components/content_settings/core/browser/host_content_settings_map.cc b/components/content_settings/core/browser/host_content_settings_map.cc index 9b906cf..b76fd31 100644 --- a/components/content_settings/core/browser/host_content_settings_map.cc +++ b/components/content_settings/core/browser/host_content_settings_map.cc @@ -567,12 +567,13 @@ bool HostContentSettingsMap::IsSettingAllowedForType( bool HostContentSettingsMap::ContentTypeHasCompoundValue( ContentSettingsType type) { // Values for content type CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, - // CONTENT_SETTINGS_TYPE_APP_BANNER, and + // CONTENT_SETTINGS_TYPE_APP_BANNER, CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT and // CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS are of type dictionary/map. // Compound types like dictionaries can't be mapped to the type // |ContentSetting|. return (type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE || type == CONTENT_SETTINGS_TYPE_APP_BANNER || + type == CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT || type == CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS); } diff --git a/components/content_settings/core/common/content_settings.cc b/components/content_settings/core/common/content_settings.cc index 91dd091..4840aa2 100644 --- a/components/content_settings/core/common/content_settings.cc +++ b/components/content_settings/core/common/content_settings.cc @@ -66,6 +66,8 @@ ContentSettingsTypeHistogram ContentSettingTypeToHistogramValue( #endif case CONTENT_SETTINGS_TYPE_APP_BANNER: return CONTENT_SETTINGS_TYPE_HISTOGRAM_APP_BANNER; + case CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT: + return CONTENT_SETTINGS_TYPE_HISTOGRAM_SITE_ENGAGEMENT; case CONTENT_SETTINGS_NUM_TYPES: return CONTENT_SETTINGS_TYPE_HISTOGRAM_INVALID; } @@ -104,6 +106,7 @@ bool IsContentSettingsTypeSyncable(ContentSettingsType content_setting) { case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: #endif case CONTENT_SETTINGS_TYPE_APP_BANNER: + case CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT: return false; case CONTENT_SETTINGS_TYPE_DEFAULT: @@ -116,7 +119,8 @@ bool IsContentSettingsTypeSyncable(ContentSettingsType content_setting) { } bool IsContentSettingsTypeLossy(ContentSettingsType content_setting) { - return content_setting == CONTENT_SETTINGS_TYPE_APP_BANNER; + return content_setting == CONTENT_SETTINGS_TYPE_APP_BANNER || + content_setting == CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT; } ContentSettingPatternSource::ContentSettingPatternSource( diff --git a/components/content_settings/core/common/content_settings_types.h b/components/content_settings/core/common/content_settings_types.h index b1cf04c..155cfd9 100644 --- a/components/content_settings/core/common/content_settings_types.h +++ b/components/content_settings/core/common/content_settings_types.h @@ -47,6 +47,7 @@ enum ContentSettingsType { CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, #endif CONTENT_SETTINGS_TYPE_APP_BANNER, + CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, CONTENT_SETTINGS_NUM_TYPES, }; @@ -79,6 +80,7 @@ enum ContentSettingsTypeHistogram { CONTENT_SETTINGS_TYPE_HISTOGRAM_METRO_SWITCH_TO_DESKTOP, CONTENT_SETTINGS_TYPE_HISTOGRAM_PROTECTED_MEDIA_IDENTIFIER, CONTENT_SETTINGS_TYPE_HISTOGRAM_APP_BANNER, + CONTENT_SETTINGS_TYPE_HISTOGRAM_SITE_ENGAGEMENT, CONTENT_SETTINGS_HISTOGRAM_NUM_TYPES, }; diff --git a/components/content_settings/core/common/pref_names.cc b/components/content_settings/core/common/pref_names.cc index bffdc49..c8de238 100644 --- a/components/content_settings/core/common/pref_names.cc +++ b/components/content_settings/core/common/pref_names.cc @@ -79,6 +79,8 @@ const char kDefaultProtectedMediaIdentifierSetting[] = #endif const char kDefaultAppBannerSetting[] = "profile.default_content_setting_values.app_banner"; +const char kDefaultSiteEngagementSetting[] = + "profile.default_content_setting_values.site_engagement"; // Boolean indicating whether the media stream default setting had been // migrated into two separate microphone and camera settings. @@ -140,6 +142,8 @@ const char kContentSettingsProtectedMediaIdentifierPatternPairs[] = #endif const char kContentSettingsAppBannerPatternPairs[] = "profile.content_settings.exceptions.app_banner"; +const char kContentSettingsSiteEngagementPatternPairs[] = + "profile.content_settings.exceptions.site_engagement"; // Whether the patern pairs have been migrated from the deprecated aggregate // preference |kContentSettingsPatternPairs| to the separate preferences diff --git a/components/content_settings/core/common/pref_names.h b/components/content_settings/core/common/pref_names.h index 69591d5..3ee44b2 100644 --- a/components/content_settings/core/common/pref_names.h +++ b/components/content_settings/core/common/pref_names.h @@ -42,6 +42,7 @@ extern const char kDefaultMetroSwitchToDesktopSetting[]; extern const char kDefaultProtectedMediaIdentifierSetting[]; #endif extern const char kDefaultAppBannerSetting[]; +extern const char kDefaultSiteEngagementSetting[]; extern const char kMigratedDefaultMediaStreamSetting[]; @@ -72,6 +73,7 @@ extern const char kContentSettingsMetroSwitchToDesktopPatternPairs[]; extern const char kContentSettingsProtectedMediaIdentifierPatternPairs[]; #endif extern const char kContentSettingsAppBannerPatternPairs[]; +extern const char kContentSettingsSiteEngagementPatternPairs[]; extern const char kMigratedContentSettingsPatternPairs[]; |