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, |
| 210 const GURL& secondary_url, |
| 211 ContentSettingsType content_type, |
| 212 const std::string& resource_identifier); |
| 213 |
| 214 // Returns the last time the pattern that matches the URL has requested |
| 215 // permission for the |content_type| setting. |
| 216 base::Time GetLastUsage(const GURL& primary_url, |
| 217 const GURL& secondary_url, |
| 218 ContentSettingsType content_type); |
| 219 |
| 220 // Returns the last time the pattern has requested permission for the |
| 221 // |content_type| setting. |
| 222 base::Time GetLastUsageByPattern( |
| 223 const ContentSettingsPattern& primary_pattern, |
| 224 const ContentSettingsPattern& secondary_pattern, |
| 225 ContentSettingsType content_type); |
| 226 |
| 227 void SetPrefClockForTesting(base::Clock* clock); |
| 228 |
202 private: | 229 private: |
203 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; | 230 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; |
204 friend class HostContentSettingsMapTest_NonDefaultSettings_Test; | 231 friend class HostContentSettingsMapTest_NonDefaultSettings_Test; |
205 | 232 |
206 typedef std::map<ProviderType, content_settings::ProviderInterface*> | 233 typedef std::map<ProviderType, content_settings::ProviderInterface*> |
207 ProviderMap; | 234 ProviderMap; |
208 typedef ProviderMap::iterator ProviderIterator; | 235 typedef ProviderMap::iterator ProviderIterator; |
209 typedef ProviderMap::const_iterator ConstProviderIterator; | 236 typedef ProviderMap::const_iterator ConstProviderIterator; |
210 | 237 |
211 virtual ~HostContentSettingsMap(); | 238 virtual ~HostContentSettingsMap(); |
(...skipping 17 matching lines...) Expand all Loading... |
229 const std::string& resource_identifier, | 256 const std::string& resource_identifier, |
230 ContentSettingsForOneType* settings, | 257 ContentSettingsForOneType* settings, |
231 bool incognito) const; | 258 bool incognito) const; |
232 | 259 |
233 // Call UsedContentSettingsProviders() whenever you access | 260 // Call UsedContentSettingsProviders() whenever you access |
234 // content_settings_providers_ (apart from initialization and | 261 // content_settings_providers_ (apart from initialization and |
235 // teardown), so that we can DCHECK in RegisterExtensionService that | 262 // teardown), so that we can DCHECK in RegisterExtensionService that |
236 // it is not being called too late. | 263 // it is not being called too late. |
237 void UsedContentSettingsProviders() const; | 264 void UsedContentSettingsProviders() const; |
238 | 265 |
| 266 // Convenience method for updating the last usage of a content type for a |
| 267 // pattern. |
| 268 void UpdateLastUsageByPattern(const ContentSettingsPattern& primary_pattern, |
| 269 const ContentSettingsPattern& secondary_pattern, |
| 270 ContentSettingsType content_type); |
| 271 |
239 #ifndef NDEBUG | 272 #ifndef NDEBUG |
240 // This starts as the thread ID of the thread that constructs this | 273 // This starts as the thread ID of the thread that constructs this |
241 // object, and remains until used by a different thread, at which | 274 // object, and remains until used by a different thread, at which |
242 // point it is set to base::kInvalidThreadId. This allows us to | 275 // point it is set to base::kInvalidThreadId. This allows us to |
243 // DCHECK on unsafe usage of content_settings_providers_ (they | 276 // DCHECK on unsafe usage of content_settings_providers_ (they |
244 // should be set up on a single thread, after which they are | 277 // should be set up on a single thread, after which they are |
245 // immutable). | 278 // immutable). |
246 mutable base::PlatformThreadId used_from_thread_id_; | 279 mutable base::PlatformThreadId used_from_thread_id_; |
247 #endif | 280 #endif |
248 | 281 |
249 // Weak; owned by the Profile. | 282 // Weak; owned by the Profile. |
250 PrefService* prefs_; | 283 PrefService* prefs_; |
251 | 284 |
252 // Whether this settings map is for an OTR session. | 285 // Whether this settings map is for an OTR session. |
253 bool is_off_the_record_; | 286 bool is_off_the_record_; |
254 | 287 |
255 // Content setting providers. This is only modified at construction | 288 // Content setting providers. This is only modified at construction |
256 // time and by RegisterExtensionService, both of which should happen | 289 // time and by RegisterExtensionService, both of which should happen |
257 // before any other uses of it. | 290 // before any other uses of it. |
258 ProviderMap content_settings_providers_; | 291 ProviderMap content_settings_providers_; |
259 | 292 |
260 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); | 293 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); |
261 }; | 294 }; |
262 | 295 |
263 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ | 296 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ |
OLD | NEW |