| 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; |
| 36 class PrefProvider; |
| 35 } | 37 } |
| 36 | 38 |
| 37 namespace user_prefs { | 39 namespace user_prefs { |
| 38 class PrefRegistrySyncable; | 40 class PrefRegistrySyncable; |
| 39 } | 41 } |
| 40 | 42 |
| 41 class HostContentSettingsMap | 43 class HostContentSettingsMap |
| 42 : public content_settings::Observer, | 44 : public content_settings::Observer, |
| 43 public base::RefCountedThreadSafe<HostContentSettingsMap> { | 45 public base::RefCountedThreadSafe<HostContentSettingsMap> { |
| 44 public: | 46 public: |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 // Returns the ProviderType associated with the given source string. | 194 // Returns the ProviderType associated with the given source string. |
| 193 // TODO(estade): I regret adding this. At the moment there are no legitimate | 195 // 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 | 196 // uses. We should stick to ProviderType rather than string so we don't have |
| 195 // to convert backwards. | 197 // to convert backwards. |
| 196 static ProviderType GetProviderTypeFromSource(const std::string& source); | 198 static ProviderType GetProviderTypeFromSource(const std::string& source); |
| 197 | 199 |
| 198 bool is_off_the_record() const { | 200 bool is_off_the_record() const { |
| 199 return is_off_the_record_; | 201 return is_off_the_record_; |
| 200 } | 202 } |
| 201 | 203 |
| 204 // Returns a single |ContentSetting| which applies to the given URLs, just as |
| 205 // |GetContentSetting| does. If the setting is allowed, it also records the |
| 206 // last usage to preferences. |
| 207 // |
| 208 // This should only be called on the UI thread, unlike |GetContentSetting|. |
| 209 ContentSetting GetContentSettingAndMaybeUpdateLastUsage( |
| 210 const GURL& primary_url, |
| 211 const GURL& secondary_url, |
| 212 ContentSettingsType content_type, |
| 213 const std::string& resource_identifier); |
| 214 |
| 215 // Sets the last time that a given content type has been used for the pattern |
| 216 // which matches the URLs to the current time. |
| 217 void UpdateLastUsage(const GURL& primary_url, |
| 218 const GURL& secondary_url, |
| 219 ContentSettingsType content_type); |
| 220 |
| 221 // Returns the last time the pattern that matches the URL has requested |
| 222 // permission for the |content_type| setting. |
| 223 base::Time GetLastUsage(const GURL& primary_url, |
| 224 const GURL& secondary_url, |
| 225 ContentSettingsType content_type); |
| 226 |
| 227 // Returns the last time the pattern has requested permission for the |
| 228 // |content_type| setting. |
| 229 base::Time GetLastUsageByPattern( |
| 230 const ContentSettingsPattern& primary_pattern, |
| 231 const ContentSettingsPattern& secondary_pattern, |
| 232 ContentSettingsType content_type); |
| 233 |
| 234 // Passes ownership of |clock|. |
| 235 void SetPrefClockForTesting(scoped_ptr<base::Clock> clock); |
| 236 |
| 202 private: | 237 private: |
| 203 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; | 238 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; |
| 204 friend class HostContentSettingsMapTest_NonDefaultSettings_Test; | 239 friend class HostContentSettingsMapTest_NonDefaultSettings_Test; |
| 205 | 240 |
| 206 typedef std::map<ProviderType, content_settings::ProviderInterface*> | 241 typedef std::map<ProviderType, content_settings::ProviderInterface*> |
| 207 ProviderMap; | 242 ProviderMap; |
| 208 typedef ProviderMap::iterator ProviderIterator; | 243 typedef ProviderMap::iterator ProviderIterator; |
| 209 typedef ProviderMap::const_iterator ConstProviderIterator; | 244 typedef ProviderMap::const_iterator ConstProviderIterator; |
| 210 | 245 |
| 211 virtual ~HostContentSettingsMap(); | 246 virtual ~HostContentSettingsMap(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 229 const std::string& resource_identifier, | 264 const std::string& resource_identifier, |
| 230 ContentSettingsForOneType* settings, | 265 ContentSettingsForOneType* settings, |
| 231 bool incognito) const; | 266 bool incognito) const; |
| 232 | 267 |
| 233 // Call UsedContentSettingsProviders() whenever you access | 268 // Call UsedContentSettingsProviders() whenever you access |
| 234 // content_settings_providers_ (apart from initialization and | 269 // content_settings_providers_ (apart from initialization and |
| 235 // teardown), so that we can DCHECK in RegisterExtensionService that | 270 // teardown), so that we can DCHECK in RegisterExtensionService that |
| 236 // it is not being called too late. | 271 // it is not being called too late. |
| 237 void UsedContentSettingsProviders() const; | 272 void UsedContentSettingsProviders() const; |
| 238 | 273 |
| 274 // Convenience method for updating the last usage of a content type for a |
| 275 // pattern. |
| 276 void UpdateLastUsageByPattern(const ContentSettingsPattern& primary_pattern, |
| 277 const ContentSettingsPattern& secondary_pattern, |
| 278 ContentSettingsType content_type); |
| 279 |
| 280 content_settings::PrefProvider* GetPrefProvider(); |
| 281 |
| 239 #ifndef NDEBUG | 282 #ifndef NDEBUG |
| 240 // This starts as the thread ID of the thread that constructs this | 283 // This starts as the thread ID of the thread that constructs this |
| 241 // object, and remains until used by a different thread, at which | 284 // object, and remains until used by a different thread, at which |
| 242 // point it is set to base::kInvalidThreadId. This allows us to | 285 // point it is set to base::kInvalidThreadId. This allows us to |
| 243 // DCHECK on unsafe usage of content_settings_providers_ (they | 286 // DCHECK on unsafe usage of content_settings_providers_ (they |
| 244 // should be set up on a single thread, after which they are | 287 // should be set up on a single thread, after which they are |
| 245 // immutable). | 288 // immutable). |
| 246 mutable base::PlatformThreadId used_from_thread_id_; | 289 mutable base::PlatformThreadId used_from_thread_id_; |
| 247 #endif | 290 #endif |
| 248 | 291 |
| 249 // Weak; owned by the Profile. | 292 // Weak; owned by the Profile. |
| 250 PrefService* prefs_; | 293 PrefService* prefs_; |
| 251 | 294 |
| 252 // Whether this settings map is for an OTR session. | 295 // Whether this settings map is for an OTR session. |
| 253 bool is_off_the_record_; | 296 bool is_off_the_record_; |
| 254 | 297 |
| 255 // Content setting providers. This is only modified at construction | 298 // Content setting providers. This is only modified at construction |
| 256 // time and by RegisterExtensionService, both of which should happen | 299 // time and by RegisterExtensionService, both of which should happen |
| 257 // before any other uses of it. | 300 // before any other uses of it. |
| 258 ProviderMap content_settings_providers_; | 301 ProviderMap content_settings_providers_; |
| 259 | 302 |
| 260 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); | 303 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); |
| 261 }; | 304 }; |
| 262 | 305 |
| 263 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ | 306 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ |
| OLD | NEW |