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

Side by Side Diff: chrome/browser/content_settings/content_settings_default_provider.cc

Issue 106433007: Update some uses of Value in chrome/browser to use the base:: namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 7 years 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 | Annotate | Revision Log
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 #include "chrome/browser/content_settings/content_settings_default_provider.h" 5 #include "chrome/browser/content_settings/content_settings_default_provider.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 92
93 // static 93 // static
94 void DefaultProvider::RegisterProfilePrefs( 94 void DefaultProvider::RegisterProfilePrefs(
95 user_prefs::PrefRegistrySyncable* registry) { 95 user_prefs::PrefRegistrySyncable* registry) {
96 // The registration of the preference prefs::kDefaultContentSettings should 96 // The registration of the preference prefs::kDefaultContentSettings should
97 // also include the default values for default content settings. This allows 97 // also include the default values for default content settings. This allows
98 // functional tests to get default content settings by reading the preference 98 // functional tests to get default content settings by reading the preference
99 // prefs::kDefaultContentSettings via pyauto. 99 // prefs::kDefaultContentSettings via pyauto.
100 // TODO(markusheintz): Write pyauto hooks for the content settings map as 100 // TODO(markusheintz): Write pyauto hooks for the content settings map as
101 // content settings should be read from the host content settings map. 101 // content settings should be read from the host content settings map.
102 DictionaryValue* default_content_settings = new DictionaryValue(); 102 base::DictionaryValue* default_content_settings = new base::DictionaryValue();
103 registry->RegisterDictionaryPref( 103 registry->RegisterDictionaryPref(
104 prefs::kDefaultContentSettings, 104 prefs::kDefaultContentSettings,
105 default_content_settings, 105 default_content_settings,
106 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 106 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
107 } 107 }
108 108
109 DefaultProvider::DefaultProvider(PrefService* prefs, bool incognito) 109 DefaultProvider::DefaultProvider(PrefService* prefs, bool incognito)
110 : prefs_(prefs), 110 : prefs_(prefs),
111 is_incognito_(incognito), 111 is_incognito_(incognito),
112 updating_preferences_(false) { 112 updating_preferences_(false) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } 173 }
174 174
175 DefaultProvider::~DefaultProvider() { 175 DefaultProvider::~DefaultProvider() {
176 } 176 }
177 177
178 bool DefaultProvider::SetWebsiteSetting( 178 bool DefaultProvider::SetWebsiteSetting(
179 const ContentSettingsPattern& primary_pattern, 179 const ContentSettingsPattern& primary_pattern,
180 const ContentSettingsPattern& secondary_pattern, 180 const ContentSettingsPattern& secondary_pattern,
181 ContentSettingsType content_type, 181 ContentSettingsType content_type,
182 const ResourceIdentifier& resource_identifier, 182 const ResourceIdentifier& resource_identifier,
183 Value* in_value) { 183 base::Value* in_value) {
184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
185 DCHECK(prefs_); 185 DCHECK(prefs_);
186 186
187 // Ignore non default settings 187 // Ignore non default settings
188 if (primary_pattern != ContentSettingsPattern::Wildcard() || 188 if (primary_pattern != ContentSettingsPattern::Wildcard() ||
189 secondary_pattern != ContentSettingsPattern::Wildcard()) { 189 secondary_pattern != ContentSettingsPattern::Wildcard()) {
190 return false; 190 return false;
191 } 191 }
192 192
193 // The default settings may not be directly modified for OTR sessions. 193 // The default settings may not be directly modified for OTR sessions.
194 // Instead, they are synced to the main profile's setting. 194 // Instead, they are synced to the main profile's setting.
195 if (is_incognito_) 195 if (is_incognito_)
196 return false; 196 return false;
197 197
198 // Put |in_value| in a scoped pointer to ensure that it gets cleaned up 198 // Put |in_value| in a scoped pointer to ensure that it gets cleaned up
199 // properly if we don't pass on the ownership. 199 // properly if we don't pass on the ownership.
200 scoped_ptr<base::Value> value(in_value); 200 scoped_ptr<base::Value> value(in_value);
201 { 201 {
202 base::AutoReset<bool> auto_reset(&updating_preferences_, true); 202 base::AutoReset<bool> auto_reset(&updating_preferences_, true);
203 203
204 // |DefaultProvider| should not send any notifications when holding 204 // |DefaultProvider| should not send any notifications when holding
205 // |lock_|. |DictionaryPrefUpdate| destructor and 205 // |lock_|. |DictionaryPrefUpdate| destructor and
206 // |PrefService::SetInteger()| send out notifications. As a response, the 206 // |PrefService::SetInteger()| send out notifications. As a response, the
207 // upper layers may call |GetAllContentSettingRules| which acquires |lock_| 207 // upper layers may call |GetAllContentSettingRules| which acquires |lock_|
208 // again. 208 // again.
209 DictionaryPrefUpdate update(prefs_, prefs::kDefaultContentSettings); 209 DictionaryPrefUpdate update(prefs_, prefs::kDefaultContentSettings);
210 DictionaryValue* default_settings_dictionary = update.Get(); 210 base::DictionaryValue* default_settings_dictionary = update.Get();
211 base::AutoLock lock(lock_); 211 base::AutoLock lock(lock_);
212 if (value.get() == NULL || 212 if (value.get() == NULL ||
213 ValueToContentSetting(value.get()) == kDefaultSettings[content_type]) { 213 ValueToContentSetting(value.get()) == kDefaultSettings[content_type]) {
214 // If |value| is NULL we need to reset the default setting the the 214 // If |value| is NULL we need to reset the default setting the the
215 // hardcoded default. 215 // hardcoded default.
216 default_settings_[content_type].reset( 216 default_settings_[content_type].reset(
217 Value::CreateIntegerValue(kDefaultSettings[content_type])); 217 base::Value::CreateIntegerValue(kDefaultSettings[content_type]));
218 218
219 // Remove the corresponding pref entry since the hardcoded default value 219 // Remove the corresponding pref entry since the hardcoded default value
220 // is used. 220 // is used.
221 default_settings_dictionary->RemoveWithoutPathExpansion( 221 default_settings_dictionary->RemoveWithoutPathExpansion(
222 GetTypeName(content_type), NULL); 222 GetTypeName(content_type), NULL);
223 } else { 223 } else {
224 default_settings_[content_type].reset(value->DeepCopy()); 224 default_settings_[content_type].reset(value->DeepCopy());
225 // Transfer ownership of |value| to the |default_settings_dictionary|. 225 // Transfer ownership of |value| to the |default_settings_dictionary|.
226 default_settings_dictionary->SetWithoutPathExpansion( 226 default_settings_dictionary->SetWithoutPathExpansion(
227 GetTypeName(content_type), value.release()); 227 GetTypeName(content_type), value.release());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 } 280 }
281 281
282 NotifyObservers(ContentSettingsPattern(), 282 NotifyObservers(ContentSettingsPattern(),
283 ContentSettingsPattern(), 283 ContentSettingsPattern(),
284 CONTENT_SETTINGS_TYPE_DEFAULT, 284 CONTENT_SETTINGS_TYPE_DEFAULT,
285 std::string()); 285 std::string());
286 } 286 }
287 287
288 void DefaultProvider::ReadDefaultSettings(bool overwrite) { 288 void DefaultProvider::ReadDefaultSettings(bool overwrite) {
289 base::AutoLock lock(lock_); 289 base::AutoLock lock(lock_);
290 const DictionaryValue* default_settings_dictionary = 290 const base::DictionaryValue* default_settings_dictionary =
291 prefs_->GetDictionary(prefs::kDefaultContentSettings); 291 prefs_->GetDictionary(prefs::kDefaultContentSettings);
292 292
293 if (overwrite) 293 if (overwrite)
294 default_settings_.clear(); 294 default_settings_.clear();
295 295
296 // Careful: The returned value could be NULL if the pref has never been set. 296 // Careful: The returned value could be NULL if the pref has never been set.
297 if (default_settings_dictionary) 297 if (default_settings_dictionary)
298 GetSettingsFromDictionary(default_settings_dictionary); 298 GetSettingsFromDictionary(default_settings_dictionary);
299 299
300 ForceDefaultsToBeExplicit(); 300 ForceDefaultsToBeExplicit();
301 } 301 }
302 302
303 void DefaultProvider::ForceDefaultsToBeExplicit() { 303 void DefaultProvider::ForceDefaultsToBeExplicit() {
304 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { 304 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
305 ContentSettingsType type = ContentSettingsType(i); 305 ContentSettingsType type = ContentSettingsType(i);
306 if (!default_settings_[type].get() && 306 if (!default_settings_[type].get() &&
307 kDefaultSettings[i] != CONTENT_SETTING_DEFAULT) { 307 kDefaultSettings[i] != CONTENT_SETTING_DEFAULT) {
308 default_settings_[type].reset( 308 default_settings_[type].reset(
309 Value::CreateIntegerValue(kDefaultSettings[i])); 309 base::Value::CreateIntegerValue(kDefaultSettings[i]));
310 } 310 }
311 } 311 }
312 } 312 }
313 313
314 void DefaultProvider::GetSettingsFromDictionary( 314 void DefaultProvider::GetSettingsFromDictionary(
315 const DictionaryValue* dictionary) { 315 const base::DictionaryValue* dictionary) {
316 for (DictionaryValue::Iterator i(*dictionary); !i.IsAtEnd(); i.Advance()) { 316 for (base::DictionaryValue::Iterator i(*dictionary);
317 !i.IsAtEnd(); i.Advance()) {
317 const std::string& content_type(i.key()); 318 const std::string& content_type(i.key());
318 for (size_t type = 0; type < CONTENT_SETTINGS_NUM_TYPES; ++type) { 319 for (size_t type = 0; type < CONTENT_SETTINGS_NUM_TYPES; ++type) {
319 if (content_type == GetTypeName(ContentSettingsType(type))) { 320 if (content_type == GetTypeName(ContentSettingsType(type))) {
320 int int_value = CONTENT_SETTING_DEFAULT; 321 int int_value = CONTENT_SETTING_DEFAULT;
321 bool is_integer = i.value().GetAsInteger(&int_value); 322 bool is_integer = i.value().GetAsInteger(&int_value);
322 DCHECK(is_integer); 323 DCHECK(is_integer);
323 default_settings_[ContentSettingsType(type)].reset( 324 default_settings_[ContentSettingsType(type)].reset(
324 Value::CreateIntegerValue(int_value)); 325 base::Value::CreateIntegerValue(int_value));
325 break; 326 break;
326 } 327 }
327 } 328 }
328 } 329 }
329 // Migrate obsolete cookie prompt mode. 330 // Migrate obsolete cookie prompt mode.
330 if (ValueToContentSetting( 331 if (ValueToContentSetting(
331 default_settings_[CONTENT_SETTINGS_TYPE_COOKIES].get()) == 332 default_settings_[CONTENT_SETTINGS_TYPE_COOKIES].get()) ==
332 CONTENT_SETTING_ASK) { 333 CONTENT_SETTING_ASK) {
333 default_settings_[CONTENT_SETTINGS_TYPE_COOKIES].reset( 334 default_settings_[CONTENT_SETTINGS_TYPE_COOKIES].reset(
334 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); 335 base::Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
335 } 336 }
336 } 337 }
337 338
338 } // namespace content_settings 339 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698