| 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_service.h" | |
| 21 #include "components/autofill/browser/webdata/autofill_webdata_service_observer.
h" | 20 #include "components/autofill/browser/webdata/autofill_webdata_service_observer.
h" |
| 22 #include "sync/api/sync_change.h" | 21 #include "sync/api/sync_change.h" |
| 23 #include "sync/api/sync_data.h" | 22 #include "sync/api/sync_data.h" |
| 24 #include "sync/api/sync_error.h" | 23 #include "sync/api/sync_error.h" |
| 25 #include "sync/api/syncable_service.h" | 24 #include "sync/api/syncable_service.h" |
| 26 | 25 |
| 27 class ProfileSyncServiceAutofillTest; | 26 class ProfileSyncServiceAutofillTest; |
| 28 | 27 |
| 29 namespace syncer { | 28 namespace syncer { |
| 30 class SyncErrorFactory; | 29 class SyncErrorFactory; |
| 31 } | 30 } |
| 32 | 31 |
| 33 namespace sync_pb { | 32 namespace sync_pb { |
| 34 class AutofillSpecifics; | 33 class AutofillSpecifics; |
| 35 } | 34 } |
| 36 | 35 |
| 36 namespace autofill { |
| 37 class AutofillBackendDelegate; |
| 38 class AutofillWebDataService; |
| 39 } // namespace autofill |
| 40 |
| 37 // The sync implementation for autocomplete. | 41 // The sync implementation for autocomplete. |
| 38 // MergeDataAndStartSyncing() called first, it does cloud->local and | 42 // MergeDataAndStartSyncing() called first, it does cloud->local and |
| 39 // local->cloud syncs. Then for each cloud change we receive | 43 // local->cloud syncs. Then for each cloud change we receive |
| 40 // ProcessSyncChanges() and for each local change Observe() is called. | 44 // ProcessSyncChanges() and for each local change Observe() is called. |
| 41 class AutocompleteSyncableService | 45 class AutocompleteSyncableService |
| 42 : public base::SupportsUserData::Data, | 46 : public base::SupportsUserData::Data, |
| 43 public syncer::SyncableService, | 47 public syncer::SyncableService, |
| 44 public autofill::AutofillWebDataServiceObserverOnDBThread, | 48 public autofill::AutofillWebDataServiceObserverOnDBThread, |
| 45 public base::NonThreadSafe { | 49 public base::NonThreadSafe { |
| 46 public: | 50 public: |
| 47 virtual ~AutocompleteSyncableService(); | 51 virtual ~AutocompleteSyncableService(); |
| 48 | 52 |
| 49 // Creates a new AutocompleteSyncableService and hangs it off of | 53 // Creates a new AutocompleteSyncableService and hangs it off of |
| 50 // |web_data_service|, which takes ownership. | 54 // |web_data_service|, which takes ownership. |
| 51 static void CreateForWebDataService( | 55 static void CreateForWebDataService( |
| 52 autofill::AutofillWebDataService* web_data_service); | 56 autofill::AutofillWebDataService* web_data_service, |
| 57 autofill::AutofillBackendDelegate* web_data_delegate); |
| 53 | 58 |
| 54 // Retrieves the AutocompleteSyncableService stored on |web_data|. | 59 // Retrieves the AutocompleteSyncableService stored on |web_data|. |
| 55 static AutocompleteSyncableService* FromWebDataService( | 60 static AutocompleteSyncableService* FromWebDataService( |
| 56 autofill::AutofillWebDataService* web_data_service); | 61 autofill::AutofillWebDataService* web_data_service); |
| 57 | 62 |
| 58 static syncer::ModelType model_type() { return syncer::AUTOFILL; } | 63 static syncer::ModelType model_type() { return syncer::AUTOFILL; } |
| 59 | 64 |
| 60 // syncer::SyncableService implementation. | 65 // syncer::SyncableService implementation. |
| 61 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( | 66 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( |
| 62 syncer::ModelType type, | 67 syncer::ModelType type, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 74 virtual void AutofillEntriesChanged( | 79 virtual void AutofillEntriesChanged( |
| 75 const autofill::AutofillChangeList& changes) OVERRIDE; | 80 const autofill::AutofillChangeList& changes) OVERRIDE; |
| 76 | 81 |
| 77 // Called via sync to tell us if we should cull expired entries when merging | 82 // Called via sync to tell us if we should cull expired entries when merging |
| 78 // and/or processing sync changes. | 83 // and/or processing sync changes. |
| 79 void UpdateCullSetting(bool cull_expired_entries); | 84 void UpdateCullSetting(bool cull_expired_entries); |
| 80 bool cull_expired_entries() const { return cull_expired_entries_; } | 85 bool cull_expired_entries() const { return cull_expired_entries_; } |
| 81 | 86 |
| 82 protected: | 87 protected: |
| 83 explicit AutocompleteSyncableService( | 88 explicit AutocompleteSyncableService( |
| 89 autofill::AutofillBackendDelegate* web_data_delegate, |
| 84 autofill::AutofillWebDataService* web_data_service); | 90 autofill::AutofillWebDataService* web_data_service); |
| 85 | 91 |
| 86 // Helper to query WebDatabase for the current autocomplete state. | 92 // Helper to query WebDatabase for the current autocomplete state. |
| 87 // Made virtual for ease of mocking in the unit-test. | 93 // Made virtual for ease of mocking in the unit-test. |
| 88 virtual bool LoadAutofillData( | 94 virtual bool LoadAutofillData( |
| 89 std::vector<autofill::AutofillEntry>* entries) const; | 95 std::vector<autofill::AutofillEntry>* entries) const; |
| 90 | 96 |
| 91 // Helper to persist any changes that occured during model association to | 97 // Helper to persist any changes that occured during model association to |
| 92 // the WebDatabase. |entries| will be either added or updated. | 98 // the WebDatabase. |entries| will be either added or updated. |
| 93 // Made virtual for ease of mocking in the unit-test. | 99 // Made virtual for ease of mocking in the unit-test. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 const std::string& value); | 147 const std::string& value); |
| 142 | 148 |
| 143 // For unit-tests. | 149 // For unit-tests. |
| 144 AutocompleteSyncableService(); | 150 AutocompleteSyncableService(); |
| 145 void set_sync_processor(syncer::SyncChangeProcessor* sync_processor) { | 151 void set_sync_processor(syncer::SyncChangeProcessor* sync_processor) { |
| 146 sync_processor_.reset(sync_processor); | 152 sync_processor_.reset(sync_processor); |
| 147 } | 153 } |
| 148 | 154 |
| 149 // Lifetime of AutocompleteSyncableService object is shorter than | 155 // Lifetime of AutocompleteSyncableService object is shorter than |
| 150 // |web_data_service_| passed to it. | 156 // |web_data_service_| passed to it. |
| 157 autofill::AutofillBackendDelegate* web_data_delegate_; |
| 151 autofill::AutofillWebDataService* web_data_service_; | 158 autofill::AutofillWebDataService* web_data_service_; |
| 152 | 159 |
| 153 ScopedObserver<autofill::AutofillWebDataService, AutocompleteSyncableService> | 160 ScopedObserver<autofill::AutofillBackendDelegate, AutocompleteSyncableService> |
| 154 scoped_observer_; | 161 scoped_observer_; |
| 155 | 162 |
| 156 // We receive ownership of |sync_processor_| in MergeDataAndStartSyncing() and | 163 // We receive ownership of |sync_processor_| in MergeDataAndStartSyncing() and |
| 157 // destroy it in StopSyncing(). | 164 // destroy it in StopSyncing(). |
| 158 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 165 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
| 159 | 166 |
| 160 // We receive ownership of |error_handler_| in MergeDataAndStartSyncing() and | 167 // We receive ownership of |error_handler_| in MergeDataAndStartSyncing() and |
| 161 // destroy it in StopSyncing(). | 168 // destroy it in StopSyncing(). |
| 162 scoped_ptr<syncer::SyncErrorFactory> error_handler_; | 169 scoped_ptr<syncer::SyncErrorFactory> error_handler_; |
| 163 | 170 |
| 164 // 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 |
| 165 // via UpdateCullingSetting. | 172 // via UpdateCullingSetting. |
| 166 bool cull_expired_entries_; | 173 bool cull_expired_entries_; |
| 167 | 174 |
| 168 DISALLOW_COPY_AND_ASSIGN(AutocompleteSyncableService); | 175 DISALLOW_COPY_AND_ASSIGN(AutocompleteSyncableService); |
| 169 }; | 176 }; |
| 170 | 177 |
| 171 #endif // CHROME_BROWSER_WEBDATA_AUTOCOMPLETE_SYNCABLE_SERVICE_H_ | 178 #endif // CHROME_BROWSER_WEBDATA_AUTOCOMPLETE_SYNCABLE_SERVICE_H_ |
| OLD | NEW |