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) OVERRIDE; | |
63 | |
64 base::Time GetLastUsage(const ContentSettingsPattern& primary_pattern, | |
65 const ContentSettingsPattern& secondary_pattern, | |
66 ContentSettingsType content_type); | |
67 | |
68 void SetClockForTesting(base::Clock* clock); | |
69 | |
58 private: | 70 private: |
59 friend class DeadlockCheckerThread; // For testing. | 71 friend class DeadlockCheckerThread; // For testing. |
60 // Reads all content settings exceptions from the preference and load them | 72 // 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 | 73 // into the |value_map_|. The |value_map_| is cleared first if |overwrite| is |
62 // true. | 74 // true. |
63 void ReadContentSettingsFromPref(bool overwrite); | 75 void ReadContentSettingsFromPref(bool overwrite); |
64 | 76 |
65 // Callback for changes in the pref with the same name. | 77 // Callback for changes in the pref with the same name. |
66 void OnContentSettingsPatternPairsChanged(); | 78 void OnContentSettingsPatternPairsChanged(); |
67 | 79 |
(...skipping 15 matching lines...) Expand all Loading... | |
83 base::DictionaryValue* all_settings_dictionary); | 95 base::DictionaryValue* all_settings_dictionary); |
84 | 96 |
85 // In the debug mode, asserts that |lock_| is not held by this thread. It's | 97 // 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 | 98 // ok if some other thread holds |lock_|, as long as it will eventually |
87 // release it. | 99 // release it. |
88 void AssertLockNotHeld() const; | 100 void AssertLockNotHeld() const; |
89 | 101 |
90 // Weak; owned by the Profile and reset in ShutdownOnUIThread. | 102 // Weak; owned by the Profile and reset in ShutdownOnUIThread. |
91 PrefService* prefs_; | 103 PrefService* prefs_; |
92 | 104 |
105 // Owned, unless set for testing. | |
106 base::Clock* clock_; | |
107 | |
93 bool is_incognito_; | 108 bool is_incognito_; |
94 | 109 |
110 // Need to know if we made the clock, or if it was passed in for a test. | |
111 bool owns_clock_; | |
scheib
2014/06/27 17:47:39
Always own the clock. Have tests pass ownership. U
Daniel Nishi
2014/06/30 22:40:16
We are now scoped.
| |
112 | |
95 PrefChangeRegistrar pref_change_registrar_; | 113 PrefChangeRegistrar pref_change_registrar_; |
96 | 114 |
97 // Whether we are currently updating preferences, this is used to ignore | 115 // Whether we are currently updating preferences, this is used to ignore |
98 // notifications from the preferences service that we triggered ourself. | 116 // notifications from the preferences service that we triggered ourself. |
99 bool updating_preferences_; | 117 bool updating_preferences_; |
100 | 118 |
101 OriginIdentifierValueMap value_map_; | 119 OriginIdentifierValueMap value_map_; |
102 | 120 |
103 OriginIdentifierValueMap incognito_value_map_; | 121 OriginIdentifierValueMap incognito_value_map_; |
104 | 122 |
105 // Used around accesses to the value map objects to guarantee thread safety. | 123 // Used around accesses to the value map objects to guarantee thread safety. |
106 mutable base::Lock lock_; | 124 mutable base::Lock lock_; |
107 | 125 |
108 DISALLOW_COPY_AND_ASSIGN(PrefProvider); | 126 DISALLOW_COPY_AND_ASSIGN(PrefProvider); |
109 }; | 127 }; |
110 | 128 |
111 } // namespace content_settings | 129 } // namespace content_settings |
112 | 130 |
113 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ | 131 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ |
OLD | NEW |