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

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

Issue 2843813002: Remove SetWithoutPathExpansion (Closed)
Patch Set: Fix CrOS Error 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
« no previous file with comments | « chromeos/network/policy_util.cc ('k') | components/policy/core/common/policy_test_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <utility>
8 9
9 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
10 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/memory/ptr_util.h"
11 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
12 #include "base/strings/string_split.h" 14 #include "base/strings/string_split.h"
15 #include "base/values.h"
13 #include "components/content_settings/core/browser/content_settings_info.h" 16 #include "components/content_settings/core/browser/content_settings_info.h"
14 #include "components/content_settings/core/browser/content_settings_registry.h" 17 #include "components/content_settings/core/browser/content_settings_registry.h"
15 #include "components/content_settings/core/browser/content_settings_rule.h" 18 #include "components/content_settings/core/browser/content_settings_rule.h"
16 #include "components/content_settings/core/browser/content_settings_utils.h" 19 #include "components/content_settings/core/browser/content_settings_utils.h"
17 #include "components/content_settings/core/browser/host_content_settings_map.h" 20 #include "components/content_settings/core/browser/host_content_settings_map.h"
18 #include "components/content_settings/core/common/content_settings.h" 21 #include "components/content_settings/core/common/content_settings.h"
19 #include "components/content_settings/core/common/content_settings_pattern.h" 22 #include "components/content_settings/core/common/content_settings_pattern.h"
20 #include "components/content_settings/core/common/pref_names.h" 23 #include "components/content_settings/core/common/pref_names.h"
21 #include "components/prefs/scoped_user_pref_update.h" 24 #include "components/prefs/scoped_user_pref_update.h"
22 #include "url/gurl.h" 25 #include "url/gurl.h"
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 base::DictionaryValue* pattern_pairs_settings = update.Get(); 335 base::DictionaryValue* pattern_pairs_settings = update.Get();
333 336
334 // Get settings dictionary for the given patterns. 337 // Get settings dictionary for the given patterns.
335 std::string pattern_str(CreatePatternString(primary_pattern, 338 std::string pattern_str(CreatePatternString(primary_pattern,
336 secondary_pattern)); 339 secondary_pattern));
337 base::DictionaryValue* settings_dictionary = NULL; 340 base::DictionaryValue* settings_dictionary = NULL;
338 bool found = pattern_pairs_settings->GetDictionaryWithoutPathExpansion( 341 bool found = pattern_pairs_settings->GetDictionaryWithoutPathExpansion(
339 pattern_str, &settings_dictionary); 342 pattern_str, &settings_dictionary);
340 343
341 if (!found && value) { 344 if (!found && value) {
342 settings_dictionary = new base::DictionaryValue;
343 pattern_pairs_settings->SetWithoutPathExpansion( 345 pattern_pairs_settings->SetWithoutPathExpansion(
344 pattern_str, settings_dictionary); 346 pattern_str, base::MakeUnique<base::DictionaryValue>());
347 pattern_pairs_settings->GetDictionaryWithoutPathExpansion(
348 pattern_str, &settings_dictionary);
345 } 349 }
346 350
347 if (settings_dictionary) { 351 if (settings_dictionary) {
348 if (SupportsResourceIdentifiers(content_type_) && 352 if (SupportsResourceIdentifiers(content_type_) &&
349 !resource_identifier.empty()) { 353 !resource_identifier.empty()) {
350 base::DictionaryValue* resource_dictionary = NULL; 354 base::DictionaryValue* resource_dictionary = NULL;
351 found = settings_dictionary->GetDictionary( 355 found = settings_dictionary->GetDictionary(
352 kPerResourceIdentifierPrefName, &resource_dictionary); 356 kPerResourceIdentifierPrefName, &resource_dictionary);
353 if (!found) { 357 if (!found) {
354 if (value == NULL) 358 if (value == NULL)
355 return; // Nothing to remove. Exit early. 359 return; // Nothing to remove. Exit early.
356 resource_dictionary = new base::DictionaryValue; 360 resource_dictionary = new base::DictionaryValue;
357 settings_dictionary->Set( 361 settings_dictionary->Set(
358 kPerResourceIdentifierPrefName, resource_dictionary); 362 kPerResourceIdentifierPrefName, resource_dictionary);
359 } 363 }
360 // Update resource dictionary. 364 // Update resource dictionary.
361 if (value == NULL) { 365 if (value == NULL) {
362 resource_dictionary->RemoveWithoutPathExpansion(resource_identifier, 366 resource_dictionary->RemoveWithoutPathExpansion(resource_identifier,
363 NULL); 367 NULL);
364 if (resource_dictionary->empty()) { 368 if (resource_dictionary->empty()) {
365 settings_dictionary->RemoveWithoutPathExpansion( 369 settings_dictionary->RemoveWithoutPathExpansion(
366 kPerResourceIdentifierPrefName, NULL); 370 kPerResourceIdentifierPrefName, NULL);
367 } 371 }
368 } else { 372 } else {
369 resource_dictionary->SetWithoutPathExpansion( 373 resource_dictionary->SetWithoutPathExpansion(resource_identifier,
370 resource_identifier, value->DeepCopy()); 374 value->CreateDeepCopy());
371 } 375 }
372 } else { 376 } else {
373 // Update settings dictionary. 377 // Update settings dictionary.
374 if (value == NULL) { 378 if (value == NULL) {
375 settings_dictionary->RemoveWithoutPathExpansion(kSettingPath, NULL); 379 settings_dictionary->RemoveWithoutPathExpansion(kSettingPath, NULL);
376 } else { 380 } else {
377 settings_dictionary->SetWithoutPathExpansion( 381 settings_dictionary->SetWithoutPathExpansion(kSettingPath,
378 kSettingPath, value->DeepCopy()); 382 value->CreateDeepCopy());
379 } 383 }
380 } 384 }
381 // Remove the settings dictionary if it is empty. 385 // Remove the settings dictionary if it is empty.
382 if (settings_dictionary->empty()) { 386 if (settings_dictionary->empty()) {
383 pattern_pairs_settings->RemoveWithoutPathExpansion( 387 pattern_pairs_settings->RemoveWithoutPathExpansion(
384 pattern_str, NULL); 388 pattern_str, NULL);
385 } 389 }
386 } 390 }
387 } 391 }
388 } 392 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 436
433 for (size_t i = 0; i < remove_items.size(); ++i) { 437 for (size_t i = 0; i < remove_items.size(); ++i) {
434 all_settings_dictionary->RemoveWithoutPathExpansion(remove_items[i], NULL); 438 all_settings_dictionary->RemoveWithoutPathExpansion(remove_items[i], NULL);
435 } 439 }
436 440
437 for (size_t i = 0; i < move_items.size(); ++i) { 441 for (size_t i = 0; i < move_items.size(); ++i) {
438 std::unique_ptr<base::Value> pattern_settings_dictionary; 442 std::unique_ptr<base::Value> pattern_settings_dictionary;
439 all_settings_dictionary->RemoveWithoutPathExpansion( 443 all_settings_dictionary->RemoveWithoutPathExpansion(
440 move_items[i].first, &pattern_settings_dictionary); 444 move_items[i].first, &pattern_settings_dictionary);
441 all_settings_dictionary->SetWithoutPathExpansion( 445 all_settings_dictionary->SetWithoutPathExpansion(
442 move_items[i].second, pattern_settings_dictionary.release()); 446 move_items[i].second, std::move(pattern_settings_dictionary));
443 } 447 }
444 } 448 }
445 449
446 void ContentSettingsPref::AssertLockNotHeld() const { 450 void ContentSettingsPref::AssertLockNotHeld() const {
447 #if !defined(NDEBUG) 451 #if !defined(NDEBUG)
448 // |Lock::Acquire()| will assert if the lock is held by this thread. 452 // |Lock::Acquire()| will assert if the lock is held by this thread.
449 lock_.Acquire(); 453 lock_.Acquire();
450 lock_.Release(); 454 lock_.Release();
451 #endif 455 #endif
452 } 456 }
453 457
454 } // namespace content_settings 458 } // namespace content_settings
OLDNEW
« no previous file with comments | « chromeos/network/policy_util.cc ('k') | components/policy/core/common/policy_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698