| OLD | NEW |
| 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/policy/url_blacklist_manager.h" | 5 #include "chrome/browser/policy/url_blacklist_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 void URLBlacklistManager::ShutdownOnUIThread() { | 290 void URLBlacklistManager::ShutdownOnUIThread() { |
| 291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 292 // Cancel any pending updates, and stop listening for pref change updates. | 292 // Cancel any pending updates, and stop listening for pref change updates. |
| 293 ui_weak_ptr_factory_.InvalidateWeakPtrs(); | 293 ui_weak_ptr_factory_.InvalidateWeakPtrs(); |
| 294 pref_change_registrar_.RemoveAll(); | 294 pref_change_registrar_.RemoveAll(); |
| 295 } | 295 } |
| 296 | 296 |
| 297 URLBlacklistManager::~URLBlacklistManager() { | 297 URLBlacklistManager::~URLBlacklistManager() { |
| 298 } | 298 } |
| 299 | 299 |
| 300 void URLBlacklistManager::Observe(int type, | 300 void URLBlacklistManager::OnPreferenceChanged(PrefServiceBase* prefs, |
| 301 const content::NotificationSource& source, | 301 const std::string& pref_name) { |
| 302 const content::NotificationDetails& details) { | |
| 303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 304 DCHECK(type == chrome::NOTIFICATION_PREF_CHANGED); | |
| 305 PrefService* prefs = content::Source<PrefService>(source).ptr(); | |
| 306 DCHECK(prefs == pref_service_); | 303 DCHECK(prefs == pref_service_); |
| 307 std::string* pref_name = content::Details<std::string>(details).ptr(); | 304 DCHECK(pref_name == prefs::kUrlBlacklist || |
| 308 DCHECK(*pref_name == prefs::kUrlBlacklist || | 305 pref_name == prefs::kUrlWhitelist); |
| 309 *pref_name == prefs::kUrlWhitelist); | |
| 310 ScheduleUpdate(); | 306 ScheduleUpdate(); |
| 311 } | 307 } |
| 312 | 308 |
| 313 void URLBlacklistManager::ScheduleUpdate() { | 309 void URLBlacklistManager::ScheduleUpdate() { |
| 314 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 310 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 315 // Cancel pending updates, if any. This can happen if two preferences that | 311 // Cancel pending updates, if any. This can happen if two preferences that |
| 316 // change the blacklist are updated in one message loop cycle. In those cases, | 312 // change the blacklist are updated in one message loop cycle. In those cases, |
| 317 // only rebuild the blacklist after all the preference updates are processed. | 313 // only rebuild the blacklist after all the preference updates are processed. |
| 318 ui_weak_ptr_factory_.InvalidateWeakPtrs(); | 314 ui_weak_ptr_factory_.InvalidateWeakPtrs(); |
| 319 MessageLoop::current()->PostTask( | 315 MessageLoop::current()->PostTask( |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 | 363 |
| 368 // static | 364 // static |
| 369 void URLBlacklistManager::RegisterPrefs(PrefService* pref_service) { | 365 void URLBlacklistManager::RegisterPrefs(PrefService* pref_service) { |
| 370 pref_service->RegisterListPref(prefs::kUrlBlacklist, | 366 pref_service->RegisterListPref(prefs::kUrlBlacklist, |
| 371 PrefService::UNSYNCABLE_PREF); | 367 PrefService::UNSYNCABLE_PREF); |
| 372 pref_service->RegisterListPref(prefs::kUrlWhitelist, | 368 pref_service->RegisterListPref(prefs::kUrlWhitelist, |
| 373 PrefService::UNSYNCABLE_PREF); | 369 PrefService::UNSYNCABLE_PREF); |
| 374 } | 370 } |
| 375 | 371 |
| 376 } // namespace policy | 372 } // namespace policy |
| OLD | NEW |