diff options
author | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-23 00:07:20 +0000 |
---|---|---|
committer | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-23 00:07:20 +0000 |
commit | d9d315355d7aa268c81edbdafc1e2c9560c1fd90 (patch) | |
tree | 25608f40e16661bf79f26b36833adbf2bfbd893a /chrome/browser/sync | |
parent | d64375e35d2fe0b7f8d4d5c2cbfa9a7f99d0f88e (diff) | |
download | chromium_src-d9d315355d7aa268c81edbdafc1e2c9560c1fd90.zip chromium_src-d9d315355d7aa268c81edbdafc1e2c9560c1fd90.tar.gz chromium_src-d9d315355d7aa268c81edbdafc1e2c9560c1fd90.tar.bz2 |
base::Bind() conversion for sync code
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/9016025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115643 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync')
64 files changed, 396 insertions, 378 deletions
diff --git a/chrome/browser/sync/abstract_profile_sync_service_test.h b/chrome/browser/sync/abstract_profile_sync_service_test.h index f82a8db..fc62d49 100644 --- a/chrome/browser/sync/abstract_profile_sync_service_test.h +++ b/chrome/browser/sync/abstract_profile_sync_service_test.h @@ -12,7 +12,6 @@ #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" -#include "base/task.h" #include "chrome/browser/net/gaia/token_service.h" #include "chrome/browser/sync/internal_api/change_record.h" #include "chrome/browser/sync/profile_sync_components_factory_mock.h" diff --git a/chrome/browser/sync/backend_migrator.h b/chrome/browser/sync/backend_migrator.h index ee040f0..f178930 100644 --- a/chrome/browser/sync/backend_migrator.h +++ b/chrome/browser/sync/backend_migrator.h @@ -8,7 +8,6 @@ #include "base/compiler_specific.h" #include "base/memory/weak_ptr.h" #include "base/observer_list.h" -#include "base/task.h" #include "chrome/browser/sync/glue/data_type_manager.h" #include "chrome/browser/sync/syncable/model_type.h" #include "content/public/browser/notification_observer.h" diff --git a/chrome/browser/sync/engine/model_changing_syncer_command.cc b/chrome/browser/sync/engine/model_changing_syncer_command.cc index 2ea2e71..1c392cb 100644 --- a/chrome/browser/sync/engine/model_changing_syncer_command.cc +++ b/chrome/browser/sync/engine/model_changing_syncer_command.cc @@ -5,7 +5,8 @@ #include "chrome/browser/sync/engine/model_changing_syncer_command.h" #include "base/basictypes.h" -#include "base/callback_old.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "chrome/browser/sync/sessions/status_controller.h" #include "chrome/browser/sync/sessions/sync_session.h" #include "chrome/browser/sync/util/unrecoverable_error_info.h" diff --git a/chrome/browser/sync/engine/model_safe_worker.h b/chrome/browser/sync/engine/model_safe_worker.h index aa065fc..a103d09 100644 --- a/chrome/browser/sync/engine/model_safe_worker.h +++ b/chrome/browser/sync/engine/model_safe_worker.h @@ -11,7 +11,6 @@ #include <vector> #include "base/callback.h" -#include "base/callback_old.h" #include "base/memory/ref_counted.h" #include "chrome/browser/sync/syncable/model_type.h" #include "chrome/browser/sync/util/unrecoverable_error_info.h" diff --git a/chrome/browser/sync/engine/syncer_unittest.cc b/chrome/browser/sync/engine/syncer_unittest.cc index fde8bb7..8ff3a44 100644 --- a/chrome/browser/sync/engine/syncer_unittest.cc +++ b/chrome/browser/sync/engine/syncer_unittest.cc @@ -12,6 +12,8 @@ #include <set> #include <string> +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/callback.h" #include "base/compiler_specific.h" #include "base/location.h" @@ -2135,8 +2137,8 @@ TEST_F(EntryCreatedInNewFolderTest, EntryCreatedInNewFolderMidSync) { } mock_server_->SetMidCommitCallback( - NewCallback<EntryCreatedInNewFolderTest>(this, - &EntryCreatedInNewFolderTest::CreateFolderInBob)); + base::Bind(&EntryCreatedInNewFolderTest::CreateFolderInBob, + base::Unretained(this))); syncer_->SyncShare(session_.get(), BUILD_COMMIT_REQUEST, SYNCER_END); EXPECT_EQ(1u, mock_server_->committed_ids().size()); { @@ -4159,8 +4161,7 @@ TEST_F(SyncerUndeletionTest, UndeleteDuringCommit) { Delete(); ExpectUnsyncedDeletion(); mock_server_->SetMidCommitCallback( - NewCallback<SyncerUndeletionTest>(this, - &SyncerUndeletionTest::Undelete)); + base::Bind(&SyncerUndeletionTest::Undelete, base::Unretained(this))); SyncShareAsDelegate(); // The item ought to exist as an unsynced undeletion (meaning, @@ -4173,7 +4174,7 @@ TEST_F(SyncerUndeletionTest, UndeleteDuringCommit) { // the server. The undeletion should prevail again and be committed. // None of this should trigger any conflict detection -- it is perfectly // normal to recieve updates from our own commits. - mock_server_->SetMidCommitCallback(NULL); + mock_server_->SetMidCommitCallback(base::Closure()); mock_server_->AddUpdateTombstone(Get(metahandle_, ID)); SyncShareAsDelegate(); EXPECT_EQ(0, status.TotalNumConflictingItems()); diff --git a/chrome/browser/sync/glue/app_notification_data_type_controller_unittest.cc b/chrome/browser/sync/glue/app_notification_data_type_controller_unittest.cc index 36a9ecc..ab777a4 100644 --- a/chrome/browser/sync/glue/app_notification_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/app_notification_data_type_controller_unittest.cc @@ -3,9 +3,9 @@ // found in the LICENSE file. #include "base/bind.h" +#include "base/bind_helpers.h" #include "base/callback.h" #include "base/memory/scoped_ptr.h" -#include "base/task.h" #include "base/tracked_objects.h" #include "chrome/browser/extensions/app_notification_manager.h" #include "chrome/browser/extensions/extension_service.h" @@ -25,7 +25,7 @@ using browser_sync::AppNotificationDataTypeController; using browser_sync::ChangeProcessorMock; using browser_sync::DataTypeController; using browser_sync::ModelAssociatorMock; -using browser_sync::StartCallback; +using browser_sync::StartCallbackMock; using content::BrowserThread; using testing::_; using testing::DoAll; @@ -135,10 +135,10 @@ class AppNotificationDataTypeControllerTest ProfileSyncServiceMock service_; ModelAssociatorMock* model_associator_; ChangeProcessorMock* change_processor_; - StartCallback start_callback_; + StartCallbackMock start_callback_; }; -// When notification manager is ready, sync assocation should happen +// When notification manager is ready, sync association should happen // successfully. TEST_F(AppNotificationDataTypeControllerTest, StartManagerReady) { InitAndLoadManager(); @@ -146,7 +146,8 @@ TEST_F(AppNotificationDataTypeControllerTest, StartManagerReady) { EXPECT_EQ(DataTypeController::NOT_RUNNING, app_notif_dtc_->state()); SetAssociateExpectations(); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - app_notif_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + app_notif_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::RUNNING, app_notif_dtc_->state()); } @@ -156,7 +157,8 @@ TEST_F(AppNotificationDataTypeControllerTest, StartManagerNotReady) { EXPECT_EQ(DataTypeController::NOT_RUNNING, app_notif_dtc_->state()); SetAssociateExpectations(); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - app_notif_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + app_notif_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::MODEL_STARTING, app_notif_dtc_->state()); // Unblock file thread and wait for it to finish all tasks. @@ -175,7 +177,8 @@ TEST_F(AppNotificationDataTypeControllerTest, StartFirstRun) { EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillRepeatedly(DoAll(SetArgumentPointee<0>(false), Return(true))); EXPECT_CALL(start_callback_, Run(DataTypeController::OK_FIRST_RUN, _)); - app_notif_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + app_notif_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); } TEST_F(AppNotificationDataTypeControllerTest, StartOk) { @@ -184,7 +187,8 @@ TEST_F(AppNotificationDataTypeControllerTest, StartOk) { EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillRepeatedly(DoAll(SetArgumentPointee<0>(true), Return(true))); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - app_notif_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + app_notif_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); } TEST_F(AppNotificationDataTypeControllerTest, StartAssociationFailed) { @@ -200,8 +204,10 @@ TEST_F(AppNotificationDataTypeControllerTest, StartAssociationFailed) { browser_sync::SetSyncError(syncable::APP_NOTIFICATIONS), Return(false))); - EXPECT_CALL(start_callback_, Run(DataTypeController::ASSOCIATION_FAILED, _)); - app_notif_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + EXPECT_CALL(start_callback_, + Run(DataTypeController::ASSOCIATION_FAILED, _)); + app_notif_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::DISABLED, app_notif_dtc_->state()); } @@ -215,8 +221,10 @@ TEST_F(AppNotificationDataTypeControllerTest, WillRepeatedly(Return(true)); EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillRepeatedly(DoAll(SetArgumentPointee<0>(false), Return(false))); - EXPECT_CALL(start_callback_, Run(DataTypeController::UNRECOVERABLE_ERROR, _)); - app_notif_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + EXPECT_CALL(start_callback_, + Run(DataTypeController::UNRECOVERABLE_ERROR, _)); + app_notif_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::NOT_RUNNING, app_notif_dtc_->state()); } @@ -228,7 +236,8 @@ TEST_F(AppNotificationDataTypeControllerTest, Stop) { EXPECT_EQ(DataTypeController::NOT_RUNNING, app_notif_dtc_->state()); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - app_notif_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + app_notif_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::RUNNING, app_notif_dtc_->state()); app_notif_dtc_->Stop(); EXPECT_EQ(DataTypeController::NOT_RUNNING, app_notif_dtc_->state()); @@ -245,7 +254,8 @@ TEST_F(AppNotificationDataTypeControllerTest, OnUnrecoverableError) { SetStopExpectations(); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - app_notif_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + app_notif_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); // This should cause app_notif_dtc_->Stop() to be called. app_notif_dtc_->OnUnrecoverableError(FROM_HERE, "Test"); PumpLoop(); diff --git a/chrome/browser/sync/glue/autofill_data_type_controller.cc b/chrome/browser/sync/glue/autofill_data_type_controller.cc index f556d3f..6d0cbd4 100644 --- a/chrome/browser/sync/glue/autofill_data_type_controller.cc +++ b/chrome/browser/sync/glue/autofill_data_type_controller.cc @@ -6,7 +6,6 @@ #include "base/bind.h" #include "base/metrics/histogram.h" -#include "base/task.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sync/api/sync_error.h" #include "chrome/browser/sync/profile_sync_components_factory.h" diff --git a/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc b/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc index 6d6b48a..83afddc 100644 --- a/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc @@ -27,7 +27,6 @@ using base::WaitableEvent; using browser_sync::AutofillDataTypeController; using browser_sync::DataTypeController; -using browser_sync::StartCallback; using content::BrowserThread; using testing::_; using testing::DoAll; diff --git a/chrome/browser/sync/glue/autofill_profile_data_type_controller.cc b/chrome/browser/sync/glue/autofill_profile_data_type_controller.cc index 1d003a0..4420450 100644 --- a/chrome/browser/sync/glue/autofill_profile_data_type_controller.cc +++ b/chrome/browser/sync/glue/autofill_profile_data_type_controller.cc @@ -4,8 +4,8 @@ #include "chrome/browser/sync/glue/autofill_profile_data_type_controller.h" +#include "base/bind.h" #include "base/metrics/histogram.h" -#include "base/task.h" #include "chrome/browser/autofill/personal_data_manager.h" #include "chrome/browser/autofill/personal_data_manager_factory.h" #include "chrome/browser/profiles/profile.h" diff --git a/chrome/browser/sync/glue/bookmark_data_type_controller_unittest.cc b/chrome/browser/sync/glue/bookmark_data_type_controller_unittest.cc index 3460b7a..04d972c 100644 --- a/chrome/browser/sync/glue/bookmark_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/bookmark_data_type_controller_unittest.cc @@ -4,10 +4,11 @@ #include "testing/gtest/include/gtest/gtest.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/callback.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" -#include "base/task.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sync/glue/bookmark_data_type_controller.h" @@ -27,7 +28,7 @@ using browser_sync::BookmarkDataTypeController; using browser_sync::ChangeProcessorMock; using browser_sync::DataTypeController; using browser_sync::ModelAssociatorMock; -using browser_sync::StartCallback; +using browser_sync::StartCallbackMock; using content::BrowserThread; using testing::_; using testing::DoAll; @@ -90,7 +91,7 @@ class BookmarkDataTypeControllerTest : public testing::Test { ProfileSyncServiceMock service_; ModelAssociatorMock* model_associator_; ChangeProcessorMock* change_processor_; - StartCallback start_callback_; + StartCallbackMock start_callback_; void PumpLoop() { message_loop_.RunAllPending(); @@ -104,7 +105,8 @@ TEST_F(BookmarkDataTypeControllerTest, StartBookmarkModelReady) { EXPECT_EQ(DataTypeController::NOT_RUNNING, bookmark_dtc_->state()); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - bookmark_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + bookmark_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::RUNNING, bookmark_dtc_->state()); } @@ -114,7 +116,8 @@ TEST_F(BookmarkDataTypeControllerTest, StartBookmarkModelNotReady) { SetAssociateExpectations(); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - bookmark_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + bookmark_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::MODEL_STARTING, bookmark_dtc_->state()); // Send the notification that the bookmark model has started. @@ -131,7 +134,8 @@ TEST_F(BookmarkDataTypeControllerTest, StartFirstRun) { EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillRepeatedly(DoAll(SetArgumentPointee<0>(false), Return(true))); EXPECT_CALL(start_callback_, Run(DataTypeController::OK_FIRST_RUN, _)); - bookmark_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + bookmark_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); } TEST_F(BookmarkDataTypeControllerTest, StartBusy) { @@ -139,8 +143,10 @@ TEST_F(BookmarkDataTypeControllerTest, StartBusy) { EXPECT_CALL(bookmark_model_, IsLoaded()).WillRepeatedly(Return(false)); EXPECT_CALL(start_callback_, Run(DataTypeController::BUSY, _)); - bookmark_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); - bookmark_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + bookmark_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); + bookmark_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); } TEST_F(BookmarkDataTypeControllerTest, StartOk) { @@ -150,7 +156,8 @@ TEST_F(BookmarkDataTypeControllerTest, StartOk) { WillRepeatedly(DoAll(SetArgumentPointee<0>(true), Return(true))); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - bookmark_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + bookmark_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); } TEST_F(BookmarkDataTypeControllerTest, StartAssociationFailed) { @@ -165,8 +172,10 @@ TEST_F(BookmarkDataTypeControllerTest, StartAssociationFailed) { WillRepeatedly(DoAll(browser_sync::SetSyncError(syncable::BOOKMARKS), Return(false))); - EXPECT_CALL(start_callback_, Run(DataTypeController::ASSOCIATION_FAILED, _)); - bookmark_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + EXPECT_CALL(start_callback_, + Run(DataTypeController::ASSOCIATION_FAILED, _)); + bookmark_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::DISABLED, bookmark_dtc_->state()); } @@ -179,8 +188,10 @@ TEST_F(BookmarkDataTypeControllerTest, WillRepeatedly(Return(true)); EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillRepeatedly(DoAll(SetArgumentPointee<0>(false), Return(false))); - EXPECT_CALL(start_callback_, Run(DataTypeController::UNRECOVERABLE_ERROR, _)); - bookmark_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + EXPECT_CALL(start_callback_, + Run(DataTypeController::UNRECOVERABLE_ERROR, _)); + bookmark_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::NOT_RUNNING, bookmark_dtc_->state()); } @@ -189,7 +200,8 @@ TEST_F(BookmarkDataTypeControllerTest, StartAborted) { EXPECT_CALL(bookmark_model_, IsLoaded()).WillRepeatedly(Return(false)); EXPECT_CALL(start_callback_, Run(DataTypeController::ABORTED, _)); - bookmark_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + bookmark_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); bookmark_dtc_->Stop(); EXPECT_EQ(DataTypeController::NOT_RUNNING, bookmark_dtc_->state()); } @@ -202,7 +214,8 @@ TEST_F(BookmarkDataTypeControllerTest, Stop) { EXPECT_EQ(DataTypeController::NOT_RUNNING, bookmark_dtc_->state()); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - bookmark_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + bookmark_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::RUNNING, bookmark_dtc_->state()); bookmark_dtc_->Stop(); EXPECT_EQ(DataTypeController::NOT_RUNNING, bookmark_dtc_->state()); @@ -219,7 +232,8 @@ TEST_F(BookmarkDataTypeControllerTest, OnUnrecoverableError) { SetStopExpectations(); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - bookmark_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + bookmark_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); // This should cause bookmark_dtc_->Stop() to be called. bookmark_dtc_->OnUnrecoverableError(FROM_HERE, "Test"); PumpLoop(); diff --git a/chrome/browser/sync/glue/bookmark_model_associator.cc b/chrome/browser/sync/glue/bookmark_model_associator.cc index 1dbb162..5b11b4b 100644 --- a/chrome/browser/sync/glue/bookmark_model_associator.cc +++ b/chrome/browser/sync/glue/bookmark_model_associator.cc @@ -6,11 +6,11 @@ #include <stack> +#include "base/bind.h" #include "base/command_line.h" #include "base/hash_tables.h" #include "base/location.h" #include "base/message_loop.h" -#include "base/task.h" #include "base/utf_string_conversions.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/profiles/profile.h" @@ -174,7 +174,7 @@ BookmarkModelAssociator::BookmarkModelAssociator( : bookmark_model_(bookmark_model), user_share_(user_share), unrecoverable_error_handler_(unrecoverable_error_handler), - ALLOW_THIS_IN_INITIALIZER_LIST(persist_associations_(this)), + ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), number_of_new_sync_nodes_created_at_association_(0) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(bookmark_model_); @@ -481,12 +481,13 @@ bool BookmarkModelAssociator::BuildAssociations(SyncError* error) { void BookmarkModelAssociator::PostPersistAssociationsTask() { // No need to post a task if a task is already pending. - if (!persist_associations_.empty()) + if (weak_factory_.HasWeakPtrs()) return; MessageLoop::current()->PostTask( FROM_HERE, - persist_associations_.NewRunnableMethod( - &BookmarkModelAssociator::PersistAssociations)); + base::Bind( + &BookmarkModelAssociator::PersistAssociations, + weak_factory_.GetWeakPtr())); } void BookmarkModelAssociator::PersistAssociations() { diff --git a/chrome/browser/sync/glue/bookmark_model_associator.h b/chrome/browser/sync/glue/bookmark_model_associator.h index 11336b0..dce7320 100644 --- a/chrome/browser/sync/glue/bookmark_model_associator.h +++ b/chrome/browser/sync/glue/bookmark_model_associator.h @@ -12,7 +12,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" -#include "base/task.h" +#include "base/memory/weak_ptr.h" #include "chrome/browser/sync/internal_api/includes/unrecoverable_error_handler.h" #include "chrome/browser/sync/glue/model_associator.h" @@ -136,7 +136,7 @@ class BookmarkModelAssociator // Used to post PersistAssociation tasks to the current message loop and // guarantees no invocations can occur if |this| has been deleted. (This // allows this class to be non-refcounted). - ScopedRunnableMethodFactory<BookmarkModelAssociator> persist_associations_; + base::WeakPtrFactory<BookmarkModelAssociator> weak_factory_; int number_of_new_sync_nodes_created_at_association_; diff --git a/chrome/browser/sync/glue/browser_thread_model_worker_unittest.cc b/chrome/browser/sync/glue/browser_thread_model_worker_unittest.cc index c34cb81..4c6881a 100644 --- a/chrome/browser/sync/glue/browser_thread_model_worker_unittest.cc +++ b/chrome/browser/sync/glue/browser_thread_model_worker_unittest.cc @@ -5,6 +5,7 @@ #include "base/bind.h" #include "base/callback.h" #include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" #include "base/message_loop.h" #include "base/test/test_timeouts.h" #include "base/threading/thread.h" @@ -29,13 +30,13 @@ class BrowserThreadModelWorkerTest : public testing::Test { did_do_work_(false), db_thread_(BrowserThread::DB), io_thread_(BrowserThread::IO, &io_loop_), - ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {} + ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {} bool did_do_work() { return did_do_work_; } BrowserThreadModelWorker* worker() { return worker_.get(); } OneShotTimer<BrowserThreadModelWorkerTest>* timer() { return &timer_; } - ScopedRunnableMethodFactory<BrowserThreadModelWorkerTest>* factory() { - return &method_factory_; + base::WeakPtrFactory<BrowserThreadModelWorkerTest>* factory() { + return &weak_factory_; } // Schedule DoWork to be executed on the DB thread and have the test fail if @@ -90,12 +91,13 @@ class BrowserThreadModelWorkerTest : public testing::Test { MessageLoopForIO io_loop_; content::TestBrowserThread io_thread_; - ScopedRunnableMethodFactory<BrowserThreadModelWorkerTest> method_factory_; + base::WeakPtrFactory<BrowserThreadModelWorkerTest> weak_factory_; }; TEST_F(BrowserThreadModelWorkerTest, DoesWorkOnDatabaseThread) { - MessageLoop::current()->PostTask(FROM_HERE, factory()->NewRunnableMethod( - &BrowserThreadModelWorkerTest::ScheduleWork)); + MessageLoop::current()->PostTask(FROM_HERE, + base::Bind(&BrowserThreadModelWorkerTest::ScheduleWork, + factory()->GetWeakPtr())); MessageLoop::current()->Run(); EXPECT_TRUE(did_do_work()); } diff --git a/chrome/browser/sync/glue/data_type_controller.h b/chrome/browser/sync/glue/data_type_controller.h index 3a5e83f..e63d5ed 100644 --- a/chrome/browser/sync/glue/data_type_controller.h +++ b/chrome/browser/sync/glue/data_type_controller.h @@ -57,7 +57,7 @@ class DataTypeController MAX_START_RESULT }; - typedef Callback2<StartResult, const SyncError&>::Type StartCallback; + typedef base::Callback<void(StartResult, const SyncError&)> StartCallback; typedef std::map<syncable::ModelType, scoped_refptr<DataTypeController> > TypeMap; @@ -69,7 +69,7 @@ class DataTypeController // activation. Upon completion, the start_callback will be invoked // on the UI thread. See the StartResult enum above for details on the // possible start results. - virtual void Start(StartCallback* start_callback) = 0; + virtual void Start(const StartCallback& start_callback) = 0; // Synchronously stops the data type. If called after Start() is // called but before the start callback is called, the start is diff --git a/chrome/browser/sync/glue/data_type_controller_mock.cc b/chrome/browser/sync/glue/data_type_controller_mock.cc index 27215b4..a6bb25f 100644 --- a/chrome/browser/sync/glue/data_type_controller_mock.cc +++ b/chrome/browser/sync/glue/data_type_controller_mock.cc @@ -6,9 +6,9 @@ namespace browser_sync { -StartCallback::StartCallback() {} +StartCallbackMock::StartCallbackMock() {} -StartCallback::~StartCallback() {} +StartCallbackMock::~StartCallbackMock() {} DataTypeControllerMock::DataTypeControllerMock() {} diff --git a/chrome/browser/sync/glue/data_type_controller_mock.h b/chrome/browser/sync/glue/data_type_controller_mock.h index 99f3b9b..fadf18a 100644 --- a/chrome/browser/sync/glue/data_type_controller_mock.h +++ b/chrome/browser/sync/glue/data_type_controller_mock.h @@ -12,10 +12,11 @@ namespace browser_sync { -class StartCallback { +class StartCallbackMock { public: - StartCallback(); - virtual ~StartCallback(); + StartCallbackMock(); + virtual ~StartCallbackMock(); + MOCK_METHOD2(Run, void(DataTypeController::StartResult result, const SyncError& error)); }; @@ -25,7 +26,7 @@ class DataTypeControllerMock : public DataTypeController { DataTypeControllerMock(); virtual ~DataTypeControllerMock(); - MOCK_METHOD1(Start, void(StartCallback* start_callback)); + MOCK_METHOD1(Start, void(const StartCallback& start_callback)); MOCK_METHOD0(Stop, void()); MOCK_METHOD0(enabled, bool()); MOCK_CONST_METHOD0(type, syncable::ModelType()); diff --git a/chrome/browser/sync/glue/data_type_manager.h b/chrome/browser/sync/glue/data_type_manager.h index 3235fdd..e93def7 100644 --- a/chrome/browser/sync/glue/data_type_manager.h +++ b/chrome/browser/sync/glue/data_type_manager.h @@ -11,7 +11,6 @@ #include <string> #include "base/memory/scoped_ptr.h" -#include "base/task.h" #include "chrome/browser/sync/api/sync_error.h" #include "chrome/browser/sync/glue/data_type_controller.h" #include "chrome/browser/sync/internal_api/configure_reason.h" diff --git a/chrome/browser/sync/glue/data_type_manager_impl.cc b/chrome/browser/sync/glue/data_type_manager_impl.cc index 714ca23..a26d3077 100644 --- a/chrome/browser/sync/glue/data_type_manager_impl.cc +++ b/chrome/browser/sync/glue/data_type_manager_impl.cc @@ -8,6 +8,7 @@ #include <functional> #include "base/bind.h" +#include "base/bind_helpers.h" #include "base/callback.h" #include "base/compiler_specific.h" #include "base/debug/trace_event.h" @@ -298,8 +299,8 @@ void DataTypeManagerImpl::StartNextType() { DVLOG(1) << "Starting " << needs_start_[0]->name(); TRACE_EVENT_BEGIN1("sync", "ModelAssociation", "DataType", ModelTypeToString(needs_start_[0]->type())); - needs_start_[0]->Start( - NewCallback(this, &DataTypeManagerImpl::TypeStartCallback)); + needs_start_[0]->Start(base::Bind(&DataTypeManagerImpl::TypeStartCallback, + base::Unretained(this))); return; } diff --git a/chrome/browser/sync/glue/data_type_manager_impl.h b/chrome/browser/sync/glue/data_type_manager_impl.h index 31df234..1228f00 100644 --- a/chrome/browser/sync/glue/data_type_manager_impl.h +++ b/chrome/browser/sync/glue/data_type_manager_impl.h @@ -15,7 +15,6 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/memory/weak_ptr.h" -#include "base/task.h" #include "base/time.h" namespace browser_sync { diff --git a/chrome/browser/sync/glue/data_type_manager_impl_unittest.cc b/chrome/browser/sync/glue/data_type_manager_impl_unittest.cc index f54b11d..88e43ad 100644 --- a/chrome/browser/sync/glue/data_type_manager_impl_unittest.cc +++ b/chrome/browser/sync/glue/data_type_manager_impl_unittest.cc @@ -193,7 +193,7 @@ class DataTypeManagerImplTest : public testing::Test { void RunConfigureWhileOneInFlightTest(bool enable_nigori) { DataTypeControllerMock* bookmark_dtc = MakeBookmarkDTC(); // Save the callback here so we can interrupt startup. - DataTypeController::StartCallback* callback; + DataTypeController::StartCallback callback; { InSequence seq; EXPECT_CALL(*bookmark_dtc, state()). @@ -230,8 +230,7 @@ class DataTypeManagerImplTest : public testing::Test { types_.Put(syncable::PREFERENCES); Configure(&dtm, types_, sync_api::CONFIGURE_REASON_RECONFIGURATION, enable_nigori); - callback->Run(DataTypeController::OK, SyncError()); - delete callback; + callback.Run(DataTypeController::OK, SyncError()); MessageLoop::current()->Run(); @@ -470,7 +469,7 @@ TEST_F(DataTypeManagerImplTest, StopWhileInFlight) { DataTypeControllerMock* preference_dtc = MakePreferenceDTC(); // Save the callback here so we can interrupt startup. - DataTypeController::StartCallback* callback; + DataTypeController::StartCallback callback; EXPECT_CALL(*preference_dtc, Start(_)). WillOnce(SaveArg<0>(&callback)); EXPECT_CALL(*preference_dtc, state()). diff --git a/chrome/browser/sync/glue/data_type_manager_mock.h b/chrome/browser/sync/glue/data_type_manager_mock.h index 71d5096..5adbbb3 100644 --- a/chrome/browser/sync/glue/data_type_manager_mock.h +++ b/chrome/browser/sync/glue/data_type_manager_mock.h @@ -17,21 +17,19 @@ ACTION_P2(InvokeCallback, datatype, callback_result) { if (callback_result != browser_sync::DataTypeController::OK) { SyncError error(FROM_HERE, "Error message", datatype); - arg0->Run(callback_result, error); + arg0.Run(callback_result, error); } else { - arg0->Run(callback_result, SyncError()); + arg0.Run(callback_result, SyncError()); } - delete arg0; } ACTION_P3(InvokeCallbackPointer, callback, datatype, callback_result) { if (callback_result != browser_sync::DataTypeController::OK) { SyncError error(FROM_HERE, "Error message", datatype); - callback->Run(callback_result, error); + callback.Run(callback_result, error); } else { - callback->Run(callback_result, SyncError()); + callback.Run(callback_result, SyncError()); } - delete callback; } ACTION_P3(NotifyFromDataTypeManagerWithResult, dtm, type, result) { diff --git a/chrome/browser/sync/glue/extension_data_type_controller_unittest.cc b/chrome/browser/sync/glue/extension_data_type_controller_unittest.cc index b3aa66f..a4cca03 100644 --- a/chrome/browser/sync/glue/extension_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/extension_data_type_controller_unittest.cc @@ -4,10 +4,11 @@ #include "testing/gtest/include/gtest/gtest.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/callback.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" -#include "base/task.h" #include "chrome/browser/sync/glue/change_processor_mock.h" #include "chrome/browser/sync/glue/data_type_controller_mock.h" #include "chrome/browser/sync/glue/extension_data_type_controller.h" @@ -21,7 +22,7 @@ using browser_sync::ExtensionDataTypeController; using browser_sync::ChangeProcessorMock; using browser_sync::DataTypeController; using browser_sync::ModelAssociatorMock; -using browser_sync::StartCallback; +using browser_sync::StartCallbackMock; using content::BrowserThread; using testing::_; using testing::DoAll; @@ -81,7 +82,7 @@ class ExtensionDataTypeControllerTest : public testing::Test { ProfileSyncServiceMock service_; ModelAssociatorMock* model_associator_; ChangeProcessorMock* change_processor_; - StartCallback start_callback_; + StartCallbackMock start_callback_; }; TEST_F(ExtensionDataTypeControllerTest, Start) { @@ -90,7 +91,8 @@ TEST_F(ExtensionDataTypeControllerTest, Start) { SetActivateExpectations(); EXPECT_EQ(DataTypeController::NOT_RUNNING, extension_dtc_->state()); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - extension_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + extension_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::RUNNING, extension_dtc_->state()); } @@ -101,7 +103,8 @@ TEST_F(ExtensionDataTypeControllerTest, StartFirstRun) { EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillRepeatedly(DoAll(SetArgumentPointee<0>(false), Return(true))); EXPECT_CALL(start_callback_, Run(DataTypeController::OK_FIRST_RUN, _)); - extension_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + extension_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); } TEST_F(ExtensionDataTypeControllerTest, StartOk) { @@ -112,7 +115,8 @@ TEST_F(ExtensionDataTypeControllerTest, StartOk) { WillRepeatedly(DoAll(SetArgumentPointee<0>(true), Return(true))); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - extension_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + extension_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); } TEST_F(ExtensionDataTypeControllerTest, StartAssociationFailed) { @@ -122,8 +126,10 @@ TEST_F(ExtensionDataTypeControllerTest, StartAssociationFailed) { WillRepeatedly(DoAll(browser_sync::SetSyncError(syncable::EXTENSIONS), Return(false))); - EXPECT_CALL(start_callback_, Run(DataTypeController::ASSOCIATION_FAILED, _)); - extension_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + EXPECT_CALL(start_callback_, + Run(DataTypeController::ASSOCIATION_FAILED, _)); + extension_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::DISABLED, extension_dtc_->state()); } @@ -135,8 +141,10 @@ TEST_F(ExtensionDataTypeControllerTest, WillRepeatedly(Return(true)); EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillRepeatedly(DoAll(SetArgumentPointee<0>(false), Return(false))); - EXPECT_CALL(start_callback_, Run(DataTypeController::UNRECOVERABLE_ERROR, _)); - extension_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + EXPECT_CALL(start_callback_, + Run(DataTypeController::UNRECOVERABLE_ERROR, _)); + extension_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::NOT_RUNNING, extension_dtc_->state()); } @@ -149,7 +157,8 @@ TEST_F(ExtensionDataTypeControllerTest, Stop) { EXPECT_EQ(DataTypeController::NOT_RUNNING, extension_dtc_->state()); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - extension_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + extension_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::RUNNING, extension_dtc_->state()); extension_dtc_->Stop(); EXPECT_EQ(DataTypeController::NOT_RUNNING, extension_dtc_->state()); @@ -168,7 +177,8 @@ TEST_F(ExtensionDataTypeControllerTest, OnUnrecoverableError) { SetStopExpectations(); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - extension_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + extension_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); // This should cause extension_dtc_->Stop() to be called. extension_dtc_->OnUnrecoverableError(FROM_HERE, "Test"); PumpLoop(); diff --git a/chrome/browser/sync/glue/frontend_data_type_controller.cc b/chrome/browser/sync/glue/frontend_data_type_controller.cc index 9bfd486..6d45b91 100644 --- a/chrome/browser/sync/glue/frontend_data_type_controller.cc +++ b/chrome/browser/sync/glue/frontend_data_type_controller.cc @@ -43,16 +43,15 @@ FrontendDataTypeController::~FrontendDataTypeController() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); } -void FrontendDataTypeController::Start(StartCallback* start_callback) { +void FrontendDataTypeController::Start(const StartCallback& start_callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK(start_callback); + DCHECK(!start_callback.is_null()); if (state_ != NOT_RUNNING) { - start_callback->Run(BUSY, SyncError()); - delete start_callback; + start_callback.Run(BUSY, SyncError()); return; } - start_callback_.reset(start_callback); + start_callback_ = start_callback; state_ = MODEL_STARTING; if (!StartModels()) { @@ -134,8 +133,9 @@ void FrontendDataTypeController::StartFailed(StartResult result, // We have to release the callback before we call it, since it's possible // invoking the callback will trigger a call to STOP(), which will get // confused by the non-NULL start_callback_. - scoped_ptr<StartCallback> callback(start_callback_.release()); - callback->Run(result, error); + StartCallback callback = start_callback_; + start_callback_.Reset(); + callback.Run(result, error); } void FrontendDataTypeController::FinishStart(StartResult result) { @@ -144,8 +144,9 @@ void FrontendDataTypeController::FinishStart(StartResult result) { // We have to release the callback before we call it, since it's possible // invoking the callback will trigger a call to STOP(), which will get // confused by the non-NULL start_callback_. - scoped_ptr<StartCallback> callback(start_callback_.release()); - callback->Run(result, SyncError()); + StartCallback callback = start_callback_; + start_callback_.Reset(); + callback.Run(result, SyncError()); } void FrontendDataTypeController::Stop() { @@ -158,7 +159,7 @@ void FrontendDataTypeController::Stop() { // still in MODEL_STARTING. return; } - DCHECK(!start_callback_.get()); + DCHECK(start_callback_.is_null()); CleanUpState(); diff --git a/chrome/browser/sync/glue/frontend_data_type_controller.h b/chrome/browser/sync/glue/frontend_data_type_controller.h index 912dce2..e6e75c7 100644 --- a/chrome/browser/sync/glue/frontend_data_type_controller.h +++ b/chrome/browser/sync/glue/frontend_data_type_controller.h @@ -47,7 +47,7 @@ class FrontendDataTypeController : public DataTypeController { virtual ~FrontendDataTypeController(); // DataTypeController interface. - virtual void Start(StartCallback* start_callback) OVERRIDE; + virtual void Start(const StartCallback& start_callback) OVERRIDE; virtual void Stop() OVERRIDE; virtual syncable::ModelType type() const = 0; virtual browser_sync::ModelSafeGroup model_safe_group() const OVERRIDE; @@ -110,7 +110,7 @@ class FrontendDataTypeController : public DataTypeController { State state_; - scoped_ptr<StartCallback> start_callback_; + StartCallback start_callback_; // TODO(sync): transition all datatypes to SyncableService and deprecate // AssociatorInterface. scoped_ptr<AssociatorInterface> model_associator_; diff --git a/chrome/browser/sync/glue/frontend_data_type_controller_mock.h b/chrome/browser/sync/glue/frontend_data_type_controller_mock.h index 6380d2e..e07855b 100644 --- a/chrome/browser/sync/glue/frontend_data_type_controller_mock.h +++ b/chrome/browser/sync/glue/frontend_data_type_controller_mock.h @@ -18,7 +18,7 @@ class FrontendDataTypeControllerMock : public FrontendDataTypeController { virtual ~FrontendDataTypeControllerMock(); // DataTypeController mocks. - MOCK_METHOD1(Start, void(StartCallback* start_callback)); + MOCK_METHOD1(Start, void(const StartCallback& start_callback)); MOCK_METHOD0(Stop, void()); MOCK_METHOD0(enabled, bool()); MOCK_CONST_METHOD0(type, syncable::ModelType()); diff --git a/chrome/browser/sync/glue/frontend_data_type_controller_unittest.cc b/chrome/browser/sync/glue/frontend_data_type_controller_unittest.cc index 965b52c..37e4dcc 100644 --- a/chrome/browser/sync/glue/frontend_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/frontend_data_type_controller_unittest.cc @@ -4,10 +4,11 @@ #include "testing/gtest/include/gtest/gtest.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/callback.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" -#include "base/task.h" #include "base/tracked_objects.h" #include "chrome/browser/sync/glue/change_processor_mock.h" #include "chrome/browser/sync/glue/data_type_controller_mock.h" @@ -24,7 +25,7 @@ using browser_sync::DataTypeController; using browser_sync::FrontendDataTypeController; using browser_sync::FrontendDataTypeControllerMock; using browser_sync::ModelAssociatorMock; -using browser_sync::StartCallback; +using browser_sync::StartCallbackMock; using content::BrowserThread; using testing::_; using testing::DoAll; @@ -143,7 +144,7 @@ class FrontendDataTypeControllerTest : public testing::Test { ProfileSyncServiceMock service_; ModelAssociatorMock* model_associator_; ChangeProcessorMock* change_processor_; - StartCallback start_callback_; + StartCallbackMock start_callback_; }; TEST_F(FrontendDataTypeControllerTest, StartOk) { @@ -151,7 +152,8 @@ TEST_F(FrontendDataTypeControllerTest, StartOk) { SetAssociateExpectations(); SetActivateExpectations(DataTypeController::OK); EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); - frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + frontend_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::RUNNING, frontend_dtc_->state()); } @@ -166,7 +168,8 @@ TEST_F(FrontendDataTypeControllerTest, StartFirstRun) { EXPECT_CALL(*dtc_mock_, RecordAssociationTime(_)); SetActivateExpectations(DataTypeController::OK_FIRST_RUN); EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); - frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + frontend_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::RUNNING, frontend_dtc_->state()); } @@ -174,7 +177,8 @@ TEST_F(FrontendDataTypeControllerTest, AbortDuringStartModels) { EXPECT_CALL(*dtc_mock_, StartModels()).WillOnce(Return(false)); SetStartFailExpectations(DataTypeController::ABORTED); EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); - frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + frontend_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::MODEL_STARTING, frontend_dtc_->state()); frontend_dtc_->Stop(); EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); @@ -193,7 +197,8 @@ TEST_F(FrontendDataTypeControllerTest, StartAssociationFailed) { SetStartFailExpectations(DataTypeController::ASSOCIATION_FAILED); // Set up association to fail with an association failed error. EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); - frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + frontend_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::DISABLED, frontend_dtc_->state()); } @@ -207,7 +212,8 @@ TEST_F(FrontendDataTypeControllerTest, EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillRepeatedly(DoAll(SetArgumentPointee<0>(false), Return(false))); EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); - frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + frontend_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); } @@ -218,7 +224,8 @@ TEST_F(FrontendDataTypeControllerTest, StartAssociationCryptoNotReady) { EXPECT_CALL(*model_associator_, CryptoReadyIfNecessary()). WillRepeatedly(Return(false)); EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); - frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + frontend_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); } @@ -228,7 +235,8 @@ TEST_F(FrontendDataTypeControllerTest, Stop) { SetActivateExpectations(DataTypeController::OK); SetStopExpectations(); EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); - frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + frontend_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::RUNNING, frontend_dtc_->state()); frontend_dtc_->Stop(); EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); @@ -244,7 +252,8 @@ TEST_F(FrontendDataTypeControllerTest, OnUnrecoverableError) { &FrontendDataTypeController::Stop)); SetStopExpectations(); EXPECT_EQ(DataTypeController::NOT_RUNNING, frontend_dtc_->state()); - frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + frontend_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::RUNNING, frontend_dtc_->state()); // This should cause frontend_dtc_->Stop() to be called. frontend_dtc_->OnUnrecoverableError(FROM_HERE, "Test"); diff --git a/chrome/browser/sync/glue/history_model_worker.cc b/chrome/browser/sync/glue/history_model_worker.cc index 84200ac..88a8193 100644 --- a/chrome/browser/sync/glue/history_model_worker.cc +++ b/chrome/browser/sync/glue/history_model_worker.cc @@ -6,7 +6,6 @@ #include "base/memory/ref_counted.h" #include "base/message_loop.h" -#include "base/task.h" #include "base/synchronization/waitable_event.h" #include "chrome/browser/history/history.h" diff --git a/chrome/browser/sync/glue/new_non_frontend_data_type_controller.cc b/chrome/browser/sync/glue/new_non_frontend_data_type_controller.cc index e95f289..a03d856 100644 --- a/chrome/browser/sync/glue/new_non_frontend_data_type_controller.cc +++ b/chrome/browser/sync/glue/new_non_frontend_data_type_controller.cc @@ -29,12 +29,12 @@ NewNonFrontendDataTypeController::NewNonFrontendDataTypeController( NewNonFrontendDataTypeController::~NewNonFrontendDataTypeController() {} -void NewNonFrontendDataTypeController::Start(StartCallback* start_callback) { +void NewNonFrontendDataTypeController::Start( + const StartCallback& start_callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK(start_callback); + DCHECK(!start_callback.is_null()); if (state() != NOT_RUNNING) { - start_callback->Run(BUSY, SyncError()); - delete start_callback; + start_callback.Run(BUSY, SyncError()); return; } diff --git a/chrome/browser/sync/glue/new_non_frontend_data_type_controller.h b/chrome/browser/sync/glue/new_non_frontend_data_type_controller.h index d412326..0854256 100644 --- a/chrome/browser/sync/glue/new_non_frontend_data_type_controller.h +++ b/chrome/browser/sync/glue/new_non_frontend_data_type_controller.h @@ -22,7 +22,7 @@ class NewNonFrontendDataTypeController : public NonFrontendDataTypeController { Profile* profile); virtual ~NewNonFrontendDataTypeController(); - virtual void Start(StartCallback* start_callback) OVERRIDE; + virtual void Start(const StartCallback& start_callback) OVERRIDE; virtual void Stop() OVERRIDE; protected: diff --git a/chrome/browser/sync/glue/new_non_frontend_data_type_controller_mock.h b/chrome/browser/sync/glue/new_non_frontend_data_type_controller_mock.h index 50ca5a3..bbb0fcd 100644 --- a/chrome/browser/sync/glue/new_non_frontend_data_type_controller_mock.h +++ b/chrome/browser/sync/glue/new_non_frontend_data_type_controller_mock.h @@ -19,7 +19,7 @@ class NewNonFrontendDataTypeControllerMock virtual ~NewNonFrontendDataTypeControllerMock(); // DataTypeController mocks. - MOCK_METHOD1(Start, void(StartCallback* start_callback)); + MOCK_METHOD1(Start, void(const StartCallback& start_callback)); MOCK_METHOD0(Stop, void()); MOCK_METHOD0(enabled, bool()); MOCK_CONST_METHOD0(type, syncable::ModelType()); diff --git a/chrome/browser/sync/glue/new_non_frontend_data_type_controller_unittest.cc b/chrome/browser/sync/glue/new_non_frontend_data_type_controller_unittest.cc index 235de89..3abfa5c 100644 --- a/chrome/browser/sync/glue/new_non_frontend_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/new_non_frontend_data_type_controller_unittest.cc @@ -4,12 +4,13 @@ #include "chrome/browser/sync/glue/new_non_frontend_data_type_controller.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/callback.h" #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" #include "base/synchronization/waitable_event.h" -#include "base/task.h" #include "base/test/test_timeouts.h" #include "base/tracked_objects.h" #include "chrome/browser/sync/api/syncable_service_mock.h" @@ -30,7 +31,7 @@ using browser_sync::DataTypeController; using browser_sync::GROUP_DB; using browser_sync::NewNonFrontendDataTypeController; using browser_sync::NewNonFrontendDataTypeControllerMock; -using browser_sync::StartCallback; +using browser_sync::StartCallbackMock; using content::BrowserThread; using syncable::AUTOFILL_PROFILE; using testing::_; @@ -137,7 +138,7 @@ class NewNonFrontendDataTypeControllerTest : public testing::Test { profile_sync_factory_.reset(new ProfileSyncComponentsFactoryMock()); change_processor_ = new SharedChangeProcessorMock(); - // Both of these are refcounted, so don't need to be released. + // All of these are refcounted, so don't need to be released. dtc_mock_ = new StrictMock<NewNonFrontendDataTypeControllerMock>(); new_non_frontend_dtc_ = new NewNonFrontendDataTypeControllerFake(profile_sync_factory_.get(), @@ -219,7 +220,7 @@ class NewNonFrontendDataTypeControllerTest : public testing::Test { ProfileMock profile_; scoped_ptr<ProfileSyncComponentsFactoryMock> profile_sync_factory_; ProfileSyncServiceMock service_; - StartCallback start_callback_; + StartCallbackMock start_callback_; // Must be destroyed after new_non_frontend_dtc_. SyncableServiceMock syncable_service_; scoped_refptr<NewNonFrontendDataTypeControllerFake> new_non_frontend_dtc_; @@ -234,7 +235,7 @@ TEST_F(NewNonFrontendDataTypeControllerTest, StartOk) { SetActivateExpectations(DataTypeController::OK); EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state()); new_non_frontend_dtc_->Start( - NewCallback(&start_callback_, &StartCallback::Run)); + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); WaitForDTC(); EXPECT_EQ(DataTypeController::RUNNING, new_non_frontend_dtc_->state()); } @@ -256,7 +257,7 @@ TEST_F(NewNonFrontendDataTypeControllerTest, StartFirstRun) { SetActivateExpectations(DataTypeController::OK_FIRST_RUN); EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state()); new_non_frontend_dtc_->Start( - NewCallback(&start_callback_, &StartCallback::Run)); + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); WaitForDTC(); EXPECT_EQ(DataTypeController::RUNNING, new_non_frontend_dtc_->state()); } @@ -268,7 +269,7 @@ TEST_F(NewNonFrontendDataTypeControllerTest, AbortDuringStartModels) { EXPECT_CALL(start_callback_, Run(DataTypeController::ABORTED,_)); EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state()); new_non_frontend_dtc_->Start( - NewCallback(&start_callback_, &StartCallback::Run)); + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); WaitForDTC(); EXPECT_EQ(DataTypeController::MODEL_STARTING, new_non_frontend_dtc_->state()); new_non_frontend_dtc_->Stop(); @@ -293,7 +294,7 @@ TEST_F(NewNonFrontendDataTypeControllerTest, StartAssociationFailed) { // Set up association to fail with an association failed error. EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state()); new_non_frontend_dtc_->Start( - NewCallback(&start_callback_, &StartCallback::Run)); + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); WaitForDTC(); EXPECT_EQ(DataTypeController::DISABLED, new_non_frontend_dtc_->state()); } @@ -311,7 +312,7 @@ TEST_F(NewNonFrontendDataTypeControllerTest, WillRepeatedly(DoAll(SetArgumentPointee<1>(false), Return(false))); EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state()); new_non_frontend_dtc_->Start( - NewCallback(&start_callback_, &StartCallback::Run)); + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); WaitForDTC(); EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state()); } @@ -326,7 +327,7 @@ TEST_F(NewNonFrontendDataTypeControllerTest, StartAssociationCryptoNotReady) { WillRepeatedly(Return(false)); EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state()); new_non_frontend_dtc_->Start( - NewCallback(&start_callback_, &StartCallback::Run)); + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); WaitForDTC(); EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state()); } @@ -356,7 +357,7 @@ TEST_F(NewNonFrontendDataTypeControllerTest, AbortDuringAssociation) { EXPECT_CALL(service_, DeactivateDataType(_)); EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state()); new_non_frontend_dtc_->Start( - NewCallback(&start_callback_, &StartCallback::Run)); + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); wait_for_db_thread_pause.Wait(); new_non_frontend_dtc_->Stop(); WaitForDTC(); @@ -370,7 +371,7 @@ TEST_F(NewNonFrontendDataTypeControllerTest, Stop) { SetStopExpectations(); EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state()); new_non_frontend_dtc_->Start( - NewCallback(&start_callback_, &StartCallback::Run)); + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); WaitForDTC(); EXPECT_EQ(DataTypeController::RUNNING, new_non_frontend_dtc_->state()); new_non_frontend_dtc_->Stop(); @@ -388,7 +389,7 @@ TEST_F(NewNonFrontendDataTypeControllerTest, OnUnrecoverableError) { SetStopExpectations(); EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state()); new_non_frontend_dtc_->Start( - NewCallback(&start_callback_, &StartCallback::Run)); + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); WaitForDTC(); EXPECT_EQ(DataTypeController::RUNNING, new_non_frontend_dtc_->state()); // This should cause new_non_frontend_dtc_->Stop() to be called. diff --git a/chrome/browser/sync/glue/non_frontend_data_type_controller.cc b/chrome/browser/sync/glue/non_frontend_data_type_controller.cc index 822bdce..9ac08cf 100644 --- a/chrome/browser/sync/glue/non_frontend_data_type_controller.cc +++ b/chrome/browser/sync/glue/non_frontend_data_type_controller.cc @@ -49,16 +49,15 @@ NonFrontendDataTypeController::~NonFrontendDataTypeController() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); } -void NonFrontendDataTypeController::Start(StartCallback* start_callback) { +void NonFrontendDataTypeController::Start(const StartCallback& start_callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK(start_callback); + DCHECK(!start_callback.is_null()); if (state_ != NOT_RUNNING) { - start_callback->Run(BUSY, SyncError()); - delete start_callback; + start_callback.Run(BUSY, SyncError()); return; } - start_callback_.reset(start_callback); + start_callback_ = start_callback; abort_association_ = false; state_ = MODEL_STARTING; @@ -158,7 +157,7 @@ void NonFrontendDataTypeController::StartDoneImpl( // (due to Stop being called) and then posted from the non-UI thread. In // this case, we drop the second call because we've already been stopped. if (state_ == NOT_RUNNING) { - DCHECK(!start_callback_.get()); + DCHECK(start_callback_.is_null()); return; } @@ -172,8 +171,9 @@ void NonFrontendDataTypeController::StartDoneImpl( // We have to release the callback before we call it, since it's possible // invoking the callback will trigger a call to STOP(), which will get // confused by the non-NULL start_callback_. - scoped_ptr<StartCallback> callback(start_callback_.release()); - callback->Run(result, error); + StartCallback callback = start_callback_; + start_callback_.Reset(); + callback.Run(result, error); } // TODO(sync): Blocking the UI thread at shutdown is bad. The new API avoids @@ -215,7 +215,7 @@ void NonFrontendDataTypeController::Stop() { StopModels(); break; } - DCHECK(!start_callback_.get()); + DCHECK(start_callback_.is_null()); // Deactivate the change processor on the UI thread. We dont want to listen // for any more changes or process them from server. @@ -292,8 +292,8 @@ ProfileSyncService* NonFrontendDataTypeController::profile_sync_service() } void NonFrontendDataTypeController::set_start_callback( - StartCallback* callback) { - start_callback_.reset(callback); + const StartCallback& callback) { + start_callback_ = callback; } void NonFrontendDataTypeController::set_state(State state) { state_ = state; diff --git a/chrome/browser/sync/glue/non_frontend_data_type_controller.h b/chrome/browser/sync/glue/non_frontend_data_type_controller.h index d61a7c4..2f07555 100644 --- a/chrome/browser/sync/glue/non_frontend_data_type_controller.h +++ b/chrome/browser/sync/glue/non_frontend_data_type_controller.h @@ -46,7 +46,7 @@ class NonFrontendDataTypeController : public DataTypeController { virtual ~NonFrontendDataTypeController(); // DataTypeController interface. - virtual void Start(StartCallback* start_callback) OVERRIDE; + virtual void Start(const StartCallback& start_callback) OVERRIDE; virtual void Stop() OVERRIDE; virtual syncable::ModelType type() const = 0; virtual browser_sync::ModelSafeGroup model_safe_group() const = 0; @@ -134,7 +134,7 @@ class NonFrontendDataTypeController : public DataTypeController { ProfileSyncComponentsFactory* profile_sync_factory() const; Profile* profile() const; ProfileSyncService* profile_sync_service() const; - void set_start_callback(StartCallback* callback); + void set_start_callback(const StartCallback& callback); void set_state(State state); virtual AssociatorInterface* associator() const; @@ -149,7 +149,7 @@ class NonFrontendDataTypeController : public DataTypeController { State state_; - scoped_ptr<StartCallback> start_callback_; + StartCallback start_callback_; scoped_ptr<AssociatorInterface> model_associator_; scoped_ptr<ChangeProcessor> change_processor_; diff --git a/chrome/browser/sync/glue/non_frontend_data_type_controller_mock.h b/chrome/browser/sync/glue/non_frontend_data_type_controller_mock.h index 8e9cca6..c0a8a73 100644 --- a/chrome/browser/sync/glue/non_frontend_data_type_controller_mock.h +++ b/chrome/browser/sync/glue/non_frontend_data_type_controller_mock.h @@ -18,7 +18,7 @@ class NonFrontendDataTypeControllerMock : public NonFrontendDataTypeController { virtual ~NonFrontendDataTypeControllerMock(); // DataTypeController mocks. - MOCK_METHOD1(Start, void(StartCallback* start_callback)); + MOCK_METHOD1(Start, void(const StartCallback& start_callback)); MOCK_METHOD0(Stop, void()); MOCK_METHOD0(enabled, bool()); MOCK_CONST_METHOD0(type, syncable::ModelType()); diff --git a/chrome/browser/sync/glue/non_frontend_data_type_controller_unittest.cc b/chrome/browser/sync/glue/non_frontend_data_type_controller_unittest.cc index 9ca6592..f5438a8 100644 --- a/chrome/browser/sync/glue/non_frontend_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/non_frontend_data_type_controller_unittest.cc @@ -4,11 +4,12 @@ #include "testing/gtest/include/gtest/gtest.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/callback.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" #include "base/synchronization/waitable_event.h" -#include "base/task.h" #include "base/test/test_timeouts.h" #include "base/tracked_objects.h" #include "chrome/browser/sync/engine/model_safe_worker.h" @@ -29,7 +30,7 @@ using browser_sync::GROUP_DB; using browser_sync::NonFrontendDataTypeController; using browser_sync::NonFrontendDataTypeControllerMock; using browser_sync::ModelAssociatorMock; -using browser_sync::StartCallback; +using browser_sync::StartCallbackMock; using content::BrowserThread; using testing::_; using testing::DoAll; @@ -118,7 +119,7 @@ class NonFrontendDataTypeControllerTest : public testing::Test { profile_sync_factory_.reset( new StrictMock<ProfileSyncComponentsFactoryMock>()); - // Both of these are refcounted, so don't need to be released. + // All of these are refcounted, so don't need to be released. dtc_mock_ = new StrictMock<NonFrontendDataTypeControllerMock>(); non_frontend_dtc_ = new NonFrontendDataTypeControllerFake(profile_sync_factory_.get(), @@ -195,7 +196,7 @@ class NonFrontendDataTypeControllerTest : public testing::Test { ProfileSyncServiceMock service_; ModelAssociatorMock* model_associator_; ChangeProcessorMock* change_processor_; - StartCallback start_callback_; + StartCallbackMock start_callback_; }; TEST_F(NonFrontendDataTypeControllerTest, StartOk) { @@ -203,7 +204,8 @@ TEST_F(NonFrontendDataTypeControllerTest, StartOk) { SetAssociateExpectations(); SetActivateExpectations(DataTypeController::OK); EXPECT_EQ(DataTypeController::NOT_RUNNING, non_frontend_dtc_->state()); - non_frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + non_frontend_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); WaitForDTC(); EXPECT_EQ(DataTypeController::RUNNING, non_frontend_dtc_->state()); } @@ -220,7 +222,8 @@ TEST_F(NonFrontendDataTypeControllerTest, StartFirstRun) { EXPECT_CALL(*dtc_mock_, RecordAssociationTime(_)); SetActivateExpectations(DataTypeController::OK_FIRST_RUN); EXPECT_EQ(DataTypeController::NOT_RUNNING, non_frontend_dtc_->state()); - non_frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + non_frontend_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); WaitForDTC(); EXPECT_EQ(DataTypeController::RUNNING, non_frontend_dtc_->state()); } @@ -229,7 +232,8 @@ TEST_F(NonFrontendDataTypeControllerTest, AbortDuringStartModels) { EXPECT_CALL(*dtc_mock_, StartModels()).WillOnce(Return(false)); SetStartFailExpectations(DataTypeController::ABORTED); EXPECT_EQ(DataTypeController::NOT_RUNNING, non_frontend_dtc_->state()); - non_frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + non_frontend_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); WaitForDTC(); EXPECT_EQ(DataTypeController::MODEL_STARTING, non_frontend_dtc_->state()); non_frontend_dtc_->Stop(); @@ -250,7 +254,8 @@ TEST_F(NonFrontendDataTypeControllerTest, StartAssociationFailed) { SetStartFailExpectations(DataTypeController::ASSOCIATION_FAILED); // Set up association to fail with an association failed error. EXPECT_EQ(DataTypeController::NOT_RUNNING, non_frontend_dtc_->state()); - non_frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + non_frontend_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); WaitForDTC(); EXPECT_EQ(DataTypeController::DISABLED, non_frontend_dtc_->state()); } @@ -266,7 +271,8 @@ TEST_F(NonFrontendDataTypeControllerTest, EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillRepeatedly(DoAll(SetArgumentPointee<0>(false), Return(false))); EXPECT_EQ(DataTypeController::NOT_RUNNING, non_frontend_dtc_->state()); - non_frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + non_frontend_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); WaitForDTC(); EXPECT_EQ(DataTypeController::NOT_RUNNING, non_frontend_dtc_->state()); } @@ -279,7 +285,8 @@ TEST_F(NonFrontendDataTypeControllerTest, StartAssociationCryptoNotReady) { EXPECT_CALL(*model_associator_, CryptoReadyIfNecessary()). WillRepeatedly(Return(false)); EXPECT_EQ(DataTypeController::NOT_RUNNING, non_frontend_dtc_->state()); - non_frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + non_frontend_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); WaitForDTC(); EXPECT_EQ(DataTypeController::NOT_RUNNING, non_frontend_dtc_->state()); } @@ -309,7 +316,8 @@ TEST_F(NonFrontendDataTypeControllerTest, AbortDuringAssociationInactive) { EXPECT_CALL(*dtc_mock_, RecordStartFailure(DataTypeController::ABORTED)); SetStopExpectations(); EXPECT_EQ(DataTypeController::NOT_RUNNING, non_frontend_dtc_->state()); - non_frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + non_frontend_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); wait_for_db_thread_pause.Wait(); non_frontend_dtc_->Stop(); WaitForDTC(); @@ -341,7 +349,8 @@ TEST_F(NonFrontendDataTypeControllerTest, AbortDuringAssociationActivated) { EXPECT_CALL(*dtc_mock_, RecordStartFailure(DataTypeController::ABORTED)); SetStopExpectations(); EXPECT_EQ(DataTypeController::NOT_RUNNING, non_frontend_dtc_->state()); - non_frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + non_frontend_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); wait_for_db_thread_pause.Wait(); non_frontend_dtc_->Stop(); WaitForDTC(); @@ -354,7 +363,8 @@ TEST_F(NonFrontendDataTypeControllerTest, Stop) { SetActivateExpectations(DataTypeController::OK); SetStopExpectations(); EXPECT_EQ(DataTypeController::NOT_RUNNING, non_frontend_dtc_->state()); - non_frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + non_frontend_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); WaitForDTC(); EXPECT_EQ(DataTypeController::RUNNING, non_frontend_dtc_->state()); non_frontend_dtc_->Stop(); @@ -371,7 +381,8 @@ TEST_F(NonFrontendDataTypeControllerTest, OnUnrecoverableError) { &NonFrontendDataTypeController::Stop)); SetStopExpectations(); EXPECT_EQ(DataTypeController::NOT_RUNNING, non_frontend_dtc_->state()); - non_frontend_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + non_frontend_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); WaitForDTC(); EXPECT_EQ(DataTypeController::RUNNING, non_frontend_dtc_->state()); // This should cause non_frontend_dtc_->Stop() to be called. diff --git a/chrome/browser/sync/glue/password_data_type_controller.cc b/chrome/browser/sync/glue/password_data_type_controller.cc index 637251e..c61a8c80 100644 --- a/chrome/browser/sync/glue/password_data_type_controller.cc +++ b/chrome/browser/sync/glue/password_data_type_controller.cc @@ -4,8 +4,8 @@ #include "chrome/browser/sync/glue/password_data_type_controller.h" +#include "base/bind.h" #include "base/metrics/histogram.h" -#include "base/task.h" #include "chrome/browser/password_manager/password_store.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sync/api/sync_error.h" diff --git a/chrome/browser/sync/glue/password_model_associator.h b/chrome/browser/sync/glue/password_model_associator.h index 22c1df8..38a3bd1 100644 --- a/chrome/browser/sync/glue/password_model_associator.h +++ b/chrome/browser/sync/glue/password_model_associator.h @@ -13,7 +13,6 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/synchronization/lock.h" -#include "base/task.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/sync/glue/model_associator.h" #include "chrome/browser/sync/protocol/password_specifics.pb.h" diff --git a/chrome/browser/sync/glue/password_model_worker.cc b/chrome/browser/sync/glue/password_model_worker.cc index d0f3c26..826cf21 100644 --- a/chrome/browser/sync/glue/password_model_worker.cc +++ b/chrome/browser/sync/glue/password_model_worker.cc @@ -4,9 +4,8 @@ #include "chrome/browser/sync/glue/password_model_worker.h" -#include "base/callback.h" +#include "base/bind.h" #include "base/memory/ref_counted.h" -#include "base/task.h" #include "base/synchronization/waitable_event.h" #include "chrome/browser/password_manager/password_store.h" diff --git a/chrome/browser/sync/glue/preference_data_type_controller_unittest.cc b/chrome/browser/sync/glue/preference_data_type_controller_unittest.cc index 732b096..9e6681f 100644 --- a/chrome/browser/sync/glue/preference_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/preference_data_type_controller_unittest.cc @@ -4,10 +4,11 @@ #include "testing/gtest/include/gtest/gtest.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/callback.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" -#include "base/task.h" #include "base/tracked_objects.h" #include "chrome/browser/sync/glue/change_processor_mock.h" #include "chrome/browser/sync/glue/data_type_controller_mock.h" @@ -22,7 +23,7 @@ using browser_sync::ChangeProcessorMock; using browser_sync::DataTypeController; using browser_sync::ModelAssociatorMock; using browser_sync::PreferenceDataTypeController; -using browser_sync::StartCallback; +using browser_sync::StartCallbackMock; using content::BrowserThread; using testing::_; using testing::DoAll; @@ -83,7 +84,7 @@ class PreferenceDataTypeControllerTest : public testing::Test { ProfileSyncServiceMock service_; ModelAssociatorMock* model_associator_; ChangeProcessorMock* change_processor_; - StartCallback start_callback_; + StartCallbackMock start_callback_; }; TEST_F(PreferenceDataTypeControllerTest, Start) { @@ -92,7 +93,8 @@ TEST_F(PreferenceDataTypeControllerTest, Start) { SetActivateExpectations(); EXPECT_EQ(DataTypeController::NOT_RUNNING, preference_dtc_->state()); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - preference_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + preference_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::RUNNING, preference_dtc_->state()); } @@ -103,7 +105,8 @@ TEST_F(PreferenceDataTypeControllerTest, StartFirstRun) { EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillRepeatedly(DoAll(SetArgumentPointee<0>(false), Return(true))); EXPECT_CALL(start_callback_, Run(DataTypeController::OK_FIRST_RUN, _)); - preference_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + preference_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); } TEST_F(PreferenceDataTypeControllerTest, StartOk) { @@ -114,7 +117,8 @@ TEST_F(PreferenceDataTypeControllerTest, StartOk) { WillRepeatedly(DoAll(SetArgumentPointee<0>(true), Return(true))); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - preference_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + preference_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); } TEST_F(PreferenceDataTypeControllerTest, StartAssociationFailed) { @@ -124,8 +128,10 @@ TEST_F(PreferenceDataTypeControllerTest, StartAssociationFailed) { WillRepeatedly(DoAll(browser_sync::SetSyncError(syncable::PREFERENCES), Return(false))); - EXPECT_CALL(start_callback_, Run(DataTypeController::ASSOCIATION_FAILED, _)); - preference_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + EXPECT_CALL(start_callback_, + Run(DataTypeController::ASSOCIATION_FAILED, _)); + preference_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::DISABLED, preference_dtc_->state()); } @@ -137,8 +143,10 @@ TEST_F(PreferenceDataTypeControllerTest, WillRepeatedly(Return(true)); EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillRepeatedly(DoAll(SetArgumentPointee<0>(false), Return(false))); - EXPECT_CALL(start_callback_, Run(DataTypeController::UNRECOVERABLE_ERROR, _)); - preference_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + EXPECT_CALL(start_callback_, + Run(DataTypeController::UNRECOVERABLE_ERROR, _)); + preference_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::NOT_RUNNING, preference_dtc_->state()); } @@ -151,7 +159,8 @@ TEST_F(PreferenceDataTypeControllerTest, Stop) { EXPECT_EQ(DataTypeController::NOT_RUNNING, preference_dtc_->state()); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - preference_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + preference_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::RUNNING, preference_dtc_->state()); preference_dtc_->Stop(); EXPECT_EQ(DataTypeController::NOT_RUNNING, preference_dtc_->state()); @@ -169,7 +178,8 @@ TEST_F(PreferenceDataTypeControllerTest, OnUnrecoverableError) { SetStopExpectations(); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - preference_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + preference_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); // This should cause preference_dtc_->Stop() to be called. preference_dtc_->OnUnrecoverableError(FROM_HERE, "Test"); PumpLoop(); diff --git a/chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc b/chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc index f744e27..25789ad 100644 --- a/chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc @@ -2,9 +2,10 @@ // 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/callback.h" #include "base/memory/scoped_ptr.h" -#include "base/task.h" #include "base/tracked_objects.h" #include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/search_engines/template_url_service_test_util.h" @@ -23,7 +24,7 @@ using browser_sync::ChangeProcessorMock; using browser_sync::DataTypeController; using browser_sync::ModelAssociatorMock; using browser_sync::SearchEngineDataTypeController; -using browser_sync::StartCallback; +using browser_sync::StartCallbackMock; using testing::_; using testing::DoAll; using testing::InvokeWithoutArgs; @@ -84,7 +85,7 @@ class SearchEngineDataTypeControllerTest : public testing::Test { ProfileSyncServiceMock service_; ModelAssociatorMock* model_associator_; ChangeProcessorMock* change_processor_; - StartCallback start_callback_; + StartCallbackMock start_callback_; }; TEST_F(SearchEngineDataTypeControllerTest, StartURLServiceReady) { @@ -95,7 +96,8 @@ TEST_F(SearchEngineDataTypeControllerTest, StartURLServiceReady) { EXPECT_EQ(DataTypeController::NOT_RUNNING, search_engine_dtc_->state()); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - search_engine_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + search_engine_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::RUNNING, search_engine_dtc_->state()); } @@ -103,7 +105,8 @@ TEST_F(SearchEngineDataTypeControllerTest, StartURLServiceNotReady) { SetAssociateExpectations(); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - search_engine_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + search_engine_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::MODEL_STARTING, search_engine_dtc_->state()); // Send the notification that the TemplateURLService has started. @@ -120,7 +123,8 @@ TEST_F(SearchEngineDataTypeControllerTest, StartFirstRun) { EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillRepeatedly(DoAll(SetArgumentPointee<0>(false), Return(true))); EXPECT_CALL(start_callback_, Run(DataTypeController::OK_FIRST_RUN, _)); - search_engine_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + search_engine_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); } TEST_F(SearchEngineDataTypeControllerTest, StartOk) { @@ -130,7 +134,8 @@ TEST_F(SearchEngineDataTypeControllerTest, StartOk) { WillRepeatedly(DoAll(SetArgumentPointee<0>(true), Return(true))); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - search_engine_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + search_engine_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); } TEST_F(SearchEngineDataTypeControllerTest, StartAssociationFailed) { @@ -144,8 +149,10 @@ TEST_F(SearchEngineDataTypeControllerTest, StartAssociationFailed) { WillRepeatedly(DoAll(browser_sync::SetSyncError(syncable::SEARCH_ENGINES), Return(false))); - EXPECT_CALL(start_callback_, Run(DataTypeController::ASSOCIATION_FAILED, _)); - search_engine_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + EXPECT_CALL(start_callback_, + Run(DataTypeController::ASSOCIATION_FAILED, _)); + search_engine_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::DISABLED, search_engine_dtc_->state()); } @@ -158,8 +165,10 @@ TEST_F(SearchEngineDataTypeControllerTest, WillRepeatedly(Return(true)); EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillRepeatedly(DoAll(SetArgumentPointee<0>(false), Return(false))); - EXPECT_CALL(start_callback_, Run(DataTypeController::UNRECOVERABLE_ERROR, _)); - search_engine_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + EXPECT_CALL(start_callback_, + Run(DataTypeController::UNRECOVERABLE_ERROR, _)); + search_engine_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::NOT_RUNNING, search_engine_dtc_->state()); } @@ -171,7 +180,8 @@ TEST_F(SearchEngineDataTypeControllerTest, Stop) { EXPECT_EQ(DataTypeController::NOT_RUNNING, search_engine_dtc_->state()); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - search_engine_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + search_engine_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::RUNNING, search_engine_dtc_->state()); search_engine_dtc_->Stop(); EXPECT_EQ(DataTypeController::NOT_RUNNING, search_engine_dtc_->state()); @@ -188,7 +198,8 @@ TEST_F(SearchEngineDataTypeControllerTest, OnUnrecoverableError) { SetStopExpectations(); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - search_engine_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + search_engine_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); // This should cause search_engine_dtc_->Stop() to be called. search_engine_dtc_->OnUnrecoverableError(FROM_HERE, "Test"); } diff --git a/chrome/browser/sync/glue/session_model_associator.cc b/chrome/browser/sync/glue/session_model_associator.cc index 51db3de..71335e4 100644 --- a/chrome/browser/sync/glue/session_model_associator.cc +++ b/chrome/browser/sync/glue/session_model_associator.cc @@ -63,7 +63,7 @@ SessionModelAssociator::SessionModelAssociator(ProfileSyncService* sync_service) stale_session_threshold_days_(kDefaultStaleSessionThresholdDays), setup_for_test_(false), waiting_for_change_(false), - ALLOW_THIS_IN_INITIALIZER_LIST(test_method_factory_(this)) { + ALLOW_THIS_IN_INITIALIZER_LIST(test_weak_factory_(this)) { DCHECK(CalledOnValidThread()); DCHECK(sync_service_); } @@ -76,7 +76,7 @@ SessionModelAssociator::SessionModelAssociator(ProfileSyncService* sync_service, stale_session_threshold_days_(kDefaultStaleSessionThresholdDays), setup_for_test_(setup_for_test), waiting_for_change_(false), - ALLOW_THIS_IN_INITIALIZER_LIST(test_method_factory_(this)) { + ALLOW_THIS_IN_INITIALIZER_LIST(test_weak_factory_(this)) { DCHECK(CalledOnValidThread()); DCHECK(sync_service_); } @@ -892,8 +892,8 @@ bool SessionModelAssociator::UpdateSyncModelDataFromClient() { // TODO(zea): the logic for determining if we want to sync and the loading of // the previous session should go here. We can probably reuse the code for // loading the current session from the old session implementation. - // SessionService::SessionCallback* callback = - // NewCallback(this, &SessionModelAssociator::OnGotSession); + // SessionService::SessionCallback callback = + // base::Bind(&SessionModelAssociator::OnGotSession, this); // GetSessionService()->GetCurrentSession(&consumer_, callback); // Associate all open windows and their tabs. @@ -1080,20 +1080,20 @@ void SessionModelAssociator::QuitLoopForSubtleTesting() { if (waiting_for_change_) { DVLOG(1) << "Quitting MessageLoop for test."; waiting_for_change_ = false; - test_method_factory_.RevokeAll(); + test_weak_factory_.InvalidateWeakPtrs(); MessageLoop::current()->Quit(); } } void SessionModelAssociator::BlockUntilLocalChangeForTest( int64 timeout_milliseconds) { - if (!test_method_factory_.empty()) + if (test_weak_factory_.HasWeakPtrs()) return; waiting_for_change_ = true; MessageLoop::current()->PostDelayedTask( FROM_HERE, - test_method_factory_.NewRunnableMethod( - &SessionModelAssociator::QuitLoopForSubtleTesting), + base::Bind(&SessionModelAssociator::QuitLoopForSubtleTesting, + test_weak_factory_.GetWeakPtr()), timeout_milliseconds); } diff --git a/chrome/browser/sync/glue/session_model_associator.h b/chrome/browser/sync/glue/session_model_associator.h index ce8a78d..bfaab71 100644 --- a/chrome/browser/sync/glue/session_model_associator.h +++ b/chrome/browser/sync/glue/session_model_associator.h @@ -465,7 +465,7 @@ class SessionModelAssociator // During integration tests, we sometimes need to block until a local change // is made. bool waiting_for_change_; - ScopedRunnableMethodFactory<SessionModelAssociator> test_method_factory_; + base::WeakPtrFactory<SessionModelAssociator> test_weak_factory_; DISALLOW_COPY_AND_ASSIGN(SessionModelAssociator); }; diff --git a/chrome/browser/sync/glue/theme_data_type_controller_unittest.cc b/chrome/browser/sync/glue/theme_data_type_controller_unittest.cc index a04d1a7..2170b93 100644 --- a/chrome/browser/sync/glue/theme_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/theme_data_type_controller_unittest.cc @@ -4,10 +4,11 @@ #include "testing/gtest/include/gtest/gtest.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/callback.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" -#include "base/task.h" #include "chrome/browser/sync/glue/change_processor_mock.h" #include "chrome/browser/sync/glue/data_type_controller_mock.h" #include "chrome/browser/sync/glue/model_associator_mock.h" @@ -21,7 +22,7 @@ using browser_sync::ThemeDataTypeController; using browser_sync::ChangeProcessorMock; using browser_sync::DataTypeController; using browser_sync::ModelAssociatorMock; -using browser_sync::StartCallback; +using browser_sync::StartCallbackMock; using content::BrowserThread; using testing::_; using testing::DoAll; @@ -80,7 +81,7 @@ class ThemeDataTypeControllerTest : public testing::Test { ProfileSyncServiceMock service_; ModelAssociatorMock* model_associator_; ChangeProcessorMock* change_processor_; - StartCallback start_callback_; + StartCallbackMock start_callback_; }; TEST_F(ThemeDataTypeControllerTest, Start) { @@ -89,7 +90,8 @@ TEST_F(ThemeDataTypeControllerTest, Start) { SetActivateExpectations(); EXPECT_EQ(DataTypeController::NOT_RUNNING, theme_dtc_->state()); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - theme_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + theme_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::RUNNING, theme_dtc_->state()); } @@ -100,7 +102,8 @@ TEST_F(ThemeDataTypeControllerTest, StartFirstRun) { EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillRepeatedly(DoAll(SetArgumentPointee<0>(false), Return(true))); EXPECT_CALL(start_callback_, Run(DataTypeController::OK_FIRST_RUN, _)); - theme_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + theme_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); } TEST_F(ThemeDataTypeControllerTest, StartOk) { @@ -111,7 +114,8 @@ TEST_F(ThemeDataTypeControllerTest, StartOk) { WillRepeatedly(DoAll(SetArgumentPointee<0>(true), Return(true))); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - theme_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + theme_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); } TEST_F(ThemeDataTypeControllerTest, StartAssociationFailed) { @@ -121,8 +125,10 @@ TEST_F(ThemeDataTypeControllerTest, StartAssociationFailed) { WillRepeatedly(DoAll(browser_sync::SetSyncError(syncable::THEMES), Return(false))); - EXPECT_CALL(start_callback_, Run(DataTypeController::ASSOCIATION_FAILED, _)); - theme_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + EXPECT_CALL(start_callback_, + Run(DataTypeController::ASSOCIATION_FAILED, _)); + theme_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::DISABLED, theme_dtc_->state()); } @@ -134,8 +140,10 @@ TEST_F(ThemeDataTypeControllerTest, WillRepeatedly(Return(true)); EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillRepeatedly(DoAll(SetArgumentPointee<0>(false), Return(false))); - EXPECT_CALL(start_callback_, Run(DataTypeController::UNRECOVERABLE_ERROR, _)); - theme_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + EXPECT_CALL(start_callback_, + Run(DataTypeController::UNRECOVERABLE_ERROR, _)); + theme_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::NOT_RUNNING, theme_dtc_->state()); } @@ -148,7 +156,8 @@ TEST_F(ThemeDataTypeControllerTest, Stop) { EXPECT_EQ(DataTypeController::NOT_RUNNING, theme_dtc_->state()); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - theme_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + theme_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); EXPECT_EQ(DataTypeController::RUNNING, theme_dtc_->state()); theme_dtc_->Stop(); EXPECT_EQ(DataTypeController::NOT_RUNNING, theme_dtc_->state()); @@ -167,7 +176,8 @@ TEST_F(ThemeDataTypeControllerTest, OnUnrecoverableError) { SetStopExpectations(); EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)); - theme_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); + theme_dtc_->Start( + base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_))); // This should cause theme_dtc_->Stop() to be called. theme_dtc_->OnUnrecoverableError(FROM_HERE, "Test"); PumpLoop(); diff --git a/chrome/browser/sync/glue/typed_url_data_type_controller.cc b/chrome/browser/sync/glue/typed_url_data_type_controller.cc index 05156f5..2d92ade 100644 --- a/chrome/browser/sync/glue/typed_url_data_type_controller.cc +++ b/chrome/browser/sync/glue/typed_url_data_type_controller.cc @@ -5,7 +5,6 @@ #include "chrome/browser/sync/glue/typed_url_data_type_controller.h" #include "base/metrics/histogram.h" -#include "base/task.h" #include "chrome/browser/history/history.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" diff --git a/chrome/browser/sync/glue/typed_url_model_associator.h b/chrome/browser/sync/glue/typed_url_model_associator.h index d472e16..ce06c17 100644 --- a/chrome/browser/sync/glue/typed_url_model_associator.h +++ b/chrome/browser/sync/glue/typed_url_model_associator.h @@ -14,7 +14,6 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/string16.h" -#include "base/task.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/sync/glue/model_associator.h" #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" diff --git a/chrome/browser/sync/glue/ui_model_worker.cc b/chrome/browser/sync/glue/ui_model_worker.cc index 70ee0eb..7753e6a 100644 --- a/chrome/browser/sync/glue/ui_model_worker.cc +++ b/chrome/browser/sync/glue/ui_model_worker.cc @@ -4,6 +4,8 @@ #include "chrome/browser/sync/glue/ui_model_worker.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/message_loop.h" #include "base/synchronization/waitable_event.h" #include "base/third_party/dynamic_annotations/dynamic_annotations.h" @@ -13,6 +15,33 @@ using content::BrowserThread; namespace browser_sync { +namespace { + +void CallDoWorkAndSignalCallback(const WorkCallback& work, + base::WaitableEvent* work_done, + UIModelWorker* const scheduler, + UnrecoverableErrorInfo* error_info) { + if (work.is_null()) { + // This can happen during tests or cases where there are more than just the + // default UIModelWorker in existence and it gets destroyed before + // the main UI loop has terminated. There is no easy way to assert the + // loop is running / not running at the moment, so we just provide cancel + // semantics here and short-circuit. + // TODO(timsteele): Maybe we should have the message loop destruction + // observer fire when the loop has ended, just a bit before it + // actually gets destroyed. + return; + } + *error_info = work.Run(); + + // Notify the UIModelWorker that scheduled us that we have run + // successfully. + scheduler->OnTaskCompleted(); + work_done->Signal(); // Unblock the syncer thread that scheduled us. +} + +} // namespace + UnrecoverableErrorInfo UIModelWorker::DoWorkAndWaitUntilDone( const WorkCallback& work) { // In most cases, this method is called in WORKING state. It is possible this @@ -36,13 +65,13 @@ UnrecoverableErrorInfo UIModelWorker::DoWorkAndWaitUntilDone( // could get Run() in Stop() and call OnTaskCompleted before we post). // The task is owned by the message loop as per usual. base::AutoLock lock(lock_); - DCHECK(!pending_work_); + DCHECK(pending_work_.is_null()); UnrecoverableErrorInfo error_info; - pending_work_ = new CallDoWorkAndSignalTask(work, &work_done, this, - &error_info); + pending_work_ = base::Bind(&CallDoWorkAndSignalCallback, work, &work_done, + base::Unretained(this), &error_info); if (!BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, pending_work_)) { LOG(WARNING) << "Could not post work to UI loop."; - pending_work_ = NULL; + pending_work_.Reset(); syncapi_event_.Signal(); return error_info; } @@ -54,7 +83,6 @@ UnrecoverableErrorInfo UIModelWorker::DoWorkAndWaitUntilDone( UIModelWorker::UIModelWorker() : state_(WORKING), - pending_work_(NULL), syncapi_has_shutdown_(false), syncapi_event_(&lock_) { } @@ -89,8 +117,8 @@ void UIModelWorker::Stop() { // Drain any final tasks manually until the SyncerThread tells us it has // totally finished. There should only ever be 0 or 1 tasks Run() here. while (!syncapi_has_shutdown_) { - if (pending_work_) - pending_work_->Run(); // OnTaskCompleted will set pending_work_ to NULL. + if (!pending_work_.is_null()) + pending_work_.Run(); // OnTaskCompleted will set reset |pending_work_|. // Wait for either a new task or SyncerThread termination. syncapi_event_.Wait(); @@ -103,28 +131,5 @@ ModelSafeGroup UIModelWorker::GetModelSafeGroup() { return GROUP_UI; } -void UIModelWorker::CallDoWorkAndSignalTask::Run() { - if (work_.is_null()) { - // This can happen during tests or cases where there are more than just the - // default UIModelWorker in existence and it gets destroyed before - // the main UI loop has terminated. There is no easy way to assert the - // loop is running / not running at the moment, so we just provide cancel - // semantics here and short-circuit. - // TODO(timsteele): Maybe we should have the message loop destruction - // observer fire when the loop has ended, just a bit before it - // actually gets destroyed. - return; - } - *error_info_ = work_.Run(); - - // Sever ties with work_ to allow the sanity-checking above that we don't - // get run twice. - work_.Reset(); - - // Notify the UIModelWorker that scheduled us that we have run - // successfully. - scheduler_->OnTaskCompleted(); - work_done_->Signal(); // Unblock the syncer thread that scheduled us. -} } // namespace browser_sync diff --git a/chrome/browser/sync/glue/ui_model_worker.h b/chrome/browser/sync/glue/ui_model_worker.h index 880e672..6592570 100644 --- a/chrome/browser/sync/glue/ui_model_worker.h +++ b/chrome/browser/sync/glue/ui_model_worker.h @@ -10,14 +10,9 @@ #include "base/compiler_specific.h" #include "base/synchronization/condition_variable.h" #include "base/synchronization/lock.h" -#include "base/task.h" #include "chrome/browser/sync/engine/model_safe_worker.h" #include "chrome/browser/sync/util/unrecoverable_error_info.h" -namespace base { -class WaitableEvent; -} - class MessageLoop; namespace browser_sync { @@ -35,36 +30,6 @@ class UIModelWorker : public browser_sync::ModelSafeWorker { UIModelWorker(); virtual ~UIModelWorker(); - // A simple task to signal a waitable event after Run()ning a Closure. - class CallDoWorkAndSignalTask : public Task { - public: - CallDoWorkAndSignalTask( - const WorkCallback& work, - base::WaitableEvent* work_done, - UIModelWorker* scheduler, - UnrecoverableErrorInfo* error_info) - : work_(work), work_done_(work_done), scheduler_(scheduler), - error_info_(error_info) { - } - virtual ~CallDoWorkAndSignalTask() { } - - // Task implementation. - virtual void Run() OVERRIDE; - - private: - // Task data - a closure and a waitable event to signal after the work has - // been done. - WorkCallback work_; - base::WaitableEvent* work_done_; - - // The UIModelWorker responsible for scheduling us. - UIModelWorker* const scheduler_; - - UnrecoverableErrorInfo* error_info_; - - DISALLOW_COPY_AND_ASSIGN(CallDoWorkAndSignalTask); - }; - // Called by the UI thread on shutdown of the sync service. Blocks until // the UIModelWorker has safely met termination conditions, namely that // no task scheduled by CallDoWorkFromModelSafeThreadAndWait remains un- @@ -84,7 +49,7 @@ class UIModelWorker : public browser_sync::ModelSafeWorker { // Callback from |pending_work_| to notify us that it has been run. // Called on ui loop. - void OnTaskCompleted() { pending_work_ = NULL; } + void OnTaskCompleted() { pending_work_.Reset(); } private: // The life-cycle of a UIModelWorker in three states. @@ -109,7 +74,7 @@ class UIModelWorker : public browser_sync::ModelSafeWorker { // We keep a reference to any task we have scheduled so we can gracefully // force them to run if the syncer is trying to shutdown. - Task* pending_work_; + base::Closure pending_work_; // Set by the SyncCoreThread when Syncapi shutdown has completed and the // SyncerThread has terminated, so no more work will be scheduled. Read by diff --git a/chrome/browser/sync/glue/ui_model_worker_unittest.cc b/chrome/browser/sync/glue/ui_model_worker_unittest.cc index dc23f56..b6b83db 100644 --- a/chrome/browser/sync/glue/ui_model_worker_unittest.cc +++ b/chrome/browser/sync/glue/ui_model_worker_unittest.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "base/bind.h" +#include "base/bind_helpers.h" #include "base/callback.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" @@ -59,53 +60,25 @@ class Syncer { DISALLOW_COPY_AND_ASSIGN(Syncer); }; -// A task run from the SyncerThread to "sync share", ie tell the Syncer to -// ask its ModelSafeWorker to do something. -class FakeSyncShareTask : public Task { - public: - FakeSyncShareTask(Syncer* syncer, UIModelWorkerVisitor* visitor) - : syncer_(syncer), visitor_(visitor) { - } - virtual void Run() { - syncer_->SyncShare(visitor_); - } - private: - Syncer* syncer_; - UIModelWorkerVisitor* visitor_; - DISALLOW_COPY_AND_ASSIGN(FakeSyncShareTask); -}; - -// A task run from the CoreThread to simulate terminating syncapi. -class FakeSyncapiShutdownTask : public Task { - public: - FakeSyncapiShutdownTask(base::Thread* syncer_thread, - UIModelWorker* worker, - base::WaitableEvent** jobs, - size_t job_count) - : syncer_thread_(syncer_thread), worker_(worker), jobs_(jobs), - job_count_(job_count), all_jobs_done_(false, false) { } - virtual void Run() { - // In real life, we would try and close a sync directory, which would - // result in the syncer calling it's own destructor, which results in - // the SyncerThread::HaltSyncer being called, which sets the - // syncer in RequestEarlyExit mode and waits until the Syncer finishes - // SyncShare to remove the syncer from it's watch. Here we just manually - // wait until all outstanding jobs are done to simulate what happens in - // SyncerThread::HaltSyncer. - all_jobs_done_.WaitMany(jobs_, job_count_); - - // These two calls are made from SyncBackendHost::Core::DoShutdown. - syncer_thread_->Stop(); - worker_->OnSyncerShutdownComplete(); - } - private: - base::Thread* syncer_thread_; - scoped_refptr<UIModelWorker> worker_; - base::WaitableEvent** jobs_; - size_t job_count_; - base::WaitableEvent all_jobs_done_; - DISALLOW_COPY_AND_ASSIGN(FakeSyncapiShutdownTask); -}; +// A callback run from the CoreThread to simulate terminating syncapi. +void FakeSyncapiShutdownCallback(base::Thread* syncer_thread, + UIModelWorker* worker, + base::WaitableEvent** jobs, + size_t job_count) { + base::WaitableEvent all_jobs_done(false, false); + // In real life, we would try and close a sync directory, which would + // result in the syncer calling it's own destructor, which results in + // the SyncerThread::HaltSyncer being called, which sets the + // syncer in RequestEarlyExit mode and waits until the Syncer finishes + // SyncShare to remove the syncer from it's watch. Here we just manually + // wait until all outstanding jobs are done to simulate what happens in + // SyncerThread::HaltSyncer. + all_jobs_done.WaitMany(jobs, job_count); + + // These two calls are made from SyncBackendHost::Core::DoShutdown. + syncer_thread->Stop(); + worker->OnSyncerShutdownComplete(); +} class UIModelWorkerTest : public testing::Test { public: @@ -139,7 +112,7 @@ TEST_F(UIModelWorkerTest, ScheduledWorkRunsOnUILoop) { new UIModelWorkerVisitor(&v_was_run, true)); syncer_thread()->message_loop()->PostTask(FROM_HERE, - new FakeSyncShareTask(syncer(), v.get())); + base::Bind(&Syncer::SyncShare, base::Unretained(syncer()), v.get())); // We are on the UI thread, so run our loop to process the // (hopefully) scheduled task from a SyncShare invocation. @@ -175,14 +148,17 @@ TEST_F(UIModelWorkerTest, StopWithPendingWork) { // The current message loop is not running, so queue a task to cause // UIModelWorker::Stop() to play a crucial role. See comment below. syncer_thread()->message_loop()->PostTask(FROM_HERE, - new FakeSyncShareTask(syncer(), v.get())); + base::Bind(&Syncer::SyncShare, base::Unretained(syncer()), v.get())); // This is what gets the core_thread blocked on the syncer_thread. core_thread()->message_loop()->PostTask(FROM_HERE, - new FakeSyncapiShutdownTask(syncer_thread(), bmw(), jobs, 1)); + base::Bind(&FakeSyncapiShutdownCallback, syncer_thread(), + base::Unretained(bmw()), + static_cast<base::WaitableEvent**>(jobs), 1)); // This is what gets the UI thread blocked until NotifyExitRequested, - // which is called when FakeSyncapiShutdownTask runs and deletes the syncer. + // which is called when FakeSyncapiShutdownCallback runs and deletes the + // syncer. bmw()->Stop(); EXPECT_FALSE(syncer_thread()->IsRunning()); @@ -213,18 +189,21 @@ TEST_F(UIModelWorkerTest, HypotheticalManualPumpFlooding) { // The current message loop is not running, so queue a task to cause // UIModelWorker::Stop() to play a crucial role. See comment below. syncer_thread()->message_loop()->PostTask(FROM_HERE, - new FakeSyncShareTask(syncer(), fox1.get())); + base::Bind(&Syncer::SyncShare, base::Unretained(syncer()), fox1.get())); syncer_thread()->message_loop()->PostTask(FROM_HERE, - new FakeSyncShareTask(syncer(), fox2.get())); + base::Bind(&Syncer::SyncShare, base::Unretained(syncer()), fox2.get())); // This is what gets the core_thread blocked on the syncer_thread. core_thread()->message_loop()->PostTask(FROM_HERE, - new FakeSyncapiShutdownTask(syncer_thread(), bmw(), jobs, 3)); + base::Bind(&FakeSyncapiShutdownCallback, syncer_thread(), + base::Unretained(bmw()), + static_cast<base::WaitableEvent**>(jobs), 3)); syncer_thread()->message_loop()->PostTask(FROM_HERE, - new FakeSyncShareTask(syncer(), fox3.get())); + base::Bind(&Syncer::SyncShare, base::Unretained(syncer()), fox3.get())); // This is what gets the UI thread blocked until NotifyExitRequested, - // which is called when FakeSyncapiShutdownTask runs and deletes the syncer. + // which is called when FakeSyncapiShutdownCallback runs and deletes the + // syncer. bmw()->Stop(); // Was the thread killed? diff --git a/chrome/browser/sync/notifier/cache_invalidation_packet_handler.cc b/chrome/browser/sync/notifier/cache_invalidation_packet_handler.cc index 0073261..d364326 100644 --- a/chrome/browser/sync/notifier/cache_invalidation_packet_handler.cc +++ b/chrome/browser/sync/notifier/cache_invalidation_packet_handler.cc @@ -6,6 +6,7 @@ #include <string> +#include "base/bind.h" #include "base/base64.h" #include "base/callback.h" #include "base/compiler_specific.h" @@ -50,8 +51,8 @@ class CacheInvalidationListenTask : public buzz::XmppTask { // Takes ownership of callback. CacheInvalidationListenTask( buzz::XmppTaskParentInterface* parent, - Callback1<const std::string&>::Type* callback, - Callback1<const std::string&>::Type* context_change_callback) + const base::Callback<void(const std::string&)>& callback, + const base::Callback<void(const std::string&)>& context_change_callback) : XmppTask(parent, buzz::XmppEngine::HL_TYPE), callback_(callback), context_change_callback_(context_change_callback) {} @@ -71,7 +72,7 @@ class CacheInvalidationListenTask : public buzz::XmppTask { DVLOG(2) << "CacheInvalidationListenTask response received"; std::string data; if (GetCacheInvalidationIqPacketData(stanza, &data)) { - callback_->Run(data); + callback_.Run(data); } else { LOG(ERROR) << "Could not get packet data"; } @@ -113,7 +114,7 @@ class CacheInvalidationListenTask : public buzz::XmppTask { // Look for a channelContext attribute in the content of the stanza. If // present, remember it so it can be echoed back. if (cache_invalidation_iq_packet->HasAttr(GetQnChannelContext())) { - context_change_callback_->Run( + context_change_callback_.Run( cache_invalidation_iq_packet->Attr(GetQnChannelContext())); } *data = cache_invalidation_iq_packet->BodyText(); @@ -121,8 +122,8 @@ class CacheInvalidationListenTask : public buzz::XmppTask { } std::string* channel_context_; - scoped_ptr<Callback1<const std::string&>::Type> callback_; - scoped_ptr<Callback1<const std::string&>::Type> context_change_callback_; + base::Callback<void(const std::string&)> callback_; + base::Callback<void(const std::string&)> context_change_callback_; DISALLOW_COPY_AND_ASSIGN(CacheInvalidationListenTask); }; @@ -224,7 +225,7 @@ std::string MakeSid() { CacheInvalidationPacketHandler::CacheInvalidationPacketHandler( base::WeakPtr<buzz::XmppTaskParentInterface> base_task) - : scoped_callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), + : weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), base_task_(base_task), seq_(0), sid_(MakeSid()) { @@ -232,10 +233,12 @@ CacheInvalidationPacketHandler::CacheInvalidationPacketHandler( // Owned by base_task. Takes ownership of the callback. CacheInvalidationListenTask* listen_task = new CacheInvalidationListenTask( - base_task_, scoped_callback_factory_.NewCallback( - &CacheInvalidationPacketHandler::HandleInboundPacket), - scoped_callback_factory_.NewCallback( - &CacheInvalidationPacketHandler::HandleChannelContextChange)); + base_task_, base::Bind( + &CacheInvalidationPacketHandler::HandleInboundPacket, + weak_factory_.GetWeakPtr()), + base::Bind( + &CacheInvalidationPacketHandler::HandleChannelContextChange, + weak_factory_.GetWeakPtr())); listen_task->Start(); } diff --git a/chrome/browser/sync/notifier/cache_invalidation_packet_handler.h b/chrome/browser/sync/notifier/cache_invalidation_packet_handler.h index 3e3943e..2316ec6 100644 --- a/chrome/browser/sync/notifier/cache_invalidation_packet_handler.h +++ b/chrome/browser/sync/notifier/cache_invalidation_packet_handler.h @@ -13,7 +13,6 @@ #include "base/basictypes.h" #include "base/gtest_prod_util.h" -#include "base/memory/scoped_callback_factory.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/threading/non_thread_safe.h" @@ -52,8 +51,7 @@ class CacheInvalidationPacketHandler { void HandleChannelContextChange(const std::string& context); base::NonThreadSafe non_thread_safe_; - base::ScopedCallbackFactory<CacheInvalidationPacketHandler> - scoped_callback_factory_; + base::WeakPtrFactory<CacheInvalidationPacketHandler> weak_factory_; base::WeakPtr<buzz::XmppTaskParentInterface> base_task_; diff --git a/chrome/browser/sync/notifier/chrome_system_resources.cc b/chrome/browser/sync/notifier/chrome_system_resources.cc index f1efe3c..71d24da 100644 --- a/chrome/browser/sync/notifier/chrome_system_resources.cc +++ b/chrome/browser/sync/notifier/chrome_system_resources.cc @@ -8,6 +8,7 @@ #include <cstring> #include <string> +#include "base/bind.h" #include "base/logging.h" #include "base/message_loop.h" #include "base/stl_util.h" diff --git a/chrome/browser/sync/notifier/chrome_system_resources.h b/chrome/browser/sync/notifier/chrome_system_resources.h index b3e3b5f..a92a6c6 100644 --- a/chrome/browser/sync/notifier/chrome_system_resources.h +++ b/chrome/browser/sync/notifier/chrome_system_resources.h @@ -18,7 +18,6 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/message_loop.h" -#include "base/task.h" #include "base/threading/non_thread_safe.h" #include "chrome/browser/sync/notifier/state_writer.h" #include "google/cacheinvalidation/v2/system-resources.h" diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc index 4ca5215..d6a4d8d 100644 --- a/chrome/browser/sync/profile_sync_service.cc +++ b/chrome/browser/sync/profile_sync_service.cc @@ -20,7 +20,6 @@ #include "base/metrics/histogram.h" #include "base/string16.h" #include "base/stringprintf.h" -#include "base/task.h" #include "base/threading/thread_restrictions.h" #include "chrome/browser/about_flags.h" #include "chrome/browser/browser_process.h" @@ -120,7 +119,7 @@ ProfileSyncService::ProfileSyncService(ProfileSyncComponentsFactory* factory, wizard_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), signin_(signin_manager), unrecoverable_error_detected_(false), - scoped_runnable_method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), + weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), expect_sync_configuration_aborted_(false), clear_server_data_state_(CLEAR_NOT_STARTED), encrypted_types_(browser_sync::Cryptographer::SensitiveTypes()), @@ -424,7 +423,7 @@ void ProfileSyncService::Shutdown(bool sync_disabled) { doomed_backend.reset(); } - scoped_runnable_method_factory_.RevokeAll(); + weak_factory_.InvalidateWeakPtrs(); // Clear various flags. expect_sync_configuration_aborted_ = false; @@ -555,8 +554,8 @@ void ProfileSyncService::OnUnrecoverableError( // Shut all data types down. MessageLoop::current()->PostTask(FROM_HERE, - scoped_runnable_method_factory_.NewRunnableMethod( - &ProfileSyncService::Shutdown, true)); + base::Bind(&ProfileSyncService::Shutdown, weak_factory_.GetWeakPtr(), + true)); } void ProfileSyncService::OnBackendInitialized( @@ -1385,8 +1384,8 @@ void ProfileSyncService::Observe(int type, } MessageLoop::current()->PostTask(FROM_HERE, - scoped_runnable_method_factory_.NewRunnableMethod( - &ProfileSyncService::OnSyncConfigureDone, *result)); + base::Bind(&ProfileSyncService::OnSyncConfigureDone, + weak_factory_.GetWeakPtr(), *result)); // We should never get in a state where we have no encrypted datatypes // enabled, and yet we still think we require a passphrase for decryption. diff --git a/chrome/browser/sync/profile_sync_service.h b/chrome/browser/sync/profile_sync_service.h index 110c58a..61eab47 100644 --- a/chrome/browser/sync/profile_sync_service.h +++ b/chrome/browser/sync/profile_sync_service.h @@ -17,7 +17,6 @@ #include "base/memory/weak_ptr.h" #include "base/observer_list.h" #include "base/string16.h" -#include "base/task.h" #include "base/time.h" #include "base/timer.h" #include "chrome/browser/sync/backend_unrecoverable_error_handler.h" @@ -648,8 +647,7 @@ class ProfileSyncService : public browser_sync::SyncFrontend, content::NotificationRegistrar registrar_; - ScopedRunnableMethodFactory<ProfileSyncService> - scoped_runnable_method_factory_; + base::WeakPtrFactory<ProfileSyncService> weak_factory_; // This allows us to gracefully handle an ABORTED return code from the // DataTypeManager in the event that the server informed us to cease and diff --git a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc index 5b28ee5..de786b5 100644 --- a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc @@ -18,7 +18,6 @@ #include "base/message_loop.h" #include "base/string16.h" #include "base/synchronization/waitable_event.h" -#include "base/task.h" #include "base/time.h" #include "base/utf_string_conversions.h" #include "chrome/browser/autofill/autofill_common_test.h" diff --git a/chrome/browser/sync/profile_sync_service_harness.cc b/chrome/browser/sync/profile_sync_service_harness.cc index 1daaeec..3bde3bd8 100644 --- a/chrome/browser/sync/profile_sync_service_harness.cc +++ b/chrome/browser/sync/profile_sync_service_harness.cc @@ -12,13 +12,13 @@ #include <vector> #include "base/base64.h" +#include "base/bind.h" #include "base/compiler_specific.h" #include "base/json/json_writer.h" #include "base/location.h" #include "base/logging.h" #include "base/memory/ref_counted.h" #include "base/message_loop.h" -#include "base/task.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sync/glue/data_type_controller.h" #include "chrome/browser/sync/sessions/session_state.h" diff --git a/chrome/browser/sync/profile_sync_service_password_unittest.cc b/chrome/browser/sync/profile_sync_service_password_unittest.cc index fff8fdc..2208bcd 100644 --- a/chrome/browser/sync/profile_sync_service_password_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_password_unittest.cc @@ -9,7 +9,6 @@ #include "base/bind.h" #include "base/location.h" #include "base/synchronization/waitable_event.h" -#include "base/task.h" #include "base/test/test_timeouts.h" #include "base/time.h" #include "base/utf_string_conversions.h" diff --git a/chrome/browser/sync/profile_sync_service_preference_unittest.cc b/chrome/browser/sync/profile_sync_service_preference_unittest.cc index 9db995b..17fc166f 100644 --- a/chrome/browser/sync/profile_sync_service_preference_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_preference_unittest.cc @@ -13,7 +13,6 @@ #include "base/location.h" #include "base/stl_util.h" #include "base/string_piece.h" -#include "base/task.h" #include "chrome/browser/prefs/pref_model_associator.h" #include "chrome/browser/prefs/scoped_user_pref_update.h" #include "chrome/browser/sync/abstract_profile_sync_service_test.h" diff --git a/chrome/browser/sync/profile_sync_service_session_unittest.cc b/chrome/browser/sync/profile_sync_service_session_unittest.cc index 9214e41..6bede13 100644 --- a/chrome/browser/sync/profile_sync_service_session_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_session_unittest.cc @@ -14,7 +14,6 @@ #include "base/message_loop.h" #include "base/scoped_temp_dir.h" #include "base/stl_util.h" -#include "base/task.h" #include "base/time.h" #include "chrome/browser/sessions/session_service.h" #include "chrome/browser/sessions/session_service_factory.h" diff --git a/chrome/browser/sync/profile_sync_test_util.cc b/chrome/browser/sync/profile_sync_test_util.cc index d36f908..2211aa1 100644 --- a/chrome/browser/sync/profile_sync_test_util.cc +++ b/chrome/browser/sync/profile_sync_test_util.cc @@ -5,7 +5,6 @@ #include "chrome/browser/sync/profile_sync_test_util.h" #include "base/bind.h" -#include "base/task.h" #include "base/threading/thread.h" using content::BrowserThread; diff --git a/chrome/browser/sync/test/engine/mock_connection_manager.cc b/chrome/browser/sync/test/engine/mock_connection_manager.cc index a48e1ee..05a345fa 100644 --- a/chrome/browser/sync/test/engine/mock_connection_manager.cc +++ b/chrome/browser/sync/test/engine/mock_connection_manager.cc @@ -70,8 +70,9 @@ void MockConnectionManager::SetCommitTimeRename(string prepend) { commit_time_rename_prepended_string_ = prepend; } -void MockConnectionManager::SetMidCommitCallback(Callback0::Type* callback) { - mid_commit_callback_.reset(callback); +void MockConnectionManager::SetMidCommitCallback( + const base::Closure& callback) { + mid_commit_callback_ = callback; } void MockConnectionManager::SetMidCommitObserver( @@ -158,8 +159,8 @@ bool MockConnectionManager::PostBufferToPath(PostBufferParams* params, response.SerializeToString(¶ms->buffer_out); if (post.message_contents() == ClientToServerMessage::COMMIT && - mid_commit_callback_.get()) { - mid_commit_callback_->Run(); + !mid_commit_callback_.is_null()) { + mid_commit_callback_.Run(); } if (mid_commit_observer_) { mid_commit_observer_->Observe(); diff --git a/chrome/browser/sync/test/engine/mock_connection_manager.h b/chrome/browser/sync/test/engine/mock_connection_manager.h index 9661c2d..4ea6c3e 100644 --- a/chrome/browser/sync/test/engine/mock_connection_manager.h +++ b/chrome/browser/sync/test/engine/mock_connection_manager.h @@ -51,7 +51,7 @@ class MockConnectionManager : public browser_sync::ServerConnectionManager { virtual bool IsUserAuthenticated() OVERRIDE; // Control of commit response. - void SetMidCommitCallback(Callback0::Type* callback); + void SetMidCommitCallback(const base::Closure& callback); void SetMidCommitObserver(MidCommitObserver* observer); // Set this if you want commit to perform commit time rename. Will request @@ -318,7 +318,7 @@ class MockConnectionManager : public browser_sync::ServerConnectionManager { // The updates we'll return to the next request. std::list<sync_pb::GetUpdatesResponse> update_queue_; - scoped_ptr<Callback0::Type> mid_commit_callback_; + base::Closure mid_commit_callback_; MidCommitObserver* mid_commit_observer_; // The clear data response we'll return in the next response diff --git a/chrome/browser/sync/test/integration/sync_test.cc b/chrome/browser/sync/test/integration/sync_test.cc index 895ac42..e7a6e53 100644 --- a/chrome/browser/sync/test/integration/sync_test.cc +++ b/chrome/browser/sync/test/integration/sync_test.cc @@ -14,7 +14,6 @@ #include "base/string_util.h" #include "base/stringprintf.h" #include "base/synchronization/waitable_event.h" -#include "base/task.h" #include "base/test/test_timeouts.h" #include "base/threading/platform_thread.h" #include "base/utf_string_conversions.h" diff --git a/chrome/browser/sync/test/integration/sync_test.h b/chrome/browser/sync/test/integration/sync_test.h index 10c08ca..a8e418e 100644 --- a/chrome/browser/sync/test/integration/sync_test.h +++ b/chrome/browser/sync/test/integration/sync_test.h @@ -17,7 +17,6 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/scoped_vector.h" #include "base/process_util.h" -#include "base/task.h" #include "chrome/browser/sync/protocol/sync_protocol_error.h" #include "chrome/browser/sync/syncable/model_type.h" #include "net/base/mock_host_resolver.h" @@ -322,6 +321,4 @@ class SyncTest : public InProcessBrowserTest { DISALLOW_COPY_AND_ASSIGN(SyncTest); }; -DISABLE_RUNNABLE_METHOD_REFCOUNT(SyncTest); - #endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_SYNC_TEST_H_ |