Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(554)

Side by Side Diff: chrome/browser/sync/glue/password_model_associator.h

Issue 1851004: Adding sync support for Passwords (Closed)
Patch Set: Ready for checkin Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2010 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_ASSOCIATOR_H_
6 #define CHROME_BROWSER_SYNC_GLUE_PASSWORD_MODEL_ASSOCIATOR_H_
7
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
12
13 #include "base/basictypes.h"
14 #include "base/lock.h"
15 #include "base/scoped_ptr.h"
16 #include "base/task.h"
17 #include "chrome/browser/chrome_thread.h"
18 #include "chrome/browser/history/history_types.h"
19 #include "chrome/browser/sync/glue/model_associator.h"
20 #include "chrome/browser/sync/protocol/password_specifics.pb.h"
21
22 class GURL;
23 class MessageLoop;
24 class PasswordStore;
25 class ProfileSyncService;
26
27 namespace webkit_glue {
28 struct PasswordForm;
29 };
30
31 namespace sync_api {
32 class WriteNode;
33 class WriteTransaction;
34 };
35
36 namespace browser_sync {
37
38 class PasswordChangeProcessor;
39 class UnrecoverableErrorHandler;
40
41 extern const char kPasswordTag[];
42
43 // Contains all model association related logic:
44 // * Algorithm to associate password model and sync model.
45 // * Persisting model associations and loading them back.
46 // We do not check if we have local data before this runs; we always
47 // merge and sync.
48 class PasswordModelAssociator
49 : public PerDataTypeAssociatorInterface<std::string, std::string> {
50 public:
51 typedef std::vector<webkit_glue::PasswordForm> PasswordVector;
52
53 static syncable::ModelType model_type() { return syncable::PASSWORD; }
54 PasswordModelAssociator(ProfileSyncService* sync_service,
55 PasswordStore* password_store,
56 UnrecoverableErrorHandler* error_handler);
57 virtual ~PasswordModelAssociator() { }
58
59 // PerDataTypeAssociatorInterface implementation.
60 //
61 // Iterates through the sync model looking for matched pairs of items.
62 virtual bool AssociateModels();
63
64 // Delete all password nodes.
65 bool DeleteAllNodes(sync_api::WriteTransaction* trans);
66
67 // Clears all associations.
68 virtual bool DisassociateModels();
69
70 // The has_nodes out param is true if the sync model has nodes other
71 // than the permanent tagged nodes.
72 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes);
73
74 // The has_nodes out param is true if the autofill model has any
75 // user-defined password entries.
76 virtual bool ChromeModelHasUserCreatedNodes(bool* has_nodes);
77
78 // See ModelAssociator interface.
79 virtual void AbortAssociation();
80
81 // Not implemented.
82 virtual const std::string* GetChromeNodeFromSyncId(int64 sync_id) {
83 return NULL;
84 }
85
86 // Not implemented.
87 virtual bool InitSyncNodeFromChromeId(std::string node_id,
88 sync_api::BaseNode* sync_node) {
89 return false;
90 }
91
92 // Returns the sync id for the given password name, or sync_api::kInvalidId
93 // if the password name is not associated to any sync id.
94 virtual int64 GetSyncIdFromChromeId(std::string node_id);
95
96 // Associates the given password name with the given sync id.
97 virtual void Associate(const std::string* node, int64 sync_id);
98
99 // Remove the association that corresponds to the given sync id.
100 virtual void Disassociate(int64 sync_id);
101
102 // Returns whether a node with the given permanent tag was found and update
103 // |sync_id| with that node's id.
104 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id);
105
106 bool WriteToPasswordStore(const PasswordVector* new_passwords,
107 const PasswordVector* updated_passwords,
108 const PasswordVector* deleted_passwords);
109
110 static std::string MakeTag(const webkit_glue::PasswordForm& password);
111 static std::string MakeTag(const sync_pb::PasswordSpecificsData& password);
112 static std::string MakeTag(const std::string& signon_realm,
113 const std::string& origin,
114 const std::string& action);
115
116 static void CopyPassword(const sync_pb::PasswordSpecificsData& password,
117 webkit_glue::PasswordForm* new_password);
118
119 static bool MergePasswords(const sync_pb::PasswordSpecificsData& password,
120 const webkit_glue::PasswordForm& password_form,
121 webkit_glue::PasswordForm* new_password);
122 static void WriteToSyncNode(const webkit_glue::PasswordForm& password_form,
123 sync_api::WriteNode* node);
124
125 // Called at various points in model association to determine if the
126 // user requested an abort.
127 bool IsAbortPending();
128
129 protected:
130 // Returns sync service instance.
131 ProfileSyncService* sync_service() { return sync_service_; }
132
133 private:
134 typedef std::map<std::string, int64> PasswordToSyncIdMap;
135 typedef std::map<int64, std::string> SyncIdToPasswordMap;
136
137 ProfileSyncService* sync_service_;
138 PasswordStore* password_store_;
139 UnrecoverableErrorHandler* error_handler_;
140 int64 password_node_id_;
141
142 // Abort association pending flag and lock. If this is set to true
143 // (via the AbortAssociation method), return from the
144 // AssociateModels method as soon as possible.
145 Lock abort_association_pending_lock_;
146 bool abort_association_pending_;
147
148 MessageLoop* expected_loop_;
149
150 PasswordToSyncIdMap id_map_;
151 SyncIdToPasswordMap id_map_inverse_;
152
153 DISALLOW_COPY_AND_ASSIGN(PasswordModelAssociator);
154 };
155
156 } // namespace browser_sync
157
158 #endif // CHROME_BROWSER_SYNC_GLUE_PASSWORD_MODEL_ASSOCIATOR_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/password_data_type_controller.cc ('k') | chrome/browser/sync/glue/password_model_associator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698