Chromium Code Reviews| 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 |
|
tim (not reviewing)
2010/12/15 20:11:42
nit - extra newline
lipalani
2010/12/15 21:28:15
Done.
| |
| 5 | |
| 5 #ifndef CHROME_BROWSER_SYNC_GLUE_AUTOFILL_PROFILE_MODEL_ASSOCIATOR_H_ | 6 #ifndef CHROME_BROWSER_SYNC_GLUE_AUTOFILL_PROFILE_MODEL_ASSOCIATOR_H_ |
| 6 #define CHROME_BROWSER_SYNC_GLUE_AUTOFILL_PROFILE_MODEL_ASSOCIATOR_H_ | 7 #define CHROME_BROWSER_SYNC_GLUE_AUTOFILL_PROFILE_MODEL_ASSOCIATOR_H_ |
| 7 #pragma once | 8 #pragma once |
| 8 | 9 |
| 9 #include <map> | 10 #include <map> |
| 10 #include <set> | 11 #include <set> |
| 11 #include <string> | 12 #include <string> |
| 12 #include <vector> | 13 #include <vector> |
| 13 | 14 |
| 14 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 15 #include "base/lock.h" | 16 #include "base/lock.h" |
| 16 #include "base/ref_counted.h" | 17 #include "base/ref_counted.h" |
| 17 #include "chrome/browser/autofill/personal_data_manager.h" | 18 #include "chrome/browser/autofill/personal_data_manager.h" |
| 18 #include "chrome/browser/sync/engine/syncapi.h" | 19 #include "chrome/browser/sync/engine/syncapi.h" |
| 19 #include "chrome/browser/sync/glue/model_associator.h" | 20 #include "chrome/browser/sync/glue/model_associator.h" |
| 20 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" | 21 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" |
| 21 #include "chrome/browser/webdata/autofill_entry.h" | 22 #include "chrome/browser/webdata/autofill_entry.h" |
| 22 | 23 |
| 23 class AutoFillProfile; | 24 class AutoFillProfile; |
| 24 | 25 |
| 25 class ProfileSyncService; | 26 class ProfileSyncService; |
| 26 class WebDatabase; | 27 class WebDatabase; |
| 27 | 28 |
| 28 namespace sync_api { | 29 namespace sync_api { |
| 29 class WriteTransaction; | 30 class WriteTransaction; |
| 30 } | 31 } |
| 31 | 32 |
| 32 namespace browser_sync { | 33 namespace browser_sync { |
| 33 | 34 |
| 35 extern const char kAutofillProfileTag[]; | |
| 36 | |
| 34 class AutofillChangeProcessor; | 37 class AutofillChangeProcessor; |
| 35 class UnrecoverableErrorHandler; | 38 class UnrecoverableErrorHandler; |
| 36 | 39 |
| 37 // Contains all model association related logic: | 40 // Contains all model association related logic: |
| 38 // * Algorithm to associate autofill model and sync model. | 41 // * Algorithm to associate autofill model and sync model. |
| 39 // We do not check if we have local data before this run; we always | 42 // We do not check if we have local data before this run; we always |
| 40 // merge and sync. | 43 // merge and sync. |
| 41 class AutofillProfileModelAssociator | 44 class AutofillProfileModelAssociator |
| 42 : public PerDataTypeAssociatorInterface<std::string, std::string> { | 45 : public PerDataTypeAssociatorInterface<std::string, std::string> { |
| 43 public: | 46 public: |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 | 90 |
| 88 // TODO(lipalani) Bug 64111. Returns whether a node with the | 91 // TODO(lipalani) Bug 64111. Returns whether a node with the |
| 89 // given permanent tag was found and update | 92 // given permanent tag was found and update |
| 90 // |sync_id| with that node's id. No current use. To Implement | 93 // |sync_id| with that node's id. No current use. To Implement |
| 91 // only for completeness. | 94 // only for completeness. |
| 92 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id); | 95 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id); |
| 93 | 96 |
| 94 // Returns sync service instance. | 97 // Returns sync service instance. |
| 95 ProfileSyncService* sync_service() { return sync_service_; } | 98 ProfileSyncService* sync_service() { return sync_service_; } |
| 96 | 99 |
| 100 static bool OverwriteProfileWithServerData( | |
| 101 AutoFillProfile* merge_into, | |
| 102 const sync_pb::AutofillProfileSpecifics& specifics); | |
| 103 | |
| 97 protected: | 104 protected: |
| 98 AutofillProfileModelAssociator(); | 105 AutofillProfileModelAssociator(); |
| 99 bool TraverseAndAssociateChromeAutoFillProfiles( | 106 bool TraverseAndAssociateChromeAutoFillProfiles( |
| 100 sync_api::WriteTransaction* write_trans, | 107 sync_api::WriteTransaction* write_trans, |
| 101 const sync_api::ReadNode& autofill_root, | 108 const sync_api::ReadNode& autofill_root, |
| 102 const std::vector<AutoFillProfile*>& all_profiles_from_db, | 109 const std::vector<AutoFillProfile*>& all_profiles_from_db, |
| 103 std::set<std::string>* current_profiles, | 110 std::set<std::string>* current_profiles, |
| 104 std::vector<AutoFillProfile*>* updated_profiles, | 111 std::vector<AutoFillProfile*>* updated_profiles, |
| 105 std::vector<AutoFillProfile*>* new_profiles, | 112 std::vector<AutoFillProfile*>* new_profiles, |
| 106 std::vector<std::string>* profiles_to_delete); | 113 std::vector<std::string>* profiles_to_delete); |
| 107 | 114 |
|
tim (not reviewing)
2010/12/15 20:11:42
nit - extra newline.
lipalani
2010/12/15 21:28:15
Done.
| |
| 115 | |
| 108 // 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 |
| 109 // to encountering a sync node that doesn't exist yet locally). | 117 // to encountering a sync node that doesn't exist yet locally). |
| 110 virtual void AddNativeProfileIfNeeded( | 118 virtual void AddNativeProfileIfNeeded( |
| 111 const sync_pb::AutofillProfileSpecifics& profile, | 119 const sync_pb::AutofillProfileSpecifics& profile, |
| 112 DataBundle* bundle, | 120 DataBundle* bundle, |
| 113 const sync_api::ReadNode& node); | 121 const sync_api::ReadNode& node); |
| 114 | 122 |
| 115 // 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 |
| 116 // 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 |
| 117 // cloud). | 125 // cloud). |
| 118 virtual bool MakeNewAutofillProfileSyncNodeIfNeeded( | 126 virtual bool MakeNewAutofillProfileSyncNodeIfNeeded( |
| 119 sync_api::WriteTransaction* trans, | 127 sync_api::WriteTransaction* trans, |
| 120 const sync_api::BaseNode& autofill_root, | 128 const sync_api::BaseNode& autofill_root, |
| 121 const AutoFillProfile& profile, | 129 const AutoFillProfile& profile, |
| 122 std::vector<AutoFillProfile*>* new_profiles, | 130 std::vector<AutoFillProfile*>* new_profiles, |
| 123 std::set<std::string>* current_profiles, | 131 std::set<std::string>* current_profiles, |
| 124 std::vector<std::string>* profiles_to_delete); | 132 std::vector<std::string>* profiles_to_delete); |
| 125 | 133 |
| 126 // 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 |
| 127 // associate all remaining nodes. | 135 // associate all remaining nodes. |
| 128 bool TraverseAndAssociateAllSyncNodes( | 136 bool TraverseAndAssociateAllSyncNodes( |
| 129 sync_api::WriteTransaction* write_trans, | 137 sync_api::WriteTransaction* write_trans, |
| 130 const sync_api::ReadNode& autofill_root, | 138 const sync_api::ReadNode& autofill_root, |
| 131 DataBundle* bundle); | 139 DataBundle* bundle); |
| 132 | 140 |
| 133 static bool OverwriteProfileWithServerData( | |
| 134 AutoFillProfile* merge_into, | |
| 135 const sync_pb::AutofillProfileSpecifics& specifics); | |
| 136 | |
| 137 private: | 141 private: |
| 138 typedef std::map<std::string, int64> AutofillToSyncIdMap; | 142 typedef std::map<std::string, int64> AutofillToSyncIdMap; |
| 139 typedef std::map<int64, std::string> SyncIdToAutofillMap; | 143 typedef std::map<int64, std::string> SyncIdToAutofillMap; |
| 140 | 144 |
| 141 // 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 |
| 142 // models, and send to the WebDatabase for persistence. | 146 // models, and send to the WebDatabase for persistence. |
| 143 // struct DataBundle; | 147 // struct DataBundle; |
| 144 | 148 |
| 145 // Helper to query WebDatabase for the current autofill state. | 149 // Helper to query WebDatabase for the current autofill state. |
| 146 bool LoadAutofillData(std::vector<AutoFillProfile*>* profiles); | 150 bool LoadAutofillData(std::vector<AutoFillProfile*>* profiles); |
| 147 | 151 |
| 148 static bool MergeField(FormGroup* f, | 152 static bool MergeField(FormGroup* f, |
| 149 AutoFillFieldType t, | 153 AutoFillFieldType t, |
| 150 const std::string& specifics_field); | 154 const std::string& specifics_field); |
| 151 | 155 |
| 152 // Helper to persist any changes that occured during model association to | 156 // Helper to persist any changes that occured during model association to |
| 153 // the WebDatabase. | 157 // the WebDatabase. |
| 154 bool SaveChangesToWebData(const DataBundle& bundle); | 158 bool SaveChangesToWebData(const DataBundle& bundle); |
| 155 | 159 |
| 156 // Called at various points in model association to determine if the | 160 // Called at various points in model association to determine if the |
| 157 // user requested an abort. | 161 // user requested an abort. |
| 158 bool IsAbortPending(); | 162 bool IsAbortPending(); |
| 159 | 163 |
| 160 int64 FindSyncNodeWithProfile(sync_api::WriteTransaction* trans, | 164 int64 FindSyncNodeWithProfile(sync_api::WriteTransaction* trans, |
| 161 const sync_api::BaseNode& autofill_root, | 165 const sync_api::BaseNode& autofill_root, |
| 162 const AutoFillProfile& profile); | 166 const AutoFillProfile& profile); |
| 163 | 167 |
| 168 bool MigrationLoggingEnabled(); | |
| 169 | |
| 164 ProfileSyncService* sync_service_; | 170 ProfileSyncService* sync_service_; |
| 165 WebDatabase* web_database_; | 171 WebDatabase* web_database_; |
| 166 PersonalDataManager* personal_data_; | 172 PersonalDataManager* personal_data_; |
| 167 int64 autofill_node_id_; | 173 int64 autofill_node_id_; |
| 168 | 174 |
| 169 AutofillToSyncIdMap id_map_; | 175 AutofillToSyncIdMap id_map_; |
| 170 SyncIdToAutofillMap id_map_inverse_; | 176 SyncIdToAutofillMap id_map_inverse_; |
| 171 | 177 |
| 172 // Abort association pending flag and lock. If this is set to true | 178 // Abort association pending flag and lock. If this is set to true |
| 173 // (via the AbortAssociation method), return from the | 179 // (via the AbortAssociation method), return from the |
| 174 // AssociateModels method as soon as possible. | 180 // AssociateModels method as soon as possible. |
| 175 Lock abort_association_pending_lock_; | 181 Lock abort_association_pending_lock_; |
| 176 bool abort_association_pending_; | 182 bool abort_association_pending_; |
| 177 | 183 |
| 184 int number_of_profiles_created_; | |
| 185 | |
| 178 DISALLOW_COPY_AND_ASSIGN(AutofillProfileModelAssociator); | 186 DISALLOW_COPY_AND_ASSIGN(AutofillProfileModelAssociator); |
| 179 }; | 187 }; |
| 180 | 188 |
| 181 struct AutofillProfileModelAssociator::DataBundle { | 189 struct AutofillProfileModelAssociator::DataBundle { |
| 182 std::set<std::string> current_profiles; | 190 std::set<std::string> current_profiles; |
| 183 std::vector<std::string> profiles_to_delete; | 191 std::vector<std::string> profiles_to_delete; |
| 184 std::vector<AutoFillProfile*> updated_profiles; | 192 std::vector<AutoFillProfile*> updated_profiles; |
| 185 std::vector<AutoFillProfile*> new_profiles; // We own these pointers. | 193 std::vector<AutoFillProfile*> new_profiles; // We own these pointers. |
| 186 ~DataBundle() { STLDeleteElements(&new_profiles); } | 194 ~DataBundle() { STLDeleteElements(&new_profiles); } |
| 187 }; | 195 }; |
| 188 | 196 |
| 189 } // namespace browser_sync | 197 } // namespace browser_sync |
| 190 | 198 |
| 191 #endif // CHROME_BROWSER_SYNC_GLUE_AUTOFILL_PROFILE_MODEL_ASSOCIATOR_H_ | 199 #endif // CHROME_BROWSER_SYNC_GLUE_AUTOFILL_PROFILE_MODEL_ASSOCIATOR_H_ |
| 200 | |
| OLD | NEW |