Commit 12465ec0 authored by groby@chromium.org's avatar groby@chromium.org

base::Bind fixes


BUG=none
TEST=none


Review URL: http://codereview.chromium.org/8589012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110554 0039d316-1c4b-4281-b951-d872f2087c98
parent e3210f6f
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/net/chrome_url_request_context.h"
#include "base/bind.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/message_loop.h" #include "base/message_loop.h"
#include "base/message_loop_proxy.h" #include "base/message_loop_proxy.h"
...@@ -161,8 +162,8 @@ net::CookieStore* ChromeURLRequestContextGetter::DONTUSEME_GetCookieStore() { ...@@ -161,8 +162,8 @@ net::CookieStore* ChromeURLRequestContextGetter::DONTUSEME_GetCookieStore() {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, BrowserThread::IO, FROM_HERE,
NewRunnableMethod(this, base::Bind(&ChromeURLRequestContextGetter::GetCookieStoreAsyncHelper,
&ChromeURLRequestContextGetter::GetCookieStoreAsyncHelper, this,
&completion, &completion,
&result)); &result));
...@@ -275,27 +276,27 @@ void ChromeURLRequestContextGetter::Observe( ...@@ -275,27 +276,27 @@ void ChromeURLRequestContextGetter::Observe(
prefs->GetString(prefs::kAcceptLanguages); prefs->GetString(prefs::kAcceptLanguages);
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, BrowserThread::IO, FROM_HERE,
NewRunnableMethod( base::Bind(
this,
&ChromeURLRequestContextGetter::OnAcceptLanguageChange, &ChromeURLRequestContextGetter::OnAcceptLanguageChange,
this,
accept_language)); accept_language));
} else if (*pref_name_in == prefs::kDefaultCharset) { } else if (*pref_name_in == prefs::kDefaultCharset) {
std::string default_charset = std::string default_charset =
prefs->GetString(prefs::kDefaultCharset); prefs->GetString(prefs::kDefaultCharset);
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, BrowserThread::IO, FROM_HERE,
NewRunnableMethod( base::Bind(
this,
&ChromeURLRequestContextGetter::OnDefaultCharsetChange, &ChromeURLRequestContextGetter::OnDefaultCharsetChange,
this,
default_charset)); default_charset));
} else if (*pref_name_in == prefs::kClearSiteDataOnExit) { } else if (*pref_name_in == prefs::kClearSiteDataOnExit) {
bool clear_site_data = bool clear_site_data =
prefs->GetBoolean(prefs::kClearSiteDataOnExit); prefs->GetBoolean(prefs::kClearSiteDataOnExit);
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, BrowserThread::IO, FROM_HERE,
NewRunnableMethod( base::Bind(
this,
&ChromeURLRequestContextGetter::OnClearSiteDataOnExitChange, &ChromeURLRequestContextGetter::OnClearSiteDataOnExitChange,
this,
clear_site_data)); clear_site_data));
} }
} else { } else {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/net/connection_tester.h" #include "chrome/browser/net/connection_tester.h"
#include "base/bind.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/logging.h" #include "base/logging.h"
...@@ -262,7 +263,7 @@ class ConnectionTester::TestRunner : public net::URLRequest::Delegate { ...@@ -262,7 +263,7 @@ class ConnectionTester::TestRunner : public net::URLRequest::Delegate {
// |tester| will be notified of completion. // |tester| will be notified of completion.
explicit TestRunner(ConnectionTester* tester) explicit TestRunner(ConnectionTester* tester)
: tester_(tester), : tester_(tester),
ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {} ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {}
// Starts running |experiment|. Notifies tester->OnExperimentCompleted() when // Starts running |experiment|. Notifies tester->OnExperimentCompleted() when
// it is done. // it is done.
...@@ -288,7 +289,7 @@ class ConnectionTester::TestRunner : public net::URLRequest::Delegate { ...@@ -288,7 +289,7 @@ class ConnectionTester::TestRunner : public net::URLRequest::Delegate {
ConnectionTester* tester_; ConnectionTester* tester_;
scoped_ptr<net::URLRequest> request_; scoped_ptr<net::URLRequest> request_;
ScopedRunnableMethodFactory<TestRunner> method_factory_; base::WeakPtrFactory<TestRunner> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(TestRunner); DISALLOW_COPY_AND_ASSIGN(TestRunner);
}; };
...@@ -340,8 +341,8 @@ void ConnectionTester::TestRunner::OnResponseCompleted( ...@@ -340,8 +341,8 @@ void ConnectionTester::TestRunner::OnResponseCompleted(
// to end up deleting the URLRequest while in the middle of processing). // to end up deleting the URLRequest while in the middle of processing).
MessageLoop::current()->PostTask( MessageLoop::current()->PostTask(
FROM_HERE, FROM_HERE,
method_factory_.NewRunnableMethod( base::Bind(&TestRunner::OnExperimentCompletedWithResult,
&TestRunner::OnExperimentCompletedWithResult, result)); weak_factory_.GetWeakPtr(), result));
} }
void ConnectionTester::TestRunner::OnExperimentCompletedWithResult(int result) { void ConnectionTester::TestRunner::OnExperimentCompletedWithResult(int result) {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/net/network_stats.h" #include "chrome/browser/net/network_stats.h"
#include "base/bind.h"
#include "base/callback_old.h" #include "base/callback_old.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/message_loop.h" #include "base/message_loop.h"
...@@ -87,7 +88,7 @@ NetworkStats::NetworkStats() ...@@ -87,7 +88,7 @@ NetworkStats::NetworkStats()
write_callback_(this, &NetworkStats::OnWriteComplete)), write_callback_(this, &NetworkStats::OnWriteComplete)),
finished_callback_(NULL), finished_callback_(NULL),
start_time_(base::TimeTicks::Now()), start_time_(base::TimeTicks::Now()),
ALLOW_THIS_IN_INITIALIZER_LIST(timers_factory_(this)) { ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
} }
NetworkStats::~NetworkStats() { NetworkStats::~NetworkStats() {
...@@ -205,7 +206,7 @@ void NetworkStats::OnReadComplete(int result) { ...@@ -205,7 +206,7 @@ void NetworkStats::OnReadComplete(int result) {
const int kReadDataDelayMs = 1; const int kReadDataDelayMs = 1;
MessageLoop::current()->PostDelayedTask( MessageLoop::current()->PostDelayedTask(
FROM_HERE, FROM_HERE,
timers_factory_.NewRunnableMethod(&NetworkStats::ReadData), base::Bind(&NetworkStats::ReadData, weak_factory_.GetWeakPtr()),
kReadDataDelayMs); kReadDataDelayMs);
} }
} }
...@@ -281,7 +282,7 @@ int NetworkStats::SendData() { ...@@ -281,7 +282,7 @@ int NetworkStats::SendData() {
void NetworkStats::StartReadDataTimer(int milliseconds) { void NetworkStats::StartReadDataTimer(int milliseconds) {
MessageLoop::current()->PostDelayedTask( MessageLoop::current()->PostDelayedTask(
FROM_HERE, FROM_HERE,
timers_factory_.NewRunnableMethod(&NetworkStats::OnReadDataTimeout), base::Bind(&NetworkStats::OnReadDataTimeout, weak_factory_.GetWeakPtr()),
milliseconds); milliseconds);
} }
...@@ -528,7 +529,7 @@ void CollectNetworkStats(const std::string& network_stats_server, ...@@ -528,7 +529,7 @@ void CollectNetworkStats(const std::string& network_stats_server,
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::IO, BrowserThread::IO,
FROM_HERE, FROM_HERE,
NewRunnableFunction( base::Bind(
&CollectNetworkStats, network_stats_server, io_thread)); &CollectNetworkStats, network_stats_server, io_thread));
return; return;
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <string> #include <string>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/bind.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/string_util.h" #include "base/string_util.h"
...@@ -191,7 +192,7 @@ class NetworkStats { ...@@ -191,7 +192,7 @@ class NetworkStats {
base::TimeTicks start_time_; base::TimeTicks start_time_;
// We use this factory to create timeout tasks for socket's ReadData. // We use this factory to create timeout tasks for socket's ReadData.
ScopedRunnableMethodFactory<NetworkStats> timers_factory_; base::WeakPtrFactory<NetworkStats> weak_factory_;
}; };
class UDPStatsClient : public NetworkStats { class UDPStatsClient : public NetworkStats {
......
...@@ -701,7 +701,8 @@ void Predictor::FinalizeInitializationOnIOThread( ...@@ -701,7 +701,8 @@ void Predictor::FinalizeInitializationOnIOThread(
// on the same thread. The predictor lives on the IO thread and will die // on the same thread. The predictor lives on the IO thread and will die
// from there so now that we're on the IO thread we need to properly // from there so now that we're on the IO thread we need to properly
// initialize the ScopedrunnableMethodFactory. // initialize the ScopedrunnableMethodFactory.
trim_task_factory_.reset(new ScopedRunnableMethodFactory<Predictor>(this)); // TODO(groby): Check if WeakPtrFactory has the same constraint.
weak_factory_.reset(new base::WeakPtrFactory<Predictor>(this));
// Prefetch these hostnames on startup. // Prefetch these hostnames on startup.
DnsPrefetchMotivatedList(startup_urls, UrlInfo::STARTUP_LIST_MOTIVATED); DnsPrefetchMotivatedList(startup_urls, UrlInfo::STARTUP_LIST_MOTIVATED);
...@@ -1054,8 +1055,8 @@ void Predictor::PostIncrementalTrimTask() { ...@@ -1054,8 +1055,8 @@ void Predictor::PostIncrementalTrimTask() {
return; return;
MessageLoop::current()->PostDelayedTask( MessageLoop::current()->PostDelayedTask(
FROM_HERE, FROM_HERE,
trim_task_factory_->NewRunnableMethod( base::Bind(&Predictor::IncrementalTrimReferrers,
&Predictor::IncrementalTrimReferrers, false), weak_factory_->GetWeakPtr(), false),
kDurationBetweenTrimmingIncrements.InMilliseconds()); kDurationBetweenTrimmingIncrements.InMilliseconds());
} }
......
...@@ -492,7 +492,7 @@ class Predictor { ...@@ -492,7 +492,7 @@ class Predictor {
// A time after which we need to do more trimming of referrers. // A time after which we need to do more trimming of referrers.
base::TimeTicks next_trim_time_; base::TimeTicks next_trim_time_;
scoped_ptr<ScopedRunnableMethodFactory<Predictor> > trim_task_factory_; scoped_ptr<base::WeakPtrFactory<Predictor> > weak_factory_;
DISALLOW_COPY_AND_ASSIGN(Predictor); DISALLOW_COPY_AND_ASSIGN(Predictor);
}; };
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/net/sdch_dictionary_fetcher.h" #include "chrome/browser/net/sdch_dictionary_fetcher.h"
#include "base/bind.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/message_loop.h" #include "base/message_loop.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -11,7 +12,7 @@ ...@@ -11,7 +12,7 @@
#include "net/url_request/url_request_status.h" #include "net/url_request/url_request_status.h"
SdchDictionaryFetcher::SdchDictionaryFetcher() SdchDictionaryFetcher::SdchDictionaryFetcher()
: ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
task_is_pending_(false) { task_is_pending_(false) {
} }
...@@ -46,7 +47,8 @@ void SdchDictionaryFetcher::ScheduleDelayedRun() { ...@@ -46,7 +47,8 @@ void SdchDictionaryFetcher::ScheduleDelayedRun() {
if (fetch_queue_.empty() || current_fetch_.get() || task_is_pending_) if (fetch_queue_.empty() || current_fetch_.get() || task_is_pending_)
return; return;
MessageLoop::current()->PostDelayedTask(FROM_HERE, MessageLoop::current()->PostDelayedTask(FROM_HERE,
method_factory_.NewRunnableMethod(&SdchDictionaryFetcher::StartFetching), base::Bind(&SdchDictionaryFetcher::StartFetching,
weak_factory_.GetWeakPtr()),
kMsDelayFromRequestTillDownload); kMsDelayFromRequestTillDownload);
task_is_pending_ = true; task_is_pending_ = true;
} }
......
...@@ -61,7 +61,7 @@ class SdchDictionaryFetcher : public content::URLFetcherDelegate, ...@@ -61,7 +61,7 @@ class SdchDictionaryFetcher : public content::URLFetcherDelegate,
// Always spread out the dictionary fetches, so that they don't steal // Always spread out the dictionary fetches, so that they don't steal
// bandwidth from the actual page load. Create delayed tasks to spread out // bandwidth from the actual page load. Create delayed tasks to spread out
// the download. // the download.
ScopedRunnableMethodFactory<SdchDictionaryFetcher> method_factory_; base::WeakPtrFactory<SdchDictionaryFetcher> weak_factory_;
bool task_is_pending_; bool task_is_pending_;
// Althought the SDCH spec does not preclude a server from using a single URL // Althought the SDCH spec does not preclude a server from using a single URL
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment