Chromium Code Reviews| Index: chrome/browser/policy/url_blacklist_manager.cc |
| diff --git a/chrome/browser/policy/url_blacklist_manager.cc b/chrome/browser/policy/url_blacklist_manager.cc |
| index 63ccddef60cb3e43b63113729b5902d5e8a64323..d77ab86d047541587d4d451331f1154be831edcc 100644 |
| --- a/chrome/browser/policy/url_blacklist_manager.cc |
| +++ b/chrome/browser/policy/url_blacklist_manager.cc |
| @@ -46,16 +46,11 @@ StringVector* ListValueToStringVector(const base::ListValue* list) { |
| return vector; |
| } |
| -// A task that builds the blacklist on the FILE thread. Takes ownership |
| -// of |block| and |allow| but not of |blacklist|. |
| +// A task that builds the blacklist on the FILE thread. |
| void BuildBlacklist(URLBlacklist* blacklist, |
| - StringVector* block, |
| - StringVector* allow) { |
| + scoped_ptr<StringVector> block, |
| + scoped_ptr<StringVector> allow) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| - |
| - scoped_ptr<StringVector> scoped_block(block); |
| - scoped_ptr<StringVector> scoped_allow(allow); |
| - |
| for (StringVector::iterator it = block->begin(); it != block->end(); ++it) { |
| blacklist->Block(*it); |
| } |
| @@ -64,18 +59,6 @@ void BuildBlacklist(URLBlacklist* blacklist, |
| } |
| } |
| -// A task that owns the URLBlacklist, and passes it to the URLBlacklistManager |
| -// on the IO thread, if the URLBlacklistManager still exists. |
| -void SetBlacklistOnIO(base::WeakPtr<URLBlacklistManager> blacklist_manager, |
| - URLBlacklist* blacklist) { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| - if (blacklist_manager) { |
| - blacklist_manager->SetBlacklist(blacklist); |
| - } else { |
| - delete blacklist; |
| - } |
| -} |
| - |
| } // namespace |
| struct URLBlacklist::PathFilter { |
| @@ -367,37 +350,43 @@ void URLBlacklistManager::Update() { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| // The preferences can only be read on the UI thread. |
| - StringVector* block = |
| - ListValueToStringVector(pref_service_->GetList(prefs::kUrlBlacklist)); |
| - StringVector* allow = |
| - ListValueToStringVector(pref_service_->GetList(prefs::kUrlWhitelist)); |
| + scoped_ptr<StringVector> block( |
| + ListValueToStringVector(pref_service_->GetList(prefs::kUrlBlacklist))); |
| + scoped_ptr<StringVector> allow( |
| + ListValueToStringVector(pref_service_->GetList(prefs::kUrlWhitelist))); |
| // Go through the IO thread to grab a WeakPtr to |this|. This is safe from |
| // here, since this task will always execute before a potential deletion of |
| // ProfileIOData on IO. |
| BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| base::Bind(&URLBlacklistManager::UpdateOnIO, |
| - base::Unretained(this), block, allow)); |
| + base::Unretained(this), |
| + base::Passed(&block), |
| + base::Passed(&allow))); |
| } |
| -void URLBlacklistManager::UpdateOnIO(StringVector* block, StringVector* allow) { |
| +void URLBlacklistManager::UpdateOnIO(scoped_ptr<StringVector> block, |
| + scoped_ptr<StringVector> allow) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| - URLBlacklist* blacklist = new URLBlacklist; |
| + scoped_ptr<URLBlacklist> blacklist(new URLBlacklist); |
| + // Get a raw pointer now, since |blacklist.get()| might be evaluated after |
| + // |Passed(&blacklist) below. |
| + URLBlacklist* raw_blacklist = blacklist.get(); |
|
Joao da Silva
2011/12/10 14:11:54
Only found this after the unit_tests crashed. Havi
awong
2011/12/12 22:01:26
Oh interesting. I had not thought about that. Yea
|
| // The URLBlacklist is built on the FILE thread. Once it's ready, it is passed |
| // to the URLBlacklistManager on IO. |
| - // |blacklist|, |block| and |allow| can leak on the unlikely event of a |
| - // policy update and shutdown happening at the same time. |
| BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, |
| base::Bind(&BuildBlacklist, |
| - blacklist, block, allow), |
| - base::Bind(&SetBlacklistOnIO, |
| + raw_blacklist, |
| + base::Passed(&block), |
| + base::Passed(&allow)), |
| + base::Bind(&URLBlacklistManager::SetBlacklist, |
| io_weak_ptr_factory_.GetWeakPtr(), |
| - blacklist)); |
| + base::Passed(&blacklist))); |
| } |
| -void URLBlacklistManager::SetBlacklist(URLBlacklist* blacklist) { |
| +void URLBlacklistManager::SetBlacklist(scoped_ptr<URLBlacklist> blacklist) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| - blacklist_.reset(blacklist); |
| + blacklist_.swap(blacklist); |
| } |
| bool URLBlacklistManager::IsURLBlocked(const GURL& url) const { |