| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_SYNC_GLUE_PASSWORD_CHANGE_PROCESSOR_H_ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_PASSWORD_CHANGE_PROCESSOR_H_ |
| 6 #define CHROME_BROWSER_SYNC_GLUE_PASSWORD_CHANGE_PROCESSOR_H_ | 6 #define CHROME_BROWSER_SYNC_GLUE_PASSWORD_CHANGE_PROCESSOR_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "chrome/browser/sync/glue/change_processor.h" | 9 #include "chrome/browser/sync/glue/change_processor.h" |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" |
| 13 #include "chrome/browser/sync/glue/password_model_associator.h" |
| 12 #include "chrome/browser/sync/glue/sync_backend_host.h" | 14 #include "chrome/browser/sync/glue/sync_backend_host.h" |
| 13 #include "content/common/notification_observer.h" | 15 #include "content/common/notification_observer.h" |
| 14 #include "content/common/notification_registrar.h" | 16 #include "content/common/notification_registrar.h" |
| 15 #include "content/common/notification_type.h" | 17 #include "content/common/notification_type.h" |
| 16 | 18 |
| 17 class PasswordStore; | 19 class PasswordStore; |
| 18 class MessageLoop; | 20 class MessageLoop; |
| 19 class NotificationService; | 21 class NotificationService; |
| 20 | 22 |
| 21 namespace browser_sync { | 23 namespace browser_sync { |
| 22 | 24 |
| 23 class PasswordModelAssociator; | |
| 24 class UnrecoverableErrorHandler; | 25 class UnrecoverableErrorHandler; |
| 25 | 26 |
| 26 // This class is responsible for taking changes from the password backend and | 27 // This class is responsible for taking changes from the password backend and |
| 27 // applying them to the sync_api 'syncable' model, and vice versa. All | 28 // applying them to the sync_api 'syncable' model, and vice versa. All |
| 28 // operations and use of this class are from the DB thread on Windows and Linux, | 29 // operations and use of this class are from the DB thread on Windows and Linux, |
| 29 // or the password thread on Mac. | 30 // or the password thread on Mac. |
| 30 class PasswordChangeProcessor : public ChangeProcessor, | 31 class PasswordChangeProcessor : public ChangeProcessor, |
| 31 public NotificationObserver { | 32 public NotificationObserver { |
| 32 public: | 33 public: |
| 33 PasswordChangeProcessor(PasswordModelAssociator* model_associator, | 34 PasswordChangeProcessor(PasswordModelAssociator* model_associator, |
| 34 PasswordStore* password_store, | 35 PasswordStore* password_store, |
| 35 UnrecoverableErrorHandler* error_handler); | 36 UnrecoverableErrorHandler* error_handler); |
| 36 virtual ~PasswordChangeProcessor(); | 37 virtual ~PasswordChangeProcessor(); |
| 37 | 38 |
| 38 // NotificationObserver implementation. | 39 // NotificationObserver implementation. |
| 39 // Passwords -> sync_api model change application. | 40 // Passwords -> sync_api model change application. |
| 40 virtual void Observe(NotificationType type, | 41 virtual void Observe(NotificationType type, |
| 41 const NotificationSource& source, | 42 const NotificationSource& source, |
| 42 const NotificationDetails& details); | 43 const NotificationDetails& details) OVERRIDE; |
| 43 | 44 |
| 44 // sync_api model -> WebDataService change application. | 45 // sync_api model -> WebDataService change application. |
| 45 virtual void ApplyChangesFromSyncModel( | 46 virtual void ApplyChangesFromSyncModel( |
| 46 const sync_api::BaseTransaction* trans, | 47 const sync_api::BaseTransaction* trans, |
| 47 const sync_api::SyncManager::ChangeRecord* changes, | 48 const sync_api::SyncManager::ChangeRecord* changes, |
| 48 int change_count); | 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; |
| 49 | 56 |
| 50 protected: | 57 protected: |
| 51 virtual void StartImpl(Profile* profile); | 58 virtual void StartImpl(Profile* profile) OVERRIDE; |
| 52 virtual void StopImpl(); | 59 virtual void StopImpl() OVERRIDE; |
| 53 | 60 |
| 54 private: | 61 private: |
| 55 void StartObserving(); | 62 void StartObserving(); |
| 56 void StopObserving(); | 63 void StopObserving(); |
| 57 | 64 |
| 58 // The two models should be associated according to this ModelAssociator. | 65 // The two models should be associated according to this ModelAssociator. |
| 59 PasswordModelAssociator* model_associator_; | 66 PasswordModelAssociator* model_associator_; |
| 60 | 67 |
| 61 // The model we are processing changes from. This is owned by the | 68 // The model we are processing changes from. This is owned by the |
| 62 // WebDataService which is kept alive by our data type controller | 69 // WebDataService which is kept alive by our data type controller |
| 63 // holding a reference. | 70 // holding a reference. |
| 64 PasswordStore* password_store_; | 71 PasswordStore* password_store_; |
| 65 | 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 |
| 66 NotificationRegistrar notification_registrar_; | 79 NotificationRegistrar notification_registrar_; |
| 67 | 80 |
| 68 bool observing_; | 81 bool observing_; |
| 69 | 82 |
| 70 MessageLoop* expected_loop_; | 83 MessageLoop* expected_loop_; |
| 71 | 84 |
| 72 DISALLOW_COPY_AND_ASSIGN(PasswordChangeProcessor); | 85 DISALLOW_COPY_AND_ASSIGN(PasswordChangeProcessor); |
| 73 }; | 86 }; |
| 74 | 87 |
| 75 } // namespace browser_sync | 88 } // namespace browser_sync |
| 76 | 89 |
| 77 #endif // CHROME_BROWSER_SYNC_GLUE_PASSWORD_CHANGE_PROCESSOR_H_ | 90 #endif // CHROME_BROWSER_SYNC_GLUE_PASSWORD_CHANGE_PROCESSOR_H_ |
| OLD | NEW |