| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_HOST_CONTENT_SETTINGS_MAP_H_ | 8 #ifndef CHROME_BROWSER_HOST_CONTENT_SETTINGS_MAP_H_ |
| 9 #define CHROME_BROWSER_HOST_CONTENT_SETTINGS_MAP_H_ | 9 #define CHROME_BROWSER_HOST_CONTENT_SETTINGS_MAP_H_ |
| 10 | 10 |
| 11 #include <map> | 11 #include <map> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <utility> | 13 #include <utility> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
| 17 #include "base/lock.h" | 17 #include "base/lock.h" |
| 18 #include "base/ref_counted.h" | 18 #include "base/ref_counted.h" |
| 19 #include "chrome/common/content_settings.h" | 19 #include "chrome/common/content_settings.h" |
| 20 | 20 |
| 21 class DictionaryValue; | 21 class DictionaryValue; |
| 22 class PrefService; | 22 class PrefService; |
| 23 class Profile; | 23 class Profile; |
| 24 | 24 |
| 25 class HostContentSettingsMap | 25 class HostContentSettingsMap |
| 26 : public base::RefCountedThreadSafe<HostContentSettingsMap> { | 26 : public base::RefCountedThreadSafe<HostContentSettingsMap> { |
| 27 public: | 27 public: |
| 28 // Details for the CONTENT_SETTINGS_CHANGED notification. This is sent when |
| 29 // content settings change for at least one host. If settings change for more |
| 30 // than one host in one user interaction, this will usually send a single |
| 31 // notification with a wildcard host field instead of one notification for |
| 32 // each host. |
| 33 class ContentSettingsDetails { |
| 34 public: |
| 35 ContentSettingsDetails(const std::string& host) : host_(host) {} |
| 36 // The host whose settings have changed. Empty if many hosts are affected |
| 37 // (e.g. if the default settings have changed). |
| 38 const std::string& host() { return host_; } |
| 39 |
| 40 private: |
| 41 std::string host_; |
| 42 }; |
| 43 |
| 28 typedef std::pair<std::string, ContentSetting> HostSettingPair; | 44 typedef std::pair<std::string, ContentSetting> HostSettingPair; |
| 29 typedef std::vector<HostSettingPair> SettingsForOneType; | 45 typedef std::vector<HostSettingPair> SettingsForOneType; |
| 30 | 46 |
| 31 explicit HostContentSettingsMap(Profile* profile); | 47 explicit HostContentSettingsMap(Profile* profile); |
| 32 | 48 |
| 33 static void RegisterUserPrefs(PrefService* prefs); | 49 static void RegisterUserPrefs(PrefService* prefs); |
| 34 | 50 |
| 35 // Returns the default setting for a particular content type. | 51 // Returns the default setting for a particular content type. |
| 36 // | 52 // |
| 37 // This may be called on any thread. | 53 // This may be called on any thread. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 void GetSettingsFromDictionary(const DictionaryValue* dictionary, | 123 void GetSettingsFromDictionary(const DictionaryValue* dictionary, |
| 108 ContentSettings* settings); | 124 ContentSettings* settings); |
| 109 | 125 |
| 110 // Forces the default settings to be explicitly set instead of themselves | 126 // Forces the default settings to be explicitly set instead of themselves |
| 111 // being CONTENT_SETTING_DEFAULT. | 127 // being CONTENT_SETTING_DEFAULT. |
| 112 void ForceDefaultsToBeExplicit(); | 128 void ForceDefaultsToBeExplicit(); |
| 113 | 129 |
| 114 // Returns true if |settings| consists entirely of CONTENT_SETTING_DEFAULT. | 130 // Returns true if |settings| consists entirely of CONTENT_SETTING_DEFAULT. |
| 115 bool AllDefault(const ContentSettings& settings) const; | 131 bool AllDefault(const ContentSettings& settings) const; |
| 116 | 132 |
| 133 // Informs observers that content settings have changed. Make sure that |
| 134 // |lock_| is not held when calling this, as listeners will usually call one |
| 135 // of the GetSettings functions in response, which would then lead to a |
| 136 // mutex deadlock. |
| 137 void NotifyObservers(const std::string& host); |
| 138 |
| 117 // The profile we're associated with. | 139 // The profile we're associated with. |
| 118 Profile* profile_; | 140 Profile* profile_; |
| 119 | 141 |
| 120 // Copies of the pref data, so that we can read it on the IO thread. | 142 // Copies of the pref data, so that we can read it on the IO thread. |
| 121 ContentSettings default_content_settings_; | 143 ContentSettings default_content_settings_; |
| 122 HostContentSettings host_content_settings_; | 144 HostContentSettings host_content_settings_; |
| 123 | 145 |
| 124 // Misc global settings. | 146 // Misc global settings. |
| 125 bool block_third_party_cookies_; | 147 bool block_third_party_cookies_; |
| 126 | 148 |
| 127 // Used around accesses to the settings objects to guarantee thread safety. | 149 // Used around accesses to the settings objects to guarantee thread safety. |
| 128 mutable Lock lock_; | 150 mutable Lock lock_; |
| 129 | 151 |
| 130 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); | 152 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); |
| 131 }; | 153 }; |
| 132 | 154 |
| 133 #endif // CHROME_BROWSER_HOST_CONTENT_SETTINGS_MAP_H_ | 155 #endif // CHROME_BROWSER_HOST_CONTENT_SETTINGS_MAP_H_ |
| OLD | NEW |