OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_ | 5 #ifndef COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_ |
6 #define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_ | 6 #define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
15 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
| 16 #include "base/time/time.h" |
16 #include "base/values.h" | 17 #include "base/values.h" |
17 #include "components/content_settings/core/browser/content_settings_origin_ident
ifier_value_map.h" | 18 #include "components/content_settings/core/browser/content_settings_origin_ident
ifier_value_map.h" |
18 #include "components/content_settings/core/browser/content_settings_provider.h" | 19 #include "components/content_settings/core/browser/content_settings_provider.h" |
19 #include "components/content_settings/core/common/content_settings_pattern.h" | 20 #include "components/content_settings/core/common/content_settings_pattern.h" |
20 #include "components/content_settings/core/common/content_settings_types.h" | 21 #include "components/content_settings/core/common/content_settings_types.h" |
21 | 22 |
22 class PrefService; | 23 class PrefService; |
23 class PrefChangeRegistrar; | 24 class PrefChangeRegistrar; |
24 | 25 |
25 namespace base { | 26 namespace base { |
(...skipping 10 matching lines...) Expand all Loading... |
36 typedef base::Callback<void(const ContentSettingsPattern&, | 37 typedef base::Callback<void(const ContentSettingsPattern&, |
37 const ContentSettingsPattern&, | 38 const ContentSettingsPattern&, |
38 ContentSettingsType, | 39 ContentSettingsType, |
39 const std::string&)> NotifyObserversCallback; | 40 const std::string&)> NotifyObserversCallback; |
40 | 41 |
41 ContentSettingsPref(ContentSettingsType content_type, | 42 ContentSettingsPref(ContentSettingsType content_type, |
42 PrefService* prefs, | 43 PrefService* prefs, |
43 PrefChangeRegistrar* registrar, | 44 PrefChangeRegistrar* registrar, |
44 const std::string& pref_name, | 45 const std::string& pref_name, |
45 bool incognito, | 46 bool incognito, |
| 47 bool store_last_modified, |
46 NotifyObserversCallback notify_callback); | 48 NotifyObserversCallback notify_callback); |
47 ~ContentSettingsPref(); | 49 ~ContentSettingsPref(); |
48 | 50 |
49 // Returns nullptr to indicate the RuleIterator is empty. | 51 // Returns nullptr to indicate the RuleIterator is empty. |
50 std::unique_ptr<RuleIterator> GetRuleIterator( | 52 std::unique_ptr<RuleIterator> GetRuleIterator( |
51 const ResourceIdentifier& resource_identifier, | 53 const ResourceIdentifier& resource_identifier, |
52 bool incognito) const; | 54 bool incognito) const; |
53 | 55 |
54 bool SetWebsiteSetting(const ContentSettingsPattern& primary_pattern, | 56 bool SetWebsiteSetting(const ContentSettingsPattern& primary_pattern, |
55 const ContentSettingsPattern& secondary_pattern, | 57 const ContentSettingsPattern& secondary_pattern, |
56 const ResourceIdentifier& resource_identifier, | 58 const ResourceIdentifier& resource_identifier, |
57 base::Value* value); | 59 base::Value* value); |
58 | 60 |
| 61 // Returns the |last_modified| date of a setting. |
| 62 base::Time GetWebsiteSettingLastModified( |
| 63 const ContentSettingsPattern& primary_pattern, |
| 64 const ContentSettingsPattern& secondary_pattern, |
| 65 const ResourceIdentifier& resource_identifier); |
| 66 |
59 void ClearPref(); | 67 void ClearPref(); |
60 | 68 |
61 void ClearAllContentSettingsRules(); | 69 void ClearAllContentSettingsRules(); |
62 | 70 |
63 size_t GetNumExceptions(); | 71 size_t GetNumExceptions(); |
64 | 72 |
65 // Tries to lock |lock_|. If successful, returns true and releases the lock. | 73 // Tries to lock |lock_|. If successful, returns true and releases the lock. |
66 bool TryLockForTesting() const; | 74 bool TryLockForTesting() const; |
67 | 75 |
68 private: | 76 private: |
69 // Reads all content settings exceptions from the preference and loads them | 77 // Reads all content settings exceptions from the preference and loads them |
70 // into the |value_map_|. The |value_map_| is cleared first. | 78 // into the |value_map_|. The |value_map_| is cleared first. |
71 void ReadContentSettingsFromPref(); | 79 void ReadContentSettingsFromPref(); |
72 | 80 |
73 // Callback for changes in the pref with the same name. | 81 // Callback for changes in the pref with the same name. |
74 void OnPrefChanged(); | 82 void OnPrefChanged(); |
75 | 83 |
76 // Update the preference that stores content settings exceptions and syncs the | 84 // Update the preference that stores content settings exceptions and syncs the |
77 // value to the obsolete preference. When calling this function, |lock_| | 85 // value to the obsolete preference. When calling this function, |lock_| |
78 // should not be held, since this function will send out notifications of | 86 // should not be held, since this function will send out notifications of |
79 // preference changes. | 87 // preference changes. |
80 void UpdatePref( | 88 void UpdatePref(const ContentSettingsPattern& primary_pattern, |
81 const ContentSettingsPattern& primary_pattern, | 89 const ContentSettingsPattern& secondary_pattern, |
82 const ContentSettingsPattern& secondary_pattern, | 90 const ResourceIdentifier& resource_identifier, |
83 const ResourceIdentifier& resource_identifier, | 91 const base::Time last_modified, |
84 const base::Value* value); | 92 const base::Value* value); |
85 | 93 |
86 static void CanonicalizeContentSettingsExceptions( | 94 static void CanonicalizeContentSettingsExceptions( |
87 base::DictionaryValue* all_settings_dictionary); | 95 base::DictionaryValue* all_settings_dictionary); |
88 | 96 |
89 // 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 |
90 // 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 |
91 // release it. | 99 // release it. |
92 void AssertLockNotHeld() const; | 100 void AssertLockNotHeld() const; |
93 | 101 |
94 // The type of content settings stored in this pref. | 102 // The type of content settings stored in this pref. |
95 ContentSettingsType content_type_; | 103 ContentSettingsType content_type_; |
96 | 104 |
97 // Weak; owned by the Profile and reset in ShutdownOnUIThread. | 105 // Weak; owned by the Profile and reset in ShutdownOnUIThread. |
98 PrefService* prefs_; | 106 PrefService* prefs_; |
99 | 107 |
100 // Owned by the PrefProvider. | 108 // Owned by the PrefProvider. |
101 PrefChangeRegistrar* registrar_; | 109 PrefChangeRegistrar* registrar_; |
102 | 110 |
103 // Name of the dictionary preference managed by this class. | 111 // Name of the dictionary preference managed by this class. |
104 const std::string& pref_name_; | 112 const std::string& pref_name_; |
105 | 113 |
106 bool is_incognito_; | 114 bool is_incognito_; |
107 | 115 |
| 116 bool store_last_modified_; |
| 117 |
108 // Whether we are currently updating preferences, this is used to ignore | 118 // Whether we are currently updating preferences, this is used to ignore |
109 // notifications from the preferences service that we triggered ourself. | 119 // notifications from the preferences service that we triggered ourself. |
110 bool updating_preferences_; | 120 bool updating_preferences_; |
111 | 121 |
112 OriginIdentifierValueMap value_map_; | 122 OriginIdentifierValueMap value_map_; |
113 | 123 |
114 OriginIdentifierValueMap incognito_value_map_; | 124 OriginIdentifierValueMap incognito_value_map_; |
115 | 125 |
116 NotifyObserversCallback notify_callback_; | 126 NotifyObserversCallback notify_callback_; |
117 | 127 |
118 // Used around accesses to the value map objects to guarantee thread safety. | 128 // Used around accesses to the value map objects to guarantee thread safety. |
119 mutable base::Lock lock_; | 129 mutable base::Lock lock_; |
120 | 130 |
121 base::ThreadChecker thread_checker_; | 131 base::ThreadChecker thread_checker_; |
122 | 132 |
123 DISALLOW_COPY_AND_ASSIGN(ContentSettingsPref); | 133 DISALLOW_COPY_AND_ASSIGN(ContentSettingsPref); |
124 }; | 134 }; |
125 | 135 |
126 } // namespace content_settings | 136 } // namespace content_settings |
127 | 137 |
128 #endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_ | 138 #endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_ |
OLD | NEW |