Home | History | Annotate | Download | only in glue
      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 namespace base {
     16 class WaitableEvent;
     17 }
     18 
     19 namespace password_manager {
     20 class PasswordStore;
     21 }
     22 
     23 namespace browser_sync {
     24 
     25 // A syncer::ModelSafeWorker for password models that accepts requests
     26 // from the syncapi that need to be fulfilled on the password thread,
     27 // which is the DB thread on Linux and Windows.
     28 class PasswordModelWorker : public syncer::ModelSafeWorker {
     29  public:
     30   PasswordModelWorker(
     31       const scoped_refptr<password_manager::PasswordStore>& password_store,
     32       syncer::WorkerLoopDestructionObserver* observer);
     33 
     34   // syncer::ModelSafeWorker implementation. Called on syncapi SyncerThread.
     35   virtual void RegisterForLoopDestruction() OVERRIDE;
     36   virtual syncer::ModelSafeGroup GetModelSafeGroup() OVERRIDE;
     37   virtual void RequestStop() OVERRIDE;
     38 
     39  protected:
     40   virtual syncer::SyncerError DoWorkAndWaitUntilDoneImpl(
     41       const syncer::WorkCallback& work) OVERRIDE;
     42 
     43  private:
     44   virtual ~PasswordModelWorker();
     45 
     46   void CallDoWorkAndSignalTask(
     47     const syncer::WorkCallback& work,
     48     base::WaitableEvent* done,
     49     syncer::SyncerError* error);
     50 
     51   // Called on password thread to add PasswordModelWorker as destruction
     52   // observer.
     53   void RegisterForPasswordLoopDestruction();
     54 
     55   // |password_store_| is used on password thread but released on UI thread.
     56   // Protected by |password_store_lock_|.
     57   base::Lock password_store_lock_;
     58   scoped_refptr<password_manager::PasswordStore> password_store_;
     59   DISALLOW_COPY_AND_ASSIGN(PasswordModelWorker);
     60 };
     61 
     62 }  // namespace browser_sync
     63 
     64 #endif  // CHROME_BROWSER_SYNC_GLUE_PASSWORD_MODEL_WORKER_H_
     65