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