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

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

Issue 7344008: Make the hcsm and its providers communicate via an observer interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_pref_provider.h" 5 #include "chrome/browser/content_settings/content_settings_pref_provider.h"
6 6
7 #include <list> 7 #include <list>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 377
378 // Obsolete prefs, for migration: 378 // Obsolete prefs, for migration:
379 prefs->RegisterDictionaryPref(prefs::kContentSettingsPatterns, 379 prefs->RegisterDictionaryPref(prefs::kContentSettingsPatterns,
380 PrefService::SYNCABLE_PREF); 380 PrefService::SYNCABLE_PREF);
381 prefs->RegisterListPref(prefs::kPopupWhitelistedHosts, 381 prefs->RegisterListPref(prefs::kPopupWhitelistedHosts,
382 PrefService::UNSYNCABLE_PREF); 382 PrefService::UNSYNCABLE_PREF);
383 prefs->RegisterDictionaryPref(prefs::kPerHostContentSettings, 383 prefs->RegisterDictionaryPref(prefs::kPerHostContentSettings,
384 PrefService::UNSYNCABLE_PREF); 384 PrefService::UNSYNCABLE_PREF);
385 } 385 }
386 386
387 PrefProvider::PrefProvider(HostContentSettingsMap* map, 387 PrefProvider::PrefProvider(Observer* observer,
388 PrefService* prefs, 388 PrefService* prefs,
389 bool incognito) 389 bool incognito)
390 : prefs_(prefs), 390 : prefs_(prefs),
391 host_content_settings_map_(map),
392 is_incognito_(incognito), 391 is_incognito_(incognito),
393 updating_preferences_(false) { 392 updating_preferences_(false) {
394 DCHECK(prefs_); 393 DCHECK(prefs_);
394 AddObserver(observer);
395 if (!is_incognito_) { 395 if (!is_incognito_) {
396 // Migrate obsolete preferences. 396 // Migrate obsolete preferences.
397 MigrateObsoletePerhostPref(); 397 MigrateObsoletePerhostPref();
398 MigrateObsoletePopupsPref(); 398 MigrateObsoletePopupsPref();
399 MigrateObsoleteContentSettingsPatternPref(); 399 MigrateObsoleteContentSettingsPatternPref();
400 } 400 }
401 401
402 // Verify preferences version. 402 // Verify preferences version.
403 if (!prefs_->HasPrefPath(prefs::kContentSettingsVersion)) { 403 if (!prefs_->HasPrefPath(prefs::kContentSettingsVersion)) {
404 prefs_->SetInteger(prefs::kContentSettingsVersion, 404 prefs_->SetInteger(prefs::kContentSettingsVersion,
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 ContentSettingsPattern(), 559 ContentSettingsPattern(),
560 content_type, 560 content_type,
561 std::string()); 561 std::string());
562 NotifyObservers(details); 562 NotifyObservers(details);
563 } 563 }
564 564
565 void PrefProvider::Observe( 565 void PrefProvider::Observe(
566 int type, 566 int type,
567 const NotificationSource& source, 567 const NotificationSource& source,
568 const NotificationDetails& details) { 568 const NotificationDetails& details) {
569 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 569 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
570 570
571 if (type == chrome::NOTIFICATION_PREF_CHANGED) { 571 if (type == chrome::NOTIFICATION_PREF_CHANGED) {
572 DCHECK_EQ(prefs_, Source<PrefService>(source).ptr()); 572 DCHECK_EQ(prefs_, Source<PrefService>(source).ptr());
573 if (updating_preferences_) 573 if (updating_preferences_)
574 return; 574 return;
575 575
576 std::string* name = Details<std::string>(details).ptr(); 576 std::string* name = Details<std::string>(details).ptr();
577 if (*name == prefs::kContentSettingsPatternPairs) { 577 if (*name == prefs::kContentSettingsPatternPairs) {
578 SyncObsoletePref(); 578 SyncObsoletePref();
579 ReadContentSettingsFromPref(true); 579 ReadContentSettingsFromPref(true);
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 890
891 for (size_t i = 0; i < move_items.size(); ++i) { 891 for (size_t i = 0; i < move_items.size(); ++i) {
892 Value* pattern_settings_dictionary = NULL; 892 Value* pattern_settings_dictionary = NULL;
893 all_settings_dictionary->RemoveWithoutPathExpansion( 893 all_settings_dictionary->RemoveWithoutPathExpansion(
894 move_items[i].first, &pattern_settings_dictionary); 894 move_items[i].first, &pattern_settings_dictionary);
895 all_settings_dictionary->SetWithoutPathExpansion( 895 all_settings_dictionary->SetWithoutPathExpansion(
896 move_items[i].second, pattern_settings_dictionary); 896 move_items[i].second, pattern_settings_dictionary);
897 } 897 }
898 } 898 }
899 899
900 void PrefProvider::NotifyObservers(
901 const ContentSettingsDetails& details) {
902 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
903 DCHECK(host_content_settings_map_);
904 NotificationService::current()->Notify(
905 chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED,
906 Source<HostContentSettingsMap>(host_content_settings_map_),
907 Details<const ContentSettingsDetails>(&details));
908 }
909
910 void PrefProvider::ShutdownOnUIThread() { 900 void PrefProvider::ShutdownOnUIThread() {
911 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 901 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
912 DCHECK(prefs_); 902 DCHECK(prefs_);
903 RemoveAllObserver();
913 pref_change_registrar_.RemoveAll(); 904 pref_change_registrar_.RemoveAll();
914 prefs_ = NULL; 905 prefs_ = NULL;
915 host_content_settings_map_ = NULL;
916 } 906 }
917 907
918 void PrefProvider::MigrateObsoletePerhostPref() { 908 void PrefProvider::MigrateObsoletePerhostPref() {
919 if (prefs_->HasPrefPath(prefs::kPerHostContentSettings)) { 909 if (prefs_->HasPrefPath(prefs::kPerHostContentSettings)) {
920 const DictionaryValue* all_settings_dictionary = 910 const DictionaryValue* all_settings_dictionary =
921 prefs_->GetDictionary(prefs::kPerHostContentSettings); 911 prefs_->GetDictionary(prefs::kPerHostContentSettings);
922 DCHECK(all_settings_dictionary); 912 DCHECK(all_settings_dictionary);
923 for (DictionaryValue::key_iterator 913 for (DictionaryValue::key_iterator
924 i(all_settings_dictionary->begin_keys()); 914 i(all_settings_dictionary->begin_keys());
925 i != all_settings_dictionary->end_keys(); ++i) { 915 i != all_settings_dictionary->end_keys(); ++i) {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 DCHECK(found); 1048 DCHECK(found);
1059 std::string new_key = pattern_pair.first.ToString(); 1049 std::string new_key = pattern_pair.first.ToString();
1060 // Existing values are overwritten. 1050 // Existing values are overwritten.
1061 obsolete_settings_dictionary->SetWithoutPathExpansion( 1051 obsolete_settings_dictionary->SetWithoutPathExpansion(
1062 new_key, dictionary->DeepCopy()); 1052 new_key, dictionary->DeepCopy());
1063 } 1053 }
1064 } 1054 }
1065 } 1055 }
1066 1056
1067 } // namespace content_settings 1057 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698