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

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

Issue 1005303003: Split the aggregate dictionary of content settings exceptions into per-type dictionaries (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase, various small changes. 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 #include "components/content_settings/core/browser/content_settings_pref_provide r.h" 5 #include "components/content_settings/core/browser/content_settings_pref_provide r.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/auto_reset.h"
11 #include "base/bind.h" 12 #include "base/bind.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
13 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
14 #include "base/prefs/pref_service.h" 15 #include "base/prefs/pref_service.h"
16 #include "base/prefs/scoped_user_pref_update.h"
15 #include "base/strings/string_split.h" 17 #include "base/strings/string_split.h"
16 #include "base/time/clock.h" 18 #include "base/time/clock.h"
17 #include "base/time/default_clock.h" 19 #include "base/time/default_clock.h"
18 #include "components/content_settings/core/browser/content_settings_pref.h" 20 #include "components/content_settings/core/browser/content_settings_pref.h"
19 #include "components/content_settings/core/browser/content_settings_rule.h" 21 #include "components/content_settings/core/browser/content_settings_rule.h"
20 #include "components/content_settings/core/browser/content_settings_utils.h" 22 #include "components/content_settings/core/browser/content_settings_utils.h"
21 #include "components/content_settings/core/browser/host_content_settings_map.h" 23 #include "components/content_settings/core/browser/host_content_settings_map.h"
22 #include "components/content_settings/core/common/content_settings.h" 24 #include "components/content_settings/core/common/content_settings.h"
23 #include "components/content_settings/core/common/content_settings_pattern.h" 25 #include "components/content_settings/core/common/content_settings_pattern.h"
24 #include "components/content_settings/core/common/pref_names.h" 26 #include "components/content_settings/core/common/pref_names.h"
25 #include "components/pref_registry/pref_registry_syncable.h" 27 #include "components/pref_registry/pref_registry_syncable.h"
26 28
27 namespace { 29 namespace {
28 30
31 const char kPerPluginPrefName[] = "per_plugin";
32
33 // If the given content type supports resource identifiers in user preferences,
34 // returns true and sets |pref_key| to the key in the content settings
35 // dictionary under which per-resource content settings are stored.
36 // Otherwise, returns false.
37 bool GetResourceTypeName(ContentSettingsType content_type,
38 std::string* pref_key) {
39 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) {
40 *pref_key = kPerPluginPrefName;
41 return true;
42 }
43 return false;
44 }
45
46 ContentSetting FixObsoleteCookiePromptMode(ContentSettingsType content_type,
47 ContentSetting setting) {
48 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES &&
49 setting == CONTENT_SETTING_ASK) {
50 return CONTENT_SETTING_BLOCK;
51 }
52 return setting;
53 }
54
29 const char kAudioKey[] = "audio"; 55 const char kAudioKey[] = "audio";
30 const char kVideoKey[] = "video"; 56 const char kVideoKey[] = "video";
31 57
58 const char* kContentSettingsExceptionsPrefs[] = {
59 prefs::kContentSettingsCookiesPatternPairs,
60 prefs::kContentSettingsImagesPatternPairs,
61 prefs::kContentSettingsJavaScriptPatternPairs,
62 prefs::kContentSettingsPluginsPatternPairs,
63 prefs::kContentSettingsPopupsPatternPairs,
64 prefs::kContentSettingsGeolocationPatternPairs,
65 prefs::kContentSettingsNotificationsPatternPairs,
66 prefs::kContentSettingsAutoSelectCertificatePatternPairs,
67 prefs::kContentSettingsFullScreenPatternPairs,
68 prefs::kContentSettingsMouseLockPatternPairs,
69 prefs::kContentSettingsMixedScriptPatternPairs,
70 prefs::kContentSettingsMediaStreamPatternPairs,
71 prefs::kContentSettingsMediaStreamMicPatternPairs,
72 prefs::kContentSettingsMediaStreamCameraPatternPairs,
73 prefs::kContentSettingsProtocolHandlersPatternPairs,
74 prefs::kContentSettingsPpapiBrokerPatternPairs,
75 prefs::kContentSettingsAutomaticDownloadsPatternPairs,
76 prefs::kContentSettingsMidiSysexPatternPairs,
77 prefs::kContentSettingsPushMessagingPatternPairs,
78 prefs::kContentSettingsSSLCertDecisionsPatternPairs,
79 #if defined(OS_WIN)
80 prefs::kContentSettingsMetroSwitchToDesktopPatternPairs,
81 #elif defined(OS_ANDROID) || defined(OS_CHROMEOS)
82 prefs::kContentSettingsProtectedMediaIdentifierPatternPairs,
83 #endif
84 prefs::kContentSettingsAppBannerPatternPairs
85 };
86 static_assert(arraysize(kContentSettingsExceptionsPrefs)
87 == CONTENT_SETTINGS_NUM_TYPES,
88 "kContentSettingsExceptionsPrefs should have "
89 "CONTENT_SETTINGS_NUM_TYPES elements");
90
32 } // namespace 91 } // namespace
33 92
34 namespace content_settings { 93 namespace content_settings {
35 94
36 // //////////////////////////////////////////////////////////////////////////// 95 // ////////////////////////////////////////////////////////////////////////////
37 // PrefProvider: 96 // PrefProvider:
38 // 97 //
39 98
40 // static 99 // static
41 void PrefProvider::RegisterProfilePrefs( 100 void PrefProvider::RegisterProfilePrefs(
42 user_prefs::PrefRegistrySyncable* registry) { 101 user_prefs::PrefRegistrySyncable* registry) {
43 registry->RegisterIntegerPref( 102 registry->RegisterIntegerPref(
44 prefs::kContentSettingsVersion, 103 prefs::kContentSettingsVersion,
45 ContentSettingsPattern::kContentSettingsPatternVersion, 104 ContentSettingsPattern::kContentSettingsPatternVersion,
46 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 105 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
47 registry->RegisterDictionaryPref( 106 registry->RegisterDictionaryPref(
48 prefs::kContentSettingsPatternPairs, 107 prefs::kContentSettingsPatternPairs,
49 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 108 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
109 registry->RegisterBooleanPref(
110 prefs::kMigratedContentSettingsPatternPairs,
111 false,
112 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
113
114 for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i)
115 registry->RegisterDictionaryPref(
116 kContentSettingsExceptionsPrefs[i],
117 IsContentSettingsTypeSyncable(ContentSettingsType(i))
118 ? user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
119 : user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
120 );
50 } 121 }
51 122
52 PrefProvider::PrefProvider(PrefService* prefs, bool incognito) 123 PrefProvider::PrefProvider(PrefService* prefs, bool incognito)
53 : prefs_(prefs), 124 : prefs_(prefs),
54 clock_(new base::DefaultClock()) { 125 clock_(new base::DefaultClock()),
126 updating_old_preferences_(false) {
55 DCHECK(prefs_); 127 DCHECK(prefs_);
56 // Verify preferences version. 128 // Verify preferences version.
57 if (!prefs_->HasPrefPath(prefs::kContentSettingsVersion)) { 129 if (!prefs_->HasPrefPath(prefs::kContentSettingsVersion)) {
58 prefs_->SetInteger(prefs::kContentSettingsVersion, 130 prefs_->SetInteger(prefs::kContentSettingsVersion,
59 ContentSettingsPattern::kContentSettingsPatternVersion); 131 ContentSettingsPattern::kContentSettingsPatternVersion);
60 } 132 }
61 if (prefs_->GetInteger(prefs::kContentSettingsVersion) > 133 if (prefs_->GetInteger(prefs::kContentSettingsVersion) >
62 ContentSettingsPattern::kContentSettingsPatternVersion) { 134 ContentSettingsPattern::kContentSettingsPatternVersion) {
63 return; 135 return;
64 } 136 }
65 137
66 pref_change_registrar_.Init(prefs_); 138 pref_change_registrar_.Init(prefs_);
67 content_settings_pref_.reset(new ContentSettingsPref( 139
68 prefs_, &pref_change_registrar_, clock_.get(), incognito, 140 pref_change_registrar_.Add(prefs::kContentSettingsPatternPairs, base::Bind(
69 base::Bind(&PrefProvider::Notify, 141 &PrefProvider::OnOldContentSettingsPatternPairsChanged,
70 base::Unretained(this)))); 142 base::Unretained(this)));
143
144 content_settings_prefs_.resize(CONTENT_SETTINGS_NUM_TYPES);
145 for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
146 content_settings_prefs_[i].reset(new ContentSettingsPref(
147 ContentSettingsType(i), prefs_, &pref_change_registrar_,
148 kContentSettingsExceptionsPrefs[i], incognito,
149 &updating_old_preferences_, base::Bind(&PrefProvider::Notify,
150 base::Unretained(this))));
151 }
152
153 ReadContentSettingsFromOldPref(NULL);
71 154
72 if (!incognito) { 155 if (!incognito) {
156 size_t num_exceptions = 0;
157 for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i)
158 num_exceptions += content_settings_prefs_[i]->GetNumExceptions();
159
73 UMA_HISTOGRAM_COUNTS("ContentSettings.NumberOfExceptions", 160 UMA_HISTOGRAM_COUNTS("ContentSettings.NumberOfExceptions",
74 content_settings_pref_->GetNumExceptions()); 161 num_exceptions);
162
163 // Migrate all the exceptions from the aggregate dictionary preference
164 // to the separate dictionaries.
165 MigrateAllExceptions();
166
75 // Migrate the obsolete media content setting exceptions to the new 167 // Migrate the obsolete media content setting exceptions to the new
76 // settings. This needs to be done after ReadContentSettingsFromPref(). 168 // settings.
77 MigrateObsoleteMediaContentSetting(); 169 MigrateObsoleteMediaContentSetting();
78 } 170 }
171
79 } 172 }
80 173
81 PrefProvider::~PrefProvider() { 174 PrefProvider::~PrefProvider() {
82 DCHECK(!prefs_); 175 DCHECK(!prefs_);
83 } 176 }
84 177
85 RuleIterator* PrefProvider::GetRuleIterator( 178 RuleIterator* PrefProvider::GetRuleIterator(
86 ContentSettingsType content_type, 179 ContentSettingsType content_type,
87 const ResourceIdentifier& resource_identifier, 180 const ResourceIdentifier& resource_identifier,
88 bool incognito) const { 181 bool incognito) const {
89 return content_settings_pref_->GetRuleIterator(content_type, 182 return content_settings_prefs_[content_type]->GetRuleIterator(
90 resource_identifier, 183 resource_identifier,
91 incognito); 184 incognito);
92 } 185 }
93 186
94 bool PrefProvider::SetWebsiteSetting( 187 bool PrefProvider::SetWebsiteSetting(
95 const ContentSettingsPattern& primary_pattern, 188 const ContentSettingsPattern& primary_pattern,
96 const ContentSettingsPattern& secondary_pattern, 189 const ContentSettingsPattern& secondary_pattern,
97 ContentSettingsType content_type, 190 ContentSettingsType content_type,
98 const ResourceIdentifier& resource_identifier, 191 const ResourceIdentifier& resource_identifier,
99 base::Value* in_value) { 192 base::Value* in_value) {
100 DCHECK(CalledOnValidThread()); 193 DCHECK(CalledOnValidThread());
101 DCHECK(prefs_); 194 DCHECK(prefs_);
102 195
103 return content_settings_pref_->SetWebsiteSetting(primary_pattern, 196 // Default settings are set using a wildcard pattern for both
104 secondary_pattern, 197 // |primary_pattern| and |secondary_pattern|. Don't store default settings in
105 content_type, 198 // the |PrefProvider|. The |PrefProvider| handles settings for specific
106 resource_identifier, 199 // sites/origins defined by the |primary_pattern| and the |secondary_pattern|.
107 in_value); 200 // Default settings are handled by the |DefaultProvider|.
201 if (primary_pattern == ContentSettingsPattern::Wildcard() &&
202 secondary_pattern == ContentSettingsPattern::Wildcard() &&
203 resource_identifier.empty()) {
204 return false;
205 }
206
207 return content_settings_prefs_[content_type]->SetWebsiteSetting(
208 primary_pattern,
209 secondary_pattern,
210 resource_identifier,
211 in_value);
108 } 212 }
109 213
110 void PrefProvider::ClearAllContentSettingsRules( 214 void PrefProvider::ClearAllContentSettingsRules(
111 ContentSettingsType content_type) { 215 ContentSettingsType content_type) {
112 DCHECK(CalledOnValidThread()); 216 DCHECK(CalledOnValidThread());
113 DCHECK(prefs_); 217 DCHECK(prefs_);
114 218
115 content_settings_pref_->ClearAllContentSettingsRules(content_type); 219 content_settings_prefs_[content_type]->ClearAllContentSettingsRules();
116 } 220 }
117 221
118 void PrefProvider::ShutdownOnUIThread() { 222 void PrefProvider::ShutdownOnUIThread() {
119 DCHECK(CalledOnValidThread()); 223 DCHECK(CalledOnValidThread());
120 DCHECK(prefs_); 224 DCHECK(prefs_);
121 RemoveAllObservers(); 225 RemoveAllObservers();
122 pref_change_registrar_.RemoveAll(); 226 pref_change_registrar_.RemoveAll();
123 prefs_ = NULL; 227 prefs_ = NULL;
124 } 228 }
125 229
126 void PrefProvider::UpdateLastUsage( 230 void PrefProvider::UpdateLastUsage(
127 const ContentSettingsPattern& primary_pattern, 231 const ContentSettingsPattern& primary_pattern,
128 const ContentSettingsPattern& secondary_pattern, 232 const ContentSettingsPattern& secondary_pattern,
129 ContentSettingsType content_type) { 233 ContentSettingsType content_type) {
130 content_settings_pref_->UpdateLastUsage(primary_pattern, 234 content_settings_prefs_[content_type]->UpdateLastUsage(primary_pattern,
131 secondary_pattern, 235 secondary_pattern,
132 content_type); 236 clock_.get());
133 } 237 }
134 238
135 base::Time PrefProvider::GetLastUsage( 239 base::Time PrefProvider::GetLastUsage(
136 const ContentSettingsPattern& primary_pattern, 240 const ContentSettingsPattern& primary_pattern,
137 const ContentSettingsPattern& secondary_pattern, 241 const ContentSettingsPattern& secondary_pattern,
138 ContentSettingsType content_type) { 242 ContentSettingsType content_type) {
139 return content_settings_pref_->GetLastUsage(primary_pattern, 243 return content_settings_prefs_[content_type]->GetLastUsage(primary_pattern,
140 secondary_pattern, 244 secondary_pattern);
141 content_type);
142 } 245 }
143 246
144 // //////////////////////////////////////////////////////////////////////////// 247 // ////////////////////////////////////////////////////////////////////////////
145 // Private 248 // Private
146 249
250 PrefProvider::ContentSettingsPrefEntry::ContentSettingsPrefEntry(
251 const ContentSettingsPattern primary_pattern,
252 const ContentSettingsPattern secondary_pattern,
253 const ResourceIdentifier resource_identifier,
254 base::Value* value)
255 : primary_pattern(primary_pattern),
256 secondary_pattern(secondary_pattern),
257 resource_identifier(resource_identifier),
258 value(value) {
259 };
260
261 PrefProvider::ContentSettingsPrefEntry::~ContentSettingsPrefEntry() {}
262
147 void PrefProvider::MigrateObsoleteMediaContentSetting() { 263 void PrefProvider::MigrateObsoleteMediaContentSetting() {
148 std::vector<Rule> rules_to_delete; 264 std::vector<Rule> rules_to_delete;
149 { 265 {
150 scoped_ptr<RuleIterator> rule_iterator(GetRuleIterator( 266 scoped_ptr<RuleIterator> rule_iterator(GetRuleIterator(
151 CONTENT_SETTINGS_TYPE_MEDIASTREAM, std::string(), false)); 267 CONTENT_SETTINGS_TYPE_MEDIASTREAM, std::string(), false));
152 while (rule_iterator->HasNext()) { 268 while (rule_iterator->HasNext()) {
153 // Skip default setting and rules without a value. 269 // Skip default setting and rules without a value.
154 const content_settings::Rule& rule = rule_iterator->Next(); 270 const content_settings::Rule& rule = rule_iterator->Next();
155 DCHECK(rule.primary_pattern != ContentSettingsPattern::Wildcard()); 271 DCHECK(rule.primary_pattern != ContentSettingsPattern::Wildcard());
156 if (!rule.value.get()) 272 if (!rule.value.get())
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 const ContentSettingsPattern& primary_pattern, 314 const ContentSettingsPattern& primary_pattern,
199 const ContentSettingsPattern& secondary_pattern, 315 const ContentSettingsPattern& secondary_pattern,
200 ContentSettingsType content_type, 316 ContentSettingsType content_type,
201 const std::string& resource_identifier) { 317 const std::string& resource_identifier) {
202 NotifyObservers(primary_pattern, 318 NotifyObservers(primary_pattern,
203 secondary_pattern, 319 secondary_pattern,
204 content_type, 320 content_type,
205 resource_identifier); 321 resource_identifier);
206 } 322 }
207 323
324 void PrefProvider::ReadContentSettingsFromOldPref(
msramek 2015/03/26 18:27:39 So this whole method is basically duplicated from
325 PrefProvider::ContentSettingsPrefEntryMap* entry_map) {
326 // |DictionaryPrefUpdate| sends out notifications when destructed. This
327 // construction order ensures |AutoLock| gets destroyed first and |old_lock_|
328 // is not held when the notifications are sent. Also, |auto_reset| must be
329 // still valid when the notifications are sent, so that |Observe| skips the
330 // notification.
331 base::AutoReset<bool> auto_reset(&updating_old_preferences_, true);
332 DictionaryPrefUpdate update(prefs_, prefs::kContentSettingsPatternPairs);
333 base::AutoLock auto_lock(old_lock_);
334
335 const base::DictionaryValue* all_settings_dictionary =
336 prefs_->GetDictionary(prefs::kContentSettingsPatternPairs);
337
338 // Careful: The returned value could be NULL if the pref has never been set.
339 if (!all_settings_dictionary)
340 return;
341
342 base::DictionaryValue* mutable_settings;
343 scoped_ptr<base::DictionaryValue> mutable_settings_scope;
344
345 if (!is_incognito_) {
346 mutable_settings = update.Get();
347 } else {
348 // Create copy as we do not want to persist anything in OTR prefs.
349 mutable_settings = all_settings_dictionary->DeepCopy();
350 mutable_settings_scope.reset(mutable_settings);
351 }
352 // Convert all Unicode patterns into punycode form, then read.
353 ContentSettingsPref::CanonicalizeContentSettingsExceptions(mutable_settings);
354
355 for (base::DictionaryValue::Iterator i(*mutable_settings); !i.IsAtEnd();
356 i.Advance()) {
357 const std::string& pattern_str(i.key());
358 std::pair<ContentSettingsPattern, ContentSettingsPattern> pattern_pair =
359 ParsePatternString(pattern_str);
360 if (!pattern_pair.first.IsValid() ||
361 !pattern_pair.second.IsValid()) {
362 // TODO: Change this to DFATAL when crbug.com/132659 is fixed.
363 LOG(ERROR) << "Invalid pattern strings: " << pattern_str;
364 continue;
365 }
366
367 // Get settings dictionary for the current pattern string, and read
368 // settings from the dictionary.
369 const base::DictionaryValue* settings_dictionary = NULL;
370 bool is_dictionary = i.value().GetAsDictionary(&settings_dictionary);
371 DCHECK(is_dictionary);
372
373 for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
374 ContentSettingsType content_type = static_cast<ContentSettingsType>(i);
375
376 std::string res_dictionary_path;
377 if (GetResourceTypeName(content_type, &res_dictionary_path)) {
378 const base::DictionaryValue* resource_dictionary = NULL;
379 if (settings_dictionary->GetDictionary(
380 res_dictionary_path, &resource_dictionary)) {
381 for (base::DictionaryValue::Iterator j(*resource_dictionary);
382 !j.IsAtEnd();
383 j.Advance()) {
384 const std::string& resource_identifier(j.key());
385 int setting = CONTENT_SETTING_DEFAULT;
386 bool is_integer = j.value().GetAsInteger(&setting);
387 DCHECK(is_integer);
388 DCHECK_NE(CONTENT_SETTING_DEFAULT, setting);
389
390 if (entry_map) {
391 (*entry_map)[content_type].push_back(ContentSettingsPrefEntry(
392 pattern_pair.first,
393 pattern_pair.second,
394 resource_identifier,
395 new base::FundamentalValue(setting)));
396 }
397 }
398 }
399 }
400 base::Value* value = NULL;
401 if (HostContentSettingsMap::ContentTypeHasCompoundValue(content_type)) {
402 const base::DictionaryValue* setting = NULL;
403 // TODO(xians): Handle the non-dictionary types.
404 if (settings_dictionary->GetDictionaryWithoutPathExpansion(
405 GetTypeName(ContentSettingsType(i)), &setting)) {
406 DCHECK(!setting->empty());
407 value = setting->DeepCopy();
408 }
409 } else {
410 int setting = CONTENT_SETTING_DEFAULT;
411 if (settings_dictionary->GetIntegerWithoutPathExpansion(
412 GetTypeName(ContentSettingsType(i)), &setting)) {
413 DCHECK_NE(CONTENT_SETTING_DEFAULT, setting);
414 setting = FixObsoleteCookiePromptMode(content_type,
415 ContentSetting(setting));
416 value = new base::FundamentalValue(setting);
417 }
418 }
419
420 // |entry_map| will take the ownership of |value|.
421 if (value != NULL && entry_map) {
422 (*entry_map)[content_type].push_back(ContentSettingsPrefEntry(
423 pattern_pair.first,
424 pattern_pair.second,
425 ResourceIdentifier(),
426 value));
427 }
428 }
429 }
430 }
431
432 void PrefProvider::WriteSettingsToNewPreferences(bool syncable_only) {
433 if (updating_old_preferences_)
434 return;
435
436 ContentSettingsPrefEntryMap old_values;
437 ReadContentSettingsFromOldPref(&old_values);
438
439 base::AutoReset<bool> auto_reset(&updating_old_preferences_, true);
440 base::AutoLock auto_lock(old_lock_);
msramek 2015/03/26 18:27:39 I readded the lock here to make sure that the migr
441
442 for (ContentSettingsPrefEntryMap::iterator it = old_values.begin();
443 it != old_values.end(); ++it) {
444 ContentSettingsType content_type = it->first;
445 if (syncable_only && !IsContentSettingsTypeSyncable(content_type))
446 return;
447
448 std::vector<ContentSettingsPrefEntry>& entries = it->second;
449
450 content_settings_prefs_[content_type]->ClearAllContentSettingsRules();
451
452 for (size_t i = 0; i < entries.size(); ++i) {
453 content_settings_prefs_[content_type]->SetWebsiteSetting(
454 entries[i].primary_pattern,
455 entries[i].secondary_pattern,
456 entries[i].resource_identifier,
457 entries[i].value->DeepCopy());
458 }
459 }
460 }
461
462 void PrefProvider::OnOldContentSettingsPatternPairsChanged() {
463 DCHECK(thread_checker_.CalledOnValidThread());
464
465 WriteSettingsToNewPreferences(true);
466 }
467
468 void PrefProvider::MigrateAllExceptions() {
469 if (prefs_->GetBoolean(prefs::kMigratedContentSettingsPatternPairs))
470 return;
471
472 WriteSettingsToNewPreferences(false);
473
474 prefs_->SetBoolean(prefs::kMigratedContentSettingsPatternPairs, true);
475 }
476
208 void PrefProvider::SetClockForTesting(scoped_ptr<base::Clock> clock) { 477 void PrefProvider::SetClockForTesting(scoped_ptr<base::Clock> clock) {
209 clock_ = clock.Pass(); 478 clock_ = clock.Pass();
210 content_settings_pref_->SetClockForTesting(clock_.get()); 479 }
480
481 bool PrefProvider::TestAllLocks() const {
482 for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
483 if (!content_settings_prefs_[i]->lock_.Try())
484 return false;
485 content_settings_prefs_[i]->lock_.Release();
486 }
487 return true;
211 } 488 }
212 489
213 } // namespace content_settings 490 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698