- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync / glue / password_model_worker.h
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_PASSWORD_MODEL_WORKER_H_
6 #define CHROME_BROWSER_SYNC_GLUE_PASSWORD_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
15 class PasswordStore;
16
17 namespace base {
18 class WaitableEvent;
19 }
20
21 namespace browser_sync {
22
23 // A syncer::ModelSafeWorker for password models that accepts requests
24 // from the syncapi that need to be fulfilled on the password thread,
25 // which is the DB thread on Linux and Windows.
26 class PasswordModelWorker : public syncer::ModelSafeWorker {
27  public:
28   PasswordModelWorker(const scoped_refptr<PasswordStore>& password_store,
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   virtual void RequestStop() OVERRIDE;
35
36  protected:
37   virtual syncer::SyncerError DoWorkAndWaitUntilDoneImpl(
38       const syncer::WorkCallback& work) OVERRIDE;
39
40  private:
41   virtual ~PasswordModelWorker();
42
43   void CallDoWorkAndSignalTask(
44     const syncer::WorkCallback& work,
45     base::WaitableEvent* done,
46     syncer::SyncerError* error);
47
48   // Called on password thread to add PasswordModelWorker as destruction
49   // observer.
50   void RegisterForPasswordLoopDestruction();
51
52   // |password_store_| is used on password thread but released on UI thread.
53   // Protected by |password_store_lock_|.
54   base::Lock password_store_lock_;
55   scoped_refptr<PasswordStore> password_store_;
56   DISALLOW_COPY_AND_ASSIGN(PasswordModelWorker);
57 };
58
59 }  // namespace browser_sync
60
61 #endif  // CHROME_BROWSER_SYNC_GLUE_PASSWORD_MODEL_WORKER_H_