| 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 MessageLoop; | 20 class MessageLoop; |
| 21 class PasswordStore; | 21 class PasswordStore; |
| 22 class ProfileSyncService; | 22 class ProfileSyncService; |
| 23 | 23 |
| 24 namespace webkit { | 24 namespace content { |
| 25 namespace forms { | |
| 26 struct PasswordForm; | 25 struct PasswordForm; |
| 27 } | 26 } |
| 28 } | |
| 29 | 27 |
| 30 namespace syncer { | 28 namespace syncer { |
| 31 class WriteNode; | 29 class WriteNode; |
| 32 class WriteTransaction; | 30 class WriteTransaction; |
| 33 } | 31 } |
| 34 | 32 |
| 35 namespace browser_sync { | 33 namespace browser_sync { |
| 36 | 34 |
| 37 extern const char kPasswordTag[]; | 35 extern const char kPasswordTag[]; |
| 38 | 36 |
| 39 // Contains all model association related logic: | 37 // Contains all model association related logic: |
| 40 // * Algorithm to associate password model and sync model. | 38 // * Algorithm to associate password model and sync model. |
| 41 // * Persisting model associations and loading them back. | 39 // * Persisting model associations and loading them back. |
| 42 // We do not check if we have local data before this runs; we always | 40 // We do not check if we have local data before this runs; we always |
| 43 // merge and sync. | 41 // merge and sync. |
| 44 class PasswordModelAssociator | 42 class PasswordModelAssociator |
| 45 : public PerDataTypeAssociatorInterface<std::string, std::string> { | 43 : public PerDataTypeAssociatorInterface<std::string, std::string> { |
| 46 public: | 44 public: |
| 47 typedef std::vector<webkit::forms::PasswordForm> PasswordVector; | 45 typedef std::vector<content::PasswordForm> PasswordVector; |
| 48 | 46 |
| 49 static syncer::ModelType model_type() { return syncer::PASSWORDS; } | 47 static syncer::ModelType model_type() { return syncer::PASSWORDS; } |
| 50 PasswordModelAssociator(ProfileSyncService* sync_service, | 48 PasswordModelAssociator(ProfileSyncService* sync_service, |
| 51 PasswordStore* password_store, | 49 PasswordStore* password_store, |
| 52 DataTypeErrorHandler* error_handler); | 50 DataTypeErrorHandler* error_handler); |
| 53 virtual ~PasswordModelAssociator(); | 51 virtual ~PasswordModelAssociator(); |
| 54 | 52 |
| 55 // PerDataTypeAssociatorInterface implementation. | 53 // PerDataTypeAssociatorInterface implementation. |
| 56 // | 54 // |
| 57 // Iterates through the sync model looking for matched pairs of items. | 55 // Iterates through the sync model looking for matched pairs of items. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 virtual void Disassociate(int64 sync_id) OVERRIDE; | 89 virtual void Disassociate(int64 sync_id) OVERRIDE; |
| 92 | 90 |
| 93 // Returns whether a node with the given permanent tag was found and update | 91 // Returns whether a node with the given permanent tag was found and update |
| 94 // |sync_id| with that node's id. | 92 // |sync_id| with that node's id. |
| 95 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id); | 93 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id); |
| 96 | 94 |
| 97 syncer::SyncError WriteToPasswordStore(const PasswordVector* new_passwords, | 95 syncer::SyncError WriteToPasswordStore(const PasswordVector* new_passwords, |
| 98 const PasswordVector* updated_passwords, | 96 const PasswordVector* updated_passwords, |
| 99 const PasswordVector* deleted_passwords); | 97 const PasswordVector* deleted_passwords); |
| 100 | 98 |
| 101 static std::string MakeTag(const webkit::forms::PasswordForm& password); | 99 static std::string MakeTag(const content::PasswordForm& password); |
| 102 static std::string MakeTag(const sync_pb::PasswordSpecificsData& password); | 100 static std::string MakeTag(const sync_pb::PasswordSpecificsData& password); |
| 103 static std::string MakeTag(const std::string& origin_url, | 101 static std::string MakeTag(const std::string& origin_url, |
| 104 const std::string& username_element, | 102 const std::string& username_element, |
| 105 const std::string& username_value, | 103 const std::string& username_value, |
| 106 const std::string& password_element, | 104 const std::string& password_element, |
| 107 const std::string& signon_realm); | 105 const std::string& signon_realm); |
| 108 | 106 |
| 109 static void CopyPassword(const sync_pb::PasswordSpecificsData& password, | 107 static void CopyPassword(const sync_pb::PasswordSpecificsData& password, |
| 110 webkit::forms::PasswordForm* new_password); | 108 content::PasswordForm* new_password); |
| 111 | 109 |
| 112 static bool MergePasswords(const sync_pb::PasswordSpecificsData& password, | 110 static bool MergePasswords(const sync_pb::PasswordSpecificsData& password, |
| 113 const webkit::forms::PasswordForm& password_form, | 111 const content::PasswordForm& password_form, |
| 114 webkit::forms::PasswordForm* new_password); | 112 content::PasswordForm* new_password); |
| 115 static void WriteToSyncNode(const webkit::forms::PasswordForm& password_form, | 113 static void WriteToSyncNode(const content::PasswordForm& password_form, |
| 116 syncer::WriteNode* node); | 114 syncer::WriteNode* node); |
| 117 | 115 |
| 118 // Called at various points in model association to determine if the | 116 // Called at various points in model association to determine if the |
| 119 // user requested an abort. | 117 // user requested an abort. |
| 120 bool IsAbortPending(); | 118 bool IsAbortPending(); |
| 121 | 119 |
| 122 private: | 120 private: |
| 123 typedef std::map<std::string, int64> PasswordToSyncIdMap; | 121 typedef std::map<std::string, int64> PasswordToSyncIdMap; |
| 124 typedef std::map<int64, std::string> SyncIdToPasswordMap; | 122 typedef std::map<int64, std::string> SyncIdToPasswordMap; |
| 125 | 123 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 138 PasswordToSyncIdMap id_map_; | 136 PasswordToSyncIdMap id_map_; |
| 139 SyncIdToPasswordMap id_map_inverse_; | 137 SyncIdToPasswordMap id_map_inverse_; |
| 140 DataTypeErrorHandler* error_handler_; | 138 DataTypeErrorHandler* error_handler_; |
| 141 | 139 |
| 142 DISALLOW_COPY_AND_ASSIGN(PasswordModelAssociator); | 140 DISALLOW_COPY_AND_ASSIGN(PasswordModelAssociator); |
| 143 }; | 141 }; |
| 144 | 142 |
| 145 } // namespace browser_sync | 143 } // namespace browser_sync |
| 146 | 144 |
| 147 #endif // CHROME_BROWSER_SYNC_GLUE_PASSWORD_MODEL_ASSOCIATOR_H_ | 145 #endif // CHROME_BROWSER_SYNC_GLUE_PASSWORD_MODEL_ASSOCIATOR_H_ |
| OLD | NEW |