OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 6 #pragma once |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
| 14 #include "base/memory/weak_ptr.h" |
14 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
15 #include "base/threading/non_thread_safe.h" | 16 #include "base/threading/non_thread_safe.h" |
16 #include "chrome/browser/sync/api/sync_change.h" | 17 #include "chrome/browser/sync/api/sync_change.h" |
17 #include "chrome/browser/sync/api/sync_data.h" | 18 #include "chrome/browser/sync/api/sync_data.h" |
18 #include "chrome/browser/sync/api/sync_error.h" | 19 #include "chrome/browser/sync/api/sync_error.h" |
19 #include "chrome/browser/sync/api/syncable_service.h" | 20 #include "chrome/browser/sync/api/syncable_service.h" |
20 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" | 21 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" |
21 #include "chrome/browser/webdata/autofill_change.h" | 22 #include "chrome/browser/webdata/autofill_change.h" |
22 #include "chrome/browser/webdata/autofill_entry.h" | 23 #include "chrome/browser/webdata/autofill_entry.h" |
23 #include "content/common/content_notification_types.h" | 24 #include "content/common/content_notification_types.h" |
(...skipping 10 matching lines...) Expand all Loading... |
34 extern const char kAutofillProfileTag[]; | 35 extern const char kAutofillProfileTag[]; |
35 | 36 |
36 class UnrecoverableErrorHandler; | 37 class UnrecoverableErrorHandler; |
37 | 38 |
38 // The sync implementation for AutofillProfiles. | 39 // The sync implementation for AutofillProfiles. |
39 // MergeDataAndStartSyncing() called first, it does cloud->local and | 40 // MergeDataAndStartSyncing() called first, it does cloud->local and |
40 // local->cloud syncs. Then for each cloud change we receive | 41 // local->cloud syncs. Then for each cloud change we receive |
41 // ProcessSyncChanges() and for each local change Observe() is called. | 42 // ProcessSyncChanges() and for each local change Observe() is called. |
42 class AutofillProfileSyncableService | 43 class AutofillProfileSyncableService |
43 : public SyncableService, | 44 : public SyncableService, |
| 45 public base::SupportsWeakPtr<AutofillProfileSyncableService>, |
44 public NotificationObserver, | 46 public NotificationObserver, |
45 public base::NonThreadSafe { | 47 public base::NonThreadSafe { |
46 public: | 48 public: |
47 explicit AutofillProfileSyncableService(WebDataService* web_data_service); | 49 explicit AutofillProfileSyncableService(WebDataService* web_data_service); |
48 virtual ~AutofillProfileSyncableService(); | 50 virtual ~AutofillProfileSyncableService(); |
49 | 51 |
50 static syncable::ModelType model_type() { return syncable::AUTOFILL_PROFILE; } | 52 static syncable::ModelType model_type() { return syncable::AUTOFILL_PROFILE; } |
51 | 53 |
52 // SyncableService implementation. | 54 // SyncableService implementation. |
53 virtual SyncError MergeDataAndStartSyncing( | 55 virtual SyncError MergeDataAndStartSyncing( |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 void ActOnChange(const AutofillProfileChange& change); | 125 void ActOnChange(const AutofillProfileChange& change); |
124 | 126 |
125 // Creates SyncData based on supplied |profile|. | 127 // Creates SyncData based on supplied |profile|. |
126 static SyncData CreateData(const AutofillProfile& profile); | 128 static SyncData CreateData(const AutofillProfile& profile); |
127 | 129 |
128 AutofillTable* GetAutofillTable() const; | 130 AutofillTable* GetAutofillTable() const; |
129 | 131 |
130 // For unit-tests. | 132 // For unit-tests. |
131 AutofillProfileSyncableService(); | 133 AutofillProfileSyncableService(); |
132 void set_sync_processor(SyncChangeProcessor* sync_processor) { | 134 void set_sync_processor(SyncChangeProcessor* sync_processor) { |
133 sync_processor_ = sync_processor; | 135 sync_processor_.reset(sync_processor); |
134 } | 136 } |
135 | 137 |
136 WebDataService* web_data_service_; // WEAK | 138 WebDataService* web_data_service_; // WEAK |
137 NotificationRegistrar notification_registrar_; | 139 NotificationRegistrar notification_registrar_; |
138 | 140 |
139 // Cached Autofill profiles. *Warning* deleted profiles are still in the | 141 // Cached Autofill profiles. *Warning* deleted profiles are still in the |
140 // vector - use the |profiles_map_| to iterate through actual profiles. | 142 // vector - use the |profiles_map_| to iterate through actual profiles. |
141 ScopedVector<AutofillProfile> profiles_; | 143 ScopedVector<AutofillProfile> profiles_; |
142 GUIDToProfileMap profiles_map_; | 144 GUIDToProfileMap profiles_map_; |
143 | 145 |
144 SyncChangeProcessor* sync_processor_; | 146 scoped_ptr<SyncChangeProcessor> sync_processor_; |
145 | 147 |
146 DISALLOW_COPY_AND_ASSIGN(AutofillProfileSyncableService); | 148 DISALLOW_COPY_AND_ASSIGN(AutofillProfileSyncableService); |
147 }; | 149 }; |
148 | 150 |
149 // This object is used in unit-tests as well, so it defined here. | 151 // This object is used in unit-tests as well, so it defined here. |
150 struct AutofillProfileSyncableService::DataBundle { | 152 struct AutofillProfileSyncableService::DataBundle { |
151 DataBundle(); | 153 DataBundle(); |
152 ~DataBundle(); | 154 ~DataBundle(); |
153 | 155 |
154 std::vector<std::string> profiles_to_delete; | 156 std::vector<std::string> profiles_to_delete; |
155 std::vector<AutofillProfile*> profiles_to_update; | 157 std::vector<AutofillProfile*> profiles_to_update; |
156 std::vector<AutofillProfile*> profiles_to_add; | 158 std::vector<AutofillProfile*> profiles_to_add; |
157 }; | 159 }; |
158 | 160 |
159 } // namespace browser_sync | 161 } // namespace browser_sync |
160 | 162 |
161 #endif // CHROME_BROWSER_WEBDATA_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_ | 163 #endif // CHROME_BROWSER_WEBDATA_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_ |
OLD | NEW |