summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorerg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-29 02:46:23 +0000
committererg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-29 02:46:23 +0000
commit962fc382a792cc0085d7ba30aa4f8288a0044cb6 (patch)
treec22450ccf203c89d51d988f2305337f02ffe6804 /chrome/browser
parent66d4dab590c5c8bd66d2b62d7b5577b2ae1508d6 (diff)
downloadchromium_src-962fc382a792cc0085d7ba30aa4f8288a0044cb6.zip
chromium_src-962fc382a792cc0085d7ba30aa4f8288a0044cb6.tar.gz
chromium_src-962fc382a792cc0085d7ba30aa4f8288a0044cb6.tar.bz2
bind: More conversions in GTK code.
BUG=none TEST=none Review URL: http://codereview.chromium.org/8068016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103229 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.cc9
-rw-r--r--chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.h3
-rw-r--r--chrome/browser/ui/gtk/bookmarks/bookmark_bubble_gtk.cc6
-rw-r--r--chrome/browser/ui/gtk/bookmarks/bookmark_bubble_gtk.h3
-rw-r--r--chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc9
-rw-r--r--chrome/browser/ui/gtk/browser_actions_toolbar_gtk.h4
-rw-r--r--chrome/browser/ui/gtk/global_bookmark_menu.cc8
-rw-r--r--chrome/browser/ui/gtk/global_bookmark_menu.h3
-rw-r--r--chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.cc17
-rw-r--r--chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.h4
-rw-r--r--chrome/browser/ui/gtk/location_bar_view_gtk.cc18
-rw-r--r--chrome/browser/ui/gtk/location_bar_view_gtk.h5
12 files changed, 56 insertions, 33 deletions
diff --git a/chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.cc b/chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.cc
index 3334cac..0274dee 100644
--- a/chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.cc
+++ b/chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.cc
@@ -6,6 +6,7 @@
#include <vector>
+#include "base/bind.h"
#include "base/metrics/histogram.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
@@ -139,7 +140,7 @@ BookmarkBarGtk::BookmarkBarGtk(BrowserWindowGtk* window,
slide_animation_(this),
last_allocation_width_(-1),
throbbing_widget_(NULL),
- method_factory_(this),
+ weak_factory_(this),
bookmark_bar_state_(BookmarkBar::DETACHED),
max_height_(0) {
Profile* profile = browser->profile();
@@ -1442,9 +1443,9 @@ void BookmarkBarGtk::OnParentSizeAllocate(GtkWidget* widget,
// gtk_widget_queue_draw by itself does not work, despite that it claims to
// be asynchronous.
if (bookmark_bar_state_ == BookmarkBar::DETACHED) {
- MessageLoop::current()->PostTask(FROM_HERE,
- method_factory_.NewRunnableMethod(
- &BookmarkBarGtk::PaintEventBox));
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&BookmarkBarGtk::PaintEventBox, weak_factory_.GetWeakPtr()));
}
}
diff --git a/chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.h b/chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.h
index c9dfce1..5aa27ac 100644
--- a/chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.h
+++ b/chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.h
@@ -12,6 +12,7 @@
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "chrome/browser/bookmarks/bookmark_context_menu_controller.h"
#include "chrome/browser/bookmarks/bookmark_model_observer.h"
#include "chrome/browser/prefs/pref_member.h"
@@ -408,7 +409,7 @@ class BookmarkBarGtk : public ui::AnimationDelegate,
// Tracks whether bookmarks can be modified.
BooleanPrefMember edit_bookmarks_enabled_;
- ScopedRunnableMethodFactory<BookmarkBarGtk> method_factory_;
+ base::WeakPtrFactory<BookmarkBarGtk> weak_factory_;
BookmarkBar::State bookmark_bar_state_;
diff --git a/chrome/browser/ui/gtk/bookmarks/bookmark_bubble_gtk.cc b/chrome/browser/ui/gtk/bookmarks/bookmark_bubble_gtk.cc
index a35a06e..558efef 100644
--- a/chrome/browser/ui/gtk/bookmarks/bookmark_bubble_gtk.cc
+++ b/chrome/browser/ui/gtk/bookmarks/bookmark_bubble_gtk.cc
@@ -7,6 +7,7 @@
#include <gtk/gtk.h>
#include "base/basictypes.h"
+#include "base/bind.h"
#include "base/i18n/rtl.h"
#include "base/logging.h"
#include "base/message_loop.h"
@@ -229,8 +230,9 @@ void BookmarkBubbleGtk::OnFolderChanged(GtkWidget* widget) {
// signal. Since showing the editor also closes the bubble, delay this
// so that GTK can unwind. Specifically gtk_menu_shell_button_release
// will run, and we need to keep the combo box alive until then.
- MessageLoop::current()->PostTask(FROM_HERE,
- factory_.NewRunnableMethod(&BookmarkBubbleGtk::ShowEditor));
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&BookmarkBubbleGtk::ShowEditor, factory_.GetWeakPtr()));
}
}
diff --git a/chrome/browser/ui/gtk/bookmarks/bookmark_bubble_gtk.h b/chrome/browser/ui/gtk/bookmarks/bookmark_bubble_gtk.h
index 13971e5..247fcdb 100644
--- a/chrome/browser/ui/gtk/bookmarks/bookmark_bubble_gtk.h
+++ b/chrome/browser/ui/gtk/bookmarks/bookmark_bubble_gtk.h
@@ -19,6 +19,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/task.h"
#include "chrome/browser/ui/gtk/bubble/bubble_gtk.h"
#include "content/common/notification_observer.h"
@@ -111,7 +112,7 @@ class BookmarkBubbleGtk : public BubbleDelegateGtk,
// We need to push some things on the back of the message loop, so we have
// a factory attached to our instance to manage task lifetimes.
- ScopedRunnableMethodFactory<BookmarkBubbleGtk> factory_;
+ base::WeakPtrFactory<BookmarkBubbleGtk> factory_;
// Whether the bubble is creating or editing an existing bookmark.
bool newly_bookmarked_;
diff --git a/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc b/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc
index 510a280..3567ce3 100644
--- a/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc
+++ b/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc
@@ -7,6 +7,7 @@
#include <algorithm>
#include <vector>
+#include "base/bind.h"
#include "base/i18n/rtl.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/extensions/extension_browser_event_router.h"
@@ -376,7 +377,7 @@ BrowserActionsToolbarGtk::BrowserActionsToolbarGtk(Browser* browser)
resize_animation_(this),
desired_width_(0),
start_width_(0),
- method_factory_(this) {
+ weak_factory_(this) {
ExtensionService* extension_service = profile_->GetExtensionService();
// The |extension_service| can be NULL in Incognito.
if (!extension_service)
@@ -815,8 +816,10 @@ void BrowserActionsToolbarGtk::OnSetFocus(GtkWidget* widget,
// call stack.
if (!popup || popup->being_inspected())
return;
- MessageLoop::current()->PostTask(FROM_HERE,
- method_factory_.NewRunnableMethod(&BrowserActionsToolbarGtk::HidePopup));
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&BrowserActionsToolbarGtk::HidePopup,
+ weak_factory_.GetWeakPtr()));
}
gboolean BrowserActionsToolbarGtk::OnGripperMotionNotify(
diff --git a/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.h b/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.h
index c5b310e..ab04fea 100644
--- a/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.h
+++ b/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.h
@@ -10,7 +10,7 @@
#include <string>
#include "base/memory/linked_ptr.h"
-#include "base/task.h"
+#include "base/memory/weak_ptr.h"
#include "chrome/browser/extensions/extension_toolbar_model.h"
#include "chrome/browser/ui/gtk/custom_button.h"
#include "chrome/browser/ui/gtk/menu_gtk.h"
@@ -215,7 +215,7 @@ class BrowserActionsToolbarGtk : public ExtensionToolbarModel::Observer,
NotificationRegistrar registrar_;
- ScopedRunnableMethodFactory<BrowserActionsToolbarGtk> method_factory_;
+ base::WeakPtrFactory<BrowserActionsToolbarGtk> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(BrowserActionsToolbarGtk);
};
diff --git a/chrome/browser/ui/gtk/global_bookmark_menu.cc b/chrome/browser/ui/gtk/global_bookmark_menu.cc
index 350397a..094e8a5 100644
--- a/chrome/browser/ui/gtk/global_bookmark_menu.cc
+++ b/chrome/browser/ui/gtk/global_bookmark_menu.cc
@@ -7,6 +7,7 @@
#include <dlfcn.h>
#include <gtk/gtk.h>
+#include "base/bind.h"
#include "base/logging.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
@@ -28,7 +29,7 @@ GlobalBookmarkMenu::GlobalBookmarkMenu(Browser* browser)
: browser_(browser),
profile_(browser->profile()),
default_favicon_(NULL),
- ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
DCHECK(profile_);
default_favicon_ = GtkThemeService::GetDefaultFavicon(true);
@@ -53,10 +54,11 @@ void GlobalBookmarkMenu::Init(GtkWidget* bookmark_menu,
}
void GlobalBookmarkMenu::RebuildMenuInFuture() {
- method_factory_.RevokeAll();
+ weak_factory_.InvalidateWeakPtrs();
MessageLoop::current()->PostTask(
FROM_HERE,
- method_factory_.NewRunnableMethod(&GlobalBookmarkMenu::RebuildMenu));
+ base::Bind(&GlobalBookmarkMenu::RebuildMenu,
+ weak_factory_.GetWeakPtr()));
}
void GlobalBookmarkMenu::RebuildMenu() {
diff --git a/chrome/browser/ui/gtk/global_bookmark_menu.h b/chrome/browser/ui/gtk/global_bookmark_menu.h
index 02c1520..92b712a 100644
--- a/chrome/browser/ui/gtk/global_bookmark_menu.h
+++ b/chrome/browser/ui/gtk/global_bookmark_menu.h
@@ -8,6 +8,7 @@
#include <map>
#include "base/compiler_specific.h"
+#include "base/memory/weak_ptr.h"
#include "base/task.h"
#include "chrome/browser/bookmarks/bookmark_model_observer.h"
#include "chrome/browser/ui/gtk/global_menu_owner.h"
@@ -116,7 +117,7 @@ class GlobalBookmarkMenu : public GlobalMenuOwner,
ui::OwnedWidgetGtk bookmark_menu_;
- ScopedRunnableMethodFactory<GlobalBookmarkMenu> method_factory_;
+ base::WeakPtrFactory<GlobalBookmarkMenu> weak_factory_;
// In order to appropriately update items in the bookmark menu, without
// forcing a rebuild, map the model's nodes to menu items.
diff --git a/chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.cc b/chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.cc
index 5ce5526..d806a73 100644
--- a/chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.cc
+++ b/chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.h"
+#include "base/bind.h"
#include "base/message_loop.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/translate/translate_infobar_delegate.h"
@@ -17,7 +18,7 @@ AfterTranslateInfoBar::AfterTranslateInfoBar(
TabContentsWrapper* owner,
TranslateInfoBarDelegate* delegate)
: TranslateInfoBarBase(owner, delegate),
- ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
}
AfterTranslateInfoBar::~AfterTranslateInfoBar() {
@@ -80,8 +81,11 @@ void AfterTranslateInfoBar::OnOriginalLanguageModified(GtkWidget* sender) {
// Setting the language will lead to a new translation that is going to close
// the infobar. This is not OK to do this from the signal handler, so we'll
// defer it.
- MessageLoop::current()->PostTask(FROM_HERE, method_factory_.NewRunnableMethod(
- &AfterTranslateInfoBar::SetOriginalLanguage, index));
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&AfterTranslateInfoBar::SetOriginalLanguage,
+ weak_factory_.GetWeakPtr(),
+ index));
}
void AfterTranslateInfoBar::OnTargetLanguageModified(GtkWidget* sender) {
@@ -90,8 +94,11 @@ void AfterTranslateInfoBar::OnTargetLanguageModified(GtkWidget* sender) {
return;
// See comment in OnOriginalLanguageModified on why we use a task.
- MessageLoop::current()->PostTask(FROM_HERE, method_factory_.NewRunnableMethod(
- &AfterTranslateInfoBar::SetTargetLanguage, index));
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&AfterTranslateInfoBar::SetTargetLanguage,
+ weak_factory_.GetWeakPtr(),
+ index));
}
void AfterTranslateInfoBar::OnRevertPressed(GtkWidget* sender) {
diff --git a/chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.h b/chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.h
index c28997a..73d2b91 100644
--- a/chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.h
+++ b/chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.h
@@ -6,7 +6,7 @@
#define CHROME_BROWSER_UI_GTK_INFOBARS_AFTER_TRANSLATE_INFOBAR_GTK_H_
#pragma once
-#include "base/task.h"
+#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/gtk/infobars/translate_infobar_base_gtk.h"
class TranslateInfoBarDelegate;
@@ -33,7 +33,7 @@ class AfterTranslateInfoBar : public TranslateInfoBarBase {
void SetOriginalLanguage(size_t language_index);
void SetTargetLanguage(size_t language_index);
- ScopedRunnableMethodFactory<AfterTranslateInfoBar> method_factory_;
+ base::WeakPtrFactory<AfterTranslateInfoBar> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(AfterTranslateInfoBar);
};
diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.cc b/chrome/browser/ui/gtk/location_bar_view_gtk.cc
index 1a4e3d4..75b481f 100644
--- a/chrome/browser/ui/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/ui/gtk/location_bar_view_gtk.cc
@@ -9,6 +9,7 @@
#include <vector>
#include "base/basictypes.h"
+#include "base/bind.h"
#include "base/i18n/rtl.h"
#include "base/logging.h"
#include "base/string_util.h"
@@ -577,9 +578,11 @@ TabContentsWrapper* LocationBarViewGtk::GetTabContentsWrapper() const {
void LocationBarViewGtk::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(
- &LocationBarViewGtk::ShowFirstRunBubbleInternal, bubble_type);
- MessageLoop::current()->PostTask(FROM_HERE, task);
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&LocationBarViewGtk::ShowFirstRunBubbleInternal,
+ first_run_bubble_.GetWeakPtr(),
+ bubble_type));
}
void LocationBarViewGtk::SetSuggestedText(const string16& text,
@@ -1226,7 +1229,7 @@ LocationBarViewGtk::ContentSettingImageViewGtk::ContentSettingImageViewGtk(
parent_(parent),
content_setting_bubble_(NULL),
animation_(this),
- method_factory_(this) {
+ weak_factory_(this) {
gtk_alignment_set_padding(GTK_ALIGNMENT(alignment_.get()), 1, 1, 0, 0);
gtk_container_add(GTK_CONTAINER(alignment_.get()), event_box_.get());
@@ -1338,9 +1341,10 @@ void LocationBarViewGtk::ContentSettingImageViewGtk::AnimationProgressed(
void LocationBarViewGtk::ContentSettingImageViewGtk::AnimationEnded(
const ui::Animation* animation) {
if (animation_.IsShowing()) {
- MessageLoop::current()->PostDelayedTask(FROM_HERE,
- method_factory_.NewRunnableMethod(
- &ContentSettingImageViewGtk::CloseAnimation),
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&ContentSettingImageViewGtk::CloseAnimation,
+ weak_factory_.GetWeakPtr()),
kContentSettingImageDisplayTime);
} else {
gtk_widget_hide(label_.get());
diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.h b/chrome/browser/ui/gtk/location_bar_view_gtk.h
index fe169bf..c704972 100644
--- a/chrome/browser/ui/gtk/location_bar_view_gtk.h
+++ b/chrome/browser/ui/gtk/location_bar_view_gtk.h
@@ -15,6 +15,7 @@
#include "base/compiler_specific.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/extension_context_menu_model.h"
#include "chrome/browser/extensions/image_loading_tracker.h"
@@ -198,7 +199,7 @@ class LocationBarViewGtk : public AutocompleteEditController,
// The label's default requisition (cached so we can animate accordingly).
GtkRequisition label_req_;
- ScopedRunnableMethodFactory<ContentSettingImageViewGtk> method_factory_;
+ base::WeakPtrFactory<ContentSettingImageViewGtk> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(ContentSettingImageViewGtk);
};
@@ -412,7 +413,7 @@ class LocationBarViewGtk : public AutocompleteEditController,
PageTransition::Type transition_;
// Used to schedule a task for the first run bubble.
- ScopedRunnableMethodFactory<LocationBarViewGtk> first_run_bubble_;
+ base::WeakPtrFactory<LocationBarViewGtk> first_run_bubble_;
// When true, the location bar view is read only and also is has a slightly
// different presentation (font size / color). This is used for popups.