Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Maps hostnames to custom content settings. Written on the UI thread and read | 5 // Maps hostnames to custom content settings. Written on the UI thread and read |
| 6 // on any thread. One instance per profile. | 6 // on any thread. One instance per profile. |
| 7 | 7 |
| 8 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ | 8 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ |
| 9 #define CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ | 9 #define CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ |
| 10 | 10 |
| 11 #include <map> | 11 #include <map> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/prefs/pref_change_registrar.h" | 17 #include "base/prefs/pref_change_registrar.h" |
| 18 #include "base/threading/platform_thread.h" | 18 #include "base/threading/platform_thread.h" |
| 19 #include "base/tuple.h" | 19 #include "base/tuple.h" |
| 20 #include "chrome/browser/content_settings/content_settings_observer.h" | 20 #include "chrome/browser/content_settings/content_settings_observer.h" |
| 21 #include "chrome/common/content_settings.h" | 21 #include "chrome/common/content_settings.h" |
| 22 #include "chrome/common/content_settings_pattern.h" | 22 #include "chrome/common/content_settings_pattern.h" |
| 23 #include "chrome/common/content_settings_types.h" | 23 #include "chrome/common/content_settings_types.h" |
| 24 | 24 |
| 25 class ExtensionService; | 25 class ExtensionService; |
| 26 class GURL; | 26 class GURL; |
| 27 class PrefService; | 27 class PrefService; |
| 28 | 28 |
| 29 namespace base { | 29 namespace base { |
| 30 class Clock; | |
| 30 class Value; | 31 class Value; |
| 31 } | 32 } |
| 32 | 33 |
| 33 namespace content_settings { | 34 namespace content_settings { |
| 34 class ProviderInterface; | 35 class ProviderInterface; |
| 35 } | 36 } |
| 36 | 37 |
| 37 namespace user_prefs { | 38 namespace user_prefs { |
| 38 class PrefRegistrySyncable; | 39 class PrefRegistrySyncable; |
| 39 } | 40 } |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 // Returns the ProviderType associated with the given source string. | 193 // Returns the ProviderType associated with the given source string. |
| 193 // TODO(estade): I regret adding this. At the moment there are no legitimate | 194 // TODO(estade): I regret adding this. At the moment there are no legitimate |
| 194 // uses. We should stick to ProviderType rather than string so we don't have | 195 // uses. We should stick to ProviderType rather than string so we don't have |
| 195 // to convert backwards. | 196 // to convert backwards. |
| 196 static ProviderType GetProviderTypeFromSource(const std::string& source); | 197 static ProviderType GetProviderTypeFromSource(const std::string& source); |
| 197 | 198 |
| 198 bool is_off_the_record() const { | 199 bool is_off_the_record() const { |
| 199 return is_off_the_record_; | 200 return is_off_the_record_; |
| 200 } | 201 } |
| 201 | 202 |
| 203 // Returns a single |ContentSetting| which applies to the given URLs, just as | |
| 204 // |GetContentSetting| does. If the setting is allowed, it also records the | |
| 205 // last usage to preferences. | |
| 206 // | |
| 207 // This should only be called on the UI thread, unlike |GetContentSetting|. | |
| 208 ContentSetting GetContentSettingAndMaybeUpdateLastUsage( | |
| 209 const GURL& primary_url, | |
|
Michael van Ouwerkerk
2014/07/01 12:53:36
Do primary_url and secondary_url correspond to req
Daniel Nishi
2014/07/01 18:37:48
That's how it seems to work from Geolocations perm
Michael van Ouwerkerk
2014/07/02 18:51:15
Right. It's for distinguishing between iframes and
| |
| 210 const GURL& secondary_url, | |
| 211 ContentSettingsType content_type, | |
| 212 const std::string& resource_identifier); | |
| 213 | |
| 214 void UpdateLastUsage(const GURL& primary_url, | |
|
Michael van Ouwerkerk
2014/07/01 11:02:23
Please document this public method.
Daniel Nishi
2014/07/01 18:37:48
Done.
| |
| 215 const GURL& secondary_url, | |
| 216 ContentSettingsType content_type); | |
| 217 | |
| 218 // Returns the last time the pattern that matches the URL has requested | |
| 219 // permission for the |content_type| setting. | |
| 220 base::Time GetLastUsage(const GURL& primary_url, | |
| 221 const GURL& secondary_url, | |
| 222 ContentSettingsType content_type); | |
| 223 | |
| 224 // Returns the last time the pattern has requested permission for the | |
| 225 // |content_type| setting. | |
| 226 base::Time GetLastUsageByPattern( | |
| 227 const ContentSettingsPattern& primary_pattern, | |
| 228 const ContentSettingsPattern& secondary_pattern, | |
| 229 ContentSettingsType content_type); | |
| 230 | |
| 231 // Passes ownership of |clock|. | |
| 232 void SetPrefClockForTesting(base::Clock* clock); | |
| 233 | |
| 202 private: | 234 private: |
| 203 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; | 235 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; |
| 204 friend class HostContentSettingsMapTest_NonDefaultSettings_Test; | 236 friend class HostContentSettingsMapTest_NonDefaultSettings_Test; |
| 205 | 237 |
| 206 typedef std::map<ProviderType, content_settings::ProviderInterface*> | 238 typedef std::map<ProviderType, content_settings::ProviderInterface*> |
| 207 ProviderMap; | 239 ProviderMap; |
| 208 typedef ProviderMap::iterator ProviderIterator; | 240 typedef ProviderMap::iterator ProviderIterator; |
| 209 typedef ProviderMap::const_iterator ConstProviderIterator; | 241 typedef ProviderMap::const_iterator ConstProviderIterator; |
| 210 | 242 |
| 211 virtual ~HostContentSettingsMap(); | 243 virtual ~HostContentSettingsMap(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 229 const std::string& resource_identifier, | 261 const std::string& resource_identifier, |
| 230 ContentSettingsForOneType* settings, | 262 ContentSettingsForOneType* settings, |
| 231 bool incognito) const; | 263 bool incognito) const; |
| 232 | 264 |
| 233 // Call UsedContentSettingsProviders() whenever you access | 265 // Call UsedContentSettingsProviders() whenever you access |
| 234 // content_settings_providers_ (apart from initialization and | 266 // content_settings_providers_ (apart from initialization and |
| 235 // teardown), so that we can DCHECK in RegisterExtensionService that | 267 // teardown), so that we can DCHECK in RegisterExtensionService that |
| 236 // it is not being called too late. | 268 // it is not being called too late. |
| 237 void UsedContentSettingsProviders() const; | 269 void UsedContentSettingsProviders() const; |
| 238 | 270 |
| 271 // Convenience method for updating the last usage of a content type for a | |
| 272 // pattern. | |
| 273 void UpdateLastUsageByPattern(const ContentSettingsPattern& primary_pattern, | |
| 274 const ContentSettingsPattern& secondary_pattern, | |
| 275 ContentSettingsType content_type); | |
| 276 | |
| 239 #ifndef NDEBUG | 277 #ifndef NDEBUG |
| 240 // This starts as the thread ID of the thread that constructs this | 278 // This starts as the thread ID of the thread that constructs this |
| 241 // object, and remains until used by a different thread, at which | 279 // object, and remains until used by a different thread, at which |
| 242 // point it is set to base::kInvalidThreadId. This allows us to | 280 // point it is set to base::kInvalidThreadId. This allows us to |
| 243 // DCHECK on unsafe usage of content_settings_providers_ (they | 281 // DCHECK on unsafe usage of content_settings_providers_ (they |
| 244 // should be set up on a single thread, after which they are | 282 // should be set up on a single thread, after which they are |
| 245 // immutable). | 283 // immutable). |
| 246 mutable base::PlatformThreadId used_from_thread_id_; | 284 mutable base::PlatformThreadId used_from_thread_id_; |
| 247 #endif | 285 #endif |
| 248 | 286 |
| 249 // Weak; owned by the Profile. | 287 // Weak; owned by the Profile. |
| 250 PrefService* prefs_; | 288 PrefService* prefs_; |
| 251 | 289 |
| 252 // Whether this settings map is for an OTR session. | 290 // Whether this settings map is for an OTR session. |
| 253 bool is_off_the_record_; | 291 bool is_off_the_record_; |
| 254 | 292 |
| 255 // Content setting providers. This is only modified at construction | 293 // Content setting providers. This is only modified at construction |
| 256 // time and by RegisterExtensionService, both of which should happen | 294 // time and by RegisterExtensionService, both of which should happen |
| 257 // before any other uses of it. | 295 // before any other uses of it. |
| 258 ProviderMap content_settings_providers_; | 296 ProviderMap content_settings_providers_; |
| 259 | 297 |
| 260 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); | 298 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); |
| 261 }; | 299 }; |
| 262 | 300 |
| 263 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ | 301 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ |
| OLD | NEW |