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 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ |
6 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ | 6 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ |
7 | 7 |
8 // A content settings provider that takes its settings out of the pref service. | 8 // A content settings provider that takes its settings out of the pref service. |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/prefs/pref_change_registrar.h" | 13 #include "base/prefs/pref_change_registrar.h" |
14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
15 #include "chrome/browser/content_settings/content_settings_observable_provider.h
" | 15 #include "chrome/browser/content_settings/content_settings_observable_provider.h
" |
16 #include "chrome/browser/content_settings/content_settings_origin_identifier_val
ue_map.h" | 16 #include "chrome/browser/content_settings/content_settings_origin_identifier_val
ue_map.h" |
17 #include "chrome/browser/content_settings/content_settings_utils.h" | 17 #include "chrome/browser/content_settings/content_settings_utils.h" |
18 | 18 |
19 class PrefService; | 19 class PrefService; |
20 | 20 |
21 namespace base { | 21 namespace base { |
| 22 class Clock; |
22 class DictionaryValue; | 23 class DictionaryValue; |
23 } | 24 } |
24 | 25 |
25 namespace user_prefs { | 26 namespace user_prefs { |
26 class PrefRegistrySyncable; | 27 class PrefRegistrySyncable; |
27 } | 28 } |
28 | 29 |
29 namespace content_settings { | 30 namespace content_settings { |
30 | 31 |
31 // Content settings provider that provides content settings from the user | 32 // Content settings provider that provides content settings from the user |
(...skipping 16 matching lines...) Expand all Loading... |
48 const ContentSettingsPattern& secondary_pattern, | 49 const ContentSettingsPattern& secondary_pattern, |
49 ContentSettingsType content_type, | 50 ContentSettingsType content_type, |
50 const ResourceIdentifier& resource_identifier, | 51 const ResourceIdentifier& resource_identifier, |
51 base::Value* value) OVERRIDE; | 52 base::Value* value) OVERRIDE; |
52 | 53 |
53 virtual void ClearAllContentSettingsRules( | 54 virtual void ClearAllContentSettingsRules( |
54 ContentSettingsType content_type) OVERRIDE; | 55 ContentSettingsType content_type) OVERRIDE; |
55 | 56 |
56 virtual void ShutdownOnUIThread() OVERRIDE; | 57 virtual void ShutdownOnUIThread() OVERRIDE; |
57 | 58 |
| 59 // Records the last time the given pattern has used a certain content setting. |
| 60 virtual void UpdateLastUsage(const ContentSettingsPattern& primary_pattern, |
| 61 const ContentSettingsPattern& secondary_pattern, |
| 62 ContentSettingsType content_type); |
| 63 |
| 64 base::Time GetLastUsage(const ContentSettingsPattern& primary_pattern, |
| 65 const ContentSettingsPattern& secondary_pattern, |
| 66 ContentSettingsType content_type); |
| 67 |
| 68 // Gains ownership of |clock|. |
| 69 void SetClockForTesting(base::Clock* clock); |
| 70 |
58 private: | 71 private: |
59 friend class DeadlockCheckerThread; // For testing. | 72 friend class DeadlockCheckerThread; // For testing. |
60 // Reads all content settings exceptions from the preference and load them | 73 // Reads all content settings exceptions from the preference and load them |
61 // into the |value_map_|. The |value_map_| is cleared first if |overwrite| is | 74 // into the |value_map_|. The |value_map_| is cleared first if |overwrite| is |
62 // true. | 75 // true. |
63 void ReadContentSettingsFromPref(bool overwrite); | 76 void ReadContentSettingsFromPref(bool overwrite); |
64 | 77 |
65 // Callback for changes in the pref with the same name. | 78 // Callback for changes in the pref with the same name. |
66 void OnContentSettingsPatternPairsChanged(); | 79 void OnContentSettingsPatternPairsChanged(); |
67 | 80 |
(...skipping 15 matching lines...) Expand all Loading... |
83 base::DictionaryValue* all_settings_dictionary); | 96 base::DictionaryValue* all_settings_dictionary); |
84 | 97 |
85 // In the debug mode, asserts that |lock_| is not held by this thread. It's | 98 // In the debug mode, asserts that |lock_| is not held by this thread. It's |
86 // ok if some other thread holds |lock_|, as long as it will eventually | 99 // ok if some other thread holds |lock_|, as long as it will eventually |
87 // release it. | 100 // release it. |
88 void AssertLockNotHeld() const; | 101 void AssertLockNotHeld() const; |
89 | 102 |
90 // Weak; owned by the Profile and reset in ShutdownOnUIThread. | 103 // Weak; owned by the Profile and reset in ShutdownOnUIThread. |
91 PrefService* prefs_; | 104 PrefService* prefs_; |
92 | 105 |
| 106 // Can be set for testing. |
| 107 scoped_ptr<base::Clock> clock_; |
| 108 |
93 bool is_incognito_; | 109 bool is_incognito_; |
94 | 110 |
95 PrefChangeRegistrar pref_change_registrar_; | 111 PrefChangeRegistrar pref_change_registrar_; |
96 | 112 |
97 // Whether we are currently updating preferences, this is used to ignore | 113 // Whether we are currently updating preferences, this is used to ignore |
98 // notifications from the preferences service that we triggered ourself. | 114 // notifications from the preferences service that we triggered ourself. |
99 bool updating_preferences_; | 115 bool updating_preferences_; |
100 | 116 |
101 OriginIdentifierValueMap value_map_; | 117 OriginIdentifierValueMap value_map_; |
102 | 118 |
103 OriginIdentifierValueMap incognito_value_map_; | 119 OriginIdentifierValueMap incognito_value_map_; |
104 | 120 |
105 // Used around accesses to the value map objects to guarantee thread safety. | 121 // Used around accesses to the value map objects to guarantee thread safety. |
106 mutable base::Lock lock_; | 122 mutable base::Lock lock_; |
107 | 123 |
108 DISALLOW_COPY_AND_ASSIGN(PrefProvider); | 124 DISALLOW_COPY_AND_ASSIGN(PrefProvider); |
109 }; | 125 }; |
110 | 126 |
111 } // namespace content_settings | 127 } // namespace content_settings |
112 | 128 |
113 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ | 129 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ |
OLD | NEW |