diff options
author | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-29 01:14:34 +0000 |
---|---|---|
committer | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-29 01:14:34 +0000 |
commit | a932d9eb4b3ea1ddc72167f30cce70cac2899345 (patch) | |
tree | 4d0cb5db939a5c7b794a092f9dfecc47c4beb264 | |
parent | 848be26b766e47e45dbf2f1bacee4aa908f307f3 (diff) | |
download | chromium_src-a932d9eb4b3ea1ddc72167f30cce70cac2899345.zip chromium_src-a932d9eb4b3ea1ddc72167f30cce70cac2899345.tar.gz chromium_src-a932d9eb4b3ea1ddc72167f30cce70cac2899345.tar.bz2 |
Convert most uses of the old callbacks in c/b/u/cocoa/ to use base::Bind().
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/8073005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103220 0039d316-1c4b-4281-b951-d872f2087c98
11 files changed, 56 insertions, 56 deletions
diff --git a/chrome/browser/ui/cocoa/browser_window_cocoa.h b/chrome/browser/ui/cocoa/browser_window_cocoa.h index 138c6ba..6fcbf53 100644 --- a/chrome/browser/ui/cocoa/browser_window_cocoa.h +++ b/chrome/browser/ui/cocoa/browser_window_cocoa.h @@ -7,7 +7,7 @@ #pragma once #include "base/memory/scoped_nsobject.h" -#include "base/task.h" +#include "base/memory/weak_ptr.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/ui/browser_window.h" #include "content/common/notification_registrar.h" @@ -138,7 +138,7 @@ class BrowserWindowCocoa : public BrowserWindow, NotificationRegistrar registrar_; Browser* browser_; // weak, owned by controller BrowserWindowController* controller_; // weak, owns us - ScopedRunnableMethodFactory<Browser> confirm_close_factory_; + base::WeakPtrFactory<Browser> confirm_close_factory_; scoped_nsobject<NSString> pending_window_title_; ui::WindowShowState initial_show_state_; }; diff --git a/chrome/browser/ui/cocoa/browser_window_cocoa.mm b/chrome/browser/ui/cocoa/browser_window_cocoa.mm index 4240680..39d914a 100644 --- a/chrome/browser/ui/cocoa/browser_window_cocoa.mm +++ b/chrome/browser/ui/cocoa/browser_window_cocoa.mm @@ -4,6 +4,7 @@ #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" +#include "base/bind.h" #include "base/command_line.h" #include "base/logging.h" #include "base/message_loop.h" @@ -399,11 +400,9 @@ void BrowserWindowCocoa::ShowThemeInstallBubble() { void BrowserWindowCocoa::ConfirmBrowserCloseWithPendingDownloads() { // Call InProgressDownloadResponse asynchronously to avoid a crash when the // browser window is closed here (http://crbug.com/44454). - MessageLoop::current()->PostTask( - FROM_HERE, - confirm_close_factory_.NewRunnableMethod( - &Browser::InProgressDownloadResponse, - true)); + MessageLoop::current()->PostTask(FROM_HERE, + base::Bind(&Browser::InProgressDownloadResponse, + confirm_close_factory_.GetWeakPtr(), true)); } gfx::NativeWindow BrowserWindowCocoa::ShowHTMLDialog( diff --git a/chrome/browser/ui/cocoa/first_run_dialog.mm b/chrome/browser/ui/cocoa/first_run_dialog.mm index 36c5788..d6cf090 100644 --- a/chrome/browser/ui/cocoa/first_run_dialog.mm +++ b/chrome/browser/ui/cocoa/first_run_dialog.mm @@ -4,6 +4,7 @@ #import "chrome/browser/ui/cocoa/first_run_dialog.h" +#include "base/bind.h" #include "base/mac/mac_util.h" #include "base/memory/ref_counted.h" #import "base/memory/scoped_nsobject.h" @@ -187,10 +188,8 @@ void ShowFirstRunDialog(Profile* profile, // Therefore the main MessageLoop is run so things work. scoped_refptr<FirstRunShowBridge> bridge(new FirstRunShowBridge(self)); - MessageLoop::current()->PostTask( - FROM_HERE, - NewRunnableMethod(bridge.get(), - &FirstRunShowBridge::ShowDialog)); + MessageLoop::current()->PostTask(FROM_HERE, + base::Bind(&FirstRunShowBridge::ShowDialog, bridge.get())); MessageLoop::current()->Run(); } diff --git a/chrome/browser/ui/cocoa/importer/import_lock_dialog_cocoa.mm b/chrome/browser/ui/cocoa/importer/import_lock_dialog_cocoa.mm index a6556d7..707e9d7 100644 --- a/chrome/browser/ui/cocoa/importer/import_lock_dialog_cocoa.mm +++ b/chrome/browser/ui/cocoa/importer/import_lock_dialog_cocoa.mm @@ -4,6 +4,7 @@ #import <Cocoa/Cocoa.h> +#include "base/bind.h" #include "base/memory/scoped_nsobject.h" #include "base/message_loop.h" #include "chrome/browser/importer/importer_host.h" @@ -27,13 +28,10 @@ void ShowImportLockDialog(gfx::NativeWindow parent, [lock_alert setMessageText:l10n_util::GetNSStringWithFixup( IDS_IMPORTER_LOCK_TITLE)]; - if ([lock_alert runModal] == NSAlertFirstButtonReturn) { - MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( - importer_host, &ImporterHost::OnImportLockDialogEnd, true)); - } else { - MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( - importer_host, &ImporterHost::OnImportLockDialogEnd, false)); - } + bool is_continue = [lock_alert runModal] == NSAlertFirstButtonReturn; + MessageLoop::current()->PostTask(FROM_HERE, + base::Bind(&ImporterHost::OnImportLockDialogEnd, + importer_host, is_continue)); UserMetrics::RecordAction(UserMetricsAction("ImportLockDialogCocoa_Shown")); } diff --git a/chrome/browser/ui/cocoa/keystone_infobar.mm b/chrome/browser/ui/cocoa/keystone_infobar.mm index 653d07a..0b14f0e 100644 --- a/chrome/browser/ui/cocoa/keystone_infobar.mm +++ b/chrome/browser/ui/cocoa/keystone_infobar.mm @@ -8,9 +8,10 @@ #include <string> +#include "base/bind.h" #include "base/command_line.h" +#include "base/memory/weak_ptr.h" #include "base/message_loop.h" -#include "base/task.h" #include "chrome/browser/first_run/first_run.h" #include "chrome/browser/infobars/infobar_tab_helper.h" #import "chrome/browser/mac/keystone_glue.h" @@ -62,7 +63,7 @@ class KeystonePromotionInfoBarDelegate : public ConfirmInfoBarDelegate { bool can_expire_; // Used to delay the expiration of the info bar. - ScopedRunnableMethodFactory<KeystonePromotionInfoBarDelegate> method_factory_; + base::WeakPtrFactory<KeystonePromotionInfoBarDelegate> weak_ptr_factory_; DISALLOW_COPY_AND_ASSIGN(KeystonePromotionInfoBarDelegate); }; @@ -72,11 +73,11 @@ KeystonePromotionInfoBarDelegate::KeystonePromotionInfoBarDelegate( : ConfirmInfoBarDelegate(tab_contents), profile_(Profile::FromBrowserContext(tab_contents->browser_context())), can_expire_(false), - ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { + ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { const int kCanExpireOnNavigationAfterMilliseconds = 8 * 1000; MessageLoop::current()->PostDelayedTask(FROM_HERE, - method_factory_.NewRunnableMethod( - &KeystonePromotionInfoBarDelegate::SetCanExpire), + base::Bind(&KeystonePromotionInfoBarDelegate::SetCanExpire, + weak_ptr_factory_.GetWeakPtr()), kCanExpireOnNavigationAfterMilliseconds); } diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h index 9a411d8..08f1556 100644 --- a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h +++ b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h @@ -13,6 +13,7 @@ #include "base/memory/scoped_nsobject.h" #include "base/memory/scoped_ptr.h" #include "base/memory/scoped_vector.h" +#include "base/memory/weak_ptr.h" #include "chrome/browser/autocomplete/autocomplete_edit.h" #include "chrome/browser/extensions/image_loading_tracker.h" #include "chrome/browser/first_run/first_run.h" @@ -223,7 +224,7 @@ class LocationBarViewMac : public AutocompleteEditController, NotificationRegistrar registrar_; // Used to schedule a task for the first run info bubble. - ScopedRunnableMethodFactory<LocationBarViewMac> first_run_bubble_; + base::WeakPtrFactory<LocationBarViewMac> weak_ptr_factory_; // Used to change the visibility of the star decoration. BooleanPrefMember edit_bookmarks_enabled_; diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm index 3b27684..d6eeddb 100644 --- a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm +++ b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm @@ -4,6 +4,7 @@ #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" +#include "base/bind.h" #include "base/stl_util.h" #include "base/string_util.h" #include "base/sys_string_conversions.h" @@ -92,7 +93,7 @@ LocationBarViewMac::LocationBarViewMac( browser_(browser), toolbar_model_(toolbar_model), transition_(PageTransition::TYPED | PageTransition::FROM_ADDRESS_BAR), - first_run_bubble_(this) { + weak_ptr_factory_(this) { for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { DCHECK_EQ(i, content_setting_decorations_.size()); ContentSettingsType type = static_cast<ContentSettingsType>(i); @@ -116,9 +117,9 @@ LocationBarViewMac::~LocationBarViewMac() { void LocationBarViewMac::ShowFirstRunBubble(FirstRun::BubbleType bubble_type) { // We need the browser window to be shown before we can show the bubble, but // we get called before that's happened. - Task* task = first_run_bubble_.NewRunnableMethod( - &LocationBarViewMac::ShowFirstRunBubbleInternal, bubble_type); - MessageLoop::current()->PostTask(FROM_HERE, task); + MessageLoop::current()->PostTask(FROM_HERE, + base::Bind(&LocationBarViewMac::ShowFirstRunBubbleInternal, + weak_ptr_factory_.GetWeakPtr(), bubble_type)); } void LocationBarViewMac::ShowFirstRunBubbleInternal( diff --git a/chrome/browser/ui/cocoa/page_info_bubble_controller.mm b/chrome/browser/ui/cocoa/page_info_bubble_controller.mm index dd288ba..bdb0389 100644 --- a/chrome/browser/ui/cocoa/page_info_bubble_controller.mm +++ b/chrome/browser/ui/cocoa/page_info_bubble_controller.mm @@ -4,10 +4,11 @@ #import "chrome/browser/ui/cocoa/page_info_bubble_controller.h" +#include "base/bind.h" #include "base/compiler_specific.h" +#include "base/memory/weak_ptr.h" #include "base/message_loop.h" #include "base/sys_string_conversions.h" -#include "base/task.h" #include "chrome/browser/certificate_viewer.h" #include "chrome/browser/google/google_util.h" #include "chrome/browser/page_info_model.h" @@ -100,27 +101,27 @@ class PageInfoModelBubbleBridge : public PageInfoModelObserver { public: PageInfoModelBubbleBridge() : controller_(nil), - ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { + ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { } // PageInfoModelObserver implementation. virtual void OnPageInfoModelChanged() OVERRIDE { // Check to see if a layout has already been scheduled. - if (!task_factory_.empty()) + if (weak_ptr_factory_.HasWeakPtrs()) return; // Delay performing layout by a second so that all the animations from // InfoBubbleWindow and origin updates from BaseBubbleController finish, so // that we don't all race trying to change the frame's origin. // - // Using ScopedRunnableMethodFactory is superior here to |-performSelector:| - // because it will not retain its target; if the child outlives its parent, - // zombies get left behind (http://crbug.com/59619). This will also cancel - // the scheduled Tasks if the controller (and thus this bridge) get - // destroyed before the message can be delivered. + // Using MessageLoop is superior here to |-performSelector:| because it will + // not retain its target; if the child outlives its parent, zombies get left + // behind (http://crbug.com/59619). This will cancel the scheduled task if + // the controller (and thus this bridge) get destroyed before the message + // can be delivered. MessageLoop::current()->PostDelayedTask(FROM_HERE, - task_factory_.NewRunnableMethod( - &PageInfoModelBubbleBridge::PerformLayout), + base::Bind(&PageInfoModelBubbleBridge::PerformLayout, + weak_ptr_factory_.GetWeakPtr()), 1000 /* milliseconds */); } @@ -140,8 +141,7 @@ class PageInfoModelBubbleBridge : public PageInfoModelObserver { PageInfoBubbleController* controller_; // weak - // Factory that vends RunnableMethod tasks for scheduling layout. - ScopedRunnableMethodFactory<PageInfoModelBubbleBridge> task_factory_; + base::WeakPtrFactory<PageInfoModelBubbleBridge> weak_ptr_factory_; DISALLOW_COPY_AND_ASSIGN(PageInfoModelBubbleBridge); }; diff --git a/chrome/browser/ui/cocoa/search_engine_dialog_controller.mm b/chrome/browser/ui/cocoa/search_engine_dialog_controller.mm index 1c654a8..9d7e525 100644 --- a/chrome/browser/ui/cocoa/search_engine_dialog_controller.mm +++ b/chrome/browser/ui/cocoa/search_engine_dialog_controller.mm @@ -6,6 +6,7 @@ #include <algorithm> +#include "base/bind.h" #include "base/mac/mac_util.h" #include "base/sys_string_conversions.h" #include "base/time.h" @@ -88,11 +89,10 @@ void SearchEngineDialogControllerBridge::OnTemplateURLServiceChanged() { searchEnginesModel_->AddObserver(bridge_.get()); if (searchEnginesModel_->loaded()) { - MessageLoop::current()->PostTask( - FROM_HERE, - NewRunnableMethod( - bridge_.get(), - &SearchEngineDialogControllerBridge::OnTemplateURLServiceChanged)); + MessageLoop::current()->PostTask(FROM_HERE, + base::Bind( + &SearchEngineDialogControllerBridge::OnTemplateURLServiceChanged, + bridge_.get())); } else { searchEnginesModel_->Load(); } diff --git a/chrome/browser/ui/cocoa/status_bubble_mac.h b/chrome/browser/ui/cocoa/status_bubble_mac.h index 575a837..7cba5a1 100644 --- a/chrome/browser/ui/cocoa/status_bubble_mac.h +++ b/chrome/browser/ui/cocoa/status_bubble_mac.h @@ -12,8 +12,8 @@ #import <QuartzCore/QuartzCore.h> #include "base/compiler_specific.h" +#include "base/memory/weak_ptr.h" #include "base/string16.h" -#include "base/task.h" #include "chrome/browser/ui/status_bubble.h" #include "googleurl/src/gurl.h" @@ -121,10 +121,10 @@ class StatusBubbleMac : public StatusBubble { void SetFrameAvoidingMouse(NSRect window_frame, const gfx::Point& mouse_pos); // The timer factory used for show and hide delay timers. - ScopedRunnableMethodFactory<StatusBubbleMac> timer_factory_; + base::WeakPtrFactory<StatusBubbleMac> timer_factory_; // The timer factory used for the expansion delay timer. - ScopedRunnableMethodFactory<StatusBubbleMac> expand_timer_factory_; + base::WeakPtrFactory<StatusBubbleMac> expand_timer_factory_; // Calculate the appropriate frame for the status bubble window. If // |expanded_width|, use entire width of parent frame. diff --git a/chrome/browser/ui/cocoa/status_bubble_mac.mm b/chrome/browser/ui/cocoa/status_bubble_mac.mm index 0dcac6c..73f2332 100644 --- a/chrome/browser/ui/cocoa/status_bubble_mac.mm +++ b/chrome/browser/ui/cocoa/status_bubble_mac.mm @@ -6,6 +6,7 @@ #include <limits> +#include "base/bind.h" #include "base/compiler_specific.h" #include "base/mac/mac_util.h" #include "base/message_loop.h" @@ -169,8 +170,9 @@ void StatusBubbleMac::SetURL(const GURL& url, const std::string& languages) { ExpandBubble(); } else if (original_url_text.length() > status.length()) { MessageLoop::current()->PostDelayedTask(FROM_HERE, - expand_timer_factory_.NewRunnableMethod( - &StatusBubbleMac::ExpandBubble), kExpandHoverDelay); + base::Bind(&StatusBubbleMac::ExpandBubble, + expand_timer_factory_.GetWeakPtr()), + kExpandHoverDelay); } } @@ -510,17 +512,16 @@ void StatusBubbleMac::StartTimer(int64 delay_ms) { // There can only be one running timer. CancelTimer(); - MessageLoop::current()->PostDelayedTask( - FROM_HERE, - timer_factory_.NewRunnableMethod(&StatusBubbleMac::TimerFired), + MessageLoop::current()->PostDelayedTask(FROM_HERE, + base::Bind(&StatusBubbleMac::TimerFired, timer_factory_.GetWeakPtr()), delay_ms); } void StatusBubbleMac::CancelTimer() { DCHECK([NSThread isMainThread]); - if (!timer_factory_.empty()) - timer_factory_.RevokeAll(); + if (timer_factory_.HasWeakPtrs()) + timer_factory_.InvalidateWeakPtrs(); } void StatusBubbleMac::TimerFired() { @@ -587,7 +588,7 @@ void StatusBubbleMac::StartHiding() { void StatusBubbleMac::CancelExpandTimer() { DCHECK([NSThread isMainThread]); - expand_timer_factory_.RevokeAll(); + expand_timer_factory_.InvalidateWeakPtrs(); } // Get the current location of the mouse in screen coordinates. To make this |