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 #ifndef CHROME_BROWSER_WEBDATA_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_ | 4 #ifndef CHROME_BROWSER_WEBDATA_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_ |
5 #define CHROME_BROWSER_WEBDATA_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_ | 5 #define CHROME_BROWSER_WEBDATA_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_ |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "sync/api/sync_change.h" | 21 #include "sync/api/sync_change.h" |
22 #include "sync/api/sync_data.h" | 22 #include "sync/api/sync_data.h" |
23 #include "sync/api/sync_error.h" | 23 #include "sync/api/sync_error.h" |
24 #include "sync/api/syncable_service.h" | 24 #include "sync/api/syncable_service.h" |
25 #include "sync/protocol/autofill_specifics.pb.h" | 25 #include "sync/protocol/autofill_specifics.pb.h" |
26 | 26 |
27 class ProfileSyncServiceAutofillTest; | 27 class ProfileSyncServiceAutofillTest; |
28 class WebDataServiceBase; | 28 class WebDataServiceBase; |
29 | 29 |
30 namespace autofill { | 30 namespace autofill { |
| 31 class AutofillBackendDelegate; |
31 class AutofillProfile; | 32 class AutofillProfile; |
32 class AutofillTable; | 33 class AutofillTable; |
33 class AutofillWebDataService; | 34 class AutofillWebDataService; |
34 class FormGroup; | 35 class FormGroup; |
35 } // namespace autofill | 36 } // namespace autofill |
36 | 37 |
37 extern const char kAutofillProfileTag[]; | 38 extern const char kAutofillProfileTag[]; |
38 | 39 |
39 // The sync implementation for AutofillProfiles. | 40 // The sync implementation for AutofillProfiles. |
40 // MergeDataAndStartSyncing() called first, it does cloud->local and | 41 // MergeDataAndStartSyncing() called first, it does cloud->local and |
41 // local->cloud syncs. Then for each cloud change we receive | 42 // local->cloud syncs. Then for each cloud change we receive |
42 // ProcessSyncChanges() and for each local change Observe() is called. | 43 // ProcessSyncChanges() and for each local change Observe() is called. |
43 class AutofillProfileSyncableService | 44 class AutofillProfileSyncableService |
44 : public base::SupportsUserData::Data, | 45 : public base::SupportsUserData::Data, |
45 public syncer::SyncableService, | 46 public syncer::SyncableService, |
46 public autofill::AutofillWebDataServiceObserverOnDBThread, | 47 public autofill::AutofillWebDataServiceObserverOnDBThread, |
47 public base::NonThreadSafe { | 48 public base::NonThreadSafe { |
48 public: | 49 public: |
49 virtual ~AutofillProfileSyncableService(); | 50 virtual ~AutofillProfileSyncableService(); |
50 | 51 |
51 // Creates a new AutofillProfileSyncableService and hangs it off of | 52 // Creates a new AutofillProfileSyncableService and hangs it off of |
52 // |web_data_service|, which takes ownership. | 53 // |web_data_service|, which takes ownership. |
53 static void CreateForWebDataService( | 54 static void CreateForWebDataService( |
54 autofill::AutofillWebDataService* web_data_service, | 55 autofill::AutofillWebDataService* web_data_service, |
| 56 autofill::AutofillBackendDelegate* web_data_delegate, |
55 const std::string& app_locale); | 57 const std::string& app_locale); |
56 | 58 |
57 // Retrieves the AutofillProfileSyncableService stored on |web_data_service|. | 59 // Retrieves the AutofillProfileSyncableService stored on |web_data_service|. |
58 static AutofillProfileSyncableService* FromWebDataService( | 60 static AutofillProfileSyncableService* FromWebDataService( |
59 autofill::AutofillWebDataService* web_data_service); | 61 autofill::AutofillWebDataService* web_data_service); |
60 | 62 |
61 static syncer::ModelType model_type() { return syncer::AUTOFILL_PROFILE; } | 63 static syncer::ModelType model_type() { return syncer::AUTOFILL_PROFILE; } |
62 | 64 |
63 // syncer::SyncableService implementation. | 65 // syncer::SyncableService implementation. |
64 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( | 66 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( |
65 syncer::ModelType type, | 67 syncer::ModelType type, |
66 const syncer::SyncDataList& initial_sync_data, | 68 const syncer::SyncDataList& initial_sync_data, |
67 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 69 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
68 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) OVERRIDE; | 70 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) OVERRIDE; |
69 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; | 71 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; |
70 virtual syncer::SyncDataList GetAllSyncData( | 72 virtual syncer::SyncDataList GetAllSyncData( |
71 syncer::ModelType type) const OVERRIDE; | 73 syncer::ModelType type) const OVERRIDE; |
72 virtual syncer::SyncError ProcessSyncChanges( | 74 virtual syncer::SyncError ProcessSyncChanges( |
73 const tracked_objects::Location& from_here, | 75 const tracked_objects::Location& from_here, |
74 const syncer::SyncChangeList& change_list) OVERRIDE; | 76 const syncer::SyncChangeList& change_list) OVERRIDE; |
75 | 77 |
76 // AutofillWebDataServiceObserverOnDBThread implementation. | 78 // AutofillWebDataServiceObserverOnDBThread implementation. |
77 virtual void AutofillProfileChanged( | 79 virtual void AutofillProfileChanged( |
78 const autofill::AutofillProfileChange& change) OVERRIDE; | 80 const autofill::AutofillProfileChange& change) OVERRIDE; |
79 | 81 |
80 protected: | 82 protected: |
81 AutofillProfileSyncableService( | 83 AutofillProfileSyncableService( |
82 autofill::AutofillWebDataService* web_data_service, | 84 autofill::AutofillWebDataService* web_data_service, |
| 85 autofill::AutofillBackendDelegate* web_data_delegate, |
83 const std::string& app_locale); | 86 const std::string& app_locale); |
84 | 87 |
85 // A convenience wrapper of a bunch of state we pass around while | 88 // A convenience wrapper of a bunch of state we pass around while |
86 // associating models, and send to the WebDatabase for persistence. | 89 // associating models, and send to the WebDatabase for persistence. |
87 // We do this so we hold the write lock for only a small period. | 90 // 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. | 91 // When storing the web db we are out of the write lock. |
89 struct DataBundle; | 92 struct DataBundle; |
90 | 93 |
91 // Helper to query WebDatabase for the current autofill state. | 94 // Helper to query WebDatabase for the current autofill state. |
92 // Made virtual for ease of mocking in the unit-test. | 95 // Made virtual for ease of mocking in the unit-test. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 autofill::AutofillProfile* merge_into, | 175 autofill::AutofillProfile* merge_into, |
173 const std::string& app_locale); | 176 const std::string& app_locale); |
174 | 177 |
175 // For unit-tests. | 178 // For unit-tests. |
176 AutofillProfileSyncableService(); | 179 AutofillProfileSyncableService(); |
177 void set_sync_processor(syncer::SyncChangeProcessor* sync_processor) { | 180 void set_sync_processor(syncer::SyncChangeProcessor* sync_processor) { |
178 sync_processor_.reset(sync_processor); | 181 sync_processor_.reset(sync_processor); |
179 } | 182 } |
180 | 183 |
181 autofill::AutofillWebDataService* web_data_service_; // WEAK | 184 autofill::AutofillWebDataService* web_data_service_; // WEAK |
| 185 autofill::AutofillBackendDelegate* web_data_delegate_; // WEAK |
182 std::string app_locale_; | 186 std::string app_locale_; |
183 ScopedObserver<autofill::AutofillWebDataService, | 187 ScopedObserver<autofill::AutofillBackendDelegate, |
184 AutofillProfileSyncableService> scoped_observer_; | 188 AutofillProfileSyncableService> scoped_observer_; |
185 | 189 |
186 // Cached Autofill profiles. *Warning* deleted profiles are still in the | 190 // Cached Autofill profiles. *Warning* deleted profiles are still in the |
187 // vector - use the |profiles_map_| to iterate through actual profiles. | 191 // vector - use the |profiles_map_| to iterate through actual profiles. |
188 ScopedVector<autofill::AutofillProfile> profiles_; | 192 ScopedVector<autofill::AutofillProfile> profiles_; |
189 GUIDToProfileMap profiles_map_; | 193 GUIDToProfileMap profiles_map_; |
190 | 194 |
191 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 195 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
192 | 196 |
193 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory_; | 197 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory_; |
(...skipping 11 matching lines...) Expand all Loading... |
205 std::vector<autofill::AutofillProfile*> profiles_to_add; | 209 std::vector<autofill::AutofillProfile*> profiles_to_add; |
206 | 210 |
207 // When we go through sync we find profiles that are similar but unmatched. | 211 // When we go through sync we find profiles that are similar but unmatched. |
208 // Merge such profiles. | 212 // Merge such profiles. |
209 GUIDToProfileMap candidates_to_merge; | 213 GUIDToProfileMap candidates_to_merge; |
210 // Profiles that have multi-valued fields that are not in sync. | 214 // Profiles that have multi-valued fields that are not in sync. |
211 std::vector<autofill::AutofillProfile*> profiles_to_sync_back; | 215 std::vector<autofill::AutofillProfile*> profiles_to_sync_back; |
212 }; | 216 }; |
213 | 217 |
214 #endif // CHROME_BROWSER_WEBDATA_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_ | 218 #endif // CHROME_BROWSER_WEBDATA_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_ |
OLD | NEW |