Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1775)

Side by Side Diff: components/content_settings/core/browser/content_settings_pref_provider.h

Issue 976243002: Split content settings pref related logic into a separate class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_PROVIDER_ H_ 5 #ifndef COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_PROVIDER_ H_
6 #define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_PROVIDER_ H_ 6 #define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_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"
15 #include "components/content_settings/core/browser/content_settings_observable_p rovider.h" 14 #include "components/content_settings/core/browser/content_settings_observable_p rovider.h"
16 #include "components/content_settings/core/browser/content_settings_origin_ident ifier_value_map.h"
17 #include "components/content_settings/core/browser/content_settings_utils.h" 15 #include "components/content_settings/core/browser/content_settings_utils.h"
18 16
19 class PrefService; 17 class PrefService;
20 18
21 namespace base { 19 namespace base {
22 class Clock; 20 class Clock;
23 class DictionaryValue; 21 class DictionaryValue;
24 } 22 }
25 23
26 namespace user_prefs { 24 namespace user_prefs {
27 class PrefRegistrySyncable; 25 class PrefRegistrySyncable;
28 } 26 }
29 27
30 namespace content_settings { 28 namespace content_settings {
31 29
30 class ContentSettingsPref;
31
32 // Content settings provider that provides content settings from the user 32 // Content settings provider that provides content settings from the user
33 // preference. 33 // preference.
34 class PrefProvider : public ObservableProvider { 34 class PrefProvider : public ObservableProvider {
35 public: 35 public:
36 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 36 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
37 37
38 PrefProvider(PrefService* prefs, bool incognito); 38 PrefProvider(PrefService* prefs, bool incognito);
39 ~PrefProvider() override; 39 ~PrefProvider() override;
40 40
41 // ProviderInterface implementations. 41 // ProviderInterface implementations.
(...skipping 13 matching lines...) Expand all
55 55
56 // Records the last time the given pattern has used a certain content setting. 56 // Records the last time the given pattern has used a certain content setting.
57 void UpdateLastUsage(const ContentSettingsPattern& primary_pattern, 57 void UpdateLastUsage(const ContentSettingsPattern& primary_pattern,
58 const ContentSettingsPattern& secondary_pattern, 58 const ContentSettingsPattern& secondary_pattern,
59 ContentSettingsType content_type); 59 ContentSettingsType content_type);
60 60
61 base::Time GetLastUsage(const ContentSettingsPattern& primary_pattern, 61 base::Time GetLastUsage(const ContentSettingsPattern& primary_pattern,
62 const ContentSettingsPattern& secondary_pattern, 62 const ContentSettingsPattern& secondary_pattern,
63 ContentSettingsType content_type); 63 ContentSettingsType content_type);
64 64
65 void Notify(const ContentSettingsPattern& primary_pattern,
66 const ContentSettingsPattern& secondary_pattern,
67 ContentSettingsType content_type,
68 const std::string& resource_identifier);
69
65 // Gains ownership of |clock|. 70 // Gains ownership of |clock|.
66 void SetClockForTesting(scoped_ptr<base::Clock> clock); 71 void SetClockForTesting(scoped_ptr<base::Clock> clock);
67 72
68 private: 73 private:
69 friend class DeadlockCheckerThread; // For testing. 74 friend class DeadlockCheckerThread; // For testing.
70 // Reads all content settings exceptions from the preference and load them
71 // into the |value_map_|. The |value_map_| is cleared first.
72 void ReadContentSettingsFromPref();
73
74 // Callback for changes in the pref with the same name.
75 void OnContentSettingsPatternPairsChanged();
76
77 // Update the preference that stores content settings exceptions and syncs the
78 // value to the obsolete preference. When calling this function, |lock_|
79 // should not be held, since this function will send out notifications of
80 // preference changes.
81 void UpdatePref(
82 const ContentSettingsPattern& primary_pattern,
83 const ContentSettingsPattern& secondary_pattern,
84 ContentSettingsType content_type,
85 const ResourceIdentifier& resource_identifier,
86 const base::Value* value);
87 75
88 // Migrate the old media setting into new mic/camera content settings. 76 // Migrate the old media setting into new mic/camera content settings.
89 void MigrateObsoleteMediaContentSetting(); 77 void MigrateObsoleteMediaContentSetting();
90 78
91 static void CanonicalizeContentSettingsExceptions(
92 base::DictionaryValue* all_settings_dictionary);
93
94 // In the debug mode, asserts that |lock_| is not held by this thread. It's
95 // ok if some other thread holds |lock_|, as long as it will eventually
96 // release it.
97 void AssertLockNotHeld() const;
98
99 // Weak; owned by the Profile and reset in ShutdownOnUIThread. 79 // Weak; owned by the Profile and reset in ShutdownOnUIThread.
100 PrefService* prefs_; 80 PrefService* prefs_;
101 81
102 // Can be set for testing. 82 // Can be set for testing.
103 scoped_ptr<base::Clock> clock_; 83 scoped_ptr<base::Clock> clock_;
104 84
105 bool is_incognito_; 85 bool is_incognito_;
106 86
107 PrefChangeRegistrar pref_change_registrar_; 87 PrefChangeRegistrar pref_change_registrar_;
108 88
109 // Whether we are currently updating preferences, this is used to ignore 89 scoped_ptr<ContentSettingsPref> content_settings_pref_;
110 // notifications from the preferences service that we triggered ourself.
111 bool updating_preferences_;
112
113 OriginIdentifierValueMap value_map_;
114
115 OriginIdentifierValueMap incognito_value_map_;
116
117 // Used around accesses to the value map objects to guarantee thread safety.
118 mutable base::Lock lock_;
119 90
120 DISALLOW_COPY_AND_ASSIGN(PrefProvider); 91 DISALLOW_COPY_AND_ASSIGN(PrefProvider);
121 }; 92 };
122 93
123 } // namespace content_settings 94 } // namespace content_settings
124 95
125 #endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_PROVID ER_H_ 96 #endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_PROVID ER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698