summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/automation/automation_provider_observers.cc3
-rw-r--r--chrome/browser/history/top_sites.cc6
-rw-r--r--chrome/browser/history/top_sites.h7
-rw-r--r--chrome/browser/history/top_sites_unittest.cc5
-rw-r--r--chrome/browser/jumplist_win.cc5
-rw-r--r--chrome/browser/prerender/prerender_manager.cc7
-rw-r--r--chrome/browser/ui/gtk/constrained_window_gtk.cc10
-rw-r--r--chrome/browser/ui/gtk/constrained_window_gtk.h3
-rw-r--r--chrome/browser/ui/gtk/dialogs_kde.cc7
-rw-r--r--chrome/browser/ui/gtk/download/download_shelf_gtk.cc9
-rw-r--r--chrome/browser/ui/gtk/download/download_shelf_gtk.h3
-rw-r--r--chrome/browser/ui/gtk/extensions/extension_installed_bubble_gtk.cc14
-rw-r--r--chrome/browser/ui/gtk/extensions/extension_popup_gtk.cc91
-rw-r--r--chrome/browser/ui/gtk/extensions/extension_popup_gtk.h8
-rw-r--r--chrome/browser/ui/gtk/global_history_menu.cc5
-rw-r--r--chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc6
-rw-r--r--chrome/browser/ui/gtk/tabs/dragged_view_gtk.cc6
-rw-r--r--chrome/browser/ui/gtk/tabs/dragged_view_gtk.h6
-rw-r--r--chrome/browser/ui/gtk/tabs/tab_gtk.cc13
-rw-r--r--chrome/browser/ui/gtk/tabs/tab_gtk.h5
-rw-r--r--chrome/browser/ui/gtk/tabs/tab_strip_gtk.cc20
-rw-r--r--chrome/browser/ui/gtk/tabs/tab_strip_gtk.h8
-rw-r--r--chrome/browser/ui/webui/ntp/most_visited_handler.cc3
-rw-r--r--content/browser/cancelable_request.h86
24 files changed, 212 insertions, 124 deletions
diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc
index 662b3b7..37be6bd 100644
--- a/chrome/browser/automation/automation_provider_observers.cc
+++ b/chrome/browser/automation/automation_provider_observers.cc
@@ -2126,7 +2126,8 @@ void NTPInfoObserver::Observe(int type,
if (request_ == *request_details.ptr()) {
top_sites_->GetMostVisitedURLs(
consumer_,
- NewCallback(this, &NTPInfoObserver::OnTopSitesReceived));
+ base::Bind(&NTPInfoObserver::OnTopSitesReceived,
+ base::Unretained(this)));
}
}
}
diff --git a/chrome/browser/history/top_sites.cc b/chrome/browser/history/top_sites.cc
index 21994e2..17c8940 100644
--- a/chrome/browser/history/top_sites.cc
+++ b/chrome/browser/history/top_sites.cc
@@ -226,7 +226,7 @@ bool TopSites::SetPageThumbnail(const GURL& url,
}
void TopSites::GetMostVisitedURLs(CancelableRequestConsumer* consumer,
- GetTopSitesCallback* callback) {
+ const GetTopSitesCallback& callback) {
// WARNING: this may be invoked on any thread.
scoped_refptr<CancelableRequest<GetTopSitesCallback> > request(
new CancelableRequest<GetTopSitesCallback>(callback));
@@ -245,7 +245,7 @@ void TopSites::GetMostVisitedURLs(CancelableRequestConsumer* consumer,
filtered_urls = thread_safe_cache_->top_sites();
}
- request->ForwardResult(GetTopSitesCallback::TupleType(filtered_urls));
+ request->ForwardResult(filtered_urls);
}
bool TopSites::GetPageThumbnail(const GURL& url,
@@ -788,7 +788,7 @@ void TopSites::ProcessPendingCallbacks(
i != pending_callbacks.end(); ++i) {
scoped_refptr<CancelableRequest<GetTopSitesCallback> > request = *i;
if (!request->canceled())
- request->ForwardResult(GetTopSitesCallback::TupleType(urls));
+ request->ForwardResult(urls);
}
}
diff --git a/chrome/browser/history/top_sites.h b/chrome/browser/history/top_sites.h
index 14c7c03..4f441b8 100644
--- a/chrome/browser/history/top_sites.h
+++ b/chrome/browser/history/top_sites.h
@@ -12,6 +12,7 @@
#include <utility>
#include "base/basictypes.h"
+#include "base/callback.h"
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
#include "base/memory/ref_counted_memory.h"
@@ -65,7 +66,7 @@ class TopSites
const ThumbnailScore& score);
// Callback for GetMostVisitedURLs.
- typedef Callback1<const MostVisitedURLList&>::Type GetTopSitesCallback;
+ typedef base::Callback<void(const MostVisitedURLList&)> GetTopSitesCallback;
typedef std::set<scoped_refptr<CancelableRequest<GetTopSitesCallback> > >
PendingCallbackSet;
@@ -73,12 +74,12 @@ class TopSites
// This may be invoked on any thread.
// NOTE: the callback is called immediately if we have the data cached.
void GetMostVisitedURLs(CancelableRequestConsumer* consumer,
- GetTopSitesCallback* callback);
+ const GetTopSitesCallback& callback);
// Get a thumbnail for a given page. Returns true iff we have the thumbnail.
// This may be invoked on any thread.
// As this method may be invoked on any thread the ref count needs to be
- // upped before this method returns, so this takes a scoped_refptr*.
+ // incremented before this method returns, so this takes a scoped_refptr*.
bool GetPageThumbnail(const GURL& url,
scoped_refptr<RefCountedBytes>* bytes);
diff --git a/chrome/browser/history/top_sites_unittest.cc b/chrome/browser/history/top_sites_unittest.cc
index 6f9f572..5d6ef8f 100644
--- a/chrome/browser/history/top_sites_unittest.cc
+++ b/chrome/browser/history/top_sites_unittest.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/format_macros.h"
@@ -71,7 +73,8 @@ class TopSitesQuerier {
int start_number_of_callbacks = number_of_callbacks_;
top_sites->GetMostVisitedURLs(
&consumer_,
- NewCallback(this, &TopSitesQuerier::OnTopSitesAvailable));
+ base::Bind(&TopSitesQuerier::OnTopSitesAvailable,
+ base::Unretained(this)));
if (wait && start_number_of_callbacks == number_of_callbacks_) {
waiting_ = true;
MessageLoop::current()->Run();
diff --git a/chrome/browser/jumplist_win.cc b/chrome/browser/jumplist_win.cc
index 87a0643..a032e9f 100644
--- a/chrome/browser/jumplist_win.cc
+++ b/chrome/browser/jumplist_win.cc
@@ -12,6 +12,8 @@
#include <string>
#include <vector>
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/command_line.h"
#include "base/file_util.h"
@@ -543,7 +545,8 @@ void JumpList::Observe(int type,
if (top_sites) {
top_sites->GetMostVisitedURLs(
&topsites_consumer_,
- NewCallback(this, &JumpList::OnMostVisitedURLsAvailable));
+ base::Bind(&JumpList::OnMostVisitedURLsAvailable,
+ base::Unretained(this)));
}
break;
}
diff --git a/chrome/browser/prerender/prerender_manager.cc b/chrome/browser/prerender/prerender_manager.cc
index 7cf72fc..a48d7efa 100644
--- a/chrome/browser/prerender/prerender_manager.cc
+++ b/chrome/browser/prerender/prerender_manager.cc
@@ -6,6 +6,8 @@
#include <string>
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/logging.h"
#include "base/stl_util.h"
#include "base/time.h"
@@ -178,9 +180,8 @@ class PrerenderManager::MostVisitedSites : public NotificationObserver {
if (top_sites) {
top_sites->GetMostVisitedURLs(
&topsites_consumer_,
- NewCallback(this,
- &prerender::PrerenderManager::MostVisitedSites::
- OnMostVisitedURLsAvailable));
+ base::Bind(&prerender::PrerenderManager::MostVisitedSites::
+ OnMostVisitedURLsAvailable, base::Unretained(this)));
}
}
diff --git a/chrome/browser/ui/gtk/constrained_window_gtk.cc b/chrome/browser/ui/gtk/constrained_window_gtk.cc
index a769891..0b8a1fc2 100644
--- a/chrome/browser/ui/gtk/constrained_window_gtk.cc
+++ b/chrome/browser/ui/gtk/constrained_window_gtk.cc
@@ -6,6 +6,7 @@
#include <gdk/gdkkeysyms.h>
+#include "base/bind.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/constrained_window_tab_helper.h"
#include "chrome/browser/ui/gtk/gtk_util.h"
@@ -39,7 +40,7 @@ ConstrainedWindowGtk::ConstrainedWindowGtk(
: wrapper_(wrapper),
delegate_(delegate),
visible_(false),
- factory_(this) {
+ weak_factory_(this) {
DCHECK(wrapper);
DCHECK(delegate);
GtkWidget* dialog = delegate->GetWidgetRoot();
@@ -144,9 +145,10 @@ gboolean ConstrainedWindowGtk::OnKeyPress(GtkWidget* sender,
if (key->keyval == GDK_Escape) {
// Let the stack unwind so the event handler can release its ref
// on widget().
- MessageLoop::current()->PostTask(FROM_HERE,
- factory_.NewRunnableMethod(
- &ConstrainedWindowGtk::CloseConstrainedWindow));
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&ConstrainedWindowGtk::CloseConstrainedWindow,
+ weak_factory_.GetWeakPtr()));
return TRUE;
}
diff --git a/chrome/browser/ui/gtk/constrained_window_gtk.h b/chrome/browser/ui/gtk/constrained_window_gtk.h
index 3716093..c8a194f 100644
--- a/chrome/browser/ui/gtk/constrained_window_gtk.h
+++ b/chrome/browser/ui/gtk/constrained_window_gtk.h
@@ -9,6 +9,7 @@
#include <gtk/gtk.h>
#include "base/basictypes.h"
+#include "base/memory/weak_ptr.h"
#include "base/task.h"
#include "chrome/browser/ui/constrained_window.h"
#include "ui/base/gtk/gtk_signal.h"
@@ -97,7 +98,7 @@ class ConstrainedWindowGtk : public ConstrainedWindow {
// Stores if |ShowConstrainedWindow()| has been called.
bool visible_;
- ScopedRunnableMethodFactory<ConstrainedWindowGtk> factory_;
+ base::WeakPtrFactory<ConstrainedWindowGtk> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowGtk);
};
diff --git a/chrome/browser/ui/gtk/dialogs_kde.cc b/chrome/browser/ui/gtk/dialogs_kde.cc
index 2bfd351..21d2fd8 100644
--- a/chrome/browser/ui/gtk/dialogs_kde.cc
+++ b/chrome/browser/ui/gtk/dialogs_kde.cc
@@ -7,6 +7,8 @@
#include <map>
#include <set>
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/logging.h"
@@ -210,8 +212,9 @@ void SelectFileDialogImplKDE::CallKDialogOutput(
std::set<GtkWindow*>::iterator iter = parents_.find(parent);
if (iter != parents_.end())
parents_.erase(iter);
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- NewRunnableMethod(this, callback, output, exit_code, params));
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(callback, this, output, exit_code, params));
}
void SelectFileDialogImplKDE::GetKDialogCommandLine(const std::string& type,
diff --git a/chrome/browser/ui/gtk/download/download_shelf_gtk.cc b/chrome/browser/ui/gtk/download/download_shelf_gtk.cc
index 8355c95..a857606 100644
--- a/chrome/browser/ui/gtk/download/download_shelf_gtk.cc
+++ b/chrome/browser/ui/gtk/download/download_shelf_gtk.cc
@@ -6,6 +6,7 @@
#include <string>
+#include "base/bind.h"
#include "chrome/browser/download/download_item_model.h"
#include "chrome/browser/download/download_util.h"
#include "chrome/browser/ui/browser.h"
@@ -66,7 +67,7 @@ DownloadShelfGtk::DownloadShelfGtk(Browser* browser, GtkWidget* parent)
theme_service_(GtkThemeService::GetFrom(browser->profile())),
close_on_mouse_out_(false),
mouse_in_shelf_(false),
- auto_close_factory_(this) {
+ weak_factory_(this) {
// Logically, the shelf is a vbox that contains two children: a one pixel
// tall event box, which serves as the top border, and an hbox, which holds
// the download items and other shelf widgets (close button, show-all-
@@ -303,7 +304,7 @@ void DownloadShelfGtk::AutoCloseIfPossible() {
void DownloadShelfGtk::CancelAutoClose() {
SetCloseOnMouseOut(false);
- auto_close_factory_.RevokeAll();
+ weak_factory_.InvalidateWeakPtrs();
}
void DownloadShelfGtk::ItemOpened() {
@@ -369,10 +370,10 @@ void DownloadShelfGtk::MouseLeftShelf() {
MessageLoop::current()->PostDelayedTask(
FROM_HERE,
- auto_close_factory_.NewRunnableMethod(&DownloadShelfGtk::Close),
+ base::Bind(&DownloadShelfGtk::Close, weak_factory_.GetWeakPtr()),
kAutoCloseDelayMs);
}
void DownloadShelfGtk::MouseEnteredShelf() {
- auto_close_factory_.RevokeAll();
+ weak_factory_.InvalidateWeakPtrs();
}
diff --git a/chrome/browser/ui/gtk/download/download_shelf_gtk.h b/chrome/browser/ui/gtk/download/download_shelf_gtk.h
index 15469de..dfc0bdc 100644
--- a/chrome/browser/ui/gtk/download/download_shelf_gtk.h
+++ b/chrome/browser/ui/gtk/download/download_shelf_gtk.h
@@ -11,6 +11,7 @@
#include <vector>
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
#include "chrome/browser/download/download_shelf.h"
#include "chrome/browser/ui/gtk/slide_animator_gtk.h"
@@ -143,7 +144,7 @@ class DownloadShelfGtk : public DownloadShelf,
// we received.
bool mouse_in_shelf_;
- ScopedRunnableMethodFactory<DownloadShelfGtk> auto_close_factory_;
+ base::WeakPtrFactory<DownloadShelfGtk> weak_factory_;
friend class DownloadItemGtk;
};
diff --git a/chrome/browser/ui/gtk/extensions/extension_installed_bubble_gtk.cc b/chrome/browser/ui/gtk/extensions/extension_installed_bubble_gtk.cc
index 5a77fc2..4ad8254 100644
--- a/chrome/browser/ui/gtk/extensions/extension_installed_bubble_gtk.cc
+++ b/chrome/browser/ui/gtk/extensions/extension_installed_bubble_gtk.cc
@@ -6,6 +6,8 @@
#include <string>
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/i18n/rtl.h"
#include "base/message_loop.h"
#include "base/utf_string_conversions.h"
@@ -104,8 +106,9 @@ void ExtensionInstalledBubbleGtk::Observe(int type,
const Extension* extension = Details<const Extension>(details).ptr();
if (extension == extension_) {
// PostTask to ourself to allow all EXTENSION_LOADED Observers to run.
- MessageLoopForUI::current()->PostTask(FROM_HERE, NewRunnableMethod(this,
- &ExtensionInstalledBubbleGtk::ShowInternal));
+ MessageLoopForUI::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&ExtensionInstalledBubbleGtk::ShowInternal, this));
}
} else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) {
const Extension* extension =
@@ -131,7 +134,7 @@ void ExtensionInstalledBubbleGtk::ShowInternal() {
if (toolbar->animating() && animation_wait_retries_-- > 0) {
MessageLoopForUI::current()->PostDelayedTask(
FROM_HERE,
- NewRunnableMethod(this, &ExtensionInstalledBubbleGtk::ShowInternal),
+ base::Bind(&ExtensionInstalledBubbleGtk::ShowInternal, this),
kAnimationWaitMS);
return;
}
@@ -312,8 +315,9 @@ void ExtensionInstalledBubbleGtk::BubbleClosing(BubbleGtk* bubble,
// We need to allow the bubble to close and remove the widgets from
// the window before we call Release() because close_button_ depends
// on all references being cleared before it is destroyed.
- MessageLoopForUI::current()->PostTask(FROM_HERE, NewRunnableMethod(this,
- &ExtensionInstalledBubbleGtk::Close));
+ MessageLoopForUI::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&ExtensionInstalledBubbleGtk::Close, this));
}
void ExtensionInstalledBubbleGtk::Close() {
diff --git a/chrome/browser/ui/gtk/extensions/extension_popup_gtk.cc b/chrome/browser/ui/gtk/extensions/extension_popup_gtk.cc
index 80a4af1..51a2bcd 100644
--- a/chrome/browser/ui/gtk/extensions/extension_popup_gtk.cc
+++ b/chrome/browser/ui/gtk/extensions/extension_popup_gtk.cc
@@ -8,6 +8,9 @@
#include <algorithm>
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/callback.h"
#include "base/i18n/rtl.h"
#include "base/message_loop.h"
#include "chrome/browser/debugger/devtools_window.h"
@@ -43,7 +46,7 @@ ExtensionPopupGtk::ExtensionPopupGtk(Browser* browser,
host_(host),
anchor_(anchor),
being_inspected_(inspect),
- method_factory_(this) {
+ weak_factory_(this) {
host_->view()->SetContainer(this);
// If the host had somehow finished loading, then we'd miss the notification
@@ -62,6 +65,20 @@ ExtensionPopupGtk::ExtensionPopupGtk(Browser* browser,
ExtensionPopupGtk::~ExtensionPopupGtk() {
}
+// static
+void ExtensionPopupGtk::Show(const GURL& url, Browser* browser,
+ GtkWidget* anchor, bool inspect) {
+ ExtensionProcessManager* manager =
+ browser->profile()->GetExtensionProcessManager();
+ DCHECK(manager);
+ if (!manager)
+ return;
+
+ ExtensionHost* host = manager->CreatePopupHost(url, browser);
+ // This object will delete itself when the bubble is closed.
+ new ExtensionPopupGtk(browser, host, anchor, inspect);
+}
+
void ExtensionPopupGtk::Observe(int type,
const NotificationSource& source,
const NotificationDetails& details) {
@@ -82,14 +99,42 @@ void ExtensionPopupGtk::Observe(int type,
// If the devtools window is closing, we post a task to ourselves to
// close the popup. This gives the devtools window a chance to finish
// detaching from the inspected RenderViewHost.
- MessageLoop::current()->PostTask(FROM_HERE,
- method_factory_.NewRunnableMethod(&ExtensionPopupGtk::DestroyPopup));
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&ExtensionPopupGtk::DestroyPopupWithoutResult,
+ weak_factory_.GetWeakPtr()));
break;
default:
NOTREACHED() << "Received unexpected notification";
}
}
+void ExtensionPopupGtk::BubbleClosing(BubbleGtk* bubble,
+ bool closed_by_escape) {
+ current_extension_popup_ = NULL;
+ delete this;
+}
+
+void ExtensionPopupGtk::OnExtensionPreferredSizeChanged(
+ ExtensionViewGtk* view,
+ const gfx::Size& new_size) {
+ int width = std::max(kMinWidth, std::min(kMaxWidth, new_size.width()));
+ int height = std::max(kMinHeight, std::min(kMaxHeight, new_size.height()));
+
+ view->render_view_host()->view()->SetSize(gfx::Size(width, height));
+ gtk_widget_set_size_request(view->native_view(), width, height);
+}
+
+bool ExtensionPopupGtk::DestroyPopup() {
+ if (!bubble_) {
+ NOTREACHED();
+ return false;
+ }
+
+ bubble_->Close();
+ return true;
+}
+
void ExtensionPopupGtk::ShowPopup() {
if (bubble_) {
NOTREACHED();
@@ -128,44 +173,8 @@ void ExtensionPopupGtk::ShowPopup() {
this);
}
-bool ExtensionPopupGtk::DestroyPopup() {
- if (!bubble_) {
- NOTREACHED();
- return false;
- }
-
- bubble_->Close();
- return true;
-}
-
-void ExtensionPopupGtk::BubbleClosing(BubbleGtk* bubble,
- bool closed_by_escape) {
- current_extension_popup_ = NULL;
- delete this;
-}
-
-void ExtensionPopupGtk::OnExtensionPreferredSizeChanged(
- ExtensionViewGtk* view,
- const gfx::Size& new_size) {
- int width = std::max(kMinWidth, std::min(kMaxWidth, new_size.width()));
- int height = std::max(kMinHeight, std::min(kMaxHeight, new_size.height()));
-
- view->render_view_host()->view()->SetSize(gfx::Size(width, height));
- gtk_widget_set_size_request(view->native_view(), width, height);
-}
-
-// static
-void ExtensionPopupGtk::Show(const GURL& url, Browser* browser,
- GtkWidget* anchor, bool inspect) {
- ExtensionProcessManager* manager =
- browser->profile()->GetExtensionProcessManager();
- DCHECK(manager);
- if (!manager)
- return;
-
- ExtensionHost* host = manager->CreatePopupHost(url, browser);
- // This object will delete itself when the bubble is closed.
- new ExtensionPopupGtk(browser, host, anchor, inspect);
+void ExtensionPopupGtk::DestroyPopupWithoutResult() {
+ DestroyPopup();
}
gfx::Rect ExtensionPopupGtk::GetViewBounds() {
diff --git a/chrome/browser/ui/gtk/extensions/extension_popup_gtk.h b/chrome/browser/ui/gtk/extensions/extension_popup_gtk.h
index 1b41510..85c4180 100644
--- a/chrome/browser/ui/gtk/extensions/extension_popup_gtk.h
+++ b/chrome/browser/ui/gtk/extensions/extension_popup_gtk.h
@@ -8,6 +8,7 @@
#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 "chrome/browser/ui/gtk/extensions/extension_view_gtk.h"
@@ -71,6 +72,11 @@ class ExtensionPopupGtk : public NotificationObserver,
// Shows the popup widget. Called after loading completes.
void ShowPopup();
+ // See DestroyPopup. Does not return success or failure. Necessitated by
+ // base::Bind and friends, which cannot handle a WeakPtr for a function that
+ // has a return value.
+ void DestroyPopupWithoutResult();
+
Browser* browser_;
BubbleGtk* bubble_;
@@ -88,7 +94,7 @@ class ExtensionPopupGtk : public NotificationObserver,
// Whether a devtools window is attached to this bubble.
bool being_inspected_;
- ScopedRunnableMethodFactory<ExtensionPopupGtk> method_factory_;
+ base::WeakPtrFactory<ExtensionPopupGtk> weak_factory_;
// Used for testing. ---------------------------------------------------------
gfx::Rect GetViewBounds();
diff --git a/chrome/browser/ui/gtk/global_history_menu.cc b/chrome/browser/ui/gtk/global_history_menu.cc
index 83f0883..ed71131 100644
--- a/chrome/browser/ui/gtk/global_history_menu.cc
+++ b/chrome/browser/ui/gtk/global_history_menu.cc
@@ -6,6 +6,8 @@
#include <gtk/gtk.h>
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/stl_util.h"
#include "base/string_number_conversions.h"
#include "base/utf_string_conversions.h"
@@ -130,7 +132,8 @@ void GlobalHistoryMenu::GetTopSitesData() {
top_sites_->GetMostVisitedURLs(
&top_sites_consumer_,
- NewCallback(this, &GlobalHistoryMenu::OnTopSitesReceived));
+ base::Bind(&GlobalHistoryMenu::OnTopSitesReceived,
+ base::Unretained(this)));
}
void GlobalHistoryMenu::OnTopSitesReceived(
diff --git a/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc b/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc
index 8e07105..b8b8026 100644
--- a/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc
+++ b/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc
@@ -6,7 +6,8 @@
#include <algorithm>
-#include "base/callback_old.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/i18n/rtl.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/tabs/tab_strip_model.h"
@@ -772,7 +773,8 @@ bool DraggedTabControllerGtk::CompleteDrag() {
// We don't need to do anything other than make the tabs visible again,
// since the dragged view is going away.
dragged_view_->AnimateToBounds(GetAnimateBounds(),
- NewCallback(this, &DraggedTabControllerGtk::OnAnimateToBoundsComplete));
+ base::Bind(&DraggedTabControllerGtk::OnAnimateToBoundsComplete,
+ base::Unretained(this)));
destroy_immediately = false;
} else {
// Compel the model to construct a new window for the detached TabContents.
diff --git a/chrome/browser/ui/gtk/tabs/dragged_view_gtk.cc b/chrome/browser/ui/gtk/tabs/dragged_view_gtk.cc
index 31dd661..b10a2ea 100644
--- a/chrome/browser/ui/gtk/tabs/dragged_view_gtk.cc
+++ b/chrome/browser/ui/gtk/tabs/dragged_view_gtk.cc
@@ -198,8 +198,8 @@ int DraggedViewGtk::GetWidthInTabStripUpToMousePointer() {
}
void DraggedViewGtk::AnimateToBounds(const gfx::Rect& bounds,
- AnimateToBoundsCallback* callback) {
- animation_callback_.reset(callback);
+ const base::Closure& callback) {
+ animation_callback_ = callback;
gint x, y, width, height;
gdk_window_get_origin(container_->window, &x, &y);
@@ -229,7 +229,7 @@ void DraggedViewGtk::AnimationProgressed(const ui::Animation* animation) {
}
void DraggedViewGtk::AnimationEnded(const ui::Animation* animation) {
- animation_callback_->Run();
+ animation_callback_.Run();
}
void DraggedViewGtk::AnimationCanceled(const ui::Animation* animation) {
diff --git a/chrome/browser/ui/gtk/tabs/dragged_view_gtk.h b/chrome/browser/ui/gtk/tabs/dragged_view_gtk.h
index 4badebc..de3c43d 100644
--- a/chrome/browser/ui/gtk/tabs/dragged_view_gtk.h
+++ b/chrome/browser/ui/gtk/tabs/dragged_view_gtk.h
@@ -62,9 +62,7 @@ class DraggedViewGtk : public ui::AnimationDelegate {
// Animates the dragged tab to the specified bounds, then calls back to
// |callback|.
- typedef Callback0::Type AnimateToBoundsCallback;
- void AnimateToBounds(const gfx::Rect& bounds,
- AnimateToBoundsCallback* callback);
+ void AnimateToBounds(const gfx::Rect& bounds, const base::Closure& callback);
// Returns the size of the dragged tab. Used when attaching to a tabstrip
// to determine where to place the tab in the attached tabstrip.
@@ -182,7 +180,7 @@ class DraggedViewGtk : public ui::AnimationDelegate {
ui::SlideAnimation close_animation_;
// A callback notified when the animation is complete.
- scoped_ptr<Callback0::Type> animation_callback_;
+ base::Closure animation_callback_;
// The start and end bounds of the animation sequence.
gfx::Rect animation_start_bounds_;
diff --git a/chrome/browser/ui/gtk/tabs/tab_gtk.cc b/chrome/browser/ui/gtk/tabs/tab_gtk.cc
index acd7394..b80abd9 100644
--- a/chrome/browser/ui/gtk/tabs/tab_gtk.cc
+++ b/chrome/browser/ui/gtk/tabs/tab_gtk.cc
@@ -6,6 +6,7 @@
#include <gdk/gdkkeysyms.h>
+#include "base/bind.h"
#include "base/memory/singleton.h"
#include "base/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
@@ -189,8 +190,9 @@ gboolean TabGtk::OnDragButtonReleased(GtkWidget* widget,
// get a follow up event to tell us the drag has finished (either a
// drag-failed or a drag-end). So we post a task to manually end the drag.
// If GTK+ does send the drag-failed or drag-end event, we cancel the task.
- MessageLoop::current()->PostTask(FROM_HERE,
- drag_end_factory_.NewRunnableMethod(&TabGtk::EndDrag, false));
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&TabGtk::EndDrag, drag_end_factory_.GetWeakPtr(), false));
return TRUE;
}
@@ -330,13 +332,14 @@ void TabGtk::StartDragging(gfx::Point drag_offset) {
void TabGtk::EndDrag(bool canceled) {
// Make sure we only run EndDrag once by canceling any tasks that want
// to call EndDrag.
- drag_end_factory_.RevokeAll();
+ drag_end_factory_.InvalidateWeakPtrs();
// We must let gtk clean up after we handle the drag operation, otherwise
// there will be outstanding references to the drag widget when we try to
// destroy it.
- MessageLoop::current()->PostTask(FROM_HERE,
- destroy_factory_.NewRunnableMethod(&TabGtk::DestroyDragWidget));
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&TabGtk::DestroyDragWidget, destroy_factory_.GetWeakPtr()));
if (last_mouse_down_) {
gdk_event_free(last_mouse_down_);
diff --git a/chrome/browser/ui/gtk/tabs/tab_gtk.h b/chrome/browser/ui/gtk/tabs/tab_gtk.h
index 84df548..9f0be60 100644
--- a/chrome/browser/ui/gtk/tabs/tab_gtk.h
+++ b/chrome/browser/ui/gtk/tabs/tab_gtk.h
@@ -7,6 +7,7 @@
#pragma once
#include "base/basictypes.h"
+#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
#include "chrome/browser/tabs/tab_strip_model.h"
#include "chrome/browser/ui/gtk/tabs/tab_renderer_gtk.h"
@@ -212,14 +213,14 @@ class TabGtk : public TabRendererGtk,
scoped_ptr<TabGtkObserverHelper> observer_;
// Used to destroy the drag widget after a return to the message loop.
- ScopedRunnableMethodFactory<TabGtk> destroy_factory_;
+ base::WeakPtrFactory<TabGtk> destroy_factory_;
// Due to a bug in GTK+, we need to force the end of a drag when we get a
// mouse release event on the the dragged widget, otherwise, we don't know
// when the drag has ended when the user presses space or enter. We queue
// a task to end the drag and only run it if GTK+ didn't send us the
// drag-failed event.
- ScopedRunnableMethodFactory<TabGtk> drag_end_factory_;
+ base::WeakPtrFactory<TabGtk> drag_end_factory_;
DISALLOW_COPY_AND_ASSIGN(TabGtk);
};
diff --git a/chrome/browser/ui/gtk/tabs/tab_strip_gtk.cc b/chrome/browser/ui/gtk/tabs/tab_strip_gtk.cc
index 8a45d30..7612289 100644
--- a/chrome/browser/ui/gtk/tabs/tab_strip_gtk.cc
+++ b/chrome/browser/ui/gtk/tabs/tab_strip_gtk.cc
@@ -6,6 +6,7 @@
#include <algorithm>
+#include "base/bind.h"
#include "base/i18n/rtl.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
@@ -703,7 +704,7 @@ TabStripGtk::TabStripGtk(TabStripModel* model, BrowserWindowGtk* window)
model_(model),
window_(window),
theme_service_(GtkThemeService::GetFrom(model->profile())),
- resize_layout_factory_(this),
+ weak_factory_(this),
added_as_message_loop_observer_(false),
hover_tab_selector_(model) {
theme_service_->InitThemesFor(this);
@@ -1387,17 +1388,18 @@ void TabStripGtk::HandleGlobalMouseMoveEvent() {
if (!IsCursorInTabStripZone()) {
// Mouse moved outside the tab slop zone, start a timer to do a resize
// layout after a short while...
- if (resize_layout_factory_.empty()) {
- MessageLoop::current()->PostDelayedTask(FROM_HERE,
- resize_layout_factory_.NewRunnableMethod(
- &TabStripGtk::ResizeLayoutTabs),
+ if (!weak_factory_.HasWeakPtrs()) {
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&TabStripGtk::ResizeLayoutTabsWithoutResult,
+ weak_factory_.GetWeakPtr()),
kResizeTabsTimeMs);
}
} else {
// Mouse moved quickly out of the tab strip and then into it again, so
// cancel the timer so that the strip doesn't move when the mouse moves
// back over it.
- resize_layout_factory_.RevokeAll();
+ weak_factory_.InvalidateWeakPtrs();
}
}
@@ -1555,7 +1557,7 @@ int TabStripGtk::tab_start_x() const {
}
bool TabStripGtk::ResizeLayoutTabs() {
- resize_layout_factory_.RevokeAll();
+ weak_factory_.InvalidateWeakPtrs();
// It is critically important that this is unhooked here, otherwise we will
// keep spying on messages forever.
@@ -1583,6 +1585,10 @@ bool TabStripGtk::ResizeLayoutTabs() {
return false;
}
+void TabStripGtk::ResizeLayoutTabsWithoutResult() {
+ ResizeLayoutTabs();
+}
+
bool TabStripGtk::IsCursorInTabStripZone() const {
gfx::Point tabstrip_topleft;
gtk_util::ConvertWidgetPointToScreen(tabstrip_.get(), &tabstrip_topleft);
diff --git a/chrome/browser/ui/gtk/tabs/tab_strip_gtk.h b/chrome/browser/ui/gtk/tabs/tab_strip_gtk.h
index 176436a..62cb727 100644
--- a/chrome/browser/ui/gtk/tabs/tab_strip_gtk.h
+++ b/chrome/browser/ui/gtk/tabs/tab_strip_gtk.h
@@ -10,6 +10,7 @@
#include <vector>
#include "base/basictypes.h"
+#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
#include "base/task.h"
#include "chrome/browser/tabs/tab_strip_model.h"
@@ -327,6 +328,11 @@ class TabStripGtk : public TabStripModelObserver,
// value returned indicates whether a resize actually took place.
bool ResizeLayoutTabs();
+ // See ResizeLayoutTabs. Does not return success or failure. Necessitated by
+ // base::Bind and friends, which cannot handle a WeakPtr for a closure that
+ // has a return value.
+ void ResizeLayoutTabsWithoutResult();
+
// Returns whether or not the cursor is currently in the "tab strip zone"
// which is defined as the region above the TabStrip and a bit below it.
bool IsCursorInTabStripZone() const;
@@ -473,7 +479,7 @@ class TabStripGtk : public TabStripModelObserver,
// A factory that is used to construct a delayed callback to the
// ResizeLayoutTabsNow method.
- ScopedRunnableMethodFactory<TabStripGtk> resize_layout_factory_;
+ base::WeakPtrFactory<TabStripGtk> weak_factory_;
// True if the tabstrip has already been added as a MessageLoop observer.
bool added_as_message_loop_observer_;
diff --git a/chrome/browser/ui/webui/ntp/most_visited_handler.cc b/chrome/browser/ui/webui/ntp/most_visited_handler.cc
index 113069a..d3513ba 100644
--- a/chrome/browser/ui/webui/ntp/most_visited_handler.cc
+++ b/chrome/browser/ui/webui/ntp/most_visited_handler.cc
@@ -142,7 +142,8 @@ void MostVisitedHandler::StartQueryForMostVisited() {
if (ts) {
ts->GetMostVisitedURLs(
&topsites_consumer_,
- NewCallback(this, &MostVisitedHandler::OnMostVisitedURLsAvailable));
+ base::Bind(&MostVisitedHandler::OnMostVisitedURLsAvailable,
+ base::Unretained(this)));
}
}
diff --git a/content/browser/cancelable_request.h b/content/browser/cancelable_request.h
index 6df0c63..04f675c 100644
--- a/content/browser/cancelable_request.h
+++ b/content/browser/cancelable_request.h
@@ -93,6 +93,7 @@
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/callback.h"
+#include "base/callback_internal.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
@@ -524,17 +525,17 @@ class CONTENT_EXPORT CancelableRequestBase
friend class CancelableRequestProvider;
// Initializes most things to empty, Init() must be called to complete
- // initialization of the object. This will be done by the provider when
- // the request is dispatched.
+ // initialization of the object. This will be done by the provider when the
+ // request is dispatched.
//
- // This must be called on the same thread the callback will be executed on,
- // it will save that thread for later.
+ // This must be called on the same thread the callback will be executed on, it
+ // will save that thread for later.
//
- // This two-phase init is done so that the constructor can have no
- // parameters, which makes it much more convenient for derived classes,
- // which can be common. The derived classes need only declare the variables
- // they provide in the constructor rather than many lines of internal
- // tracking data that are passed to the base class (us).
+ // This two-phase init is done so that the constructor can have no parameters,
+ // which makes it much more convenient for derived classes, which can be
+ // common. The derived classes need only declare the variables they provide in
+ // the constructor rather than many lines of internal tracking data that are
+ // passed to the base class (us).
//
// In addition, not all of the information (for example, the handle) is known
// at construction time.
@@ -775,12 +776,13 @@ class CancelableRequest<base::Callback<void(A1)> > :
DCHECK(!callback.is_null()) << "Callback must be initialized.";
}
- void ForwardResult(const A1& a1) {
+ void ForwardResult(typename base::internal::ParamTraits<A1>::ForwardType a1) {
if (canceled()) return;
DoForward(base::Bind(callback_, a1), false);
}
- void ForwardResultAsync(const A1& a1) {
+ void ForwardResultAsync(
+ typename base::internal::ParamTraits<A1>::ForwardType a1) {
if (canceled()) return;
DoForward(base::Bind(callback_, a1), true);
}
@@ -804,12 +806,15 @@ class CancelableRequest<base::Callback<void(A1,A2)> > :
DCHECK(!callback.is_null()) << "Callback must be initialized.";
}
- void ForwardResult(const A1& a1, const A2& a2) {
+ void ForwardResult(typename base::internal::ParamTraits<A1>::ForwardType a1,
+ typename base::internal::ParamTraits<A2>::ForwardType a2) {
if (canceled()) return;
DoForward(base::Bind(callback_, a1, a2), false);
}
- void ForwardResultAsync(const A1& a1, const A2& a2) {
+ void ForwardResultAsync(
+ typename base::internal::ParamTraits<A1>::ForwardType a1,
+ typename base::internal::ParamTraits<A2>::ForwardType a2) {
if (canceled()) return;
DoForward(base::Bind(callback_, a1, a2), true);
}
@@ -833,12 +838,17 @@ class CancelableRequest<base::Callback<void(A1,A2,A3)> > :
DCHECK(!callback.is_null()) << "Callback must be initialized.";
}
- void ForwardResult(const A1& a1, const A2& a2, const A3& a3) {
+ void ForwardResult(typename base::internal::ParamTraits<A1>::ForwardType a1,
+ typename base::internal::ParamTraits<A2>::ForwardType a2,
+ typename base::internal::ParamTraits<A3>::ForwardType a3) {
if (canceled()) return;
DoForward(base::Bind(callback_, a1, a2, a3), false);
}
- void ForwardResultAsync(const A1& a1, const A2& a2, const A3& a3) {
+ void ForwardResultAsync(
+ typename base::internal::ParamTraits<A1>::ForwardType a1,
+ typename base::internal::ParamTraits<A2>::ForwardType a2,
+ typename base::internal::ParamTraits<A3>::ForwardType a3) {
if (canceled()) return;
DoForward(base::Bind(callback_, a1, a2, a3), true);
}
@@ -862,13 +872,19 @@ class CancelableRequest<base::Callback<void(A1, A2, A3, A4)> > :
DCHECK(!callback.is_null()) << "Callback must be initialized.";
}
- void ForwardResult(const A1& a1, const A2& a2, const A3& a3, const A4& a4) {
+ void ForwardResult(typename base::internal::ParamTraits<A1>::ForwardType a1,
+ typename base::internal::ParamTraits<A2>::ForwardType a2,
+ typename base::internal::ParamTraits<A3>::ForwardType a3,
+ typename base::internal::ParamTraits<A4>::ForwardType a4) {
if (canceled()) return;
DoForward(base::Bind(callback_, a1, a2, a3, a4), false);
}
- void ForwardResultAsync(const A1& a1, const A2& a2, const A3& a3,
- const A4& a4) {
+ void ForwardResultAsync(
+ typename base::internal::ParamTraits<A1>::ForwardType a1,
+ typename base::internal::ParamTraits<A2>::ForwardType a2,
+ typename base::internal::ParamTraits<A3>::ForwardType a3,
+ typename base::internal::ParamTraits<A4>::ForwardType a4) {
if (canceled()) return;
DoForward(base::Bind(callback_, a1, a2, a3, a4), true);
}
@@ -892,14 +908,21 @@ class CancelableRequest<base::Callback<void(A1, A2, A3, A4, A5)> > :
DCHECK(!callback.is_null()) << "Callback must be initialized.";
}
- void ForwardResult(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
- const A5& a5) {
+ void ForwardResult(typename base::internal::ParamTraits<A1>::ForwardType a1,
+ typename base::internal::ParamTraits<A2>::ForwardType a2,
+ typename base::internal::ParamTraits<A3>::ForwardType a3,
+ typename base::internal::ParamTraits<A4>::ForwardType a4,
+ typename base::internal::ParamTraits<A5>::ForwardType a5) {
if (canceled()) return;
DoForward(base::Bind(callback_, a1, a2, a3, a4, a5), false);
}
- void ForwardResultAsync(const A1& a1, const A2& a2, const A3& a3,
- const A4& a4, const A5& a5) {
+ void ForwardResultAsync(
+ typename base::internal::ParamTraits<A1>::ForwardType a1,
+ typename base::internal::ParamTraits<A2>::ForwardType a2,
+ typename base::internal::ParamTraits<A3>::ForwardType a3,
+ typename base::internal::ParamTraits<A4>::ForwardType a4,
+ typename base::internal::ParamTraits<A5>::ForwardType a5) {
if (canceled()) return;
DoForward(base::Bind(callback_, a1, a2, a3, a4, a5), true);
}
@@ -924,14 +947,23 @@ class CancelableRequest<base::Callback<void(A1, A2, A3, A4, A5, A6)> > :
DCHECK(!callback.is_null()) << "Callback must be initialized.";
}
- void ForwardResult(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
- const A5& a5, const A6& a6) {
+ void ForwardResult(typename base::internal::ParamTraits<A1>::ForwardType a1,
+ typename base::internal::ParamTraits<A2>::ForwardType a2,
+ typename base::internal::ParamTraits<A3>::ForwardType a3,
+ typename base::internal::ParamTraits<A4>::ForwardType a4,
+ typename base::internal::ParamTraits<A5>::ForwardType a5,
+ typename base::internal::ParamTraits<A6>::ForwardType a6) {
if (canceled()) return;
DoForward(base::Bind(callback_, a1, a2, a3, a4, a5, a6), false);
}
- void ForwardResultAsync(const A1& a1, const A2& a2, const A3& a3,
- const A4& a4, const A5& a5, const A6& a6) {
+ void ForwardResultAsync(
+ typename base::internal::ParamTraits<A1>::ForwardType a1,
+ typename base::internal::ParamTraits<A2>::ForwardType a2,
+ typename base::internal::ParamTraits<A3>::ForwardType a3,
+ typename base::internal::ParamTraits<A4>::ForwardType a4,
+ typename base::internal::ParamTraits<A5>::ForwardType a5,
+ typename base::internal::ParamTraits<A6>::ForwardType a6) {
if (canceled()) return;
DoForward(base::Bind(callback_, a1, a2, a3, a4, a5, a6), true);
}
@@ -952,7 +984,7 @@ class CancelableRequest<base::Callback<void(A1, A2, A3, A4, A5, A6)> > :
// typedef Callback2<Handle, std::vector<Foo>*>::Type FooCallback;
// 2. Define the CancelableRequest1 type.
// typedef CancelableRequest1<FooCallback, std::vector<Foo>> FooRequest;
-// 3. The provider method should then fillin the contents of the vector,
+// 3. The provider method should then fill in the contents of the vector,
// forwarding the result like so:
// request->ForwardResult(FooRequest::TupleType(request->handle(),
// &request->value));