Home | History | Annotate | Download | only in glue
      1 // Copyright (c) 2011 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_CHANGE_PROCESSOR_H_
      6 #define CHROME_BROWSER_SYNC_GLUE_PASSWORD_CHANGE_PROCESSOR_H_
      7 #pragma once
      8 
      9 #include "chrome/browser/sync/glue/change_processor.h"
     10 
     11 #include "base/basictypes.h"
     12 #include "base/compiler_specific.h"
     13 #include "chrome/browser/sync/glue/password_model_associator.h"
     14 #include "chrome/browser/sync/glue/sync_backend_host.h"
     15 #include "content/common/notification_observer.h"
     16 #include "content/common/notification_registrar.h"
     17 #include "content/common/notification_type.h"
     18 
     19 class PasswordStore;
     20 class MessageLoop;
     21 class NotificationService;
     22 
     23 namespace browser_sync {
     24 
     25 class UnrecoverableErrorHandler;
     26 
     27 // This class is responsible for taking changes from the password backend and
     28 // applying them to the sync_api 'syncable' model, and vice versa. All
     29 // operations and use of this class are from the DB thread on Windows and Linux,
     30 // or the password thread on Mac.
     31 class PasswordChangeProcessor : public ChangeProcessor,
     32                                 public NotificationObserver {
     33  public:
     34   PasswordChangeProcessor(PasswordModelAssociator* model_associator,
     35                           PasswordStore* password_store,
     36                           UnrecoverableErrorHandler* error_handler);
     37   virtual ~PasswordChangeProcessor();
     38 
     39   // NotificationObserver implementation.
     40   // Passwords -> sync_api model change application.
     41   virtual void Observe(NotificationType type,
     42                        const NotificationSource& source,
     43                        const NotificationDetails& details) OVERRIDE;
     44 
     45   // sync_api model -> WebDataService change application.
     46   virtual void ApplyChangesFromSyncModel(
     47       const sync_api::BaseTransaction* trans,
     48       const sync_api::SyncManager::ChangeRecord* changes,
     49       int change_count) OVERRIDE;
     50 
     51   // Commit changes buffered during ApplyChanges. We must commit them to the
     52   // password store only after the sync_api transaction is released, else there
     53   // is risk of deadlock due to the password store posting tasks to the UI
     54   // thread (http://crbug.com/70658).
     55   virtual void CommitChangesFromSyncModel() OVERRIDE;
     56 
     57  protected:
     58   virtual void StartImpl(Profile* profile) OVERRIDE;
     59   virtual void StopImpl() OVERRIDE;
     60 
     61  private:
     62   void StartObserving();
     63   void StopObserving();
     64 
     65   // The two models should be associated according to this ModelAssociator.
     66   PasswordModelAssociator* model_associator_;
     67 
     68   // The model we are processing changes from.  This is owned by the
     69   // WebDataService which is kept alive by our data type controller
     70   // holding a reference.
     71   PasswordStore* password_store_;
     72 
     73   // Buffers used between ApplyChangesFromSyncModel and
     74   // CommitChangesFromSyncModel.
     75   PasswordModelAssociator::PasswordVector new_passwords_;
     76   PasswordModelAssociator::PasswordVector updated_passwords_;
     77   PasswordModelAssociator::PasswordVector deleted_passwords_;
     78 
     79   NotificationRegistrar notification_registrar_;
     80 
     81   bool observing_;
     82 
     83   MessageLoop* expected_loop_;
     84 
     85   DISALLOW_COPY_AND_ASSIGN(PasswordChangeProcessor);
     86 };
     87 
     88 }  // namespace browser_sync
     89 
     90 #endif  // CHROME_BROWSER_SYNC_GLUE_PASSWORD_CHANGE_PROCESSOR_H_
     91