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. 4 5 #ifndef CHROME_BROWSER_SYNC_GLUE_HISTORY_MODEL_WORKER_H_ 6 #define CHROME_BROWSER_SYNC_GLUE_HISTORY_MODEL_WORKER_H_ 7 8 #include "sync/internal_api/public/engine/model_safe_worker.h" 9 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" 18 19 class HistoryService; 20 21 namespace browser_sync { 22 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 { 26 public: 27 explicit HistoryModelWorker( 28 const base::WeakPtr<HistoryService>& history_service, 29 syncer::WorkerLoopDestructionObserver* observer); 30 31 // syncer::ModelSafeWorker implementation. Called on syncapi SyncerThread. 32 virtual void RegisterForLoopDestruction() OVERRIDE; 33 virtual syncer::ModelSafeGroup GetModelSafeGroup() OVERRIDE; 34 35 // Called on history DB thread to register HistoryModelWorker to observe 36 // destruction of history backend loop. 37 void RegisterOnDBThread(); 38 39 protected: 40 virtual syncer::SyncerError DoWorkAndWaitUntilDoneImpl( 41 const syncer::WorkCallback& work) OVERRIDE; 42 43 private: 44 virtual ~HistoryModelWorker(); 45 46 const base::WeakPtr<HistoryService> history_service_; 47 // Helper object to make sure we don't leave tasks running on the history 48 // thread. 49 CancelableRequestConsumerT<int, 0> cancelable_consumer_; 50 DISALLOW_COPY_AND_ASSIGN(HistoryModelWorker); 51 }; 52 53 } // namespace browser_sync 54 55 #endif // CHROME_BROWSER_SYNC_GLUE_HISTORY_MODEL_WORKER_H_ 56