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

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

Issue 2812113004: Write last_modified date to Content Settings in the PrefProvider (Closed)
Patch Set: fix comments Created 3 years, 8 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 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 #include "components/content_settings/core/browser/content_settings_pref.h" 5 #include "components/content_settings/core/browser/content_settings_pref.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
12 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
13 #include "components/content_settings/core/browser/content_settings_info.h" 14 #include "components/content_settings/core/browser/content_settings_info.h"
14 #include "components/content_settings/core/browser/content_settings_registry.h" 15 #include "components/content_settings/core/browser/content_settings_registry.h"
15 #include "components/content_settings/core/browser/content_settings_rule.h" 16 #include "components/content_settings/core/browser/content_settings_rule.h"
16 #include "components/content_settings/core/browser/content_settings_utils.h" 17 #include "components/content_settings/core/browser/content_settings_utils.h"
17 #include "components/content_settings/core/browser/host_content_settings_map.h" 18 #include "components/content_settings/core/browser/host_content_settings_map.h"
18 #include "components/content_settings/core/common/content_settings.h" 19 #include "components/content_settings/core/common/content_settings.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/pref_names.h" 21 #include "components/content_settings/core/common/pref_names.h"
21 #include "components/prefs/scoped_user_pref_update.h" 22 #include "components/prefs/scoped_user_pref_update.h"
22 #include "url/gurl.h" 23 #include "url/gurl.h"
23 24
24 namespace { 25 namespace {
25 26
26 const char kSettingPath[] = "setting"; 27 const char kSettingPath[] = "setting";
28 const char kLastModifiedPath[] = "last_modified";
27 const char kPerResourceIdentifierPrefName[] = "per_resource"; 29 const char kPerResourceIdentifierPrefName[] = "per_resource";
28 30
29 // If the given content type supports resource identifiers in user preferences, 31 // If the given content type supports resource identifiers in user preferences,
30 // returns true and sets |pref_key| to the key in the content settings 32 // returns true and sets |pref_key| to the key in the content settings
31 // dictionary under which per-resource content settings are stored. 33 // dictionary under which per-resource content settings are stored.
32 // Otherwise, returns false. 34 // Otherwise, returns false.
33 bool SupportsResourceIdentifiers(ContentSettingsType content_type) { 35 bool SupportsResourceIdentifiers(ContentSettingsType content_type) {
34 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; 36 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS;
35 } 37 }
36 38
37 bool IsValueAllowedForType(const base::Value* value, ContentSettingsType type) { 39 bool IsValueAllowedForType(const base::Value* value, ContentSettingsType type) {
38 const content_settings::ContentSettingsInfo* info = 40 const content_settings::ContentSettingsInfo* info =
39 content_settings::ContentSettingsRegistry::GetInstance()->Get(type); 41 content_settings::ContentSettingsRegistry::GetInstance()->Get(type);
40 if (info) { 42 if (info) {
41 int setting; 43 int setting;
42 if (!value->GetAsInteger(&setting)) 44 if (!value->GetAsInteger(&setting))
43 return false; 45 return false;
44 if (setting == CONTENT_SETTING_DEFAULT) 46 if (setting == CONTENT_SETTING_DEFAULT)
45 return false; 47 return false;
46 return info->IsSettingValid(IntToContentSetting(setting)); 48 return info->IsSettingValid(IntToContentSetting(setting));
47 } 49 }
48 50
49 // TODO(raymes): We should permit different types of base::Value for 51 // TODO(raymes): We should permit different types of base::Value for
50 // website settings. 52 // website settings.
51 return value->GetType() == base::Value::Type::DICTIONARY; 53 return value->GetType() == base::Value::Type::DICTIONARY;
52 } 54 }
53 55
56 // Extract a timestamp from |dictionary[kLastModifiedPath]|.
57 // Will return base::Time() if no timestamp exists.
58 base::Time GetTimeStamp(const base::DictionaryValue* dictionary) {
59 std::string timestamp_str;
60 dictionary->GetStringWithoutPathExpansion(kLastModifiedPath, &timestamp_str);
61 int64_t timestamp = 0;
62 base::StringToInt64(timestamp_str, &timestamp);
63 base::Time last_modified = base::Time::FromInternalValue(timestamp);
64 return last_modified;
65 }
66
54 } // namespace 67 } // namespace
55 68
56 namespace content_settings { 69 namespace content_settings {
57 70
58 ContentSettingsPref::ContentSettingsPref( 71 ContentSettingsPref::ContentSettingsPref(
59 ContentSettingsType content_type, 72 ContentSettingsType content_type,
60 PrefService* prefs, 73 PrefService* prefs,
61 PrefChangeRegistrar* registrar, 74 PrefChangeRegistrar* registrar,
62 const std::string& pref_name, 75 const std::string& pref_name,
63 bool incognito, 76 bool incognito,
77 bool store_last_modified,
64 NotifyObserversCallback notify_callback) 78 NotifyObserversCallback notify_callback)
65 : content_type_(content_type), 79 : content_type_(content_type),
66 prefs_(prefs), 80 prefs_(prefs),
67 registrar_(registrar), 81 registrar_(registrar),
68 pref_name_(pref_name), 82 pref_name_(pref_name),
69 is_incognito_(incognito), 83 is_incognito_(incognito),
84 store_last_modified_(store_last_modified),
70 updating_preferences_(false), 85 updating_preferences_(false),
71 notify_callback_(notify_callback) { 86 notify_callback_(notify_callback) {
72 DCHECK(prefs_); 87 DCHECK(prefs_);
73 88
74 ReadContentSettingsFromPref(); 89 ReadContentSettingsFromPref();
75 90
76 registrar_->Add( 91 registrar_->Add(
77 pref_name_, 92 pref_name_,
78 base::Bind(&ContentSettingsPref::OnPrefChanged, base::Unretained(this))); 93 base::Bind(&ContentSettingsPref::OnPrefChanged, base::Unretained(this)));
79 } 94 }
(...skipping 24 matching lines...) Expand all
104 !resource_identifier.empty()); 119 !resource_identifier.empty());
105 120
106 // At this point take the ownership of the |in_value|. 121 // At this point take the ownership of the |in_value|.
107 std::unique_ptr<base::Value> value(in_value); 122 std::unique_ptr<base::Value> value(in_value);
108 123
109 // Update in memory value map. 124 // Update in memory value map.
110 OriginIdentifierValueMap* map_to_modify = &incognito_value_map_; 125 OriginIdentifierValueMap* map_to_modify = &incognito_value_map_;
111 if (!is_incognito_) 126 if (!is_incognito_)
112 map_to_modify = &value_map_; 127 map_to_modify = &value_map_;
113 128
129 base::Time modified_time =
130 store_last_modified_ ? base::Time::Now() : base::Time();
131
114 { 132 {
115 base::AutoLock auto_lock(lock_); 133 base::AutoLock auto_lock(lock_);
116 if (value.get()) { 134 if (value.get()) {
117 map_to_modify->SetValue( 135 map_to_modify->SetValue(primary_pattern, secondary_pattern, content_type_,
118 primary_pattern, 136 resource_identifier, modified_time,
119 secondary_pattern, 137 value->DeepCopy());
120 content_type_,
121 resource_identifier,
122 value->DeepCopy());
123 } else { 138 } else {
124 map_to_modify->DeleteValue( 139 map_to_modify->DeleteValue(
125 primary_pattern, 140 primary_pattern,
126 secondary_pattern, 141 secondary_pattern,
127 content_type_, 142 content_type_,
128 resource_identifier); 143 resource_identifier);
129 } 144 }
130 } 145 }
131 // Update the content settings preference. 146 // Update the content settings preference.
132 if (!is_incognito_) { 147 if (!is_incognito_) {
133 UpdatePref(primary_pattern, 148 UpdatePref(primary_pattern, secondary_pattern, resource_identifier,
134 secondary_pattern, 149 modified_time, value.get());
135 resource_identifier,
136 value.get());
137 } 150 }
138 151
139 notify_callback_.Run( 152 notify_callback_.Run(
140 primary_pattern, secondary_pattern, content_type_, resource_identifier); 153 primary_pattern, secondary_pattern, content_type_, resource_identifier);
141 154
142 return true; 155 return true;
143 } 156 }
144 157
158 void ContentSettingsPref::DeleteWebsiteSettingAfterDate(
159 const ContentSettingsPattern& primary_pattern,
160 const ContentSettingsPattern& secondary_pattern,
161 base::Time begin_time) {
162 OriginIdentifierValueMap* map_to_modify = &incognito_value_map_;
163 if (!is_incognito_)
164 map_to_modify = &value_map_;
165
166 base::Time last_modified = map_to_modify->GetLastModified(
167 primary_pattern, secondary_pattern, content_type_, ResourceIdentifier());
168 if (begin_time <= last_modified) {
169 SetWebsiteSetting(primary_pattern, secondary_pattern, ResourceIdentifier(),
170 nullptr);
171 }
172 }
173
145 void ContentSettingsPref::ClearPref() { 174 void ContentSettingsPref::ClearPref() {
146 DCHECK(thread_checker_.CalledOnValidThread()); 175 DCHECK(thread_checker_.CalledOnValidThread());
147 DCHECK(prefs_); 176 DCHECK(prefs_);
148 177
149 { 178 {
150 base::AutoLock auto_lock(lock_); 179 base::AutoLock auto_lock(lock_);
151 value_map_.clear(); 180 value_map_.clear();
152 } 181 }
153 182
154 { 183 {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 // notification. 224 // notification.
196 base::AutoReset<bool> auto_reset(&updating_preferences_, true); 225 base::AutoReset<bool> auto_reset(&updating_preferences_, true);
197 DictionaryPrefUpdate update(prefs_, pref_name_); 226 DictionaryPrefUpdate update(prefs_, pref_name_);
198 base::AutoLock auto_lock(lock_); 227 base::AutoLock auto_lock(lock_);
199 228
200 const base::DictionaryValue* all_settings_dictionary = 229 const base::DictionaryValue* all_settings_dictionary =
201 prefs_->GetDictionary(pref_name_); 230 prefs_->GetDictionary(pref_name_);
202 231
203 value_map_.clear(); 232 value_map_.clear();
204 233
205 // Careful: The returned value could be NULL if the pref has never been set. 234 // Careful: The returned value could be nullptr if the pref has never been
235 // set.
206 if (!all_settings_dictionary) 236 if (!all_settings_dictionary)
207 return; 237 return;
208 238
209 base::DictionaryValue* mutable_settings; 239 base::DictionaryValue* mutable_settings;
210 std::unique_ptr<base::DictionaryValue> mutable_settings_scope; 240 std::unique_ptr<base::DictionaryValue> mutable_settings_scope;
211 241
212 if (!is_incognito_) { 242 if (!is_incognito_) {
213 mutable_settings = update.Get(); 243 mutable_settings = update.Get();
214 } else { 244 } else {
215 // Create copy as we do not want to persist anything in incognito prefs. 245 // Create copy as we do not want to persist anything in incognito prefs.
(...skipping 13 matching lines...) Expand all
229 ParsePatternString(pattern_str); 259 ParsePatternString(pattern_str);
230 if (!pattern_pair.first.IsValid() || 260 if (!pattern_pair.first.IsValid() ||
231 !pattern_pair.second.IsValid()) { 261 !pattern_pair.second.IsValid()) {
232 // TODO: Change this to DFATAL when crbug.com/132659 is fixed. 262 // TODO: Change this to DFATAL when crbug.com/132659 is fixed.
233 LOG(ERROR) << "Invalid pattern strings: " << pattern_str; 263 LOG(ERROR) << "Invalid pattern strings: " << pattern_str;
234 continue; 264 continue;
235 } 265 }
236 266
237 // Get settings dictionary for the current pattern string, and read 267 // Get settings dictionary for the current pattern string, and read
238 // settings from the dictionary. 268 // settings from the dictionary.
239 const base::DictionaryValue* settings_dictionary = NULL; 269 const base::DictionaryValue* settings_dictionary = nullptr;
240 bool is_dictionary = i.value().GetAsDictionary(&settings_dictionary); 270 bool is_dictionary = i.value().GetAsDictionary(&settings_dictionary);
241 DCHECK(is_dictionary); 271 DCHECK(is_dictionary);
242 272
243 if (SupportsResourceIdentifiers(content_type_)) { 273 if (SupportsResourceIdentifiers(content_type_)) {
244 const base::DictionaryValue* resource_dictionary = NULL; 274 const base::DictionaryValue* resource_dictionary = nullptr;
245 if (settings_dictionary->GetDictionary( 275 if (settings_dictionary->GetDictionary(
246 kPerResourceIdentifierPrefName, &resource_dictionary)) { 276 kPerResourceIdentifierPrefName, &resource_dictionary)) {
247 for (base::DictionaryValue::Iterator j(*resource_dictionary); 277 for (base::DictionaryValue::Iterator j(*resource_dictionary);
248 !j.IsAtEnd(); 278 !j.IsAtEnd();
249 j.Advance()) { 279 j.Advance()) {
250 const std::string& resource_identifier(j.key()); 280 const std::string& resource_identifier(j.key());
251 int setting = CONTENT_SETTING_DEFAULT; 281 int setting = CONTENT_SETTING_DEFAULT;
252 bool is_integer = j.value().GetAsInteger(&setting); 282 bool is_integer = j.value().GetAsInteger(&setting);
253 DCHECK(is_integer); 283 DCHECK(is_integer);
254 DCHECK_NE(CONTENT_SETTING_DEFAULT, setting); 284 DCHECK_NE(CONTENT_SETTING_DEFAULT, setting);
255 std::unique_ptr<base::Value> setting_ptr(new base::Value(setting)); 285 std::unique_ptr<base::Value> setting_ptr(new base::Value(setting));
256 value_map_.SetValue(pattern_pair.first, 286 // Per resource settings don't support last_modified timestamps.
257 pattern_pair.second, 287 value_map_.SetValue(pattern_pair.first, pattern_pair.second,
258 content_type_, 288 content_type_, resource_identifier, base::Time(),
259 resource_identifier,
260 setting_ptr->DeepCopy()); 289 setting_ptr->DeepCopy());
261 } 290 }
262 } 291 }
263 } 292 }
264 293
265 const base::Value* value = nullptr; 294 const base::Value* value = nullptr;
266 settings_dictionary->GetWithoutPathExpansion(kSettingPath, &value); 295 settings_dictionary->GetWithoutPathExpansion(kSettingPath, &value);
267
268 if (value) { 296 if (value) {
297 base::Time last_modified = GetTimeStamp(settings_dictionary);
269 DCHECK(IsValueAllowedForType(value, content_type_)); 298 DCHECK(IsValueAllowedForType(value, content_type_));
270 value_map_.SetValue(pattern_pair.first, 299 value_map_.SetValue(pattern_pair.first, pattern_pair.second,
271 pattern_pair.second, 300 content_type_, ResourceIdentifier(), last_modified,
272 content_type_,
273 ResourceIdentifier(),
274 value->DeepCopy()); 301 value->DeepCopy());
275 if (content_type_ == CONTENT_SETTINGS_TYPE_COOKIES) { 302 if (content_type_ == CONTENT_SETTINGS_TYPE_COOKIES) {
276 ContentSetting s = ValueToContentSetting(value); 303 ContentSetting s = ValueToContentSetting(value);
277 switch (s) { 304 switch (s) {
278 case CONTENT_SETTING_ALLOW : 305 case CONTENT_SETTING_ALLOW :
279 ++cookies_allow_exception_count; 306 ++cookies_allow_exception_count;
280 break; 307 break;
281 case CONTENT_SETTING_BLOCK : 308 case CONTENT_SETTING_BLOCK :
282 ++cookies_block_exception_count; 309 ++cookies_block_exception_count;
283 break; 310 break;
(...skipping 30 matching lines...) Expand all
314 notify_callback_.Run(ContentSettingsPattern(), 341 notify_callback_.Run(ContentSettingsPattern(),
315 ContentSettingsPattern(), 342 ContentSettingsPattern(),
316 content_type_, 343 content_type_,
317 ResourceIdentifier()); 344 ResourceIdentifier());
318 } 345 }
319 346
320 void ContentSettingsPref::UpdatePref( 347 void ContentSettingsPref::UpdatePref(
321 const ContentSettingsPattern& primary_pattern, 348 const ContentSettingsPattern& primary_pattern,
322 const ContentSettingsPattern& secondary_pattern, 349 const ContentSettingsPattern& secondary_pattern,
323 const ResourceIdentifier& resource_identifier, 350 const ResourceIdentifier& resource_identifier,
351 const base::Time last_modified,
324 const base::Value* value) { 352 const base::Value* value) {
325 // Ensure that |lock_| is not held by this thread, since this function will 353 // Ensure that |lock_| is not held by this thread, since this function will
326 // send out notifications (by |~DictionaryPrefUpdate|). 354 // send out notifications (by |~DictionaryPrefUpdate|).
327 AssertLockNotHeld(); 355 AssertLockNotHeld();
328 356
329 base::AutoReset<bool> auto_reset(&updating_preferences_, true); 357 base::AutoReset<bool> auto_reset(&updating_preferences_, true);
330 { 358 {
331 DictionaryPrefUpdate update(prefs_, pref_name_); 359 DictionaryPrefUpdate update(prefs_, pref_name_);
332 base::DictionaryValue* pattern_pairs_settings = update.Get(); 360 base::DictionaryValue* pattern_pairs_settings = update.Get();
333 361
334 // Get settings dictionary for the given patterns. 362 // Get settings dictionary for the given patterns.
335 std::string pattern_str(CreatePatternString(primary_pattern, 363 std::string pattern_str(CreatePatternString(primary_pattern,
336 secondary_pattern)); 364 secondary_pattern));
337 base::DictionaryValue* settings_dictionary = NULL; 365 base::DictionaryValue* settings_dictionary = nullptr;
338 bool found = pattern_pairs_settings->GetDictionaryWithoutPathExpansion( 366 bool found = pattern_pairs_settings->GetDictionaryWithoutPathExpansion(
339 pattern_str, &settings_dictionary); 367 pattern_str, &settings_dictionary);
340 368
341 if (!found && value) { 369 if (!found && value) {
342 settings_dictionary = new base::DictionaryValue; 370 settings_dictionary = new base::DictionaryValue;
343 pattern_pairs_settings->SetWithoutPathExpansion( 371 pattern_pairs_settings->SetWithoutPathExpansion(
344 pattern_str, settings_dictionary); 372 pattern_str, settings_dictionary);
345 } 373 }
346 374
347 if (settings_dictionary) { 375 if (settings_dictionary) {
348 if (SupportsResourceIdentifiers(content_type_) && 376 if (SupportsResourceIdentifiers(content_type_) &&
349 !resource_identifier.empty()) { 377 !resource_identifier.empty()) {
350 base::DictionaryValue* resource_dictionary = NULL; 378 base::DictionaryValue* resource_dictionary = nullptr;
351 found = settings_dictionary->GetDictionary( 379 found = settings_dictionary->GetDictionary(
352 kPerResourceIdentifierPrefName, &resource_dictionary); 380 kPerResourceIdentifierPrefName, &resource_dictionary);
353 if (!found) { 381 if (!found) {
354 if (value == NULL) 382 if (value == nullptr)
355 return; // Nothing to remove. Exit early. 383 return; // Nothing to remove. Exit early.
356 resource_dictionary = new base::DictionaryValue; 384 resource_dictionary = new base::DictionaryValue;
357 settings_dictionary->Set( 385 settings_dictionary->Set(
358 kPerResourceIdentifierPrefName, resource_dictionary); 386 kPerResourceIdentifierPrefName, resource_dictionary);
359 } 387 }
360 // Update resource dictionary. 388 // Update resource dictionary.
361 if (value == NULL) { 389 if (value == nullptr) {
362 resource_dictionary->RemoveWithoutPathExpansion(resource_identifier, 390 resource_dictionary->RemoveWithoutPathExpansion(resource_identifier,
363 NULL); 391 nullptr);
364 if (resource_dictionary->empty()) { 392 if (resource_dictionary->empty()) {
365 settings_dictionary->RemoveWithoutPathExpansion( 393 settings_dictionary->RemoveWithoutPathExpansion(
366 kPerResourceIdentifierPrefName, NULL); 394 kPerResourceIdentifierPrefName, nullptr);
367 } 395 }
368 } else { 396 } else {
369 resource_dictionary->SetWithoutPathExpansion( 397 resource_dictionary->SetWithoutPathExpansion(
370 resource_identifier, value->DeepCopy()); 398 resource_identifier, value->DeepCopy());
371 } 399 }
372 } else { 400 } else {
373 // Update settings dictionary. 401 // Update settings dictionary.
374 if (value == NULL) { 402 if (value == nullptr) {
375 settings_dictionary->RemoveWithoutPathExpansion(kSettingPath, NULL); 403 settings_dictionary->RemoveWithoutPathExpansion(kSettingPath,
404 nullptr);
405 settings_dictionary->RemoveWithoutPathExpansion(kLastModifiedPath,
406 nullptr);
376 } else { 407 } else {
377 settings_dictionary->SetWithoutPathExpansion( 408 settings_dictionary->SetWithoutPathExpansion(
378 kSettingPath, value->DeepCopy()); 409 kSettingPath, value->DeepCopy());
410 settings_dictionary->SetStringWithoutPathExpansion(
411 kLastModifiedPath,
412 base::Int64ToString(last_modified.ToInternalValue()));
379 } 413 }
380 } 414 }
381 // Remove the settings dictionary if it is empty. 415 // Remove the settings dictionary if it is empty.
382 if (settings_dictionary->empty()) { 416 if (settings_dictionary->empty()) {
383 pattern_pairs_settings->RemoveWithoutPathExpansion( 417 pattern_pairs_settings->RemoveWithoutPathExpansion(pattern_str,
384 pattern_str, NULL); 418 nullptr);
385 } 419 }
386 } 420 }
387 } 421 }
388 } 422 }
389 423
390 // static 424 // static
391 void ContentSettingsPref::CanonicalizeContentSettingsExceptions( 425 void ContentSettingsPref::CanonicalizeContentSettingsExceptions(
392 base::DictionaryValue* all_settings_dictionary) { 426 base::DictionaryValue* all_settings_dictionary) {
393 DCHECK(all_settings_dictionary); 427 DCHECK(all_settings_dictionary);
394 428
(...skipping 13 matching lines...) Expand all
408 442
409 const std::string canonicalized_pattern_str = CreatePatternString( 443 const std::string canonicalized_pattern_str = CreatePatternString(
410 pattern_pair.first, pattern_pair.second); 444 pattern_pair.first, pattern_pair.second);
411 445
412 if (canonicalized_pattern_str.empty() || 446 if (canonicalized_pattern_str.empty() ||
413 canonicalized_pattern_str == pattern_str) { 447 canonicalized_pattern_str == pattern_str) {
414 continue; 448 continue;
415 } 449 }
416 450
417 // Clear old pattern if prefs already have canonicalized pattern. 451 // Clear old pattern if prefs already have canonicalized pattern.
418 const base::DictionaryValue* new_pattern_settings_dictionary = NULL; 452 const base::DictionaryValue* new_pattern_settings_dictionary = nullptr;
419 if (all_settings_dictionary->GetDictionaryWithoutPathExpansion( 453 if (all_settings_dictionary->GetDictionaryWithoutPathExpansion(
420 canonicalized_pattern_str, &new_pattern_settings_dictionary)) { 454 canonicalized_pattern_str, &new_pattern_settings_dictionary)) {
421 remove_items.push_back(pattern_str); 455 remove_items.push_back(pattern_str);
422 continue; 456 continue;
423 } 457 }
424 458
425 // Move old pattern to canonicalized pattern. 459 // Move old pattern to canonicalized pattern.
426 const base::DictionaryValue* old_pattern_settings_dictionary = NULL; 460 const base::DictionaryValue* old_pattern_settings_dictionary = nullptr;
427 if (i.value().GetAsDictionary(&old_pattern_settings_dictionary)) { 461 if (i.value().GetAsDictionary(&old_pattern_settings_dictionary)) {
428 move_items.push_back( 462 move_items.push_back(
429 std::make_pair(pattern_str, canonicalized_pattern_str)); 463 std::make_pair(pattern_str, canonicalized_pattern_str));
430 } 464 }
431 } 465 }
432 466
433 for (size_t i = 0; i < remove_items.size(); ++i) { 467 for (size_t i = 0; i < remove_items.size(); ++i) {
434 all_settings_dictionary->RemoveWithoutPathExpansion(remove_items[i], NULL); 468 all_settings_dictionary->RemoveWithoutPathExpansion(remove_items[i],
469 nullptr);
435 } 470 }
436 471
437 for (size_t i = 0; i < move_items.size(); ++i) { 472 for (size_t i = 0; i < move_items.size(); ++i) {
438 std::unique_ptr<base::Value> pattern_settings_dictionary; 473 std::unique_ptr<base::Value> pattern_settings_dictionary;
439 all_settings_dictionary->RemoveWithoutPathExpansion( 474 all_settings_dictionary->RemoveWithoutPathExpansion(
440 move_items[i].first, &pattern_settings_dictionary); 475 move_items[i].first, &pattern_settings_dictionary);
441 all_settings_dictionary->SetWithoutPathExpansion( 476 all_settings_dictionary->SetWithoutPathExpansion(
442 move_items[i].second, pattern_settings_dictionary.release()); 477 move_items[i].second, pattern_settings_dictionary.release());
443 } 478 }
444 } 479 }
445 480
446 void ContentSettingsPref::AssertLockNotHeld() const { 481 void ContentSettingsPref::AssertLockNotHeld() const {
447 #if !defined(NDEBUG) 482 #if !defined(NDEBUG)
448 // |Lock::Acquire()| will assert if the lock is held by this thread. 483 // |Lock::Acquire()| will assert if the lock is held by this thread.
449 lock_.Acquire(); 484 lock_.Acquire();
450 lock_.Release(); 485 lock_.Release();
451 #endif 486 #endif
452 } 487 }
453 488
454 } // namespace content_settings 489 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698