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

Side by Side Diff: chrome/browser/webdata/autofill_profile_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_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_ 4 #ifndef CHROME_BROWSER_WEBDATA_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_
5 #define CHROME_BROWSER_WEBDATA_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_ 5 #define CHROME_BROWSER_WEBDATA_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
14 #include "base/threading/non_thread_safe.h" 14 #include "base/threading/non_thread_safe.h"
15 #include "chrome/browser/webdata/autofill_change.h" 15 #include "chrome/browser/webdata/autofill_change.h"
16 #include "chrome/browser/webdata/autofill_entry.h" 16 #include "chrome/browser/webdata/autofill_entry.h"
17 #include "chrome/browser/webdata/web_data_service_observer.h"
17 #include "components/autofill/browser/autofill_type.h" 18 #include "components/autofill/browser/autofill_type.h"
18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h"
20 #include "content/public/browser/notification_types.h"
21 #include "sync/api/sync_change.h" 19 #include "sync/api/sync_change.h"
22 #include "sync/api/sync_data.h" 20 #include "sync/api/sync_data.h"
23 #include "sync/api/sync_error.h" 21 #include "sync/api/sync_error.h"
24 #include "sync/api/syncable_service.h" 22 #include "sync/api/syncable_service.h"
25 #include "sync/protocol/autofill_specifics.pb.h" 23 #include "sync/protocol/autofill_specifics.pb.h"
26 24
27 class AutofillProfile; 25 class AutofillProfile;
28 class AutofillTable; 26 class AutofillTable;
29 class FormGroup; 27 class FormGroup;
30 class ProfileSyncServiceAutofillTest; 28 class ProfileSyncServiceAutofillTest;
31 class WebDataService; 29 class WebDataService;
32 30
33 extern const char kAutofillProfileTag[]; 31 extern const char kAutofillProfileTag[];
34 32
35 // The sync implementation for AutofillProfiles. 33 // The sync implementation for AutofillProfiles.
36 // MergeDataAndStartSyncing() called first, it does cloud->local and 34 // MergeDataAndStartSyncing() called first, it does cloud->local and
37 // local->cloud syncs. Then for each cloud change we receive 35 // local->cloud syncs. Then for each cloud change we receive
38 // ProcessSyncChanges() and for each local change Observe() is called. 36 // ProcessSyncChanges() and for each local change Observe() is called.
39 class AutofillProfileSyncableService 37 class AutofillProfileSyncableService : public syncer::SyncableService,
40 : public syncer::SyncableService, 38 public WebDataServiceObserver,
41 public content::NotificationObserver, 39 public base::NonThreadSafe {
42 public base::NonThreadSafe {
43 public: 40 public:
44 explicit AutofillProfileSyncableService(WebDataService* web_data_service); 41 explicit AutofillProfileSyncableService(WebDataService* web_data_service);
45 virtual ~AutofillProfileSyncableService(); 42 virtual ~AutofillProfileSyncableService();
46 43
47 static syncer::ModelType model_type() { return syncer::AUTOFILL_PROFILE; } 44 static syncer::ModelType model_type() { return syncer::AUTOFILL_PROFILE; }
48 45
49 // syncer::SyncableService implementation. 46 // syncer::SyncableService implementation.
50 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( 47 virtual syncer::SyncMergeResult MergeDataAndStartSyncing(
51 syncer::ModelType type, 48 syncer::ModelType type,
52 const syncer::SyncDataList& initial_sync_data, 49 const syncer::SyncDataList& initial_sync_data,
53 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, 50 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
54 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) OVERRIDE; 51 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) OVERRIDE;
55 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; 52 virtual void StopSyncing(syncer::ModelType type) OVERRIDE;
56 virtual syncer::SyncDataList GetAllSyncData( 53 virtual syncer::SyncDataList GetAllSyncData(
57 syncer::ModelType type) const OVERRIDE; 54 syncer::ModelType type) const OVERRIDE;
58 virtual syncer::SyncError ProcessSyncChanges( 55 virtual syncer::SyncError ProcessSyncChanges(
59 const tracked_objects::Location& from_here, 56 const tracked_objects::Location& from_here,
60 const syncer::SyncChangeList& change_list) OVERRIDE; 57 const syncer::SyncChangeList& change_list) OVERRIDE;
61 58
62 // content::NotificationObserver implementation. 59 // WebDataServiceObserver implementation.
63 virtual void Observe(int type, 60 virtual void AutofillProfileChanged(const AutofillProfileChange& change)
dhollowa 2013/03/12 22:22:28 nit: wrap at arg, not at OVERRIDE.
kaiwang 2013/03/13 04:57:20 Done.
64 const content::NotificationSource& source, 61 OVERRIDE;
65 const content::NotificationDetails& details) OVERRIDE;
66 62
67 protected: 63 protected:
68 // A convenience wrapper of a bunch of state we pass around while 64 // A convenience wrapper of a bunch of state we pass around while
69 // associating models, and send to the WebDatabase for persistence. 65 // associating models, and send to the WebDatabase for persistence.
70 // We do this so we hold the write lock for only a small period. 66 // We do this so we hold the write lock for only a small period.
71 // When storing the web db we are out of the write lock. 67 // When storing the web db we are out of the write lock.
72 struct DataBundle; 68 struct DataBundle;
73 69
74 // Helper to query WebDatabase for the current autofill state. 70 // Helper to query WebDatabase for the current autofill state.
75 // Made virtual for ease of mocking in the unit-test. 71 // Made virtual for ease of mocking in the unit-test.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 static bool MergeProfile(const AutofillProfile& merge_from, 147 static bool MergeProfile(const AutofillProfile& merge_from,
152 AutofillProfile* merge_into); 148 AutofillProfile* merge_into);
153 149
154 // For unit-tests. 150 // For unit-tests.
155 AutofillProfileSyncableService(); 151 AutofillProfileSyncableService();
156 void set_sync_processor(syncer::SyncChangeProcessor* sync_processor) { 152 void set_sync_processor(syncer::SyncChangeProcessor* sync_processor) {
157 sync_processor_.reset(sync_processor); 153 sync_processor_.reset(sync_processor);
158 } 154 }
159 155
160 WebDataService* web_data_service_; // WEAK 156 WebDataService* web_data_service_; // WEAK
161 content::NotificationRegistrar notification_registrar_;
162 157
163 // Cached Autofill profiles. *Warning* deleted profiles are still in the 158 // Cached Autofill profiles. *Warning* deleted profiles are still in the
164 // vector - use the |profiles_map_| to iterate through actual profiles. 159 // vector - use the |profiles_map_| to iterate through actual profiles.
165 ScopedVector<AutofillProfile> profiles_; 160 ScopedVector<AutofillProfile> profiles_;
166 GUIDToProfileMap profiles_map_; 161 GUIDToProfileMap profiles_map_;
167 162
168 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; 163 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
169 164
170 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory_; 165 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory_;
171 166
(...skipping 10 matching lines...) Expand all
182 std::vector<AutofillProfile*> profiles_to_add; 177 std::vector<AutofillProfile*> profiles_to_add;
183 178
184 // When we go through sync we find profiles that are similar but unmatched. 179 // When we go through sync we find profiles that are similar but unmatched.
185 // Merge such profiles. 180 // Merge such profiles.
186 GUIDToProfileMap candidates_to_merge; 181 GUIDToProfileMap candidates_to_merge;
187 // Profiles that have multi-valued fields that are not in sync. 182 // Profiles that have multi-valued fields that are not in sync.
188 std::vector<AutofillProfile*> profiles_to_sync_back; 183 std::vector<AutofillProfile*> profiles_to_sync_back;
189 }; 184 };
190 185
191 #endif // CHROME_BROWSER_WEBDATA_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_ 186 #endif // CHROME_BROWSER_WEBDATA_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698