Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Unified Diff: chrome/browser/sync/glue/typed_url_data_type_controller.cc

Issue 9264062: [Sync] Consolidate DataTypeController methods that post on the backend thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add suppressions Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/sync/glue/typed_url_data_type_controller.cc
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 835022602b55ecf4c4f93aa36f99fdcc50d8ecf5..ec56c8827986c8a627a6fd617018b4afcfecf4ff 100644
--- a/chrome/browser/sync/glue/typed_url_data_type_controller.cc
+++ b/chrome/browser/sync/glue/typed_url_data_type_controller.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/sync/glue/typed_url_data_type_controller.h"
+#include "base/bind.h"
+#include "base/callback.h"
#include "base/metrics/histogram.h"
#include "chrome/browser/history/history.h"
#include "chrome/browser/prefs/pref_service.h"
@@ -15,32 +17,34 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_details.h"
+namespace browser_sync {
+
using content::BrowserThread;
-namespace browser_sync {
+namespace {
-class ControlTask : public HistoryDBTask {
+typedef base::Callback<void(history::HistoryBackend*)> HistoryBackendTask;
+
+class RunHistoryBackendTask : public HistoryDBTask {
public:
- ControlTask(TypedUrlDataTypeController* controller, bool start)
- : controller_(controller), start_(start) {}
+ explicit RunHistoryBackendTask(const HistoryBackendTask& task)
+ : task_(task) {}
+ virtual ~RunHistoryBackendTask() {}
virtual bool RunOnDBThread(history::HistoryBackend* backend,
history::HistoryDatabase* db) {
- controller_->RunOnHistoryThread(start_, backend);
-
- // Release the reference to the controller. This ensures that
- // the controller isn't held past its lifetime in unit tests.
- controller_ = NULL;
+ task_.Run(backend);
return true;
}
virtual void DoneRunOnMainThread() {}
protected:
- scoped_refptr<TypedUrlDataTypeController> controller_;
- bool start_;
+ HistoryBackendTask task_;
};
+} // namespace
+
TypedUrlDataTypeController::TypedUrlDataTypeController(
ProfileSyncComponentsFactory* profile_sync_factory,
Profile* profile,
@@ -56,30 +60,19 @@ TypedUrlDataTypeController::TypedUrlDataTypeController(
TypedUrlDataTypeController::~TypedUrlDataTypeController() {
}
-void TypedUrlDataTypeController::RunOnHistoryThread(bool start,
- history::HistoryBackend* backend) {
- DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
- // The only variable we can access here is backend_, since it is always
- // read from the DB thread. Touching anything else could lead to memory
- // corruption.
- backend_ = backend;
- if (start) {
- StartAssociation();
- } else {
- StopAssociation();
- }
- backend_ = NULL;
-}
-
-bool TypedUrlDataTypeController::StartAssociationAsync() {
+bool TypedUrlDataTypeController::PostTaskOnBackendThread(
+ const tracked_objects::Location& from_here,
+ const base::Closure& task) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK_EQ(state(), ASSOCIATING);
HistoryService* history = profile()->GetHistoryService(
Profile::IMPLICIT_ACCESS);
if (history) {
history_service_ = history;
- history_service_->ScheduleDBTask(new ControlTask(this, true),
- &cancelable_consumer_);
+ history_service_->ScheduleDBTask(
+ new RunHistoryBackendTask(
+ base::Bind(&TypedUrlDataTypeController::RunTaskOnBackendThread,
+ this, task)),
+ &cancelable_consumer_);
return true;
} else {
// History must be disabled - don't start.
@@ -88,6 +81,14 @@ bool TypedUrlDataTypeController::StartAssociationAsync() {
}
}
+void TypedUrlDataTypeController::RunTaskOnBackendThread(
+ const base::Closure& task,
+ history::HistoryBackend* backend) {
+ // Store |backend| so that |task| can use it.
+ backend_ = backend;
+ task.Run();
+}
+
void TypedUrlDataTypeController::CreateSyncComponents() {
DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK_EQ(state(), ASSOCIATING);
@@ -134,15 +135,6 @@ void TypedUrlDataTypeController::StopModels() {
notification_registrar_.RemoveAll();
}
-bool TypedUrlDataTypeController::StopAssociationAsync() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK_EQ(state(), STOPPING);
- DCHECK(history_service_.get());
- history_service_->ScheduleDBTask(new ControlTask(this, false),
- &cancelable_consumer_);
- return true;
-}
-
syncable::ModelType TypedUrlDataTypeController::type() const {
return syncable::TYPED_URLS;
}

Powered by Google App Engine
This is Rietveld 408576698