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_AUTOCOMPLETE_SYNCABLE_SERVICE_H_ | 4 #ifndef CHROME_BROWSER_WEBDATA_AUTOCOMPLETE_SYNCABLE_SERVICE_H_ |
5 #define CHROME_BROWSER_WEBDATA_AUTOCOMPLETE_SYNCABLE_SERVICE_H_ | 5 #define CHROME_BROWSER_WEBDATA_AUTOCOMPLETE_SYNCABLE_SERVICE_H_ |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/scoped_observer.h" | 15 #include "base/scoped_observer.h" |
16 #include "base/supports_user_data.h" | 16 #include "base/supports_user_data.h" |
17 #include "base/threading/non_thread_safe.h" | 17 #include "base/threading/non_thread_safe.h" |
18 #include "components/autofill/browser/webdata/autofill_change.h" | 18 #include "components/autofill/browser/webdata/autofill_change.h" |
19 #include "components/autofill/browser/webdata/autofill_entry.h" | 19 #include "components/autofill/browser/webdata/autofill_entry.h" |
| 20 #include "components/autofill/browser/webdata/autofill_webdata_backend.h" |
20 #include "components/autofill/browser/webdata/autofill_webdata_service.h" | 21 #include "components/autofill/browser/webdata/autofill_webdata_service.h" |
21 #include "components/autofill/browser/webdata/autofill_webdata_service_observer.
h" | 22 #include "components/autofill/browser/webdata/autofill_webdata_service_observer.
h" |
22 #include "sync/api/sync_change.h" | 23 #include "sync/api/sync_change.h" |
23 #include "sync/api/sync_data.h" | 24 #include "sync/api/sync_data.h" |
24 #include "sync/api/sync_error.h" | 25 #include "sync/api/sync_error.h" |
25 #include "sync/api/syncable_service.h" | 26 #include "sync/api/syncable_service.h" |
26 | 27 |
27 class ProfileSyncServiceAutofillTest; | 28 class ProfileSyncServiceAutofillTest; |
28 | 29 |
29 namespace syncer { | 30 namespace syncer { |
(...skipping 11 matching lines...) Expand all Loading... |
41 class AutocompleteSyncableService | 42 class AutocompleteSyncableService |
42 : public base::SupportsUserData::Data, | 43 : public base::SupportsUserData::Data, |
43 public syncer::SyncableService, | 44 public syncer::SyncableService, |
44 public autofill::AutofillWebDataServiceObserverOnDBThread, | 45 public autofill::AutofillWebDataServiceObserverOnDBThread, |
45 public base::NonThreadSafe { | 46 public base::NonThreadSafe { |
46 public: | 47 public: |
47 virtual ~AutocompleteSyncableService(); | 48 virtual ~AutocompleteSyncableService(); |
48 | 49 |
49 // Creates a new AutocompleteSyncableService and hangs it off of | 50 // Creates a new AutocompleteSyncableService and hangs it off of |
50 // |web_data_service|, which takes ownership. | 51 // |web_data_service|, which takes ownership. |
51 static void CreateForWebDataService( | 52 static void CreateForWebDataServiceAndBackend( |
52 autofill::AutofillWebDataService* web_data_service); | 53 autofill::AutofillWebDataService* web_data_service, |
| 54 autofill::AutofillWebDataBackend* webdata_backend); |
53 | 55 |
54 // Retrieves the AutocompleteSyncableService stored on |web_data|. | 56 // Retrieves the AutocompleteSyncableService stored on |web_data|. |
55 static AutocompleteSyncableService* FromWebDataService( | 57 static AutocompleteSyncableService* FromWebDataService( |
56 autofill::AutofillWebDataService* web_data_service); | 58 autofill::AutofillWebDataService* web_data_service); |
57 | 59 |
58 static syncer::ModelType model_type() { return syncer::AUTOFILL; } | 60 static syncer::ModelType model_type() { return syncer::AUTOFILL; } |
59 | 61 |
60 // syncer::SyncableService implementation. | 62 // syncer::SyncableService implementation. |
61 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( | 63 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( |
62 syncer::ModelType type, | 64 syncer::ModelType type, |
(...skipping 16 matching lines...) Expand all Loading... |
79 void UpdateCullSetting(bool cull_expired_entries); | 81 void UpdateCullSetting(bool cull_expired_entries); |
80 bool cull_expired_entries() const { return cull_expired_entries_; } | 82 bool cull_expired_entries() const { return cull_expired_entries_; } |
81 | 83 |
82 // Provides a StartSyncFlare to the SyncableService. See | 84 // Provides a StartSyncFlare to the SyncableService. See |
83 // sync_start_util for more. | 85 // sync_start_util for more. |
84 void InjectStartSyncFlare( | 86 void InjectStartSyncFlare( |
85 const syncer::SyncableService::StartSyncFlare& flare); | 87 const syncer::SyncableService::StartSyncFlare& flare); |
86 | 88 |
87 protected: | 89 protected: |
88 explicit AutocompleteSyncableService( | 90 explicit AutocompleteSyncableService( |
89 autofill::AutofillWebDataService* web_data_service); | 91 autofill::AutofillWebDataBackend* webdata_backend); |
90 | 92 |
91 // Helper to query WebDatabase for the current autocomplete state. | 93 // Helper to query WebDatabase for the current autocomplete state. |
92 // Made virtual for ease of mocking in the unit-test. | 94 // Made virtual for ease of mocking in the unit-test. |
93 virtual bool LoadAutofillData( | 95 virtual bool LoadAutofillData( |
94 std::vector<autofill::AutofillEntry>* entries) const; | 96 std::vector<autofill::AutofillEntry>* entries) const; |
95 | 97 |
96 // Helper to persist any changes that occured during model association to | 98 // Helper to persist any changes that occured during model association to |
97 // the WebDatabase. |entries| will be either added or updated. | 99 // the WebDatabase. |entries| will be either added or updated. |
98 // Made virtual for ease of mocking in the unit-test. | 100 // Made virtual for ease of mocking in the unit-test. |
99 virtual bool SaveChangesToWebData( | 101 virtual bool SaveChangesToWebData( |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 static std::string KeyToTag(const std::string& name, | 147 static std::string KeyToTag(const std::string& name, |
146 const std::string& value); | 148 const std::string& value); |
147 | 149 |
148 // For unit-tests. | 150 // For unit-tests. |
149 AutocompleteSyncableService(); | 151 AutocompleteSyncableService(); |
150 void set_sync_processor(syncer::SyncChangeProcessor* sync_processor) { | 152 void set_sync_processor(syncer::SyncChangeProcessor* sync_processor) { |
151 sync_processor_.reset(sync_processor); | 153 sync_processor_.reset(sync_processor); |
152 } | 154 } |
153 | 155 |
154 // Lifetime of AutocompleteSyncableService object is shorter than | 156 // Lifetime of AutocompleteSyncableService object is shorter than |
155 // |web_data_service_| passed to it. | 157 // |autofill_webdata_backend_| passed to it. |
156 autofill::AutofillWebDataService* web_data_service_; | 158 autofill::AutofillWebDataBackend* webdata_backend_; |
157 | 159 |
158 ScopedObserver<autofill::AutofillWebDataService, AutocompleteSyncableService> | 160 ScopedObserver<autofill::AutofillWebDataBackend, AutocompleteSyncableService> |
159 scoped_observer_; | 161 scoped_observer_; |
160 | 162 |
161 // We receive ownership of |sync_processor_| in MergeDataAndStartSyncing() and | 163 // We receive ownership of |sync_processor_| in MergeDataAndStartSyncing() and |
162 // destroy it in StopSyncing(). | 164 // destroy it in StopSyncing(). |
163 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 165 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
164 | 166 |
165 // We receive ownership of |error_handler_| in MergeDataAndStartSyncing() and | 167 // We receive ownership of |error_handler_| in MergeDataAndStartSyncing() and |
166 // destroy it in StopSyncing(). | 168 // destroy it in StopSyncing(). |
167 scoped_ptr<syncer::SyncErrorFactory> error_handler_; | 169 scoped_ptr<syncer::SyncErrorFactory> error_handler_; |
168 | 170 |
169 // Whether we should cull expired autofill entries, can be updated by sync | 171 // Whether we should cull expired autofill entries, can be updated by sync |
170 // via UpdateCullingSetting. | 172 // via UpdateCullingSetting. |
171 bool cull_expired_entries_; | 173 bool cull_expired_entries_; |
172 | 174 |
173 syncer::SyncableService::StartSyncFlare flare_; | 175 syncer::SyncableService::StartSyncFlare flare_; |
174 | 176 |
175 DISALLOW_COPY_AND_ASSIGN(AutocompleteSyncableService); | 177 DISALLOW_COPY_AND_ASSIGN(AutocompleteSyncableService); |
176 }; | 178 }; |
177 | 179 |
178 #endif // CHROME_BROWSER_WEBDATA_AUTOCOMPLETE_SYNCABLE_SERVICE_H_ | 180 #endif // CHROME_BROWSER_WEBDATA_AUTOCOMPLETE_SYNCABLE_SERVICE_H_ |
OLD | NEW |