| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_SYNCABLE_SERVICE_H__ | 5 #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_SYNCABLE_SERVICE_H__ |
| 6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_SYNCABLE_SERVICE_H__ | 6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_SYNCABLE_SERVICE_H__ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/sequence_checker.h" | 13 #include "base/sequence_checker.h" |
| 14 #include "base/time/clock.h" |
| 14 #include "components/password_manager/core/browser/password_store_change.h" | 15 #include "components/password_manager/core/browser/password_store_change.h" |
| 15 #include "components/sync/model/sync_change.h" | 16 #include "components/sync/model/sync_change.h" |
| 16 #include "components/sync/model/sync_data.h" | 17 #include "components/sync/model/sync_data.h" |
| 17 #include "components/sync/model/sync_error.h" | 18 #include "components/sync/model/sync_error.h" |
| 18 #include "components/sync/model/syncable_service.h" | 19 #include "components/sync/model/syncable_service.h" |
| 19 #include "components/sync/protocol/password_specifics.pb.h" | 20 #include "components/sync/protocol/password_specifics.pb.h" |
| 20 #include "components/sync/protocol/sync.pb.h" | 21 #include "components/sync/protocol/sync.pb.h" |
| 21 | 22 |
| 22 namespace autofill { | 23 namespace autofill { |
| 23 struct PasswordForm; | 24 struct PasswordForm; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 53 const syncer::SyncChangeList& change_list) override; | 54 const syncer::SyncChangeList& change_list) override; |
| 54 | 55 |
| 55 // Notifies the Sync engine of changes to the password database. | 56 // Notifies the Sync engine of changes to the password database. |
| 56 void ActOnPasswordStoreChanges(const PasswordStoreChangeList& changes); | 57 void ActOnPasswordStoreChanges(const PasswordStoreChangeList& changes); |
| 57 | 58 |
| 58 // Provides a StartSyncFlare to the SyncableService. See | 59 // Provides a StartSyncFlare to the SyncableService. See |
| 59 // chrome/browser/sync/glue/sync_start_util.h for more. | 60 // chrome/browser/sync/glue/sync_start_util.h for more. |
| 60 void InjectStartSyncFlare( | 61 void InjectStartSyncFlare( |
| 61 const syncer::SyncableService::StartSyncFlare& flare); | 62 const syncer::SyncableService::StartSyncFlare& flare); |
| 62 | 63 |
| 64 #if defined(UNIT_TEST) |
| 65 void set_clock(std::unique_ptr<base::Clock> clock) { |
| 66 clock_ = std::move(clock); |
| 67 } |
| 68 #endif |
| 69 |
| 63 private: | 70 private: |
| 64 // Map from password sync tag to password form. | 71 // Map from password sync tag to password form. |
| 65 typedef std::map<std::string, autofill::PasswordForm*> PasswordEntryMap; | 72 typedef std::map<std::string, autofill::PasswordForm*> PasswordEntryMap; |
| 66 | 73 |
| 67 // The type of PasswordStoreSync::AddLoginImpl, | 74 // The type of PasswordStoreSync::AddLoginImpl, |
| 68 // PasswordStoreSync::UpdateLoginImpl and PasswordStoreSync::RemoveLoginImpl. | 75 // PasswordStoreSync::UpdateLoginImpl and PasswordStoreSync::RemoveLoginImpl. |
| 69 typedef PasswordStoreChangeList (PasswordStoreSync::*DatabaseOperation)( | 76 typedef PasswordStoreChangeList (PasswordStoreSync::*DatabaseOperation)( |
| 70 const autofill::PasswordForm& form); | 77 const autofill::PasswordForm& form); |
| 71 | 78 |
| 72 struct SyncEntries; | 79 struct SyncEntries; |
| 73 | 80 |
| 74 // Retrieves the entries from password db and fills both |password_entries| | 81 // Retrieves the entries from password db and fills both |password_entries| |
| 75 // and |passwords_entry_map|. |passwords_entry_map| can be NULL. | 82 // and |passwords_entry_map|. |passwords_entry_map| can be NULL. |
| 76 bool ReadFromPasswordStore( | 83 bool ReadFromPasswordStore( |
| 77 std::vector<std::unique_ptr<autofill::PasswordForm>>* password_entries, | 84 std::vector<std::unique_ptr<autofill::PasswordForm>>* password_entries, |
| 78 PasswordEntryMap* passwords_entry_map) const; | 85 PasswordEntryMap* passwords_entry_map) const; |
| 79 | 86 |
| 80 // Uses the |PasswordStore| APIs to change entries. | 87 // Uses the |PasswordStore| APIs to change entries. |
| 81 void WriteToPasswordStore(const SyncEntries& entries); | 88 void WriteToPasswordStore(const SyncEntries& entries); |
| 82 | 89 |
| 90 // Goes through |sync_data| and for each entry merges the data with |
| 91 // |unmatched_data_from_password_db|. The result of merge is recorded in |
| 92 // |sync_entries| or |updated_db_entries|. Successfully merged elements are |
| 93 // removed from |unmatched_data_from_password_db|. |
| 94 void MergeSyncDataWithLocalData( |
| 95 const syncer::SyncDataList& sync_data, |
| 96 PasswordEntryMap* unmatched_data_from_password_db, |
| 97 SyncEntries* sync_entries, |
| 98 syncer::SyncChangeList* updated_db_entries); |
| 99 |
| 83 // Examines |data|, an entry in sync db, and updates |sync_entries| or | 100 // Examines |data|, an entry in sync db, and updates |sync_entries| or |
| 84 // |updated_db_entries| accordingly. An element is removed from | 101 // |updated_db_entries| accordingly. An element is removed from |
| 85 // |unmatched_data_from_password_db| if its tag is identical to |data|'s. | 102 // |unmatched_data_from_password_db| if its tag is identical to |data|'s. |
| 86 static void CreateOrUpdateEntry( | 103 void CreateOrUpdateEntry(const sync_pb::PasswordSpecificsData& data, |
| 87 const syncer::SyncData& data, | 104 PasswordEntryMap* unmatched_data_from_password_db, |
| 88 PasswordEntryMap* unmatched_data_from_password_db, | 105 SyncEntries* sync_entries, |
| 89 SyncEntries* sync_entries, | 106 syncer::SyncChangeList* updated_db_entries); |
| 90 syncer::SyncChangeList* updated_db_entries); | |
| 91 | 107 |
| 92 // Calls |operation| for each element in |entries| and appends the changes to | 108 // Calls |operation| for each element in |entries| and appends the changes to |
| 93 // |all_changes|. | 109 // |all_changes|. |
| 94 void WriteEntriesToDatabase( | 110 void WriteEntriesToDatabase( |
| 95 DatabaseOperation operation, | 111 DatabaseOperation operation, |
| 96 const std::vector<std::unique_ptr<autofill::PasswordForm>>& entries, | 112 const std::vector<std::unique_ptr<autofill::PasswordForm>>& entries, |
| 97 PasswordStoreChangeList* all_changes); | 113 PasswordStoreChangeList* all_changes); |
| 98 | 114 |
| 99 // The factory that creates sync errors. |SyncError| has rich data | 115 // The factory that creates sync errors. |SyncError| has rich data |
| 100 // suitable for debugging. | 116 // suitable for debugging. |
| 101 std::unique_ptr<syncer::SyncErrorFactory> sync_error_factory_; | 117 std::unique_ptr<syncer::SyncErrorFactory> sync_error_factory_; |
| 102 | 118 |
| 103 // |sync_processor_| will mirror the |PasswordStore| changes in the sync db. | 119 // |sync_processor_| will mirror the |PasswordStore| changes in the sync db. |
| 104 std::unique_ptr<syncer::SyncChangeProcessor> sync_processor_; | 120 std::unique_ptr<syncer::SyncChangeProcessor> sync_processor_; |
| 105 | 121 |
| 106 // The password store that adds/updates/deletes password entries. Not owned. | 122 // The password store that adds/updates/deletes password entries. Not owned. |
| 107 PasswordStoreSync* const password_store_; | 123 PasswordStoreSync* const password_store_; |
| 108 | 124 |
| 109 // A signal activated by this class to start sync as soon as possible. | 125 // A signal activated by this class to start sync as soon as possible. |
| 110 syncer::SyncableService::StartSyncFlare flare_; | 126 syncer::SyncableService::StartSyncFlare flare_; |
| 111 | 127 |
| 128 // Clock for date_synced updates. |
| 129 std::unique_ptr<base::Clock> clock_; |
| 130 |
| 112 // True if processing sync changes is in progress. | 131 // True if processing sync changes is in progress. |
| 113 bool is_processing_sync_changes_; | 132 bool is_processing_sync_changes_; |
| 114 | 133 |
| 115 SEQUENCE_CHECKER(sequence_checker_); | 134 SEQUENCE_CHECKER(sequence_checker_); |
| 116 | 135 |
| 117 DISALLOW_COPY_AND_ASSIGN(PasswordSyncableService); | 136 DISALLOW_COPY_AND_ASSIGN(PasswordSyncableService); |
| 118 }; | 137 }; |
| 119 | 138 |
| 120 } // namespace password_manager | 139 } // namespace password_manager |
| 121 | 140 |
| 122 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_SYNCABLE_SERVICE_H_
_ | 141 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_SYNCABLE_SERVICE_H_
_ |
| OLD | NEW |