| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_PASSWORD_MODEL_ASSOCIATOR_H_ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_PASSWORD_MODEL_ASSOCIATOR_H_ |
| 6 #define CHROME_BROWSER_SYNC_GLUE_PASSWORD_MODEL_ASSOCIATOR_H_ | 6 #define CHROME_BROWSER_SYNC_GLUE_PASSWORD_MODEL_ASSOCIATOR_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 15 #include "chrome/browser/history/history_types.h" | 15 #include "chrome/browser/history/history_types.h" |
| 16 #include "chrome/browser/sync/glue/data_type_error_handler.h" | 16 #include "chrome/browser/sync/glue/data_type_error_handler.h" |
| 17 #include "chrome/browser/sync/glue/model_associator.h" | 17 #include "chrome/browser/sync/glue/model_associator.h" |
| 18 #include "sync/protocol/password_specifics.pb.h" | 18 #include "sync/protocol/password_specifics.pb.h" |
| 19 | 19 |
| 20 class PasswordStore; | 20 class PasswordStore; |
| 21 class ProfileSyncService; | 21 class ProfileSyncService; |
| 22 | 22 |
| 23 namespace autofill { |
| 24 struct PasswordForm; |
| 25 } |
| 26 |
| 23 namespace base { | 27 namespace base { |
| 24 class MessageLoop; | 28 class MessageLoop; |
| 25 } | 29 } |
| 26 | 30 |
| 27 namespace content { | |
| 28 struct PasswordForm; | |
| 29 } | |
| 30 | |
| 31 namespace syncer { | 31 namespace syncer { |
| 32 class WriteNode; | 32 class WriteNode; |
| 33 class WriteTransaction; | 33 class WriteTransaction; |
| 34 } | 34 } |
| 35 | 35 |
| 36 namespace browser_sync { | 36 namespace browser_sync { |
| 37 | 37 |
| 38 extern const char kPasswordTag[]; | 38 extern const char kPasswordTag[]; |
| 39 | 39 |
| 40 // Contains all model association related logic: | 40 // Contains all model association related logic: |
| 41 // * Algorithm to associate password model and sync model. | 41 // * Algorithm to associate password model and sync model. |
| 42 // * Persisting model associations and loading them back. | 42 // * Persisting model associations and loading them back. |
| 43 // We do not check if we have local data before this runs; we always | 43 // We do not check if we have local data before this runs; we always |
| 44 // merge and sync. | 44 // merge and sync. |
| 45 class PasswordModelAssociator | 45 class PasswordModelAssociator |
| 46 : public PerDataTypeAssociatorInterface<std::string, std::string> { | 46 : public PerDataTypeAssociatorInterface<std::string, std::string> { |
| 47 public: | 47 public: |
| 48 typedef std::vector<content::PasswordForm> PasswordVector; | 48 typedef std::vector<autofill::PasswordForm> PasswordVector; |
| 49 | 49 |
| 50 static syncer::ModelType model_type() { return syncer::PASSWORDS; } | 50 static syncer::ModelType model_type() { return syncer::PASSWORDS; } |
| 51 PasswordModelAssociator(ProfileSyncService* sync_service, | 51 PasswordModelAssociator(ProfileSyncService* sync_service, |
| 52 PasswordStore* password_store, | 52 PasswordStore* password_store, |
| 53 DataTypeErrorHandler* error_handler); | 53 DataTypeErrorHandler* error_handler); |
| 54 virtual ~PasswordModelAssociator(); | 54 virtual ~PasswordModelAssociator(); |
| 55 | 55 |
| 56 // PerDataTypeAssociatorInterface implementation. | 56 // PerDataTypeAssociatorInterface implementation. |
| 57 // | 57 // |
| 58 // Iterates through the sync model looking for matched pairs of items. | 58 // Iterates through the sync model looking for matched pairs of items. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 virtual void Disassociate(int64 sync_id) OVERRIDE; | 94 virtual void Disassociate(int64 sync_id) OVERRIDE; |
| 95 | 95 |
| 96 // Returns whether a node with the given permanent tag was found and update | 96 // Returns whether a node with the given permanent tag was found and update |
| 97 // |sync_id| with that node's id. | 97 // |sync_id| with that node's id. |
| 98 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id); | 98 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id); |
| 99 | 99 |
| 100 syncer::SyncError WriteToPasswordStore(const PasswordVector* new_passwords, | 100 syncer::SyncError WriteToPasswordStore(const PasswordVector* new_passwords, |
| 101 const PasswordVector* updated_passwords, | 101 const PasswordVector* updated_passwords, |
| 102 const PasswordVector* deleted_passwords); | 102 const PasswordVector* deleted_passwords); |
| 103 | 103 |
| 104 static std::string MakeTag(const content::PasswordForm& password); | 104 static std::string MakeTag(const autofill::PasswordForm& password); |
| 105 static std::string MakeTag(const sync_pb::PasswordSpecificsData& password); | 105 static std::string MakeTag(const sync_pb::PasswordSpecificsData& password); |
| 106 static std::string MakeTag(const std::string& origin_url, | 106 static std::string MakeTag(const std::string& origin_url, |
| 107 const std::string& username_element, | 107 const std::string& username_element, |
| 108 const std::string& username_value, | 108 const std::string& username_value, |
| 109 const std::string& password_element, | 109 const std::string& password_element, |
| 110 const std::string& signon_realm); | 110 const std::string& signon_realm); |
| 111 | 111 |
| 112 static void CopyPassword(const sync_pb::PasswordSpecificsData& password, | 112 static void CopyPassword(const sync_pb::PasswordSpecificsData& password, |
| 113 content::PasswordForm* new_password); | 113 autofill::PasswordForm* new_password); |
| 114 | 114 |
| 115 static bool MergePasswords(const sync_pb::PasswordSpecificsData& password, | 115 static bool MergePasswords(const sync_pb::PasswordSpecificsData& password, |
| 116 const content::PasswordForm& password_form, | 116 const autofill::PasswordForm& password_form, |
| 117 content::PasswordForm* new_password); | 117 autofill::PasswordForm* new_password); |
| 118 static void WriteToSyncNode(const content::PasswordForm& password_form, | 118 static void WriteToSyncNode(const autofill::PasswordForm& password_form, |
| 119 syncer::WriteNode* node); | 119 syncer::WriteNode* node); |
| 120 | 120 |
| 121 private: | 121 private: |
| 122 typedef std::map<std::string, int64> PasswordToSyncIdMap; | 122 typedef std::map<std::string, int64> PasswordToSyncIdMap; |
| 123 typedef std::map<int64, std::string> SyncIdToPasswordMap; | 123 typedef std::map<int64, std::string> SyncIdToPasswordMap; |
| 124 | 124 |
| 125 ProfileSyncService* sync_service_; | 125 ProfileSyncService* sync_service_; |
| 126 PasswordStore* password_store_; | 126 PasswordStore* password_store_; |
| 127 int64 password_node_id_; | 127 int64 password_node_id_; |
| 128 | 128 |
| 129 // Set true by AbortAssociation. | 129 // Set true by AbortAssociation. |
| 130 bool abort_association_requested_; | 130 bool abort_association_requested_; |
| 131 base::Lock association_lock_; | 131 base::Lock association_lock_; |
| 132 | 132 |
| 133 base::MessageLoop* expected_loop_; | 133 base::MessageLoop* expected_loop_; |
| 134 | 134 |
| 135 PasswordToSyncIdMap id_map_; | 135 PasswordToSyncIdMap id_map_; |
| 136 SyncIdToPasswordMap id_map_inverse_; | 136 SyncIdToPasswordMap id_map_inverse_; |
| 137 DataTypeErrorHandler* error_handler_; | 137 DataTypeErrorHandler* error_handler_; |
| 138 | 138 |
| 139 DISALLOW_COPY_AND_ASSIGN(PasswordModelAssociator); | 139 DISALLOW_COPY_AND_ASSIGN(PasswordModelAssociator); |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 } // namespace browser_sync | 142 } // namespace browser_sync |
| 143 | 143 |
| 144 #endif // CHROME_BROWSER_SYNC_GLUE_PASSWORD_MODEL_ASSOCIATOR_H_ | 144 #endif // CHROME_BROWSER_SYNC_GLUE_PASSWORD_MODEL_ASSOCIATOR_H_ |
| OLD | NEW |