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

Unified Diff: chrome/browser/content_settings/host_content_settings_map.cc

Issue 356543003: Audit the last usage of Geolocation and Notification permissions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Jam nits. Created 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/content_settings/host_content_settings_map.cc
diff --git a/chrome/browser/content_settings/host_content_settings_map.cc b/chrome/browser/content_settings/host_content_settings_map.cc
index a1ff14c776a34c7e224d358a578ad0037efcfcf0..2c8d92c04fa2c66300c3da2099aa9f03e687f0a3 100644
--- a/chrome/browser/content_settings/host_content_settings_map.cc
+++ b/chrome/browser/content_settings/host_content_settings_map.cc
@@ -12,6 +12,7 @@
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/time/clock.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/content_settings/content_settings_custom_extension_provider.h"
#include "chrome/browser/content_settings/content_settings_default_provider.h"
@@ -298,6 +299,13 @@ void HostContentSettingsMap::SetContentSetting(
const std::string& resource_identifier,
ContentSetting setting) {
DCHECK(!ContentTypeHasCompoundValue(content_type));
+
+ if (setting == CONTENT_SETTING_ALLOW &&
+ (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION ||
+ content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS)) {
+ UpdateLastUsageByPattern(primary_pattern, secondary_pattern, content_type);
+ }
+
base::Value* value = NULL;
if (setting != CONTENT_SETTING_DEFAULT)
value = base::Value::CreateIntegerValue(setting);
@@ -308,6 +316,70 @@ void HostContentSettingsMap::SetContentSetting(
value);
}
+ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage(
+ const GURL& primary_url,
+ const GURL& secondary_url,
+ ContentSettingsType content_type,
+ const std::string& resource_identifier) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+
+ ContentSetting setting = GetContentSetting(
+ primary_url, secondary_url, content_type, resource_identifier);
+ if (setting == CONTENT_SETTING_ALLOW) {
+ UpdateLastUsageByPattern(
+ ContentSettingsPattern::FromURLNoWildcard(primary_url),
+ ContentSettingsPattern::FromURLNoWildcard(secondary_url),
+ content_type);
+ }
+ return setting;
+}
+
+void HostContentSettingsMap::UpdateLastUsage(const GURL& primary_url,
+ const GURL& secondary_url,
+ ContentSettingsType content_type) {
+ UpdateLastUsageByPattern(
+ ContentSettingsPattern::FromURLNoWildcard(primary_url),
+ ContentSettingsPattern::FromURLNoWildcard(secondary_url),
+ content_type);
+}
+
+void HostContentSettingsMap::UpdateLastUsageByPattern(
+ const ContentSettingsPattern& primary_pattern,
+ const ContentSettingsPattern& secondary_pattern,
+ ContentSettingsType content_type) {
+ UsedContentSettingsProviders();
+
+ GetPrefProvider()->UpdateLastUsage(
+ primary_pattern, secondary_pattern, content_type);
+}
+
+base::Time HostContentSettingsMap::GetLastUsage(
+ const GURL& primary_url,
+ const GURL& secondary_url,
+ ContentSettingsType content_type) {
+ return GetLastUsageByPattern(
+ ContentSettingsPattern::FromURLNoWildcard(primary_url),
+ ContentSettingsPattern::FromURLNoWildcard(secondary_url),
+ content_type);
+}
+
+base::Time HostContentSettingsMap::GetLastUsageByPattern(
+ const ContentSettingsPattern& primary_pattern,
+ const ContentSettingsPattern& secondary_pattern,
+ ContentSettingsType content_type) {
+ UsedContentSettingsProviders();
+
+ return GetPrefProvider()->GetLastUsage(
+ primary_pattern, secondary_pattern, content_type);
+}
+
+void HostContentSettingsMap::SetPrefClockForTesting(
+ scoped_ptr<base::Clock> clock) {
+ UsedContentSettingsProviders();
+
+ GetPrefProvider()->SetClockForTesting(clock.Pass());
+}
+
void HostContentSettingsMap::AddExceptionForURL(
const GURL& primary_url,
const GURL& secondary_url,
@@ -638,3 +710,8 @@ HostContentSettingsMap::ProviderType
NOTREACHED();
return DEFAULT_PROVIDER;
}
+
+content_settings::PrefProvider* HostContentSettingsMap::GetPrefProvider() {
+ return static_cast<content_settings::PrefProvider*>(
+ content_settings_providers_[PREF_PROVIDER]);
+}

Powered by Google App Engine
This is Rietveld 408576698