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

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

Issue 5159001: Rest of the autofill work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Autofill code after fixing the lint errors. Created 10 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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.s
4 4
5 #ifndef CHROME_BROWSER_SYNC_GLUE_AUTOFILL_PROFILE_MODEL_ASSOCIATOR_H_ 5 #ifndef CHROME_BROWSER_SYNC_GLUE_AUTOFILL_PROFILE_MODEL_ASSOCIATOR_H_
6 #define CHROME_BROWSER_SYNC_GLUE_AUTOFILL_PROFILE_MODEL_ASSOCIATOR_H_ 6 #define CHROME_BROWSER_SYNC_GLUE_AUTOFILL_PROFILE_MODEL_ASSOCIATOR_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
(...skipping 10 matching lines...) Expand all
24 24
25 class ProfileSyncService; 25 class ProfileSyncService;
26 class WebDatabase; 26 class WebDatabase;
27 27
28 namespace sync_api { 28 namespace sync_api {
29 class WriteTransaction; 29 class WriteTransaction;
30 } 30 }
31 31
32 namespace browser_sync { 32 namespace browser_sync {
33 33
34 extern const char kAutofillProfileTag[];
35
34 class AutofillChangeProcessor; 36 class AutofillChangeProcessor;
35 class UnrecoverableErrorHandler; 37 class UnrecoverableErrorHandler;
36 38
37 // Contains all model association related logic: 39 // Contains all model association related logic:
38 // * Algorithm to associate autofill model and sync model. 40 // * Algorithm to associate autofill model and sync model.
39 // We do not check if we have local data before this run; we always 41 // We do not check if we have local data before this run; we always
40 // merge and sync. 42 // merge and sync.
41 class AutofillProfileModelAssociator 43 class AutofillProfileModelAssociator
42 : public PerDataTypeAssociatorInterface<std::string, std::string> { 44 : public PerDataTypeAssociatorInterface<std::string, std::string> {
43 public: 45 public:
(...skipping 19 matching lines...) Expand all
63 virtual bool DisassociateModels(); 65 virtual bool DisassociateModels();
64 66
65 // TODO(lipalani) Bug 64111. 67 // TODO(lipalani) Bug 64111.
66 // The has_nodes out param is true if the sync model has nodes other 68 // The has_nodes out param is true if the sync model has nodes other
67 // than the permanent tagged nodes. 69 // than the permanent tagged nodes.
68 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes); 70 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes);
69 71
70 // See ModelAssociator interface. 72 // See ModelAssociator interface.
71 virtual void AbortAssociation(); 73 virtual void AbortAssociation();
72 74
73 virtual const std::string* GetChromeNodeFromSyncId( 75 virtual const std::string* GetChromeNodeFromSyncId(int64 sync_id);
74 int64 sync_id) {
75 return NULL;
76 }
77 76
78 virtual bool InitSyncNodeFromChromeId(std::string node_id, 77 virtual bool InitSyncNodeFromChromeId(std::string node_id,
79 sync_api::BaseNode* sync_node) { 78 sync_api::BaseNode* sync_node) {
80 return false; 79 return false;
81 } 80 }
82 81
83 // Returns the sync id for the given autofill name, or sync_api::kInvalidId 82 // Returns the sync id for the given autofill name, or sync_api::kInvalidId
84 // if the autofill name is not associated to any sync id. 83 // if the autofill name is not associated to any sync id.
85 virtual int64 GetSyncIdFromChromeId(std::string node_id); 84 virtual int64 GetSyncIdFromChromeId(std::string node_id);
86 85
87 // Associates the given autofill name with the given sync id. 86 // Associates the given autofill name with the given sync id.
88 virtual void Associate(const std::string* node, int64 sync_id); 87 virtual void Associate(const std::string* node, int64 sync_id);
89 88
90 // Remove the association that corresponds to the given sync id. 89 // Remove the association that corresponds to the given sync id.
91 virtual void Disassociate(int64 sync_id); 90 virtual void Disassociate(int64 sync_id);
92 91
93 // TODO(lipalani) Bug 64111. Returns whether a node with the 92 // TODO(lipalani) Bug 64111. Returns whether a node with the
94 // given permanent tag was found and update 93 // given permanent tag was found and update
95 // |sync_id| with that node's id. No current use. To Implement 94 // |sync_id| with that node's id. No current use. To Implement
96 // only for completeness. 95 // only for completeness.
97 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id) { 96 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id);
98 return false;
99 }
100 97
101 // Returns sync service instance. 98 // Returns sync service instance.
102 ProfileSyncService* sync_service() { return sync_service_; } 99 ProfileSyncService* sync_service() { return sync_service_; }
103 100
101 static bool OverwriteProfileWithServerData(
102 AutoFillProfile* merge_into,
103 const sync_pb::AutofillProfileSpecifics& specifics);
104
lipalani 2010/12/09 19:45:25 remove the extra space here.
lipalani 2010/12/11 00:12:36 Done.
104 protected: 105 protected:
105 AutofillProfileModelAssociator() {} 106 AutofillProfileModelAssociator() {}
106 bool TraverseAndAssociateChromeAutoFillProfiles( 107 bool TraverseAndAssociateChromeAutoFillProfiles(
107 sync_api::WriteTransaction* write_trans, 108 sync_api::WriteTransaction* write_trans,
108 const sync_api::ReadNode& autofill_root, 109 const sync_api::ReadNode& autofill_root,
109 const std::vector<AutoFillProfile*>& all_profiles_from_db, 110 const std::vector<AutoFillProfile*>& all_profiles_from_db,
110 std::set<std::string>* current_profiles, 111 std::set<std::string>* current_profiles,
111 std::vector<AutoFillProfile*>* updated_profiles, 112 std::vector<AutoFillProfile*>* updated_profiles,
112 std::vector<AutoFillProfile*>* new_profiles, 113 std::vector<AutoFillProfile*>* new_profiles,
113 std::vector<std::string>* profiles_to_delete); 114 std::vector<std::string>* profiles_to_delete);
114 115
115 // Helper to insert an AutoFillProfile into the WebDatabase (e.g. in response 116 // Helper to insert an AutoFillProfile into the WebDatabase (e.g. in response
116 // to encountering a sync node that doesn't exist yet locally). 117 // to encountering a sync node that doesn't exist yet locally).
117 virtual void AddNativeProfileIfNeeded( 118 virtual void AddNativeProfileIfNeeded(
118 const sync_pb::AutofillProfileSpecifics& profile, 119 const sync_pb::AutofillProfileSpecifics& profile,
119 DataBundle* bundle, 120 DataBundle* bundle,
120 const sync_api::ReadNode& node); 121 const sync_api::ReadNode& node);
121 122
122 // Helper to insert a sync node for the given AutoFillProfile (e.g. in 123 // Helper to insert a sync node for the given AutoFillProfile (e.g. in
123 // response to encountering a native profile that doesn't exist yet in the 124 // response to encountering a native profile that doesn't exist yet in the
124 // cloud). 125 // cloud).
125 virtual bool MakeNewAutofillProfileSyncNodeIfNeeded( 126 virtual bool MakeNewAutofillProfileSyncNodeIfNeeded(
126 sync_api::WriteTransaction* trans, 127 sync_api::WriteTransaction* trans,
127 const sync_api::BaseNode& autofill_root, 128 const sync_api::BaseNode& autofill_root,
128 const AutoFillProfile& profile, 129 const AutoFillProfile& profile,
129 std::vector<AutoFillProfile*>* new_profiles, 130 std::vector<AutoFillProfile*>* new_profiles,
130 std::set<std::string>* current_profiles, 131 std::set<std::string>* current_profiles,
131 std::vector<std::string>* profiles_to_delete); 132 std::vector<std::string>* profiles_to_delete);
132 133
133 // Once the above traversals are complete, we traverse the sync model to 134 // Once the above traversals are complete, we traverse the sync model to
134 // associate all remaining nodes. 135 // associate all remaining nodes.
135 bool TraverseAndAssociateAllSyncNodes( 136 bool TraverseAndAssociateAllSyncNodes(
136 sync_api::WriteTransaction* write_trans, 137 sync_api::WriteTransaction* write_trans,
137 const sync_api::ReadNode& autofill_root, 138 const sync_api::ReadNode& autofill_root,
138 DataBundle* bundle); 139 DataBundle* bundle);
139 140
140 static bool OverwriteProfileWithServerData(
141 AutoFillProfile* merge_into,
142 const sync_pb::AutofillProfileSpecifics& specifics);
143
144 private: 141 private:
145 typedef std::map<std::string, int64> AutofillToSyncIdMap; 142 typedef std::map<std::string, int64> AutofillToSyncIdMap;
146 typedef std::map<int64, std::string> SyncIdToAutofillMap; 143 typedef std::map<int64, std::string> SyncIdToAutofillMap;
147 144
148 // A convenience wrapper of a bunch of state we pass around while associating 145 // A convenience wrapper of a bunch of state we pass around while associating
149 // models, and send to the WebDatabase for persistence. 146 // models, and send to the WebDatabase for persistence.
150 // struct DataBundle; 147 // struct DataBundle;
151 148
152 // Helper to query WebDatabase for the current autofill state. 149 // Helper to query WebDatabase for the current autofill state.
153 bool LoadAutofillData(std::vector<AutoFillProfile*>* profiles); 150 bool LoadAutofillData(std::vector<AutoFillProfile*>* profiles);
(...skipping 20 matching lines...) Expand all
174 int64 autofill_node_id_; 171 int64 autofill_node_id_;
175 172
176 AutofillToSyncIdMap id_map_; 173 AutofillToSyncIdMap id_map_;
177 SyncIdToAutofillMap id_map_inverse_; 174 SyncIdToAutofillMap id_map_inverse_;
178 175
179 // Abort association pending flag and lock. If this is set to true 176 // Abort association pending flag and lock. If this is set to true
180 // (via the AbortAssociation method), return from the 177 // (via the AbortAssociation method), return from the
181 // AssociateModels method as soon as possible. 178 // AssociateModels method as soon as possible.
182 Lock abort_association_pending_lock_; 179 Lock abort_association_pending_lock_;
183 bool abort_association_pending_; 180 bool abort_association_pending_;
181 int number_of_profiles_created_;
184 182
185 DISALLOW_COPY_AND_ASSIGN(AutofillProfileModelAssociator); 183 DISALLOW_COPY_AND_ASSIGN(AutofillProfileModelAssociator);
186 }; 184 };
187 185
188 struct AutofillProfileModelAssociator::DataBundle { 186 struct AutofillProfileModelAssociator::DataBundle {
189 std::set<std::string> current_profiles; 187 std::set<std::string> current_profiles;
190 std::vector<std::string> profiles_to_delete; 188 std::vector<std::string> profiles_to_delete;
191 std::vector<AutoFillProfile*> updated_profiles; 189 std::vector<AutoFillProfile*> updated_profiles;
192 std::vector<AutoFillProfile*> new_profiles; // We own these pointers. 190 std::vector<AutoFillProfile*> new_profiles; // We own these pointers.
193 ~DataBundle() { STLDeleteElements(&new_profiles); } 191 ~DataBundle() { STLDeleteElements(&new_profiles); }
194 }; 192 };
195 193
196 } // namespace browser_sync 194 } // namespace browser_sync
197 195
198 #endif // CHROME_BROWSER_SYNC_GLUE_AUTOFILL_PROFILE_MODEL_ASSOCIATOR_H_ 196 #endif // CHROME_BROWSER_SYNC_GLUE_AUTOFILL_PROFILE_MODEL_ASSOCIATOR_H_
199 197
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698