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 |
| 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> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/lock.h" | 15 #include "base/lock.h" |
| 16 #include "base/ref_counted.h" | 16 #include "base/ref_counted.h" |
| 17 #include "chrome/browser/autofill/personal_data_manager.h" | 17 #include "chrome/browser/autofill/personal_data_manager.h" |
| 18 #include "chrome/browser/sync/engine/syncapi.h" | 18 #include "chrome/browser/sync/engine/syncapi.h" |
| 19 #include "chrome/browser/sync/glue/autofill_model_associator2.h" | 19 #include "chrome/browser/sync/glue/autofill_model_associator2.h" |
| 20 #include "chrome/browser/sync/glue/model_associator.h" | 20 #include "chrome/browser/sync/glue/model_associator.h" |
| 21 #include "chrome/browser/sync/syncable/syncable.h" | |
|
tim (not reviewing)
2010/12/13 19:24:33
illegal include
lipalani
2010/12/15 09:08:33
Done.
| |
| 21 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" | 22 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" |
| 22 #include "chrome/browser/webdata/autofill_entry.h" | 23 #include "chrome/browser/webdata/autofill_entry.h" |
| 23 | 24 |
| 24 class AutoFillProfile; | 25 class AutoFillProfile; |
| 25 | 26 |
| 26 class ProfileSyncService; | 27 class ProfileSyncService; |
| 27 class WebDatabase; | 28 class WebDatabase; |
| 28 | 29 |
| 29 namespace sync_api { | 30 namespace sync_api { |
| 30 class WriteTransaction; | 31 class WriteTransaction; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 45 // merge and sync. | 46 // merge and sync. |
| 46 class AutofillModelAssociator | 47 class AutofillModelAssociator |
| 47 : public PerDataTypeAssociatorInterface<std::string, std::string> { | 48 : public PerDataTypeAssociatorInterface<std::string, std::string> { |
| 48 public: | 49 public: |
| 49 static syncable::ModelType model_type() { return syncable::AUTOFILL; } | 50 static syncable::ModelType model_type() { return syncable::AUTOFILL; } |
| 50 AutofillModelAssociator(ProfileSyncService* sync_service, | 51 AutofillModelAssociator(ProfileSyncService* sync_service, |
| 51 WebDatabase* web_database, | 52 WebDatabase* web_database, |
| 52 PersonalDataManager* data_manager); | 53 PersonalDataManager* data_manager); |
| 53 virtual ~AutofillModelAssociator(); | 54 virtual ~AutofillModelAssociator(); |
| 54 | 55 |
| 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. | 56 // PerDataTypeAssociatorInterface implementation. |
| 67 // | 57 // |
| 68 // Iterates through the sync model looking for matched pairs of items. | 58 // Iterates through the sync model looking for matched pairs of items. |
| 69 virtual bool AssociateModels(); | 59 virtual bool AssociateModels(); |
| 70 | 60 |
| 71 // Clears all associations. | 61 // Clears all associations. |
| 72 virtual bool DisassociateModels(); | 62 virtual bool DisassociateModels(); |
| 73 | 63 |
| 74 // The has_nodes out param is true if the sync model has nodes other | 64 // The has_nodes out param is true if the sync model has nodes other |
| 75 // than the permanent tagged nodes. | 65 // than the permanent tagged nodes. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 static bool FillProfileWithServerData( | 97 static bool FillProfileWithServerData( |
| 108 AutoFillProfile* merge_into, | 98 AutoFillProfile* merge_into, |
| 109 const sync_pb::AutofillProfileSpecifics& specifics); | 99 const sync_pb::AutofillProfileSpecifics& specifics); |
| 110 | 100 |
| 111 // TODO(georgey) : add the same processing for CC info (already in protocol | 101 // TODO(georgey) : add the same processing for CC info (already in protocol |
| 112 // buffers). | 102 // buffers). |
| 113 | 103 |
| 114 // Returns sync service instance. | 104 // Returns sync service instance. |
| 115 ProfileSyncService* sync_service() { return sync_service_; } | 105 ProfileSyncService* sync_service() { return sync_service_; } |
| 116 | 106 |
| 117 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 HasNotMigratedYet(); | 111 virtual bool HasNotMigratedYet(const sync_api::BaseTransaction* trans); |
| 123 | 112 |
| 113 protected: | |
| 124 // Given a profile from sync db it tries to match the profile against | 114 // 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. | 115 // one in web db. it ignores the guid and compares the actual data. |
| 126 AutoFillProfile* FindCorrespondingNodeFromWebDB( | 116 AutoFillProfile* FindCorrespondingNodeFromWebDB( |
| 127 const sync_pb::AutofillProfileSpecifics& profile, | 117 const sync_pb::AutofillProfileSpecifics& profile, |
| 128 const std::vector<AutoFillProfile*>& all_profiles_from_db); | 118 const std::vector<AutoFillProfile*>& all_profiles_from_db); |
| 129 | 119 |
| 130 private: | 120 private: |
| 131 typedef std::map<std::string, int64> AutofillToSyncIdMap; | 121 typedef std::map<std::string, int64> AutofillToSyncIdMap; |
| 132 typedef std::map<int64, std::string> SyncIdToAutofillMap; | 122 typedef std::map<int64, std::string> SyncIdToAutofillMap; |
| 133 | 123 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 const sync_api::ReadNode& node); | 163 const sync_api::ReadNode& node); |
| 174 | 164 |
| 175 // Helper to insert an AutoFillProfile into the WebDatabase (e.g. in response | 165 // Helper to insert an AutoFillProfile into the WebDatabase (e.g. in response |
| 176 // to encountering a sync node that doesn't exist yet locally). | 166 // to encountering a sync node that doesn't exist yet locally). |
| 177 void AddNativeProfileIfNeeded( | 167 void AddNativeProfileIfNeeded( |
| 178 const sync_pb::AutofillProfileSpecifics& profile, | 168 const sync_pb::AutofillProfileSpecifics& profile, |
| 179 DataBundle* bundle, | 169 DataBundle* bundle, |
| 180 const sync_api::ReadNode& node, | 170 const sync_api::ReadNode& node, |
| 181 const std::vector<AutoFillProfile*>& all_profiles_from_db); | 171 const std::vector<AutoFillProfile*>& all_profiles_from_db); |
| 182 | 172 |
| 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 | 173 // Called at various points in model association to determine if the |
| 194 // user requested an abort. | 174 // user requested an abort. |
| 195 bool IsAbortPending(); | 175 bool IsAbortPending(); |
| 196 | 176 |
| 177 bool MigrationLoggingEnabled(); | |
| 178 | |
| 197 ProfileSyncService* sync_service_; | 179 ProfileSyncService* sync_service_; |
| 198 WebDatabase* web_database_; | 180 WebDatabase* web_database_; |
| 199 PersonalDataManager* personal_data_; | 181 PersonalDataManager* personal_data_; |
| 200 int64 autofill_node_id_; | 182 int64 autofill_node_id_; |
| 201 | 183 |
| 202 AutofillToSyncIdMap id_map_; | 184 AutofillToSyncIdMap id_map_; |
| 203 SyncIdToAutofillMap id_map_inverse_; | 185 SyncIdToAutofillMap id_map_inverse_; |
| 204 | 186 |
| 205 // Abort association pending flag and lock. If this is set to true | 187 // Abort association pending flag and lock. If this is set to true |
| 206 // (via the AbortAssociation method), return from the | 188 // (via the AbortAssociation method), return from the |
| 207 // AssociateModels method as soon as possible. | 189 // AssociateModels method as soon as possible. |
| 208 Lock abort_association_pending_lock_; | 190 Lock abort_association_pending_lock_; |
| 209 bool abort_association_pending_; | 191 bool abort_association_pending_; |
| 192 int number_of_entries_created_; | |
| 193 | |
| 194 syncable::AutofillMigrationState | |
|
tim (not reviewing)
2010/12/13 19:24:33
shouldn't this be in the autofill_migration.h?
lipalani
2010/12/15 09:08:33
removed.
On 2010/12/13 19:24:33, timsteele wrote:
| |
| 195 autofill_migration_state_; | |
| 210 | 196 |
| 211 DISALLOW_COPY_AND_ASSIGN(AutofillModelAssociator); | 197 DISALLOW_COPY_AND_ASSIGN(AutofillModelAssociator); |
| 212 }; | 198 }; |
| 213 | 199 |
| 214 } // namespace browser_sync | 200 } // namespace browser_sync |
| 215 | 201 |
| 216 #endif // CHROME_BROWSER_SYNC_GLUE_AUTOFILL_MODEL_ASSOCIATOR_H_ | 202 #endif // CHROME_BROWSER_SYNC_GLUE_AUTOFILL_MODEL_ASSOCIATOR_H_ |
| OLD | NEW |