| 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/supports_user_data.h" |   16 #include "base/supports_user_data.h" | 
|   16 #include "base/threading/non_thread_safe.h" |   17 #include "base/threading/non_thread_safe.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/autofill_web_data_service.h" |   20 #include "chrome/browser/webdata/autofill_web_data_service.h" | 
|   20 #include "content/public/browser/notification_observer.h" |   21 #include "chrome/browser/webdata/autofill_web_data_service_observer.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 { | 
|   30 class SyncErrorFactory; |   30 class SyncErrorFactory; | 
|   31 } |   31 } | 
|   32  |   32  | 
|   33 namespace sync_pb { |   33 namespace sync_pb { | 
|   34 class AutofillSpecifics; |   34 class AutofillSpecifics; | 
|   35 } |   35 } | 
|   36  |   36  | 
|   37 // The sync implementation for autocomplete. |   37 // The sync implementation for autocomplete. | 
|   38 // MergeDataAndStartSyncing() called first, it does cloud->local and |   38 // MergeDataAndStartSyncing() called first, it does cloud->local and | 
|   39 // local->cloud syncs. Then for each cloud change we receive |   39 // local->cloud syncs. Then for each cloud change we receive | 
|   40 // ProcessSyncChanges() and for each local change Observe() is called. |   40 // ProcessSyncChanges() and for each local change Observe() is called. | 
|   41 // TODO(georgey) : remove reliance on the notifications and make it to be called |  | 
|   42 // from web_data_service directly. |  | 
|   43 class AutocompleteSyncableService |   41 class AutocompleteSyncableService | 
|   44     : public base::SupportsUserData::Data, |   42     : public base::SupportsUserData::Data, | 
|   45       public syncer::SyncableService, |   43       public syncer::SyncableService, | 
|   46       public content::NotificationObserver, |   44       public AutofillWebDataServiceObserverOnDBThread, | 
|   47       public base::NonThreadSafe { |   45       public base::NonThreadSafe { | 
|   48  public: |   46  public: | 
|   49   virtual ~AutocompleteSyncableService(); |   47   virtual ~AutocompleteSyncableService(); | 
|   50  |   48  | 
|   51   // Creates a new AutocompleteSyncableService and hangs it off of |   49   // Creates a new AutocompleteSyncableService and hangs it off of | 
|   52   // |web_data_service|, which takes ownership. |   50   // |web_data_service|, which takes ownership. | 
|   53   static void CreateForWebDataService(AutofillWebDataService* web_data_service); |   51   static void CreateForWebDataService(AutofillWebDataService* web_data_service); | 
|   54   // Retrieves the AutocompleteSyncableService stored on |web_data|. |   52   // Retrieves the AutocompleteSyncableService stored on |web_data|. | 
|   55   static AutocompleteSyncableService* FromWebDataService( |   53   static AutocompleteSyncableService* FromWebDataService( | 
|   56       AutofillWebDataService* web_data_service); |   54       AutofillWebDataService* web_data_service); | 
|   57  |   55  | 
|   58   static syncer::ModelType model_type() { return syncer::AUTOFILL; } |   56   static syncer::ModelType model_type() { return syncer::AUTOFILL; } | 
|   59  |   57  | 
|   60   // syncer::SyncableService implementation. |   58   // syncer::SyncableService implementation. | 
|   61   virtual syncer::SyncMergeResult MergeDataAndStartSyncing( |   59   virtual syncer::SyncMergeResult MergeDataAndStartSyncing( | 
|   62       syncer::ModelType type, |   60       syncer::ModelType type, | 
|   63       const syncer::SyncDataList& initial_sync_data, |   61       const syncer::SyncDataList& initial_sync_data, | 
|   64       scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |   62       scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 
|   65       scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; |   63       scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; | 
|   66   virtual void StopSyncing(syncer::ModelType type) OVERRIDE; |   64   virtual void StopSyncing(syncer::ModelType type) OVERRIDE; | 
|   67   virtual syncer::SyncDataList GetAllSyncData( |   65   virtual syncer::SyncDataList GetAllSyncData( | 
|   68       syncer::ModelType type) const OVERRIDE; |   66       syncer::ModelType type) const OVERRIDE; | 
|   69   virtual syncer::SyncError ProcessSyncChanges( |   67   virtual syncer::SyncError ProcessSyncChanges( | 
|   70       const tracked_objects::Location& from_here, |   68       const tracked_objects::Location& from_here, | 
|   71       const syncer::SyncChangeList& change_list) OVERRIDE; |   69       const syncer::SyncChangeList& change_list) OVERRIDE; | 
|   72  |   70  | 
|   73   // NotificationObserver implementation. |   71   // AutofillWebDataServiceObserverOnDBThread implementation. | 
|   74   virtual void Observe(int type, |   72   virtual void AutofillEntriesChanged( | 
|   75                        const content::NotificationSource& source, |   73       const AutofillChangeList& changes) OVERRIDE; | 
|   76                        const content::NotificationDetails& details) OVERRIDE; |  | 
|   77  |   74  | 
|   78   // Called via sync to tell us if we should cull expired entries when merging |   75   // Called via sync to tell us if we should cull expired entries when merging | 
|   79   // and/or processing sync changes. |   76   // and/or processing sync changes. | 
|   80   void UpdateCullSetting(bool cull_expired_entries); |   77   void UpdateCullSetting(bool cull_expired_entries); | 
|   81   bool cull_expired_entries() const { return cull_expired_entries_; } |   78   bool cull_expired_entries() const { return cull_expired_entries_; } | 
|   82  |   79  | 
|   83  protected: |   80  protected: | 
|   84   explicit AutocompleteSyncableService( |   81   explicit AutocompleteSyncableService( | 
|   85       AutofillWebDataService* web_data_service); |   82       AutofillWebDataService* web_data_service); | 
|   86  |   83  | 
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  142   // For unit-tests. |  139   // For unit-tests. | 
|  143   AutocompleteSyncableService(); |  140   AutocompleteSyncableService(); | 
|  144   void set_sync_processor(syncer::SyncChangeProcessor* sync_processor) { |  141   void set_sync_processor(syncer::SyncChangeProcessor* sync_processor) { | 
|  145     sync_processor_.reset(sync_processor); |  142     sync_processor_.reset(sync_processor); | 
|  146   } |  143   } | 
|  147  |  144  | 
|  148   // Lifetime of AutocompleteSyncableService object is shorter than |  145   // Lifetime of AutocompleteSyncableService object is shorter than | 
|  149   // |web_data_service_| passed to it. |  146   // |web_data_service_| passed to it. | 
|  150   AutofillWebDataService* web_data_service_; |  147   AutofillWebDataService* web_data_service_; | 
|  151  |  148  | 
|  152   content::NotificationRegistrar notification_registrar_; |  149   ScopedObserver<AutofillWebDataService, AutocompleteSyncableService> | 
 |  150       scoped_observer_; | 
|  153  |  151  | 
|  154   // We receive ownership of |sync_processor_| in MergeDataAndStartSyncing() and |  152   // We receive ownership of |sync_processor_| in MergeDataAndStartSyncing() and | 
|  155   // destroy it in StopSyncing(). |  153   // destroy it in StopSyncing(). | 
|  156   scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |  154   scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 
|  157  |  155  | 
|  158   // We receive ownership of |error_handler_| in MergeDataAndStartSyncing() and |  156   // We receive ownership of |error_handler_| in MergeDataAndStartSyncing() and | 
|  159   // destroy it in StopSyncing(). |  157   // destroy it in StopSyncing(). | 
|  160   scoped_ptr<syncer::SyncErrorFactory> error_handler_; |  158   scoped_ptr<syncer::SyncErrorFactory> error_handler_; | 
|  161  |  159  | 
|  162   // Whether we should cull expired autofill entries, can be updated by sync |  160   // Whether we should cull expired autofill entries, can be updated by sync | 
|  163   // via UpdateCullingSetting. |  161   // via UpdateCullingSetting. | 
|  164   bool cull_expired_entries_; |  162   bool cull_expired_entries_; | 
|  165  |  163  | 
|  166   DISALLOW_COPY_AND_ASSIGN(AutocompleteSyncableService); |  164   DISALLOW_COPY_AND_ASSIGN(AutocompleteSyncableService); | 
|  167 }; |  165 }; | 
|  168  |  166  | 
|  169 #endif  // CHROME_BROWSER_WEBDATA_AUTOCOMPLETE_SYNCABLE_SERVICE_H_ |  167 #endif  // CHROME_BROWSER_WEBDATA_AUTOCOMPLETE_SYNCABLE_SERVICE_H_ | 
| OLD | NEW |