diff options
-rw-r--r-- | chrome/browser/sync/engine/sync_scheduler.cc | 80 | ||||
-rw-r--r-- | chrome/browser/sync/engine/sync_scheduler.h | 19 | ||||
-rw-r--r-- | chrome/browser/sync/engine/sync_scheduler_unittest.cc | 10 | ||||
-rw-r--r-- | chrome/browser/sync/glue/sync_backend_host.cc | 10 | ||||
-rw-r--r-- | chrome/browser/sync/glue/sync_backend_host.h | 4 | ||||
-rw-r--r-- | chrome/browser/sync/internal_api/sync_manager.cc | 8 | ||||
-rw-r--r-- | chrome/browser/sync/internal_api/sync_manager.h | 6 | ||||
-rw-r--r-- | chrome/browser/sync/test_profile_sync_service.cc | 3 | ||||
-rw-r--r-- | chrome/browser/sync/test_profile_sync_service.h | 2 |
9 files changed, 73 insertions, 69 deletions
diff --git a/chrome/browser/sync/engine/sync_scheduler.cc b/chrome/browser/sync/engine/sync_scheduler.cc index 14991e6..e2b2353 100644 --- a/chrome/browser/sync/engine/sync_scheduler.cc +++ b/chrome/browser/sync/engine/sync_scheduler.cc @@ -7,6 +7,7 @@ #include <algorithm> #include <cstring> +#include "base/bind.h" #include "base/compiler_specific.h" #include "base/location.h" #include "base/logging.h" @@ -174,7 +175,7 @@ bool IsConfigRelatedUpdateSourceValue( SyncScheduler::SyncScheduler(const std::string& name, sessions::SyncSessionContext* context, Syncer* syncer) - : method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), + : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), name_(name), sync_loop_(MessageLoop::current()), started_(false), @@ -229,7 +230,7 @@ void SyncScheduler::CheckServerConnectionManagerStatus( } } -void SyncScheduler::Start(Mode mode, ModeChangeCallback* callback) { +void SyncScheduler::Start(Mode mode, const base::Closure& callback) { DCHECK_EQ(MessageLoop::current(), sync_loop_); std::string thread_name = MessageLoop::current()->thread_name(); if (thread_name.empty()) @@ -239,15 +240,13 @@ void SyncScheduler::Start(Mode mode, ModeChangeCallback* callback) { if (!started_) { WatchConnectionManager(); PostTask(FROM_HERE, "SendInitialSnapshot", - method_factory_.NewRunnableMethod( - &SyncScheduler::SendInitialSnapshot)); + base::Bind(&SyncScheduler::SendInitialSnapshot, + weak_ptr_factory_.GetWeakPtr())); } started_ = true; - // TODO(sync): This will leak if StartImpl is never run. Fix this. - // Might be easiest to just use base::Callback. PostTask(FROM_HERE, "StartImpl", - method_factory_.NewRunnableMethod( - &SyncScheduler::StartImpl, mode, callback)); + base::Bind(&SyncScheduler::StartImpl, + weak_ptr_factory_.GetWeakPtr(), mode, callback)); } void SyncScheduler::SendInitialSnapshot() { @@ -265,25 +264,24 @@ void SyncScheduler::WatchConnectionManager() { DCHECK_EQ(MessageLoop::current(), sync_loop_); ServerConnectionManager* scm = session_context_->connection_manager(); PostTask(FROM_HERE, "CheckServerConnectionManagerStatus", - method_factory_.NewRunnableMethod( - &SyncScheduler::CheckServerConnectionManagerStatus, - scm->server_status())); + base::Bind(&SyncScheduler::CheckServerConnectionManagerStatus, + weak_ptr_factory_.GetWeakPtr(), + scm->server_status())); scm->AddListener(this); } -void SyncScheduler::StartImpl(Mode mode, ModeChangeCallback* callback) { +void SyncScheduler::StartImpl(Mode mode, const base::Closure& callback) { DCHECK_EQ(MessageLoop::current(), sync_loop_); SVLOG(2) << "In StartImpl with mode " << GetModeString(mode); - scoped_ptr<ModeChangeCallback> scoped_callback(callback); DCHECK_EQ(MessageLoop::current(), sync_loop_); DCHECK(!session_context_->account_name().empty()); DCHECK(syncer_.get()); Mode old_mode = mode_; mode_ = mode; AdjustPolling(NULL); // Will kick start poll timer if needed. - if (scoped_callback.get()) - scoped_callback->Run(); + if (!callback.is_null()) + callback.Run(); if (old_mode != mode_) { // We just changed our mode. See if there are any pending jobs that we could @@ -441,8 +439,8 @@ struct ModelSafeWorkerGroupIs { void SyncScheduler::ScheduleClearUserData() { DCHECK_EQ(MessageLoop::current(), sync_loop_); PostTask(FROM_HERE, "ScheduleClearUserDataImpl", - method_factory_.NewRunnableMethod( - &SyncScheduler::ScheduleClearUserDataImpl)); + base::Bind(&SyncScheduler::ScheduleClearUserDataImpl, + weak_ptr_factory_.GetWeakPtr())); } // TODO(sync): Remove the *Impl methods for the other Schedule* @@ -467,10 +465,13 @@ void SyncScheduler::ScheduleNudge( ModelTypePayloadMap types_with_payloads = syncable::ModelTypePayloadMapFromBitSet(types, std::string()); PostTask(nudge_location, "ScheduleNudgeImpl", - method_factory_.NewRunnableMethod( - &SyncScheduler::ScheduleNudgeImpl, delay, - GetUpdatesFromNudgeSource(source), types_with_payloads, false, - nudge_location)); + base::Bind(&SyncScheduler::ScheduleNudgeImpl, + weak_ptr_factory_.GetWeakPtr(), + delay, + GetUpdatesFromNudgeSource(source), + types_with_payloads, + false, + nudge_location)); } void SyncScheduler::ScheduleNudgeWithPayloads( @@ -485,10 +486,13 @@ void SyncScheduler::ScheduleNudgeWithPayloads( << syncable::ModelTypePayloadMapToString(types_with_payloads); PostTask(nudge_location, "ScheduleNudgeImpl", - method_factory_.NewRunnableMethod( - &SyncScheduler::ScheduleNudgeImpl, delay, - GetUpdatesFromNudgeSource(source), types_with_payloads, false, - nudge_location)); + base::Bind(&SyncScheduler::ScheduleNudgeImpl, + weak_ptr_factory_.GetWeakPtr(), + delay, + GetUpdatesFromNudgeSource(source), + types_with_payloads, + false, + nudge_location)); } void SyncScheduler::ScheduleClearUserDataImpl() { @@ -608,8 +612,11 @@ void SyncScheduler::ScheduleConfig( &routes, &workers); PostTask(FROM_HERE, "ScheduleConfigImpl", - method_factory_.NewRunnableMethod( - &SyncScheduler::ScheduleConfigImpl, routes, workers, source)); + base::Bind(&SyncScheduler::ScheduleConfigImpl, + weak_ptr_factory_.GetWeakPtr(), + routes, + workers, + source)); } void SyncScheduler::ScheduleConfigImpl( @@ -626,7 +633,7 @@ void SyncScheduler::ScheduleConfigImpl( routing_info, std::string())), routing_info, workers); ScheduleSyncSessionJob(TimeDelta::FromSeconds(0), - SyncSessionJob::CONFIGURATION, session, FROM_HERE); + SyncSessionJob::CONFIGURATION, session, FROM_HERE); } const char* SyncScheduler::GetModeString(SyncScheduler::Mode mode) { @@ -649,14 +656,14 @@ const char* SyncScheduler::GetDecisionString( void SyncScheduler::PostTask( const tracked_objects::Location& from_here, - const char* name, Task* task) { + const char* name, const base::Closure& task) { SVLOG_LOC(from_here, 3) << "Posting " << name << " task"; sync_loop_->PostTask(from_here, task); } void SyncScheduler::PostDelayedTask( const tracked_objects::Location& from_here, - const char* name, Task* task, int64 delay_ms) { + const char* name, const base::Closure& task, int64 delay_ms) { SVLOG_LOC(from_here, 3) << "Posting " << name << " task with " << delay_ms << " ms delay"; sync_loop_->PostDelayedTask(from_here, task, delay_ms); @@ -681,8 +688,9 @@ void SyncScheduler::ScheduleSyncSessionJob( pending_nudge_.reset(new SyncSessionJob(job)); } PostDelayedTask(from_here, "DoSyncSessionJob", - method_factory_.NewRunnableMethod( - &SyncScheduler::DoSyncSessionJob, job), + base::Bind(&SyncScheduler::DoSyncSessionJob, + weak_ptr_factory_.GetWeakPtr(), + job), delay.InMilliseconds()); } @@ -980,7 +988,7 @@ void SyncScheduler::RequestEarlyExit() { void SyncScheduler::Stop() { DCHECK_EQ(MessageLoop::current(), sync_loop_); SVLOG(2) << "Stop called"; - method_factory_.RevokeAll(); + weak_ptr_factory_.InvalidateWeakPtrs(); wait_interval_.reset(); poll_timer_.Stop(); if (started_) { @@ -1138,9 +1146,9 @@ void SyncScheduler::OnServerConnectionEvent( const ServerConnectionEvent& event) { DCHECK_EQ(MessageLoop::current(), sync_loop_); PostTask(FROM_HERE, "CheckServerConnectionManagerStatus", - method_factory_.NewRunnableMethod( - &SyncScheduler::CheckServerConnectionManagerStatus, - event.connection_code)); + base::Bind(&SyncScheduler::CheckServerConnectionManagerStatus, + weak_ptr_factory_.GetWeakPtr(), + event.connection_code)); } void SyncScheduler::set_notifications_enabled(bool notifications_enabled) { diff --git a/chrome/browser/sync/engine/sync_scheduler.h b/chrome/browser/sync/engine/sync_scheduler.h index 2f0dd6a..850bc66 100644 --- a/chrome/browser/sync/engine/sync_scheduler.h +++ b/chrome/browser/sync/engine/sync_scheduler.h @@ -14,8 +14,8 @@ #include "base/gtest_prod_util.h" #include "base/memory/linked_ptr.h" #include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" #include "base/observer_list.h" -#include "base/task.h" #include "base/time.h" #include "base/timer.h" #include "chrome/browser/sync/engine/net/server_connection_manager.h" @@ -61,14 +61,12 @@ class SyncScheduler : public sessions::SyncSession::Delegate, // Calls Stop(). virtual ~SyncScheduler(); - typedef Callback0::Type ModeChangeCallback; - // Start the scheduler with the given mode. If the scheduler is // already started, switch to the given mode, although some // scheduled tasks from the old mode may still run. If non-NULL, // |callback| will be invoked when the mode has been changed to // |mode|. Takes ownership of |callback|. - void Start(Mode mode, ModeChangeCallback* callback); + void Start(Mode mode, const base::Closure& callback); // Request that any running syncer task stop as soon as possible. // This function can be called from any thread. Stop must still be @@ -249,12 +247,14 @@ class SyncScheduler : public sessions::SyncSession::Delegate, static const char* GetDecisionString(JobProcessDecision decision); // Helpers that log before posting to |sync_loop_|. - // TODO(akalin): Use base::Closure. void PostTask(const tracked_objects::Location& from_here, - const char* name, Task* task); + const char* name, + const base::Closure& task); void PostDelayedTask(const tracked_objects::Location& from_here, - const char* name, Task* task, int64 delay_ms); + const char* name, + const base::Closure& task, + int64 delay_ms); // Helper to assemble a job and post a delayed task to sync. void ScheduleSyncSessionJob( @@ -306,7 +306,7 @@ class SyncScheduler : public sessions::SyncSession::Delegate, // 'Impl' here refers to real implementation of public functions, running on // |thread_|. - void StartImpl(Mode mode, ModeChangeCallback* callback); + void StartImpl(Mode mode, const base::Closure& callback); void ScheduleNudgeImpl( const base::TimeDelta& delay, sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, @@ -359,8 +359,7 @@ class SyncScheduler : public sessions::SyncSession::Delegate, virtual void OnActionableError(const sessions::SyncSessionSnapshot& snapshot); - - ScopedRunnableMethodFactory<SyncScheduler> method_factory_; + base::WeakPtrFactory<SyncScheduler> weak_ptr_factory_; // Used for logging. const std::string name_; diff --git a/chrome/browser/sync/engine/sync_scheduler_unittest.cc b/chrome/browser/sync/engine/sync_scheduler_unittest.cc index 57e05c1..ad158d5a 100644 --- a/chrome/browser/sync/engine/sync_scheduler_unittest.cc +++ b/chrome/browser/sync/engine/sync_scheduler_unittest.cc @@ -5,9 +5,8 @@ #include "base/bind.h" #include "base/callback.h" #include "base/compiler_specific.h" -#include "base/memory/scoped_callback_factory.h" +#include "base/memory/weak_ptr.h" #include "base/message_loop.h" -#include "base/task.h" #include "base/test/test_timeouts.h" #include "chrome/browser/sync/engine/mock_model_safe_workers.h" #include "chrome/browser/sync/engine/sync_scheduler.h" @@ -73,7 +72,7 @@ static const size_t kMinNumSamples = 5; class SyncSchedulerTest : public testing::Test { public: SyncSchedulerTest() - : callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), + : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), context_(NULL), syncer_(NULL), delay_(NULL) {} @@ -140,7 +139,8 @@ class SyncSchedulerTest : public testing::Test { void StartSyncScheduler(SyncScheduler::Mode mode) { scheduler()->Start( mode, - callback_factory_.NewCallback(&SyncSchedulerTest::DoQuitLoopNow)); + base::Bind(&SyncSchedulerTest::DoQuitLoopNow, + weak_ptr_factory_.GetWeakPtr())); } bool GetBackoffAndResetTest() { @@ -190,7 +190,7 @@ class SyncSchedulerTest : public testing::Test { SyncSessionContext* context() { return context_; } private: - base::ScopedCallbackFactory<SyncSchedulerTest> callback_factory_; + base::WeakPtrFactory<SyncSchedulerTest> weak_ptr_factory_; MessageLoop message_loop_; scoped_ptr<SyncScheduler> scheduler_; scoped_ptr<MockConnectionManager> connection_; diff --git a/chrome/browser/sync/glue/sync_backend_host.cc b/chrome/browser/sync/glue/sync_backend_host.cc index 6fe2af1..be84a1e 100644 --- a/chrome/browser/sync/glue/sync_backend_host.cc +++ b/chrome/browser/sync/glue/sync_backend_host.cc @@ -14,7 +14,6 @@ #include "base/compiler_specific.h" #include "base/file_util.h" #include "base/location.h" -#include "base/task.h" #include "base/threading/thread_restrictions.h" #include "base/utf_string_conversions.h" #include "chrome/browser/net/gaia/token_service.h" @@ -243,11 +242,11 @@ void SyncBackendHost::ConfigureDataTypes( &SyncBackendHost::Core::DoRequestCleanupDisabledTypes)); } - StartConfiguration(NewCallback(core_.get(), - &SyncBackendHost::Core::FinishConfigureDataTypes)); + StartConfiguration(base::Bind( + &SyncBackendHost::Core::FinishConfigureDataTypes, core_.get())); } -void SyncBackendHost::StartConfiguration(Callback0::Type* callback) { +void SyncBackendHost::StartConfiguration(const base::Closure& callback) { // Put syncer in the config mode. DTM will put us in normal mode once it is // done. This is to ensure we dont do a normal sync when we are doing model // association. @@ -640,7 +639,8 @@ void SyncBackendHost::Core::DoRequestConfig( sync_manager_->RequestConfig(types_to_config, reason); } -void SyncBackendHost::Core::DoStartConfiguration(Callback0::Type* callback) { +void SyncBackendHost::Core::DoStartConfiguration( + const base::Closure& callback) { DCHECK_EQ(MessageLoop::current(), sync_loop_); sync_manager_->StartConfigurationMode(callback); } diff --git a/chrome/browser/sync/glue/sync_backend_host.h b/chrome/browser/sync/glue/sync_backend_host.h index e13d6a8..f0d17be 100644 --- a/chrome/browser/sync/glue/sync_backend_host.h +++ b/chrome/browser/sync/glue/sync_backend_host.h @@ -173,7 +173,7 @@ class SyncBackendHost { // Makes an asynchronous call to syncer to switch to config mode. When done // syncer will call us back on FinishConfigureDataTypes. - virtual void StartConfiguration(Callback0::Type* callback); + virtual void StartConfiguration(const base::Closure& callback); // Turns on encryption of all present and future sync data. virtual void EnableEncryptEverything(); @@ -363,7 +363,7 @@ class SyncBackendHost { // Start the configuration mode. |callback| is called on the sync // thread. - virtual void DoStartConfiguration(Callback0::Type* callback); + virtual void DoStartConfiguration(const base::Closure& callback); // Set the base request context to use when making HTTP calls. // This method will add a reference to the context to persist it diff --git a/chrome/browser/sync/internal_api/sync_manager.cc b/chrome/browser/sync/internal_api/sync_manager.cc index 5e1c537..a80a028 100644 --- a/chrome/browser/sync/internal_api/sync_manager.cc +++ b/chrome/browser/sync/internal_api/sync_manager.cc @@ -707,11 +707,11 @@ void SyncManager::RequestConfig(const syncable::ModelTypeBitSet& types, << "null"; return; } - StartConfigurationMode(NULL); + StartConfigurationMode(base::Closure()); data_->scheduler()->ScheduleConfig(types, GetSourceFromReason(reason)); } -void SyncManager::StartConfigurationMode(ModeChangeCallback* callback) { +void SyncManager::StartConfigurationMode(const base::Closure& callback) { DCHECK(thread_checker_.CalledOnValidThread()); if (!data_->scheduler()) { LOG(INFO) @@ -795,7 +795,7 @@ bool SyncManager::SyncInternal::Init( if (signed_in || setup_for_test_mode_) { if (scheduler()) { scheduler()->Start( - browser_sync::SyncScheduler::CONFIGURATION_MODE, NULL); + browser_sync::SyncScheduler::CONFIGURATION_MODE, base::Closure()); } initialized_ = true; @@ -875,7 +875,7 @@ void SyncManager::SyncInternal::StartSyncingNormally() { // syncing until at least the DirectoryManager broadcasts the OPENED // event, and a valid server connection is detected. if (scheduler()) // NULL during certain unittests. - scheduler()->Start(SyncScheduler::NORMAL_MODE, NULL); + scheduler()->Start(SyncScheduler::NORMAL_MODE, base::Closure()); } bool SyncManager::SyncInternal::OpenDirectory() { diff --git a/chrome/browser/sync/internal_api/sync_manager.h b/chrome/browser/sync/internal_api/sync_manager.h index acf71f2..3e75098 100644 --- a/chrome/browser/sync/internal_api/sync_manager.h +++ b/chrome/browser/sync/internal_api/sync_manager.h @@ -9,7 +9,7 @@ #include <vector> #include "base/basictypes.h" -#include "base/callback_old.h" +#include "base/callback.h" #include "base/threading/thread_checker.h" #include "chrome/browser/sync/internal_api/change_record.h" #include "chrome/browser/sync/internal_api/configure_reason.h" @@ -387,8 +387,6 @@ class SyncManager { virtual ~Observer(); }; - typedef Callback0::Type ModeChangeCallback; - // Create an uninitialized SyncManager. Callers must Init() before using. explicit SyncManager(const std::string& name); virtual ~SyncManager(); @@ -464,7 +462,7 @@ class SyncManager { // will occur, but calls to RequestConfig will be supported. If |callback| // is provided, it will be invoked (from the internal SyncScheduler) when // the thread has changed to configuration mode. - void StartConfigurationMode(ModeChangeCallback* callback); + void StartConfigurationMode(const base::Closure& callback); // Switches the mode of operation to CONFIGURATION_MODE and // schedules a config task to fetch updates for |types|. diff --git a/chrome/browser/sync/test_profile_sync_service.cc b/chrome/browser/sync/test_profile_sync_service.cc index ec5ac17..e6fcd31 100644 --- a/chrome/browser/sync/test_profile_sync_service.cc +++ b/chrome/browser/sync/test_profile_sync_service.cc @@ -93,8 +93,7 @@ void SyncBackendHostForProfileSyncTest::InitCore( } void SyncBackendHostForProfileSyncTest::StartConfiguration( - Callback0::Type* callback) { - scoped_ptr<Callback0::Type> scoped_callback(callback); + const base::Closure& callback) { SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop(); if (initialization_state_ == DOWNLOADING_NIGORI) { syncable::ModelTypeBitSet sync_ended; diff --git a/chrome/browser/sync/test_profile_sync_service.h b/chrome/browser/sync/test_profile_sync_service.h index 743cdeb..6d15e0f 100644 --- a/chrome/browser/sync/test_profile_sync_service.h +++ b/chrome/browser/sync/test_profile_sync_service.h @@ -45,7 +45,7 @@ class SyncBackendHostForProfileSyncTest : public SyncBackendHost { virtual sync_api::HttpPostProviderFactory* MakeHttpBridgeFactory( const scoped_refptr<net::URLRequestContextGetter>& getter) OVERRIDE; - virtual void StartConfiguration(Callback0::Type* callback) OVERRIDE; + virtual void StartConfiguration(const base::Closure& callback) OVERRIDE; static void SetDefaultExpectationsForWorkerCreation(ProfileMock* profile); |