OLD | NEW |
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. |
4 | 4 |
5 #ifndef CHROME_BROWSER_SYNC_GLUE_AUTOFILL_MODEL_ASSOCIATOR_H_ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_AUTOFILL_MODEL_ASSOCIATOR_H_ |
6 #define CHROME_BROWSER_SYNC_GLUE_AUTOFILL_MODEL_ASSOCIATOR_H_ | 6 #define CHROME_BROWSER_SYNC_GLUE_AUTOFILL_MODEL_ASSOCIATOR_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // merge and sync. | 45 // merge and sync. |
46 class AutofillModelAssociator | 46 class AutofillModelAssociator |
47 : public PerDataTypeAssociatorInterface<std::string, std::string> { | 47 : public PerDataTypeAssociatorInterface<std::string, std::string> { |
48 public: | 48 public: |
49 static syncable::ModelType model_type() { return syncable::AUTOFILL; } | 49 static syncable::ModelType model_type() { return syncable::AUTOFILL; } |
50 AutofillModelAssociator(ProfileSyncService* sync_service, | 50 AutofillModelAssociator(ProfileSyncService* sync_service, |
51 WebDatabase* web_database, | 51 WebDatabase* web_database, |
52 PersonalDataManager* data_manager); | 52 PersonalDataManager* data_manager); |
53 virtual ~AutofillModelAssociator(); | 53 virtual ~AutofillModelAssociator(); |
54 | 54 |
55 // A task used by this class and the change processor to inform the | |
56 // PersonalDataManager living on the UI thread that it needs to refresh. | |
57 class DoOptimisticRefreshTask : public Task { | |
58 public: | |
59 explicit DoOptimisticRefreshTask(PersonalDataManager* pdm); | |
60 virtual ~DoOptimisticRefreshTask(); | |
61 virtual void Run(); | |
62 private: | |
63 scoped_refptr<PersonalDataManager> pdm_; | |
64 }; | |
65 | |
66 // PerDataTypeAssociatorInterface implementation. | 55 // PerDataTypeAssociatorInterface implementation. |
67 // | 56 // |
68 // Iterates through the sync model looking for matched pairs of items. | 57 // Iterates through the sync model looking for matched pairs of items. |
69 virtual bool AssociateModels(); | 58 virtual bool AssociateModels(); |
70 | 59 |
71 // Clears all associations. | 60 // Clears all associations. |
72 virtual bool DisassociateModels(); | 61 virtual bool DisassociateModels(); |
73 | 62 |
74 // The has_nodes out param is true if the sync model has nodes other | 63 // The has_nodes out param is true if the sync model has nodes other |
75 // than the permanent tagged nodes. | 64 // than the permanent tagged nodes. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 static bool FillProfileWithServerData( | 96 static bool FillProfileWithServerData( |
108 AutoFillProfile* merge_into, | 97 AutoFillProfile* merge_into, |
109 const sync_pb::AutofillProfileSpecifics& specifics); | 98 const sync_pb::AutofillProfileSpecifics& specifics); |
110 | 99 |
111 // TODO(georgey) : add the same processing for CC info (already in protocol | 100 // TODO(georgey) : add the same processing for CC info (already in protocol |
112 // buffers). | 101 // buffers). |
113 | 102 |
114 // Returns sync service instance. | 103 // Returns sync service instance. |
115 ProfileSyncService* sync_service() { return sync_service_; } | 104 ProfileSyncService* sync_service() { return sync_service_; } |
116 | 105 |
117 protected: | |
118 // Is called to determine if we need to upgrade to the new | 106 // Is called to determine if we need to upgrade to the new |
119 // autofillprofile2 data type. If so we need to sync up autofillprofile | 107 // autofillprofile2 data type. If so we need to sync up autofillprofile |
120 // first to the latest available changes on the server and then upgrade | 108 // first to the latest available changes on the server and then upgrade |
121 // to autofillprofile2. | 109 // to autofillprofile2. |
122 virtual bool HasNotMigratedYet(); | 110 virtual bool HasNotMigratedYet(const sync_api::BaseTransaction* trans); |
123 | 111 |
| 112 protected: |
124 // Given a profile from sync db it tries to match the profile against | 113 // Given a profile from sync db it tries to match the profile against |
125 // one in web db. it ignores the guid and compares the actual data. | 114 // one in web db. it ignores the guid and compares the actual data. |
126 AutoFillProfile* FindCorrespondingNodeFromWebDB( | 115 AutoFillProfile* FindCorrespondingNodeFromWebDB( |
127 const sync_pb::AutofillProfileSpecifics& profile, | 116 const sync_pb::AutofillProfileSpecifics& profile, |
128 const std::vector<AutoFillProfile*>& all_profiles_from_db); | 117 const std::vector<AutoFillProfile*>& all_profiles_from_db); |
129 | 118 |
130 private: | 119 private: |
131 typedef std::map<std::string, int64> AutofillToSyncIdMap; | 120 typedef std::map<std::string, int64> AutofillToSyncIdMap; |
132 typedef std::map<int64, std::string> SyncIdToAutofillMap; | 121 typedef std::map<int64, std::string> SyncIdToAutofillMap; |
133 | 122 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 const sync_api::ReadNode& node); | 162 const sync_api::ReadNode& node); |
174 | 163 |
175 // Helper to insert an AutoFillProfile into the WebDatabase (e.g. in response | 164 // Helper to insert an AutoFillProfile into the WebDatabase (e.g. in response |
176 // to encountering a sync node that doesn't exist yet locally). | 165 // to encountering a sync node that doesn't exist yet locally). |
177 void AddNativeProfileIfNeeded( | 166 void AddNativeProfileIfNeeded( |
178 const sync_pb::AutofillProfileSpecifics& profile, | 167 const sync_pb::AutofillProfileSpecifics& profile, |
179 DataBundle* bundle, | 168 DataBundle* bundle, |
180 const sync_api::ReadNode& node, | 169 const sync_api::ReadNode& node, |
181 const std::vector<AutoFillProfile*>& all_profiles_from_db); | 170 const std::vector<AutoFillProfile*>& all_profiles_from_db); |
182 | 171 |
183 // Helper to insert a sync node for the given AutoFillProfile (e.g. in | |
184 // response to encountering a native profile that doesn't exist yet in the | |
185 // cloud). | |
186 bool MakeNewAutofillProfileSyncNode( | |
187 sync_api::WriteTransaction* trans, | |
188 const sync_api::BaseNode& autofill_root, | |
189 const std::string& tag, | |
190 const AutoFillProfile& profile, | |
191 int64* sync_id); | |
192 | |
193 // Called at various points in model association to determine if the | 172 // Called at various points in model association to determine if the |
194 // user requested an abort. | 173 // user requested an abort. |
195 bool IsAbortPending(); | 174 bool IsAbortPending(); |
196 | 175 |
| 176 bool MigrationLoggingEnabled(); |
| 177 |
197 ProfileSyncService* sync_service_; | 178 ProfileSyncService* sync_service_; |
198 WebDatabase* web_database_; | 179 WebDatabase* web_database_; |
199 PersonalDataManager* personal_data_; | 180 PersonalDataManager* personal_data_; |
200 int64 autofill_node_id_; | 181 int64 autofill_node_id_; |
201 | 182 |
202 AutofillToSyncIdMap id_map_; | 183 AutofillToSyncIdMap id_map_; |
203 SyncIdToAutofillMap id_map_inverse_; | 184 SyncIdToAutofillMap id_map_inverse_; |
204 | 185 |
205 // Abort association pending flag and lock. If this is set to true | 186 // Abort association pending flag and lock. If this is set to true |
206 // (via the AbortAssociation method), return from the | 187 // (via the AbortAssociation method), return from the |
207 // AssociateModels method as soon as possible. | 188 // AssociateModels method as soon as possible. |
208 Lock abort_association_pending_lock_; | 189 Lock abort_association_pending_lock_; |
209 bool abort_association_pending_; | 190 bool abort_association_pending_; |
| 191 int number_of_entries_created_; |
210 | 192 |
211 DISALLOW_COPY_AND_ASSIGN(AutofillModelAssociator); | 193 DISALLOW_COPY_AND_ASSIGN(AutofillModelAssociator); |
212 }; | 194 }; |
213 | 195 |
214 } // namespace browser_sync | 196 } // namespace browser_sync |
215 | 197 |
216 #endif // CHROME_BROWSER_SYNC_GLUE_AUTOFILL_MODEL_ASSOCIATOR_H_ | 198 #endif // CHROME_BROWSER_SYNC_GLUE_AUTOFILL_MODEL_ASSOCIATOR_H_ |
OLD | NEW |