1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SYNC_GLUE_HISTORY_MODEL_WORKER_H_
6 #define CHROME_BROWSER_SYNC_GLUE_HISTORY_MODEL_WORKER_H_
8 #include "sync/internal_api/public/engine/model_safe_worker.h"
10 #include "base/basictypes.h"
11 #include "base/callback_forward.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h"
15 #include "chrome/browser/common/cancelable_request.h"
16 #include "chrome/browser/history/history_db_task.h"
17 #include "chrome/browser/history/history_service.h"
21 namespace browser_sync
{
23 // A syncer::ModelSafeWorker for history models that accepts requests
24 // from the syncapi that need to be fulfilled on the history thread.
25 class HistoryModelWorker
: public syncer::ModelSafeWorker
{
27 explicit HistoryModelWorker(
28 const base::WeakPtr
<HistoryService
>& history_service
,
29 syncer::WorkerLoopDestructionObserver
* observer
);
31 // syncer::ModelSafeWorker implementation. Called on syncapi SyncerThread.
32 virtual void RegisterForLoopDestruction() OVERRIDE
;
33 virtual syncer::ModelSafeGroup
GetModelSafeGroup() OVERRIDE
;
35 // Called on history DB thread to register HistoryModelWorker to observe
36 // destruction of history backend loop.
37 void RegisterOnDBThread();
40 virtual syncer::SyncerError
DoWorkAndWaitUntilDoneImpl(
41 const syncer::WorkCallback
& work
) OVERRIDE
;
44 virtual ~HistoryModelWorker();
46 const base::WeakPtr
<HistoryService
> history_service_
;
47 // Helper object to make sure we don't leave tasks running on the history
49 CancelableRequestConsumerT
<int, 0> cancelable_consumer_
;
50 DISALLOW_COPY_AND_ASSIGN(HistoryModelWorker
);
53 } // namespace browser_sync
55 #endif // CHROME_BROWSER_SYNC_GLUE_HISTORY_MODEL_WORKER_H_