|
OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_SYNC_GLUE_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_ | |
6 #define CHROME_BROWSER_SYNC_GLUE_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_ | |
7 #pragma once | |
8 | |
9 #include <map> | |
10 #include <set> | |
11 #include <string> | |
12 #include <vector> | |
13 | |
14 #include "base/basictypes.h" | |
15 #include "base/memory/ref_counted.h" | |
16 #include "base/synchronization/lock.h" | |
17 #include "base/threading/non_thread_safe.h" | |
18 #include "chrome/browser/autofill/personal_data_manager.h" | |
19 #include "chrome/browser/sync/api/sync_change.h" | |
20 #include "chrome/browser/sync/api/sync_data.h" | |
21 #include "chrome/browser/sync/api/sync_error.h" | |
22 #include "chrome/browser/sync/api/syncable_service.h" | |
23 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" | |
24 #include "chrome/browser/webdata/autofill_change.h" | |
25 #include "chrome/browser/webdata/autofill_entry.h" | |
26 #include "content/common/content_notification_types.h" | |
27 #include "content/common/notification_observer.h" | |
28 #include "content/common/notification_registrar.h" | |
29 | |
30 class AutofillProfile; | |
31 | |
dhollowa
2011/09/01 20:17:49
nit: please remove extra line.
GeorgeY
2011/09/02 04:34:12
Done.
| |
32 class WebDatabase; | |
33 | |
34 namespace browser_sync { | |
35 | |
36 extern const char kAutofillProfileTag[]; | |
37 | |
38 class UnrecoverableErrorHandler; | |
39 | |
40 // Contains all model association related logic: | |
41 // * Algorithm to associate autofill model and sync model. | |
42 // We do not check if we have local data before this run; we always | |
43 // merge and sync. | |
44 class AutofillProfileSyncableService | |
45 : public SyncableService, | |
46 public NotificationObserver, | |
47 public base::NonThreadSafe { | |
48 public: | |
49 AutofillProfileSyncableService(WebDatabase* web_database, | |
50 PersonalDataManager* data_manager); | |
51 virtual ~AutofillProfileSyncableService(); | |
52 | |
53 static syncable::ModelType model_type() { return syncable::AUTOFILL_PROFILE; } | |
54 | |
55 // SyncableService implementation. | |
56 virtual SyncError MergeDataAndStartSyncing( | |
57 syncable::ModelType type, | |
58 const SyncDataList& initial_sync_data, | |
59 SyncChangeProcessor* sync_processor) OVERRIDE; | |
60 virtual void StopSyncing(syncable::ModelType type) OVERRIDE; | |
61 virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE; | |
62 virtual SyncError ProcessSyncChanges( | |
63 const tracked_objects::Location& from_here, | |
64 const SyncChangeList& change_list) OVERRIDE; | |
65 | |
66 // NotificationObserver implementation. | |
67 virtual void Observe(int type, | |
68 const NotificationSource& source, | |
69 const NotificationDetails& details); | |
dhollowa
2011/09/01 20:17:49
nit: OVERRIDE
GeorgeY
2011/09/02 04:34:12
Done.
| |
70 | |
71 // Helper function that overwrites |merge_into| with data from proto-buffer | |
72 // |specifics|. | |
73 static bool OverwriteProfileWithServerData( | |
dhollowa
2011/09/01 20:17:49
Since these are helpers for unit tests, please mak
GeorgeY
2011/09/02 04:34:12
Done.
| |
74 AutofillProfile* merge_into, | |
dhollowa
2011/09/01 20:17:49
nit: output parameters come after input parameters
GeorgeY
2011/09/02 04:34:12
Copied verbatim from the old file - changed, sure.
| |
75 const sync_pb::AutofillProfileSpecifics& specifics); | |
76 | |
77 // Writes |profile| data into supplied |profile_specifics|. | |
78 static void WriteAutofillProfile(const AutofillProfile& profile, | |
79 sync_pb::EntitySpecifics* profile_specifics); | |
80 | |
81 protected: | |
dhollowa
2011/09/01 20:17:49
It looks like too much is "protected". Only |Data
GeorgeY
2011/09/02 04:34:12
Done.
| |
82 typedef std::map<std::string, ScopedVector<AutofillProfile>::iterator> | |
83 GuidToProfileMap; | |
dhollowa
2011/09/01 20:17:49
nit: To keep consistent with webdata and other aut
GeorgeY
2011/09/02 04:34:12
Done.
| |
84 | |
85 // A convenience wrapper of a bunch of state we pass around while | |
86 // associating models, and send to the WebDatabase for persistence. | |
87 // We do this so we hold the write lock for only a small period. | |
88 // When storing the web db we are out of the write lock. | |
89 struct DataBundle; | |
90 | |
91 // Helper to query WebDatabase for the current autofill state. | |
92 // Made virtual for ease of mocking in the unit-test. | |
93 virtual bool LoadAutofillData(std::vector<AutofillProfile*>* profiles) const; | |
94 | |
95 // Helper to persist any changes that occured during model association to | |
96 // the WebDatabase. | |
97 // Made virtual for ease of mocking in the unit-test. | |
98 virtual bool SaveChangesToWebData(const DataBundle& bundle); | |
99 | |
100 // Creates SyncChange based on supplied |action| and |profile|. | |
101 SyncChange CreateChange(SyncChange::SyncChangeType action, | |
dhollowa
2011/09/01 20:17:49
It appears that all of these "Create*" methods don
GeorgeY
2011/09/02 04:34:12
Done.
dhollowa
2011/09/07 01:48:15
CreateGUIDToProfileMap and CreateData did not get
GeorgeY
2011/09/07 20:55:07
Please verify that you are looking at latest code.
| |
102 const AutofillProfile& profile); | |
103 | |
104 // Creates ACTION_DELETE SyncChange based on supplied |guid|. | |
105 SyncChange CreateDeleteChange(const std::string& guid); | |
106 | |
107 // Creates SyncData based on supplied |profile|. | |
108 SyncData CreateData(const AutofillProfile& profile); | |
109 | |
110 // Creates |profile_map| from the supplied |profiles| vector. Necessary for | |
111 // fast processing of the changes. | |
112 void CreateGuidToProfileMap(ScopedVector<AutofillProfile>* profiles, | |
113 GuidToProfileMap* profile_map); | |
114 | |
115 // Creates or updates a profile based on |data|. Looks at the guid of the data | |
116 // if a profile with such guid is present in |profile_map| updates it. If not | |
117 // searches through |profiles| for similar profiles. if similar profile is | |
118 // found substitutes it for the new one, otherwise add a new profile. Returns | |
119 // true if addition happened, false otherwise. | |
120 bool CreateOrUpdateProfile(const SyncData& data, | |
121 ScopedVector<AutofillProfile>* profiles, | |
122 GuidToProfileMap* profile_map, | |
123 DataBundle *bundle); | |
dhollowa
2011/09/01 20:17:49
nit: s/ */* /
GeorgeY
2011/09/02 04:34:12
Done.
| |
124 | |
125 // Syncs |change| to the cloud. | |
126 void ActOnChange(AutofillProfileChange* change); | |
127 | |
128 // For unit-tests. | |
129 AutofillProfileSyncableService(); | |
130 void set_sync_processor(SyncChangeProcessor* sync_processor) { | |
131 sync_processor_ = sync_processor; | |
132 } | |
133 | |
134 private: | |
135 FRIEND_TEST_ALL_PREFIXES(AutofillProfileSyncableServiceTest, | |
136 MergeDataAndStartSyncing); | |
137 FRIEND_TEST_ALL_PREFIXES(AutofillProfileSyncableServiceTest, GetAllSyncData); | |
138 FRIEND_TEST_ALL_PREFIXES(AutofillProfileSyncableServiceTest, | |
139 ProcessSyncChanges); | |
140 // A convenience wrapper of a bunch of state we pass around while associating | |
141 // models, and send to the WebDatabase for persistence. | |
142 // struct DataBundle; | |
dhollowa
2011/09/01 20:17:49
nit: Looks like this comment should go.
GeorgeY
2011/09/02 04:34:12
Done. Remnants from the old file
| |
143 static bool MergeField(FormGroup* f, | |
dhollowa
2011/09/01 20:17:49
This could also be moved into the .cc file in an a
GeorgeY
2011/09/02 04:34:12
Again, most of supporting functions were copied ve
| |
144 AutofillFieldType t, | |
145 const std::string& specifics_field); | |
146 WebDatabase* web_database_; | |
147 PersonalDataManager* personal_data_; | |
148 NotificationRegistrar notification_registrar_; | |
149 | |
150 SyncChangeProcessor* sync_processor_; | |
151 | |
152 int number_of_profiles_created_; | |
dhollowa
2011/09/01 20:17:49
I don't see where this is used.
GeorgeY
2011/09/02 04:34:12
Removed - was used in old unit-test.
| |
153 | |
154 DISALLOW_COPY_AND_ASSIGN(AutofillProfileSyncableService); | |
155 }; | |
156 | |
157 struct AutofillProfileSyncableService::DataBundle { | |
dhollowa
2011/09/01 20:17:49
Move this to the .cc file.
GeorgeY
2011/09/02 04:34:12
Done.
dhollowa
2011/09/07 01:48:15
It appears from other comments (and code) that thi
GeorgeY
2011/09/07 20:55:07
Done.
| |
158 DataBundle(); | |
159 ~DataBundle(); | |
160 | |
161 std::vector<std::string> profiles_to_delete; | |
162 std::vector<AutofillProfile*> updated_profiles; | |
dhollowa
2011/09/01 23:11:46
profiles_to_update?
dhollowa
2011/09/07 01:48:15
This didn't get changed.
GeorgeY
2011/09/07 20:55:07
Done.
| |
163 std::vector<AutofillProfile*> new_profiles; // We own these pointers. | |
dhollowa
2011/09/01 20:17:49
If these are owned, how about using a scoped vecto
dhollowa
2011/09/01 23:11:46
profiles_to_add?
GeorgeY
2011/09/02 04:34:12
Originall class from Model*
Not anymore :).
dhollowa
2011/09/07 01:48:15
This didn't get changed.
(1) s/new_profiles/profi
GeorgeY
2011/09/07 20:55:07
1. Done.
2. It is not owned by bundle anymore.
| |
164 }; | |
165 | |
166 } // namespace browser_sync | |
167 | |
168 #endif // CHROME_BROWSER_SYNC_GLUE_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_ | |
169 | |
OLD | NEW |