diff options
author | joaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-07 15:51:07 +0000 |
---|---|---|
committer | joaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-07 15:51:07 +0000 |
commit | 2526ddaed31aa448d34afcb7f03298fb076353e8 (patch) | |
tree | 7f2f38128211321d54b54077db3683333b96cf9e | |
parent | 8b2f1dfdf5392bb3e66b50cd28621994319a75ed (diff) | |
download | chromium_src-2526ddaed31aa448d34afcb7f03298fb076353e8.zip chromium_src-2526ddaed31aa448d34afcb7f03298fb076353e8.tar.gz chromium_src-2526ddaed31aa448d34afcb7f03298fb076353e8.tar.bz2 |
Remove update delay in URLBlacklistManager for tests.
This prevents tests using automation from having to wait for the blacklist
policies to be in place.
BUG=None
TEST=URLBlacklistManagerTest.* pass, everything works as before
Review URL: http://codereview.chromium.org/8197004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104488 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/policy/url_blacklist_manager.cc | 20 | ||||
-rw-r--r-- | chrome/browser/policy/url_blacklist_manager.h | 7 | ||||
-rw-r--r-- | chrome/browser/policy/url_blacklist_manager_unittest.cc | 5 |
3 files changed, 11 insertions, 21 deletions
diff --git a/chrome/browser/policy/url_blacklist_manager.cc b/chrome/browser/policy/url_blacklist_manager.cc index b8502b4..4b6591f 100644 --- a/chrome/browser/policy/url_blacklist_manager.cc +++ b/chrome/browser/policy/url_blacklist_manager.cc @@ -21,10 +21,6 @@ namespace policy { namespace { -// Time to wait before starting an update of the blacklist. Scheduling another -// update during this period will reset the timer. -const int64 kUpdateDelayMs = 1000; - // Maximum filters per policy. Filters over this index are ignored. const size_t kMaxFiltersPerPolicy = 100; @@ -336,16 +332,14 @@ void URLBlacklistManager::Observe(int type, void URLBlacklistManager::ScheduleUpdate() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - // Cancel pending updates, if any. + // Cancel pending updates, if any. This can happen if two preferences that + // change the blacklist are updated in one message loop cycle. In those cases, + // only rebuild the blacklist after all the preference updates are processed. ui_weak_ptr_factory_.InvalidateWeakPtrs(); - PostUpdateTask(base::Bind(&URLBlacklistManager::Update, - ui_weak_ptr_factory_.GetWeakPtr())); -} - -void URLBlacklistManager::PostUpdateTask(const base::Closure& task) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - // This is overridden in tests to post the task without the delay. - MessageLoop::current()->PostDelayedTask(FROM_HERE, task, kUpdateDelayMs); + MessageLoop::current()->PostTask( + FROM_HERE, + base::Bind(&URLBlacklistManager::Update, + ui_weak_ptr_factory_.GetWeakPtr())); } void URLBlacklistManager::Update() { diff --git a/chrome/browser/policy/url_blacklist_manager.h b/chrome/browser/policy/url_blacklist_manager.h index 4be5509..72a22df 100644 --- a/chrome/browser/policy/url_blacklist_manager.h +++ b/chrome/browser/policy/url_blacklist_manager.h @@ -131,11 +131,12 @@ class URLBlacklistManager : public NotificationObserver { protected: typedef std::vector<std::string> StringVector; - // These are used to delay updating the blacklist while the preferences are + // Used to delay updating the blacklist while the preferences are // changing, and execute only one update per simultaneous prefs changes. void ScheduleUpdate(); - // The following methods are virtual for testing. - virtual void PostUpdateTask(const base::Closure& task); + + // Updates the blacklist using the current preference values. + // Virtual for testing. virtual void Update(); // Starts the blacklist update on the IO thread, using the filters in diff --git a/chrome/browser/policy/url_blacklist_manager_unittest.cc b/chrome/browser/policy/url_blacklist_manager_unittest.cc index 816208a..80d9e7f 100644 --- a/chrome/browser/policy/url_blacklist_manager_unittest.cc +++ b/chrome/browser/policy/url_blacklist_manager_unittest.cc @@ -36,11 +36,6 @@ class TestingURLBlacklistManager : public URLBlacklistManager { // Make this method public for testing. using URLBlacklistManager::ScheduleUpdate; - // Post tasks without a delay during tests. - virtual void PostUpdateTask(const base::Closure& task) OVERRIDE { - MessageLoop::current()->PostTask(FROM_HERE, task); - } - // Makes a direct call to UpdateOnIO during tests. void UpdateOnIO() { StringVector* block = new StringVector; |