| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 16 #include "base/task.h" | 16 #include "base/task.h" |
| 17 #include "chrome/browser/history/history_types.h" | 17 #include "chrome/browser/history/history_types.h" |
| 18 #include "chrome/browser/sync/glue/model_associator.h" | 18 #include "chrome/browser/sync/glue/model_associator.h" |
| 19 #include "chrome/browser/sync/protocol/password_specifics.pb.h" | 19 #include "chrome/browser/sync/protocol/password_specifics.pb.h" |
| 20 | 20 |
| 21 class MessageLoop; | 21 class MessageLoop; |
| 22 class PasswordStore; | 22 class PasswordStore; |
| 23 class ProfileSyncService; | 23 class ProfileSyncService; |
| 24 | 24 |
| 25 namespace webkit_glue { | 25 namespace webkit { |
| 26 namespace forms { |
| 26 struct PasswordForm; | 27 struct PasswordForm; |
| 27 }; | 28 } |
| 29 } |
| 28 | 30 |
| 29 namespace sync_api { | 31 namespace sync_api { |
| 30 class WriteNode; | 32 class WriteNode; |
| 31 class WriteTransaction; | 33 class WriteTransaction; |
| 32 }; | 34 } |
| 33 | 35 |
| 34 namespace browser_sync { | 36 namespace browser_sync { |
| 35 | 37 |
| 36 extern const char kPasswordTag[]; | 38 extern const char kPasswordTag[]; |
| 37 | 39 |
| 38 // Contains all model association related logic: | 40 // Contains all model association related logic: |
| 39 // * Algorithm to associate password model and sync model. | 41 // * Algorithm to associate password model and sync model. |
| 40 // * Persisting model associations and loading them back. | 42 // * Persisting model associations and loading them back. |
| 41 // 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 |
| 42 // merge and sync. | 44 // merge and sync. |
| 43 class PasswordModelAssociator | 45 class PasswordModelAssociator |
| 44 : public PerDataTypeAssociatorInterface<std::string, std::string> { | 46 : public PerDataTypeAssociatorInterface<std::string, std::string> { |
| 45 public: | 47 public: |
| 46 typedef std::vector<webkit_glue::PasswordForm> PasswordVector; | 48 typedef std::vector<webkit::forms::PasswordForm> PasswordVector; |
| 47 | 49 |
| 48 static syncable::ModelType model_type() { return syncable::PASSWORDS; } | 50 static syncable::ModelType model_type() { return syncable::PASSWORDS; } |
| 49 PasswordModelAssociator(ProfileSyncService* sync_service, | 51 PasswordModelAssociator(ProfileSyncService* sync_service, |
| 50 PasswordStore* password_store); | 52 PasswordStore* password_store); |
| 51 virtual ~PasswordModelAssociator(); | 53 virtual ~PasswordModelAssociator(); |
| 52 | 54 |
| 53 // PerDataTypeAssociatorInterface implementation. | 55 // PerDataTypeAssociatorInterface implementation. |
| 54 // | 56 // |
| 55 // Iterates through the sync model looking for matched pairs of items. | 57 // Iterates through the sync model looking for matched pairs of items. |
| 56 virtual bool AssociateModels(SyncError* error) OVERRIDE; | 58 virtual bool AssociateModels(SyncError* error) OVERRIDE; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 virtual void Disassociate(int64 sync_id) OVERRIDE; | 91 virtual void Disassociate(int64 sync_id) OVERRIDE; |
| 90 | 92 |
| 91 // Returns whether a node with the given permanent tag was found and update | 93 // Returns whether a node with the given permanent tag was found and update |
| 92 // |sync_id| with that node's id. | 94 // |sync_id| with that node's id. |
| 93 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id); | 95 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id); |
| 94 | 96 |
| 95 bool WriteToPasswordStore(const PasswordVector* new_passwords, | 97 bool WriteToPasswordStore(const PasswordVector* new_passwords, |
| 96 const PasswordVector* updated_passwords, | 98 const PasswordVector* updated_passwords, |
| 97 const PasswordVector* deleted_passwords); | 99 const PasswordVector* deleted_passwords); |
| 98 | 100 |
| 99 static std::string MakeTag(const webkit_glue::PasswordForm& password); | 101 static std::string MakeTag(const webkit::forms::PasswordForm& password); |
| 100 static std::string MakeTag(const sync_pb::PasswordSpecificsData& password); | 102 static std::string MakeTag(const sync_pb::PasswordSpecificsData& password); |
| 101 static std::string MakeTag(const std::string& origin_url, | 103 static std::string MakeTag(const std::string& origin_url, |
| 102 const std::string& username_element, | 104 const std::string& username_element, |
| 103 const std::string& username_value, | 105 const std::string& username_value, |
| 104 const std::string& password_element, | 106 const std::string& password_element, |
| 105 const std::string& signon_realm); | 107 const std::string& signon_realm); |
| 106 | 108 |
| 107 static void CopyPassword(const sync_pb::PasswordSpecificsData& password, | 109 static void CopyPassword(const sync_pb::PasswordSpecificsData& password, |
| 108 webkit_glue::PasswordForm* new_password); | 110 webkit::forms::PasswordForm* new_password); |
| 109 | 111 |
| 110 static bool MergePasswords(const sync_pb::PasswordSpecificsData& password, | 112 static bool MergePasswords(const sync_pb::PasswordSpecificsData& password, |
| 111 const webkit_glue::PasswordForm& password_form, | 113 const webkit::forms::PasswordForm& password_form, |
| 112 webkit_glue::PasswordForm* new_password); | 114 webkit::forms::PasswordForm* new_password); |
| 113 static void WriteToSyncNode(const webkit_glue::PasswordForm& password_form, | 115 static void WriteToSyncNode(const webkit::forms::PasswordForm& password_form, |
| 114 sync_api::WriteNode* node); | 116 sync_api::WriteNode* node); |
| 115 | 117 |
| 116 // Called at various points in model association to determine if the | 118 // Called at various points in model association to determine if the |
| 117 // user requested an abort. | 119 // user requested an abort. |
| 118 bool IsAbortPending(); | 120 bool IsAbortPending(); |
| 119 | 121 |
| 120 private: | 122 private: |
| 121 typedef std::map<std::string, int64> PasswordToSyncIdMap; | 123 typedef std::map<std::string, int64> PasswordToSyncIdMap; |
| 122 typedef std::map<int64, std::string> SyncIdToPasswordMap; | 124 typedef std::map<int64, std::string> SyncIdToPasswordMap; |
| 123 | 125 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 135 | 137 |
| 136 PasswordToSyncIdMap id_map_; | 138 PasswordToSyncIdMap id_map_; |
| 137 SyncIdToPasswordMap id_map_inverse_; | 139 SyncIdToPasswordMap id_map_inverse_; |
| 138 | 140 |
| 139 DISALLOW_COPY_AND_ASSIGN(PasswordModelAssociator); | 141 DISALLOW_COPY_AND_ASSIGN(PasswordModelAssociator); |
| 140 }; | 142 }; |
| 141 | 143 |
| 142 } // namespace browser_sync | 144 } // namespace browser_sync |
| 143 | 145 |
| 144 #endif // CHROME_BROWSER_SYNC_GLUE_PASSWORD_MODEL_ASSOCIATOR_H_ | 146 #endif // CHROME_BROWSER_SYNC_GLUE_PASSWORD_MODEL_ASSOCIATOR_H_ |
| OLD | NEW |