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