| 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/supports_user_data.h" | 15 #include "base/supports_user_data.h" |
| 16 #include "base/threading/non_thread_safe.h" | 16 #include "base/threading/non_thread_safe.h" |
| 17 #include "chrome/browser/api/webdata/autofill_web_data_service.h" |
| 17 #include "chrome/browser/webdata/autofill_change.h" | 18 #include "chrome/browser/webdata/autofill_change.h" |
| 18 #include "chrome/browser/webdata/autofill_entry.h" | 19 #include "chrome/browser/webdata/autofill_entry.h" |
| 19 #include "chrome/browser/webdata/web_data_service.h" | |
| 20 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
| 21 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
| 22 #include "sync/api/sync_change.h" | 22 #include "sync/api/sync_change.h" |
| 23 #include "sync/api/sync_data.h" | 23 #include "sync/api/sync_data.h" |
| 24 #include "sync/api/sync_error.h" | 24 #include "sync/api/sync_error.h" |
| 25 #include "sync/api/syncable_service.h" | 25 #include "sync/api/syncable_service.h" |
| 26 | 26 |
| 27 class ProfileSyncServiceAutofillTest; | 27 class ProfileSyncServiceAutofillTest; |
| 28 | 28 |
| 29 namespace syncer { | 29 namespace syncer { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 41 // TODO(georgey) : remove reliance on the notifications and make it to be called | 41 // TODO(georgey) : remove reliance on the notifications and make it to be called |
| 42 // from web_data_service directly. | 42 // from web_data_service directly. |
| 43 class AutocompleteSyncableService | 43 class AutocompleteSyncableService |
| 44 : public base::SupportsUserData::Data, | 44 : public base::SupportsUserData::Data, |
| 45 public syncer::SyncableService, | 45 public syncer::SyncableService, |
| 46 public content::NotificationObserver, | 46 public content::NotificationObserver, |
| 47 public base::NonThreadSafe { | 47 public base::NonThreadSafe { |
| 48 public: | 48 public: |
| 49 virtual ~AutocompleteSyncableService(); | 49 virtual ~AutocompleteSyncableService(); |
| 50 | 50 |
| 51 // TODO(joi): Change this to key off AutofillWebDataService instead | |
| 52 // of WebDataService, once it is truly separate. | |
| 53 | |
| 54 // Creates a new AutocompleteSyncableService and hangs it off of | 51 // Creates a new AutocompleteSyncableService and hangs it off of |
| 55 // |web_data|, which takes ownership. | 52 // |web_data|, which takes ownership. |
| 56 static void CreateForWebDataService(WebDataService* web_data); | 53 static void CreateForWebDataService(AutofillWebDataService* web_data); |
| 57 // Retrieves the AutocompleteSyncableService stored on |web_data|. | 54 // Retrieves the AutocompleteSyncableService stored on |web_data|. |
| 58 static AutocompleteSyncableService* FromWebDataService( | 55 static AutocompleteSyncableService* FromWebDataService( |
| 59 WebDataService* web_data); | 56 AutofillWebDataService* web_data); |
| 60 | 57 |
| 61 static syncer::ModelType model_type() { return syncer::AUTOFILL; } | 58 static syncer::ModelType model_type() { return syncer::AUTOFILL; } |
| 62 | 59 |
| 63 // syncer::SyncableService implementation. | 60 // syncer::SyncableService implementation. |
| 64 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( | 61 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( |
| 65 syncer::ModelType type, | 62 syncer::ModelType type, |
| 66 const syncer::SyncDataList& initial_sync_data, | 63 const syncer::SyncDataList& initial_sync_data, |
| 67 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 64 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
| 68 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; | 65 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; |
| 69 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; | 66 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; |
| 70 virtual syncer::SyncDataList GetAllSyncData( | 67 virtual syncer::SyncDataList GetAllSyncData( |
| 71 syncer::ModelType type) const OVERRIDE; | 68 syncer::ModelType type) const OVERRIDE; |
| 72 virtual syncer::SyncError ProcessSyncChanges( | 69 virtual syncer::SyncError ProcessSyncChanges( |
| 73 const tracked_objects::Location& from_here, | 70 const tracked_objects::Location& from_here, |
| 74 const syncer::SyncChangeList& change_list) OVERRIDE; | 71 const syncer::SyncChangeList& change_list) OVERRIDE; |
| 75 | 72 |
| 76 // NotificationObserver implementation. | 73 // NotificationObserver implementation. |
| 77 virtual void Observe(int type, | 74 virtual void Observe(int type, |
| 78 const content::NotificationSource& source, | 75 const content::NotificationSource& source, |
| 79 const content::NotificationDetails& details) OVERRIDE; | 76 const content::NotificationDetails& details) OVERRIDE; |
| 80 | 77 |
| 81 // Called via sync to tell us if we should cull expired entries when merging | 78 // Called via sync to tell us if we should cull expired entries when merging |
| 82 // and/or processing sync changes. | 79 // and/or processing sync changes. |
| 83 void UpdateCullSetting(bool cull_expired_entries); | 80 void UpdateCullSetting(bool cull_expired_entries); |
| 84 bool cull_expired_entries() const { return cull_expired_entries_; } | 81 bool cull_expired_entries() const { return cull_expired_entries_; } |
| 85 | 82 |
| 86 protected: | 83 protected: |
| 87 explicit AutocompleteSyncableService(WebDataService* web_data_service); | 84 explicit AutocompleteSyncableService( |
| 85 AutofillWebDataService* web_data_service); |
| 88 | 86 |
| 89 // Helper to query WebDatabase for the current autocomplete state. | 87 // Helper to query WebDatabase for the current autocomplete state. |
| 90 // Made virtual for ease of mocking in the unit-test. | 88 // Made virtual for ease of mocking in the unit-test. |
| 91 virtual bool LoadAutofillData(std::vector<AutofillEntry>* entries) const; | 89 virtual bool LoadAutofillData(std::vector<AutofillEntry>* entries) const; |
| 92 | 90 |
| 93 // Helper to persist any changes that occured during model association to | 91 // Helper to persist any changes that occured during model association to |
| 94 // the WebDatabase. |entries| will be either added or updated. | 92 // the WebDatabase. |entries| will be either added or updated. |
| 95 // Made virtual for ease of mocking in the unit-test. | 93 // Made virtual for ease of mocking in the unit-test. |
| 96 virtual bool SaveChangesToWebData(const std::vector<AutofillEntry>& entries); | 94 virtual bool SaveChangesToWebData(const std::vector<AutofillEntry>& entries); |
| 97 | 95 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 const std::string& value); | 140 const std::string& value); |
| 143 | 141 |
| 144 // For unit-tests. | 142 // For unit-tests. |
| 145 AutocompleteSyncableService(); | 143 AutocompleteSyncableService(); |
| 146 void set_sync_processor(syncer::SyncChangeProcessor* sync_processor) { | 144 void set_sync_processor(syncer::SyncChangeProcessor* sync_processor) { |
| 147 sync_processor_.reset(sync_processor); | 145 sync_processor_.reset(sync_processor); |
| 148 } | 146 } |
| 149 | 147 |
| 150 // Lifetime of AutocompleteSyncableService object is shorter than | 148 // Lifetime of AutocompleteSyncableService object is shorter than |
| 151 // |web_data_service_| passed to it. | 149 // |web_data_service_| passed to it. |
| 152 WebDataService* web_data_service_; | 150 AutofillWebDataService* web_data_service_; |
| 153 | 151 |
| 154 content::NotificationRegistrar notification_registrar_; | 152 content::NotificationRegistrar notification_registrar_; |
| 155 | 153 |
| 156 // We receive ownership of |sync_processor_| in MergeDataAndStartSyncing() and | 154 // We receive ownership of |sync_processor_| in MergeDataAndStartSyncing() and |
| 157 // destroy it in StopSyncing(). | 155 // destroy it in StopSyncing(). |
| 158 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 156 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
| 159 | 157 |
| 160 // We receive ownership of |error_handler_| in MergeDataAndStartSyncing() and | 158 // We receive ownership of |error_handler_| in MergeDataAndStartSyncing() and |
| 161 // destroy it in StopSyncing(). | 159 // destroy it in StopSyncing(). |
| 162 scoped_ptr<syncer::SyncErrorFactory> error_handler_; | 160 scoped_ptr<syncer::SyncErrorFactory> error_handler_; |
| 163 | 161 |
| 164 // Whether we should cull expired autofill entries, can be updated by sync | 162 // Whether we should cull expired autofill entries, can be updated by sync |
| 165 // via UpdateCullingSetting. | 163 // via UpdateCullingSetting. |
| 166 bool cull_expired_entries_; | 164 bool cull_expired_entries_; |
| 167 | 165 |
| 168 DISALLOW_COPY_AND_ASSIGN(AutocompleteSyncableService); | 166 DISALLOW_COPY_AND_ASSIGN(AutocompleteSyncableService); |
| 169 }; | 167 }; |
| 170 | 168 |
| 171 #endif // CHROME_BROWSER_WEBDATA_AUTOCOMPLETE_SYNCABLE_SERVICE_H_ | 169 #endif // CHROME_BROWSER_WEBDATA_AUTOCOMPLETE_SYNCABLE_SERVICE_H_ |
| OLD | NEW |