diff options
-rw-r--r-- | base/ref_counted.h | 18 | ||||
-rw-r--r-- | chrome/browser/browser_about_handler.cc | 3 | ||||
-rw-r--r-- | chrome/browser/dom_ui/downloads_dom_handler.cc | 7 | ||||
-rw-r--r-- | chrome/browser/dom_ui/downloads_ui.cc | 2 | ||||
-rw-r--r-- | chrome/browser/dom_ui/filebrowse_ui.cc | 4 | ||||
-rw-r--r-- | chrome/browser/dom_ui/history_ui.cc | 4 | ||||
-rw-r--r-- | chrome/browser/dom_ui/most_visited_handler.cc | 18 | ||||
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui.cc | 16 | ||||
-rw-r--r-- | chrome/browser/dom_ui/print_ui.cc | 2 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_updater.cc | 2 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_ui.cc | 2 | ||||
-rw-r--r-- | chrome/browser/sync/sync_setup_wizard.cc | 8 | ||||
-rw-r--r-- | webkit/appcache/mock_appcache_storage.cc | 15 |
13 files changed, 54 insertions, 47 deletions
diff --git a/base/ref_counted.h b/base/ref_counted.h index f2e4327..e8413d9 100644 --- a/base/ref_counted.h +++ b/base/ref_counted.h @@ -227,6 +227,12 @@ class scoped_refptr { ptr_->AddRef(); } + template <typename U> + scoped_refptr(const scoped_refptr<U>& r) : ptr_(r.get()) { + if (ptr_) + ptr_->AddRef(); + } + ~scoped_refptr() { if (ptr_) ptr_->Release(); @@ -261,6 +267,11 @@ class scoped_refptr { return *this = r.ptr_; } + template <typename U> + scoped_refptr<T>& operator=(const scoped_refptr<U>& r) { + return *this = r.get(); + } + void swap(T** pp) { T* p = ptr_; ptr_ = *pp; @@ -275,4 +286,11 @@ class scoped_refptr { T* ptr_; }; +// Handy utility for creating a scoped_refptr<T> out of a T* explicitly without +// having to retype all the template arguments +template <typename T> +scoped_refptr<T> make_scoped_refptr(T* t) { + return scoped_refptr<T>(t); +} + #endif // BASE_REF_COUNTED_H_ diff --git a/chrome/browser/browser_about_handler.cc b/chrome/browser/browser_about_handler.cc index 44fab78..79abe28 100644 --- a/chrome/browser/browser_about_handler.cc +++ b/chrome/browser/browser_about_handler.cc @@ -598,7 +598,8 @@ AboutSource::AboutSource() ChromeThread::IO, FROM_HERE, NewRunnableMethod( Singleton<ChromeURLDataManager>::get(), - &ChromeURLDataManager::AddDataSource, this)); + &ChromeURLDataManager::AddDataSource, + make_scoped_refptr(this))); } AboutSource::~AboutSource() { diff --git a/chrome/browser/dom_ui/downloads_dom_handler.cc b/chrome/browser/dom_ui/downloads_dom_handler.cc index 028b21a..7e8d1a0 100644 --- a/chrome/browser/dom_ui/downloads_dom_handler.cc +++ b/chrome/browser/dom_ui/downloads_dom_handler.cc @@ -49,9 +49,10 @@ DownloadsDOMHandler::DownloadsDOMHandler(DownloadManager* dlm) // Create our fileicon data source. ChromeThread::PostTask( ChromeThread::IO, FROM_HERE, - NewRunnableMethod(Singleton<ChromeURLDataManager>::get(), - &ChromeURLDataManager::AddDataSource, - new FileIconSource())); + NewRunnableMethod( + Singleton<ChromeURLDataManager>::get(), + &ChromeURLDataManager::AddDataSource, + make_scoped_refptr(new FileIconSource()))); } DownloadsDOMHandler::~DownloadsDOMHandler() { diff --git a/chrome/browser/dom_ui/downloads_ui.cc b/chrome/browser/dom_ui/downloads_ui.cc index e36654f..f12e812 100644 --- a/chrome/browser/dom_ui/downloads_ui.cc +++ b/chrome/browser/dom_ui/downloads_ui.cc @@ -133,7 +133,7 @@ DownloadsUI::DownloadsUI(TabContents* contents) : DOMUI(contents) { ChromeThread::IO, FROM_HERE, NewRunnableMethod(Singleton<ChromeURLDataManager>::get(), &ChromeURLDataManager::AddDataSource, - html_source)); + make_scoped_refptr(html_source))); } // static diff --git a/chrome/browser/dom_ui/filebrowse_ui.cc b/chrome/browser/dom_ui/filebrowse_ui.cc index 48ed389..13b6539 100644 --- a/chrome/browser/dom_ui/filebrowse_ui.cc +++ b/chrome/browser/dom_ui/filebrowse_ui.cc @@ -157,7 +157,7 @@ DOMMessageHandler* FilebrowseHandler::Attach(DOMUI* dom_ui) { NewRunnableMethod( Singleton<ChromeURLDataManager>::get(), &ChromeURLDataManager::AddDataSource, - new DOMUIFavIconSource(dom_ui->GetProfile()))); + make_scoped_refptr(new DOMUIFavIconSource(dom_ui->GetProfile())))); profile_ = dom_ui->GetProfile(); return DOMMessageHandler::Attach(dom_ui); } @@ -323,5 +323,5 @@ FileBrowseUI::FileBrowseUI(TabContents* contents) : DOMUI(contents) { NewRunnableMethod( Singleton<ChromeURLDataManager>::get(), &ChromeURLDataManager::AddDataSource, - html_source)); + make_scoped_refptr(html_source))); } diff --git a/chrome/browser/dom_ui/history_ui.cc b/chrome/browser/dom_ui/history_ui.cc index dce9cdb..a97992b 100644 --- a/chrome/browser/dom_ui/history_ui.cc +++ b/chrome/browser/dom_ui/history_ui.cc @@ -116,7 +116,7 @@ DOMMessageHandler* BrowsingHistoryHandler::Attach(DOMUI* dom_ui) { NewRunnableMethod( Singleton<ChromeURLDataManager>::get(), &ChromeURLDataManager::AddDataSource, - new DOMUIFavIconSource(dom_ui->GetProfile()))); + make_scoped_refptr(new DOMUIFavIconSource(dom_ui->GetProfile())))); // Get notifications when history is cleared. registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, @@ -371,7 +371,7 @@ HistoryUI::HistoryUI(TabContents* contents) : DOMUI(contents) { NewRunnableMethod( Singleton<ChromeURLDataManager>::get(), &ChromeURLDataManager::AddDataSource, - html_source)); + make_scoped_refptr(html_source))); } // static diff --git a/chrome/browser/dom_ui/most_visited_handler.cc b/chrome/browser/dom_ui/most_visited_handler.cc index 7dc5569..8901d3f9 100644 --- a/chrome/browser/dom_ui/most_visited_handler.cc +++ b/chrome/browser/dom_ui/most_visited_handler.cc @@ -59,24 +59,18 @@ DOMMessageHandler* MostVisitedHandler::Attach(DOMUI* dom_ui) { // Set up our sources for thumbnail and favicon data. DOMUIThumbnailSource* thumbnail_src = new DOMUIThumbnailSource(dom_ui->GetProfile()); - bool posted = ChromeThread::PostTask( + ChromeThread::PostTask( ChromeThread::IO, FROM_HERE, NewRunnableMethod(Singleton<ChromeURLDataManager>::get(), - &ChromeURLDataManager::AddDataSource, thumbnail_src)); - if (!posted) { - thumbnail_src->AddRef(); - thumbnail_src->Release(); // Keep Valgrind happy in unit tests. - } + &ChromeURLDataManager::AddDataSource, + make_scoped_refptr(thumbnail_src))); DOMUIFavIconSource* favicon_src = new DOMUIFavIconSource(dom_ui->GetProfile()); - posted = ChromeThread::PostTask( + ChromeThread::PostTask( ChromeThread::IO, FROM_HERE, NewRunnableMethod(Singleton<ChromeURLDataManager>::get(), - &ChromeURLDataManager::AddDataSource, favicon_src)); - if (!posted) { - favicon_src->AddRef(); - favicon_src->Release(); // Keep Valgrind happy in unit tests. - } + &ChromeURLDataManager::AddDataSource, + make_scoped_refptr(favicon_src))); // Get notifications when history is cleared. registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc index b11d7b4..a69a4ba 100644 --- a/chrome/browser/dom_ui/new_tab_ui.cc +++ b/chrome/browser/dom_ui/new_tab_ui.cc @@ -483,16 +483,12 @@ NewTabUI::NewTabUI(TabContents* contents) InitializeCSSCaches(); NewTabHTMLSource* html_source = new NewTabHTMLSource(GetProfile()->GetOriginalProfile()); - bool posted = ChromeThread::PostTask( + ChromeThread::PostTask( ChromeThread::IO, FROM_HERE, NewRunnableMethod( Singleton<ChromeURLDataManager>::get(), &ChromeURLDataManager::AddDataSource, - html_source)); - if (!posted) { - html_source->AddRef(); - html_source->Release(); // Keep Valgrind happy in tests. - } + make_scoped_refptr(html_source))); if (!GetProfile()->IsOffTheRecord()) { AddMessageHandler((new ShownSectionsHandler())->Attach(this)); @@ -544,16 +540,12 @@ void NewTabUI::Observe(NotificationType type, void NewTabUI::InitializeCSSCaches() { DOMUIThemeSource* theme = new DOMUIThemeSource(GetProfile()); - bool posted = ChromeThread::PostTask( + ChromeThread::PostTask( ChromeThread::IO, FROM_HERE, NewRunnableMethod( Singleton<ChromeURLDataManager>::get(), &ChromeURLDataManager::AddDataSource, - theme)); - if (!posted) { - theme->AddRef(); - theme->Release(); // Keep Valgrind happy in tests. - } + make_scoped_refptr(theme))); } // static diff --git a/chrome/browser/dom_ui/print_ui.cc b/chrome/browser/dom_ui/print_ui.cc index 31146ab..5aea8d7 100644 --- a/chrome/browser/dom_ui/print_ui.cc +++ b/chrome/browser/dom_ui/print_ui.cc @@ -32,7 +32,7 @@ PrintUI::PrintUI(TabContents* contents) : DOMUI(contents) { NewRunnableMethod( Singleton<ChromeURLDataManager>::get(), &ChromeURLDataManager::AddDataSource, - html_source)); + make_scoped_refptr(html_source))); } //////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/extensions/extension_updater.cc b/chrome/browser/extensions/extension_updater.cc index 6578024..a219b0d 100644 --- a/chrome/browser/extensions/extension_updater.cc +++ b/chrome/browser/extensions/extension_updater.cc @@ -363,7 +363,7 @@ void ExtensionUpdater::OnCRXFetchComplete(const GURL& url, ChromeThread::FILE, FROM_HERE, NewRunnableMethod( file_handler_.get(), &ExtensionUpdaterFileHandler::WriteTempFile, - current_extension_fetch_.id, data, this)); + current_extension_fetch_.id, data, make_scoped_refptr(this))); } } else { // TODO(asargent) do things like exponential backoff, handling diff --git a/chrome/browser/extensions/extensions_ui.cc b/chrome/browser/extensions/extensions_ui.cc index 2af1c01..7eb58bb 100644 --- a/chrome/browser/extensions/extensions_ui.cc +++ b/chrome/browser/extensions/extensions_ui.cc @@ -739,7 +739,7 @@ ExtensionsUI::ExtensionsUI(TabContents* contents) : DOMUI(contents) { NewRunnableMethod( Singleton<ChromeURLDataManager>::get(), &ChromeURLDataManager::AddDataSource, - html_source)); + make_scoped_refptr(html_source))); } // static diff --git a/chrome/browser/sync/sync_setup_wizard.cc b/chrome/browser/sync/sync_setup_wizard.cc index e6f7bd8..e003b49 100644 --- a/chrome/browser/sync/sync_setup_wizard.cc +++ b/chrome/browser/sync/sync_setup_wizard.cc @@ -180,15 +180,11 @@ SyncSetupWizard::SyncSetupWizard(ProfileSyncService* service) flow_container_(new SyncSetupFlowContainer()) { // Add our network layer data source for 'cloudy' URLs. SyncResourcesSource* sync_source = new SyncResourcesSource(); - bool posted = ChromeThread::PostTask( + ChromeThread::PostTask( ChromeThread::IO, FROM_HERE, NewRunnableMethod(Singleton<ChromeURLDataManager>::get(), &ChromeURLDataManager::AddDataSource, - sync_source)); - if (!posted) { - sync_source->AddRef(); - sync_source->Release(); // Keep Valgrind happy in unit tests. - } + make_scoped_refptr(sync_source))); } SyncSetupWizard::~SyncSetupWizard() { diff --git a/webkit/appcache/mock_appcache_storage.cc b/webkit/appcache/mock_appcache_storage.cc index d176288..cf93338 100644 --- a/webkit/appcache/mock_appcache_storage.cc +++ b/webkit/appcache/mock_appcache_storage.cc @@ -50,7 +50,7 @@ void MockAppCacheStorage::LoadCache(int64 id, Delegate* delegate) { if (ShouldCacheLoadAppearAsync(cache)) { ScheduleTask(method_factory_.NewRunnableMethod( &MockAppCacheStorage::ProcessLoadCache, - id, GetOrCreateDelegateReference(delegate))); + id, make_scoped_refptr(GetOrCreateDelegateReference(delegate)))); return; } ProcessLoadCache(id, GetOrCreateDelegateReference(delegate)); @@ -63,7 +63,8 @@ void MockAppCacheStorage::LoadOrCreateGroup( if (ShouldGroupLoadAppearAsync(group)) { ScheduleTask(method_factory_.NewRunnableMethod( &MockAppCacheStorage::ProcessLoadOrCreateGroup, - manifest_url, GetOrCreateDelegateReference(delegate))); + manifest_url, + make_scoped_refptr(GetOrCreateDelegateReference(delegate)))); return; } ProcessLoadOrCreateGroup( @@ -78,7 +79,9 @@ void MockAppCacheStorage::StoreGroupAndNewestCache( // Always make this operation look async. ScheduleTask(method_factory_.NewRunnableMethod( &MockAppCacheStorage::ProcessStoreGroupAndNewestCache, - group, newest_cache, GetOrCreateDelegateReference(delegate))); + make_scoped_refptr(group), + make_scoped_refptr(newest_cache), + make_scoped_refptr(GetOrCreateDelegateReference(delegate)))); } void MockAppCacheStorage::FindResponseForMainRequest( @@ -88,7 +91,8 @@ void MockAppCacheStorage::FindResponseForMainRequest( // Always make this operation look async. ScheduleTask(method_factory_.NewRunnableMethod( &MockAppCacheStorage::ProcessFindResponseForMainRequest, - url, GetOrCreateDelegateReference(delegate))); + url, + make_scoped_refptr(GetOrCreateDelegateReference(delegate)))); } void MockAppCacheStorage::FindResponseForSubRequest( @@ -132,7 +136,8 @@ void MockAppCacheStorage::MakeGroupObsolete( // Always make this method look async. ScheduleTask(method_factory_.NewRunnableMethod( &MockAppCacheStorage::ProcessMakeGroupObsolete, - group, GetOrCreateDelegateReference(delegate))); + make_scoped_refptr(group), + make_scoped_refptr(GetOrCreateDelegateReference(delegate)))); } AppCacheResponseReader* MockAppCacheStorage::CreateResponseReader( |