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

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: Update the utils. 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..14550014a217c2505067f6c5a52de40d439d3f17 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,72 @@ 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();
+
+ static_cast<content_settings::PrefProvider*>(
+ content_settings_providers_[PREF_PROVIDER])
Bernhard Bauer 2014/07/14 10:50:32 It might be worth adding a private helper method t
Daniel Nishi 2014/07/14 17:12:54 Done.
+ ->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 static_cast<content_settings::PrefProvider*>(
+ content_settings_providers_[PREF_PROVIDER])
+ ->GetLastUsage(primary_pattern, secondary_pattern, content_type);
+}
+
+void HostContentSettingsMap::SetPrefClockForTesting(base::Clock* clock) {
+ UsedContentSettingsProviders();
+
+ static_cast<content_settings::PrefProvider*>(
+ content_settings_providers_[PREF_PROVIDER])->SetClockForTesting(clock);
+}
+
void HostContentSettingsMap::AddExceptionForURL(
const GURL& primary_url,
const GURL& secondary_url,

Powered by Google App Engine
This is Rietveld 408576698