Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / sync / glue / password_change_processor.h
blob5a5d80e869f402aa27e064ef1b313ec6dd0dd843
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.
5 #ifndef CHROME_BROWSER_SYNC_GLUE_PASSWORD_CHANGE_PROCESSOR_H_
6 #define CHROME_BROWSER_SYNC_GLUE_PASSWORD_CHANGE_PROCESSOR_H_
8 #include "chrome/browser/sync/glue/change_processor.h"
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"
19 class PasswordStore;
21 namespace base {
22 class MessageLoop;
25 namespace browser_sync {
27 class DataTypeErrorHandler;
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();
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;
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;
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;
59 // Stop processing changes and wait for being destroyed.
60 void Disconnect();
62 protected:
63 virtual void StartImpl(Profile* profile) OVERRIDE;
65 private:
66 friend class ScopedStopObserving<PasswordChangeProcessor>;
67 void StartObserving();
68 void StopObserving();
70 // Registers to observe password change for the first time.
71 void InitObserving();
73 // The two models should be associated according to this ModelAssociator.
74 PasswordModelAssociator* model_associator_;
76 // The model we are processing changes from. This is owned by the
77 // WebDataService which is kept alive by our data type controller
78 // holding a reference.
79 scoped_refptr<PasswordStore> password_store_;
81 // Buffers used between ApplyChangesFromSyncModel and
82 // CommitChangesFromSyncModel.
83 PasswordModelAssociator::PasswordVector new_passwords_;
84 PasswordModelAssociator::PasswordVector updated_passwords_;
85 PasswordModelAssociator::PasswordVector deleted_passwords_;
87 content::NotificationRegistrar notification_registrar_;
89 base::MessageLoop* expected_loop_;
91 // If disconnected is true, local/sync changes are dropped without modifying
92 // sync/local models.
93 bool disconnected_;
94 base::Lock disconnect_lock_;
96 DISALLOW_COPY_AND_ASSIGN(PasswordChangeProcessor);
99 } // namespace browser_sync
101 #endif // CHROME_BROWSER_SYNC_GLUE_PASSWORD_CHANGE_PROCESSOR_H_