| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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: | 106 protected: |
| 118 // Is called to determine if we need to upgrade to the new | 107 // Is called to determine if we need to upgrade to the new |
| 119 // autofillprofile2 data type. If so we need to sync up autofillprofile | 108 // autofillprofile2 data type. If so we need to sync up autofillprofile |
| 120 // first to the latest available changes on the server and then upgrade | 109 // first to the latest available changes on the server and then upgrade |
| 121 // to autofillprofile2. | 110 // to autofillprofile2. |
| 122 virtual bool IsUpgrading(); | 111 virtual bool IsUpgrading(sync_api::WriteTransaction* trans); |
| 123 | 112 |
| 124 AutoFillProfile* FindCorrespondingNodeFromWebDB( | 113 AutoFillProfile* FindCorrespondingNodeFromWebDB( |
| 125 const sync_pb::AutofillProfileSpecifics& profile, | 114 const sync_pb::AutofillProfileSpecifics& profile, |
| 126 const std::vector<AutoFillProfile*>& all_profiles_from_db); | 115 const std::vector<AutoFillProfile*>& all_profiles_from_db); |
| 127 | 116 |
| 128 private: | 117 private: |
| 129 typedef std::map<std::string, int64> AutofillToSyncIdMap; | 118 typedef std::map<std::string, int64> AutofillToSyncIdMap; |
| 130 typedef std::map<int64, std::string> SyncIdToAutofillMap; | 119 typedef std::map<int64, std::string> SyncIdToAutofillMap; |
| 131 | 120 |
| 132 // A convenience wrapper of a bunch of state we pass around while associating | 121 // A convenience wrapper of a bunch of state we pass around while associating |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 const sync_api::ReadNode& node); | 160 const sync_api::ReadNode& node); |
| 172 | 161 |
| 173 // Helper to insert an AutoFillProfile into the WebDatabase (e.g. in response | 162 // Helper to insert an AutoFillProfile into the WebDatabase (e.g. in response |
| 174 // to encountering a sync node that doesn't exist yet locally). | 163 // to encountering a sync node that doesn't exist yet locally). |
| 175 void AddNativeProfileIfNeeded( | 164 void AddNativeProfileIfNeeded( |
| 176 const sync_pb::AutofillProfileSpecifics& profile, | 165 const sync_pb::AutofillProfileSpecifics& profile, |
| 177 DataBundle* bundle, | 166 DataBundle* bundle, |
| 178 const sync_api::ReadNode& node, | 167 const sync_api::ReadNode& node, |
| 179 std::vector<AutoFillProfile*>& all_profiles_from_db); | 168 std::vector<AutoFillProfile*>& all_profiles_from_db); |
| 180 | 169 |
| 181 // Helper to insert a sync node for the given AutoFillProfile (e.g. in | |
| 182 // response to encountering a native profile that doesn't exist yet in the | |
| 183 // cloud). | |
| 184 bool MakeNewAutofillProfileSyncNode( | |
| 185 sync_api::WriteTransaction* trans, | |
| 186 const sync_api::BaseNode& autofill_root, | |
| 187 const std::string& tag, | |
| 188 const AutoFillProfile& profile, | |
| 189 int64* sync_id); | |
| 190 | |
| 191 // Called at various points in model association to determine if the | 170 // Called at various points in model association to determine if the |
| 192 // user requested an abort. | 171 // user requested an abort. |
| 193 bool IsAbortPending(); | 172 bool IsAbortPending(); |
| 194 | 173 |
| 195 ProfileSyncService* sync_service_; | 174 ProfileSyncService* sync_service_; |
| 196 WebDatabase* web_database_; | 175 WebDatabase* web_database_; |
| 197 PersonalDataManager* personal_data_; | 176 PersonalDataManager* personal_data_; |
| 198 int64 autofill_node_id_; | 177 int64 autofill_node_id_; |
| 199 | 178 |
| 200 AutofillToSyncIdMap id_map_; | 179 AutofillToSyncIdMap id_map_; |
| 201 SyncIdToAutofillMap id_map_inverse_; | 180 SyncIdToAutofillMap id_map_inverse_; |
| 202 | 181 |
| 203 // Abort association pending flag and lock. If this is set to true | 182 // Abort association pending flag and lock. If this is set to true |
| 204 // (via the AbortAssociation method), return from the | 183 // (via the AbortAssociation method), return from the |
| 205 // AssociateModels method as soon as possible. | 184 // AssociateModels method as soon as possible. |
| 206 Lock abort_association_pending_lock_; | 185 Lock abort_association_pending_lock_; |
| 207 bool abort_association_pending_; | 186 bool abort_association_pending_; |
| 208 | 187 |
| 209 DISALLOW_COPY_AND_ASSIGN(AutofillModelAssociator); | 188 DISALLOW_COPY_AND_ASSIGN(AutofillModelAssociator); |
| 210 }; | 189 }; |
| 211 | 190 |
| 212 } // namespace browser_sync | 191 } // namespace browser_sync |
| 213 | 192 |
| 214 #endif // CHROME_BROWSER_SYNC_GLUE_AUTOFILL_MODEL_ASSOCIATOR_H_ | 193 #endif // CHROME_BROWSER_SYNC_GLUE_AUTOFILL_MODEL_ASSOCIATOR_H_ |
| OLD | NEW |