OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_PASSWORD_MANAGER_PASSWORD_SYNCABLE_SERVICE_H__ | 5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_SYNCABLE_SERVICE_H__ |
6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_SYNCABLE_SERVICE_H__ | 6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_SYNCABLE_SERVICE_H__ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/scoped_vector.h" | |
12 #include "sync/api/sync_change.h" | 13 #include "sync/api/sync_change.h" |
13 #include "sync/api/sync_data.h" | 14 #include "sync/api/sync_data.h" |
14 #include "sync/api/sync_error.h" | 15 #include "sync/api/sync_error.h" |
15 #include "sync/api/syncable_service.h" | 16 #include "sync/api/syncable_service.h" |
16 #include "sync/protocol/password_specifics.pb.h" | 17 #include "sync/protocol/password_specifics.pb.h" |
17 #include "sync/protocol/sync.pb.h" | 18 #include "sync/protocol/sync.pb.h" |
18 | 19 |
19 namespace autofill { | 20 namespace autofill { |
20 struct PasswordForm; | 21 struct PasswordForm; |
21 } | 22 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 // Returns the unique tag that will serve as the sync identifier for the | 54 // Returns the unique tag that will serve as the sync identifier for the |
54 // |password| entry. | 55 // |password| entry. |
55 static std::string MakeTag(const autofill::PasswordForm& password); | 56 static std::string MakeTag(const autofill::PasswordForm& password); |
56 static std::string MakeTag(const sync_pb::PasswordSpecificsData& password); | 57 static std::string MakeTag(const sync_pb::PasswordSpecificsData& password); |
57 static std::string MakeTag(const std::string& origin_url, | 58 static std::string MakeTag(const std::string& origin_url, |
58 const std::string& username_element, | 59 const std::string& username_element, |
59 const std::string& username_value, | 60 const std::string& username_value, |
60 const std::string& password_element, | 61 const std::string& password_element, |
61 const std::string& signon_realm); | 62 const std::string& signon_realm); |
62 | 63 |
64 protected: | |
65 // Notifies password store of a change that was performed by sync. | |
66 // Virtual so tests can override. | |
67 virtual void NotifyPasswordStoreOfLoginChanges(); | |
68 | |
63 private: | 69 private: |
64 typedef std::vector<autofill::PasswordForm*> PasswordForms; | 70 typedef std::vector<autofill::PasswordForm*> PasswordForms; |
71 typedef std::map<std::string, autofill::PasswordForm*> | |
72 PasswordEntryMap; | |
73 | |
74 friend class PasswordStoreDataVerifier; | |
75 friend class TestSyncChangeProcessor; | |
65 | 76 |
66 // Use the |PasswordStore| APIs to add and update entries. | 77 // Use the |PasswordStore| APIs to add and update entries. |
67 void WriteToPasswordStore(PasswordForms* new_entries, | 78 void WriteToPasswordStore(const PasswordForms& new_entries, |
68 PasswordForms* udpated_entries); | 79 const PasswordForms& updated_entries); |
69 | 80 |
70 // Converts the |PasswordForm| to |SyncData| suitable for syncing. | 81 // Checks if |data|, the entry in sync db, needs to be created or updated |
71 syncer::SyncData CreateSyncData(const autofill::PasswordForm& password); | 82 // in the passwords db. Depending on what action needs to be performed the |
Ilya Sherman
2013/12/05 07:01:54
nit: "needs to be performed the" -> "needs to be p
| |
83 // entry may be added to |new_entries| or |updated_entries|. If the item is | |
Ilya Sherman
2013/12/05 07:01:54
nit: "to |new_entries| or |updated_entries|" -> "t
| |
84 // identical to an entry in passwords db, no action is performed. If an | |
Ilya Sherman
2013/12/05 07:01:54
nit: "in passwords db" -> "in the passwords db"
| |
85 // item needs to be updated in the sync database then the item is also | |
Ilya Sherman
2013/12/05 07:01:54
nit: Might as well be consistent about "database"
Ilya Sherman
2013/12/05 07:01:54
nit: "in the sync database then" -> "in the sync d
| |
86 // added to |updated_local_entries| list. If |data|'s tag is identical to an | |
87 // entry's tag in |umatched_data_from_password_db| then that entry | |
Ilya Sherman
2013/12/05 07:01:54
nit: Spurious leading whitespace.
| |
88 // will be removed from |umatched_data_from_password_db|. | |
89 void CreateOrUpdateEntry( | |
90 const syncer::SyncData& data, | |
91 PasswordEntryMap* umatched_data_from_password_db, | |
92 ScopedVector<autofill::PasswordForm>* new_entries, | |
93 ScopedVector<autofill::PasswordForm>* updated_entries, | |
94 syncer::SyncChangeList* updated_local_entries); | |
95 | |
96 // Converts the |password| into a SyncData object. | |
97 static syncer::SyncData CreateSyncData( | |
98 const autofill::PasswordForm& password); | |
99 | |
100 // Extracts the |PasswordForm| data from sync's protobuffer | |
101 // format, |PasswordSpecificsData|. | |
102 static void ExtractPasswordFromSpecifics( | |
103 const sync_pb::PasswordSpecificsData& password, | |
104 autofill::PasswordForm* new_password); | |
105 | |
106 // Merges the local and sync passwords and outputs the entry into | |
107 // |new_password_form|. Returns true if the local and the sync | |
108 // passwords differ. Returns false if they are identical. | |
109 bool MergeLocalAndSyncPasswords( | |
110 const sync_pb::PasswordSpecificsData& password_specifics, | |
111 const autofill::PasswordForm& password_form, | |
112 autofill::PasswordForm* new_password_form); | |
72 | 113 |
73 // The factory that creates sync errors. |SyncError| has rich data | 114 // The factory that creates sync errors. |SyncError| has rich data |
74 // suitable for debugging. | 115 // suitable for debugging. |
75 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory_; | 116 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory_; |
76 | 117 |
77 // |SyncProcessor| will mirror the |PasswordStore| changes in the sync db. | 118 // |SyncProcessor| will mirror the |PasswordStore| changes in the sync db. |
78 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 119 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
79 | 120 |
80 // The password store that adds/updates/deletes password entries. | 121 // The password store that adds/updates/deletes password entries. |
81 scoped_refptr<PasswordStore> password_store_; | 122 scoped_refptr<PasswordStore> password_store_; |
82 }; | 123 }; |
83 | 124 |
84 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_SYNCABLE_SERVICE_H__ | 125 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_SYNCABLE_SERVICE_H__ |
85 | 126 |
OLD | NEW |