| 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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  271 } |  271 } | 
|  272  |  272  | 
|  273 URLBlacklistManager::URLBlacklistManager(PrefService* pref_service) |  273 URLBlacklistManager::URLBlacklistManager(PrefService* pref_service) | 
|  274     : ALLOW_THIS_IN_INITIALIZER_LIST(ui_weak_ptr_factory_(this)), |  274     : ALLOW_THIS_IN_INITIALIZER_LIST(ui_weak_ptr_factory_(this)), | 
|  275       pref_service_(pref_service), |  275       pref_service_(pref_service), | 
|  276       ALLOW_THIS_IN_INITIALIZER_LIST(io_weak_ptr_factory_(this)), |  276       ALLOW_THIS_IN_INITIALIZER_LIST(io_weak_ptr_factory_(this)), | 
|  277       blacklist_(new URLBlacklist) { |  277       blacklist_(new URLBlacklist) { | 
|  278   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |  278   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
|  279  |  279  | 
|  280   pref_change_registrar_.Init(pref_service_); |  280   pref_change_registrar_.Init(pref_service_); | 
|  281   pref_change_registrar_.Add(prefs::kUrlBlacklist, this); |  281   base::Closure callback = base::Bind(&URLBlacklistManager::ScheduleUpdate, | 
|  282   pref_change_registrar_.Add(prefs::kUrlWhitelist, this); |  282                                       base::Unretained(this)); | 
 |  283   pref_change_registrar_.Add(prefs::kUrlBlacklist, callback); | 
 |  284   pref_change_registrar_.Add(prefs::kUrlWhitelist, callback); | 
|  283  |  285  | 
|  284   // Start enforcing the policies without a delay when they are present at |  286   // Start enforcing the policies without a delay when they are present at | 
|  285   // startup. |  287   // startup. | 
|  286   if (pref_service_->HasPrefPath(prefs::kUrlBlacklist)) |  288   if (pref_service_->HasPrefPath(prefs::kUrlBlacklist)) | 
|  287     Update(); |  289     Update(); | 
|  288 } |  290 } | 
|  289  |  291  | 
|  290 void URLBlacklistManager::ShutdownOnUIThread() { |  292 void URLBlacklistManager::ShutdownOnUIThread() { | 
|  291   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |  293   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
|  292   // Cancel any pending updates, and stop listening for pref change updates. |  294   // Cancel any pending updates, and stop listening for pref change updates. | 
|  293   ui_weak_ptr_factory_.InvalidateWeakPtrs(); |  295   ui_weak_ptr_factory_.InvalidateWeakPtrs(); | 
|  294   pref_change_registrar_.RemoveAll(); |  296   pref_change_registrar_.RemoveAll(); | 
|  295 } |  297 } | 
|  296  |  298  | 
|  297 URLBlacklistManager::~URLBlacklistManager() { |  299 URLBlacklistManager::~URLBlacklistManager() { | 
|  298 } |  300 } | 
|  299  |  301  | 
|  300 void URLBlacklistManager::OnPreferenceChanged(PrefServiceBase* prefs, |  | 
|  301                                               const std::string& pref_name) { |  | 
|  302   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |  | 
|  303   DCHECK(prefs == pref_service_); |  | 
|  304   DCHECK(pref_name == prefs::kUrlBlacklist || |  | 
|  305          pref_name == prefs::kUrlWhitelist); |  | 
|  306   ScheduleUpdate(); |  | 
|  307 } |  | 
|  308  |  | 
|  309 void URLBlacklistManager::ScheduleUpdate() { |  302 void URLBlacklistManager::ScheduleUpdate() { | 
|  310   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |  303   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
|  311   // Cancel pending updates, if any. This can happen if two preferences that |  304   // Cancel pending updates, if any. This can happen if two preferences that | 
|  312   // change the blacklist are updated in one message loop cycle. In those cases, |  305   // change the blacklist are updated in one message loop cycle. In those cases, | 
|  313   // only rebuild the blacklist after all the preference updates are processed. |  306   // only rebuild the blacklist after all the preference updates are processed. | 
|  314   ui_weak_ptr_factory_.InvalidateWeakPtrs(); |  307   ui_weak_ptr_factory_.InvalidateWeakPtrs(); | 
|  315   MessageLoop::current()->PostTask( |  308   MessageLoop::current()->PostTask( | 
|  316       FROM_HERE, |  309       FROM_HERE, | 
|  317       base::Bind(&URLBlacklistManager::Update, |  310       base::Bind(&URLBlacklistManager::Update, | 
|  318                  ui_weak_ptr_factory_.GetWeakPtr())); |  311                  ui_weak_ptr_factory_.GetWeakPtr())); | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  363  |  356  | 
|  364 // static |  357 // static | 
|  365 void URLBlacklistManager::RegisterPrefs(PrefService* pref_service) { |  358 void URLBlacklistManager::RegisterPrefs(PrefService* pref_service) { | 
|  366   pref_service->RegisterListPref(prefs::kUrlBlacklist, |  359   pref_service->RegisterListPref(prefs::kUrlBlacklist, | 
|  367                                  PrefService::UNSYNCABLE_PREF); |  360                                  PrefService::UNSYNCABLE_PREF); | 
|  368   pref_service->RegisterListPref(prefs::kUrlWhitelist, |  361   pref_service->RegisterListPref(prefs::kUrlWhitelist, | 
|  369                                  PrefService::UNSYNCABLE_PREF); |  362                                  PrefService::UNSYNCABLE_PREF); | 
|  370 } |  363 } | 
|  371  |  364  | 
|  372 }  // namespace policy |  365 }  // namespace policy | 
| OLD | NEW |