Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: chrome/browser/webdata/autocomplete_syncable_service.h

Issue 12476031: Refactor notifications of chrome/browser/webdata (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase again Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/threading/non_thread_safe.h" 15 #include "base/threading/non_thread_safe.h"
16 #include "chrome/browser/webdata/autofill_change.h" 16 #include "chrome/browser/webdata/autofill_change.h"
17 #include "chrome/browser/webdata/autofill_entry.h" 17 #include "chrome/browser/webdata/autofill_entry.h"
18 #include "chrome/browser/webdata/web_data_service.h" 18 #include "chrome/browser/webdata/web_data_service.h"
19 #include "content/public/browser/notification_observer.h" 19 #include "chrome/browser/webdata/web_data_service_observer.h"
20 #include "content/public/browser/notification_registrar.h"
21 #include "sync/api/sync_change.h" 20 #include "sync/api/sync_change.h"
22 #include "sync/api/sync_data.h" 21 #include "sync/api/sync_data.h"
23 #include "sync/api/sync_error.h" 22 #include "sync/api/sync_error.h"
24 #include "sync/api/syncable_service.h" 23 #include "sync/api/syncable_service.h"
25 24
26 class ProfileSyncServiceAutofillTest; 25 class ProfileSyncServiceAutofillTest;
27 26
28 namespace syncer { 27 namespace syncer {
29 class SyncErrorFactory; 28 class SyncErrorFactory;
30 } 29 }
31 30
32 namespace sync_pb { 31 namespace sync_pb {
33 class AutofillSpecifics; 32 class AutofillSpecifics;
34 } 33 }
35 34
36 // The sync implementation for autocomplete. 35 // The sync implementation for autocomplete.
37 // MergeDataAndStartSyncing() called first, it does cloud->local and 36 // MergeDataAndStartSyncing() called first, it does cloud->local and
38 // local->cloud syncs. Then for each cloud change we receive 37 // local->cloud syncs. Then for each cloud change we receive
39 // ProcessSyncChanges() and for each local change Observe() is called. 38 // ProcessSyncChanges() and for each local change Observe() is called.
40 // TODO(georgey) : remove reliance on the notifications and make it to be called 39 // TODO(georgey) : remove reliance on the notifications and make it to be called
41 // from web_data_service directly. 40 // from web_data_service directly.
42 class AutocompleteSyncableService 41 class AutocompleteSyncableService : public syncer::SyncableService,
43 : public syncer::SyncableService, 42 public WebDataServiceObserver,
44 public content::NotificationObserver, 43 public base::NonThreadSafe {
45 public base::NonThreadSafe {
46 public: 44 public:
47 explicit AutocompleteSyncableService(WebDataService* web_data_service); 45 explicit AutocompleteSyncableService(WebDataService* web_data_service);
48 virtual ~AutocompleteSyncableService(); 46 virtual ~AutocompleteSyncableService();
49 47
50 static syncer::ModelType model_type() { return syncer::AUTOFILL; } 48 static syncer::ModelType model_type() { return syncer::AUTOFILL; }
51 49
52 // syncer::SyncableService implementation. 50 // syncer::SyncableService implementation.
53 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( 51 virtual syncer::SyncMergeResult MergeDataAndStartSyncing(
54 syncer::ModelType type, 52 syncer::ModelType type,
55 const syncer::SyncDataList& initial_sync_data, 53 const syncer::SyncDataList& initial_sync_data,
56 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, 54 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
57 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; 55 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE;
58 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; 56 virtual void StopSyncing(syncer::ModelType type) OVERRIDE;
59 virtual syncer::SyncDataList GetAllSyncData( 57 virtual syncer::SyncDataList GetAllSyncData(
60 syncer::ModelType type) const OVERRIDE; 58 syncer::ModelType type) const OVERRIDE;
61 virtual syncer::SyncError ProcessSyncChanges( 59 virtual syncer::SyncError ProcessSyncChanges(
62 const tracked_objects::Location& from_here, 60 const tracked_objects::Location& from_here,
63 const syncer::SyncChangeList& change_list) OVERRIDE; 61 const syncer::SyncChangeList& change_list) OVERRIDE;
64 62
65 // NotificationObserver implementation. 63 // WebDataServiceObserver implementation.
66 virtual void Observe(int type, 64 virtual void AutofillEntriesChanged(const AutofillChangeList& changes)
dhollowa 2013/03/12 22:22:28 nit: wrap at the arg, not at the OVERRIDE.
kaiwang 2013/03/13 04:57:20 Done.
67 const content::NotificationSource& source, 65 OVERRIDE;
68 const content::NotificationDetails& details) OVERRIDE;
69 66
70 // Called via sync to tell us if we should cull expired entries when merging 67 // Called via sync to tell us if we should cull expired entries when merging
71 // and/or processing sync changes. 68 // and/or processing sync changes.
72 void UpdateCullSetting(bool cull_expired_entries); 69 void UpdateCullSetting(bool cull_expired_entries);
73 bool cull_expired_entries() const { return cull_expired_entries_; } 70 bool cull_expired_entries() const { return cull_expired_entries_; }
74 71
75 protected: 72 protected:
76 // Helper to query WebDatabase for the current autocomplete state. 73 // Helper to query WebDatabase for the current autocomplete state.
77 // Made virtual for ease of mocking in the unit-test. 74 // Made virtual for ease of mocking in the unit-test.
78 virtual bool LoadAutofillData(std::vector<AutofillEntry>* entries) const; 75 virtual bool LoadAutofillData(std::vector<AutofillEntry>* entries) const;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // For unit-tests. 128 // For unit-tests.
132 AutocompleteSyncableService(); 129 AutocompleteSyncableService();
133 void set_sync_processor(syncer::SyncChangeProcessor* sync_processor) { 130 void set_sync_processor(syncer::SyncChangeProcessor* sync_processor) {
134 sync_processor_.reset(sync_processor); 131 sync_processor_.reset(sync_processor);
135 } 132 }
136 133
137 // Lifetime of AutocompleteSyncableService object is shorter than 134 // Lifetime of AutocompleteSyncableService object is shorter than
138 // |web_data_service_| passed to it. 135 // |web_data_service_| passed to it.
139 WebDataService* web_data_service_; 136 WebDataService* web_data_service_;
140 137
141 content::NotificationRegistrar notification_registrar_;
142
143 // We receive ownership of |sync_processor_| in MergeDataAndStartSyncing() and 138 // We receive ownership of |sync_processor_| in MergeDataAndStartSyncing() and
144 // destroy it in StopSyncing(). 139 // destroy it in StopSyncing().
145 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; 140 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
146 141
147 // We receive ownership of |error_handler_| in MergeDataAndStartSyncing() and 142 // We receive ownership of |error_handler_| in MergeDataAndStartSyncing() and
148 // destroy it in StopSyncing(). 143 // destroy it in StopSyncing().
149 scoped_ptr<syncer::SyncErrorFactory> error_handler_; 144 scoped_ptr<syncer::SyncErrorFactory> error_handler_;
150 145
151 // Whether we should cull expired autofill entries, can be updated by sync 146 // Whether we should cull expired autofill entries, can be updated by sync
152 // via UpdateCullingSetting. 147 // via UpdateCullingSetting.
153 bool cull_expired_entries_; 148 bool cull_expired_entries_;
154 149
155 DISALLOW_COPY_AND_ASSIGN(AutocompleteSyncableService); 150 DISALLOW_COPY_AND_ASSIGN(AutocompleteSyncableService);
156 }; 151 };
157 152
158 #endif // CHROME_BROWSER_WEBDATA_AUTOCOMPLETE_SYNCABLE_SERVICE_H_ 153 #endif // CHROME_BROWSER_WEBDATA_AUTOCOMPLETE_SYNCABLE_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698