| 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/threading/non_thread_safe.h" | 16 #include "base/threading/non_thread_safe.h" |
| 16 #include "chrome/browser/webdata/autofill_change.h" | 17 #include "chrome/browser/webdata/autofill_change.h" |
| 17 #include "chrome/browser/webdata/autofill_entry.h" | 18 #include "chrome/browser/webdata/autofill_entry.h" |
| 18 #include "chrome/browser/webdata/web_data_service.h" | 19 #include "chrome/browser/webdata/web_data_service.h" |
| 19 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
| 20 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
| 21 #include "sync/api/sync_change.h" | 22 #include "sync/api/sync_change.h" |
| 22 #include "sync/api/sync_data.h" | 23 #include "sync/api/sync_data.h" |
| 23 #include "sync/api/sync_error.h" | 24 #include "sync/api/sync_error.h" |
| 24 #include "sync/api/syncable_service.h" | 25 #include "sync/api/syncable_service.h" |
| 25 | 26 |
| 26 class ProfileSyncServiceAutofillTest; | 27 class ProfileSyncServiceAutofillTest; |
| 27 | 28 |
| 28 namespace syncer { | 29 namespace syncer { |
| 29 class SyncErrorFactory; | 30 class SyncErrorFactory; |
| 30 } | 31 } |
| 31 | 32 |
| 32 namespace sync_pb { | 33 namespace sync_pb { |
| 33 class AutofillSpecifics; | 34 class AutofillSpecifics; |
| 34 } | 35 } |
| 35 | 36 |
| 36 // The sync implementation for autocomplete. | 37 // The sync implementation for autocomplete. |
| 37 // MergeDataAndStartSyncing() called first, it does cloud->local and | 38 // MergeDataAndStartSyncing() called first, it does cloud->local and |
| 38 // local->cloud syncs. Then for each cloud change we receive | 39 // local->cloud syncs. Then for each cloud change we receive |
| 39 // ProcessSyncChanges() and for each local change Observe() is called. | 40 // ProcessSyncChanges() and for each local change Observe() is called. |
| 40 // 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 |
| 41 // from web_data_service directly. | 42 // from web_data_service directly. |
| 42 class AutocompleteSyncableService | 43 class AutocompleteSyncableService |
| 43 : public syncer::SyncableService, | 44 : public base::SupportsUserData::Data, |
| 45 public syncer::SyncableService, |
| 44 public content::NotificationObserver, | 46 public content::NotificationObserver, |
| 45 public base::NonThreadSafe { | 47 public base::NonThreadSafe { |
| 46 public: | 48 public: |
| 47 explicit AutocompleteSyncableService(WebDataService* web_data_service); | |
| 48 virtual ~AutocompleteSyncableService(); | 49 virtual ~AutocompleteSyncableService(); |
| 49 | 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 |
| 55 // |web_data|, which takes ownership. |
| 56 static void CreateForWebDataService(WebDataService* web_data); |
| 57 // Retrieves the AutocompleteSyncableService stored on |web_data|. |
| 58 static AutocompleteSyncableService* FromWebDataService( |
| 59 WebDataService* web_data); |
| 60 |
| 50 static syncer::ModelType model_type() { return syncer::AUTOFILL; } | 61 static syncer::ModelType model_type() { return syncer::AUTOFILL; } |
| 51 | 62 |
| 52 // syncer::SyncableService implementation. | 63 // syncer::SyncableService implementation. |
| 53 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( | 64 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( |
| 54 syncer::ModelType type, | 65 syncer::ModelType type, |
| 55 const syncer::SyncDataList& initial_sync_data, | 66 const syncer::SyncDataList& initial_sync_data, |
| 56 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 67 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
| 57 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; | 68 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; |
| 58 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; | 69 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; |
| 59 virtual syncer::SyncDataList GetAllSyncData( | 70 virtual syncer::SyncDataList GetAllSyncData( |
| 60 syncer::ModelType type) const OVERRIDE; | 71 syncer::ModelType type) const OVERRIDE; |
| 61 virtual syncer::SyncError ProcessSyncChanges( | 72 virtual syncer::SyncError ProcessSyncChanges( |
| 62 const tracked_objects::Location& from_here, | 73 const tracked_objects::Location& from_here, |
| 63 const syncer::SyncChangeList& change_list) OVERRIDE; | 74 const syncer::SyncChangeList& change_list) OVERRIDE; |
| 64 | 75 |
| 65 // NotificationObserver implementation. | 76 // NotificationObserver implementation. |
| 66 virtual void Observe(int type, | 77 virtual void Observe(int type, |
| 67 const content::NotificationSource& source, | 78 const content::NotificationSource& source, |
| 68 const content::NotificationDetails& details) OVERRIDE; | 79 const content::NotificationDetails& details) OVERRIDE; |
| 69 | 80 |
| 70 // Called via sync to tell us if we should cull expired entries when merging | 81 // Called via sync to tell us if we should cull expired entries when merging |
| 71 // and/or processing sync changes. | 82 // and/or processing sync changes. |
| 72 void UpdateCullSetting(bool cull_expired_entries); | 83 void UpdateCullSetting(bool cull_expired_entries); |
| 73 bool cull_expired_entries() const { return cull_expired_entries_; } | 84 bool cull_expired_entries() const { return cull_expired_entries_; } |
| 74 | 85 |
| 75 protected: | 86 protected: |
| 87 explicit AutocompleteSyncableService(WebDataService* web_data_service); |
| 88 |
| 76 // Helper to query WebDatabase for the current autocomplete state. | 89 // Helper to query WebDatabase for the current autocomplete state. |
| 77 // Made virtual for ease of mocking in the unit-test. | 90 // Made virtual for ease of mocking in the unit-test. |
| 78 virtual bool LoadAutofillData(std::vector<AutofillEntry>* entries) const; | 91 virtual bool LoadAutofillData(std::vector<AutofillEntry>* entries) const; |
| 79 | 92 |
| 80 // Helper to persist any changes that occured during model association to | 93 // Helper to persist any changes that occured during model association to |
| 81 // the WebDatabase. |entries| will be either added or updated. | 94 // the WebDatabase. |entries| will be either added or updated. |
| 82 // Made virtual for ease of mocking in the unit-test. | 95 // Made virtual for ease of mocking in the unit-test. |
| 83 virtual bool SaveChangesToWebData(const std::vector<AutofillEntry>& entries); | 96 virtual bool SaveChangesToWebData(const std::vector<AutofillEntry>& entries); |
| 84 | 97 |
| 85 private: | 98 private: |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 scoped_ptr<syncer::SyncErrorFactory> error_handler_; | 162 scoped_ptr<syncer::SyncErrorFactory> error_handler_; |
| 150 | 163 |
| 151 // Whether we should cull expired autofill entries, can be updated by sync | 164 // Whether we should cull expired autofill entries, can be updated by sync |
| 152 // via UpdateCullingSetting. | 165 // via UpdateCullingSetting. |
| 153 bool cull_expired_entries_; | 166 bool cull_expired_entries_; |
| 154 | 167 |
| 155 DISALLOW_COPY_AND_ASSIGN(AutocompleteSyncableService); | 168 DISALLOW_COPY_AND_ASSIGN(AutocompleteSyncableService); |
| 156 }; | 169 }; |
| 157 | 170 |
| 158 #endif // CHROME_BROWSER_WEBDATA_AUTOCOMPLETE_SYNCABLE_SERVICE_H_ | 171 #endif // CHROME_BROWSER_WEBDATA_AUTOCOMPLETE_SYNCABLE_SERVICE_H_ |
| OLD | NEW |