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/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
15 #include "base/threading/non_thread_safe.h" | 15 #include "base/threading/non_thread_safe.h" |
16 #include "chrome/browser/sync/api/sync_change.h" | 16 #include "chrome/browser/sync/api/sync_change.h" |
17 #include "chrome/browser/sync/api/sync_data.h" | 17 #include "chrome/browser/sync/api/sync_data.h" |
18 #include "chrome/browser/sync/api/sync_error.h" | 18 #include "chrome/browser/sync/api/sync_error.h" |
19 #include "chrome/browser/sync/api/syncable_service.h" | 19 #include "chrome/browser/sync/api/syncable_service.h" |
20 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" | 20 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" |
21 #include "chrome/browser/webdata/autofill_change.h" | 21 #include "chrome/browser/webdata/autofill_change.h" |
22 #include "chrome/browser/webdata/autofill_entry.h" | 22 #include "chrome/browser/webdata/autofill_entry.h" |
23 #include "content/common/content_notification_types.h" | 23 #include "content/common/content_notification_types.h" |
24 #include "content/common/notification_observer.h" | 24 #include "content/common/notification_observer.h" |
25 #include "content/common/notification_registrar.h" | 25 #include "content/common/notification_registrar.h" |
26 | 26 |
27 class AutofillProfile; | 27 class AutofillProfile; |
28 class Profile; | 28 class Profile; |
29 class ProfileSyncServiceAutofillTest; | 29 class ProfileSyncServiceAutofillTest; |
30 | |
31 class WebDatabase; | 30 class WebDatabase; |
32 | 31 |
33 namespace browser_sync { | 32 namespace browser_sync { |
33 class UnrecoverableErrorHandler; | |
34 } | |
34 | 35 |
35 extern const char kAutofillProfileTag[]; | 36 extern const char kAutofillProfileTag[]; |
36 | 37 |
37 class UnrecoverableErrorHandler; | |
38 | |
39 // The sync implementation for AutofillProfiles. | 38 // The sync implementation for AutofillProfiles. |
40 // MergeDataAndStartSyncing() called first, it does cloud->local and | 39 // MergeDataAndStartSyncing() called first, it does cloud->local and |
41 // local->cloud syncs. Then for each cloud change we receive | 40 // local->cloud syncs. Then for each cloud change we receive |
42 // ProcessSyncChanges() and for each local change Observe() is called. | 41 // ProcessSyncChanges() and for each local change Observe() is called. |
43 class AutofillProfileSyncableService | 42 class AutofillProfileSyncableService |
44 : public SyncableService, | 43 : public SyncableService, |
45 public NotificationObserver, | 44 public NotificationObserver, |
46 public base::NonThreadSafe { | 45 public base::NonThreadSafe { |
47 public: | 46 public: |
48 AutofillProfileSyncableService(WebDatabase* web_database, Profile* profile); | 47 AutofillProfileSyncableService(WebDatabase* web_database, Profile* profile); |
(...skipping 10 matching lines...) Expand all Loading... | |
59 virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE; | 58 virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE; |
60 virtual SyncError ProcessSyncChanges( | 59 virtual SyncError ProcessSyncChanges( |
61 const tracked_objects::Location& from_here, | 60 const tracked_objects::Location& from_here, |
62 const SyncChangeList& change_list) OVERRIDE; | 61 const SyncChangeList& change_list) OVERRIDE; |
63 | 62 |
64 // NotificationObserver implementation. | 63 // NotificationObserver implementation. |
65 virtual void Observe(int type, | 64 virtual void Observe(int type, |
66 const NotificationSource& source, | 65 const NotificationSource& source, |
67 const NotificationDetails& details) OVERRIDE; | 66 const NotificationDetails& details) OVERRIDE; |
68 | 67 |
68 const WebDatabase* web_database() { return web_database_; } | |
akalin
2011/10/10 21:58:57
where are these used?
Ilya Sherman
2011/10/10 22:33:13
I added them for the sake of the DCHECK's in the a
| |
69 const Profile* profile() { return profile_; } | |
70 | |
69 protected: | 71 protected: |
70 // A convenience wrapper of a bunch of state we pass around while | 72 // A convenience wrapper of a bunch of state we pass around while |
71 // associating models, and send to the WebDatabase for persistence. | 73 // associating models, and send to the WebDatabase for persistence. |
72 // We do this so we hold the write lock for only a small period. | 74 // We do this so we hold the write lock for only a small period. |
73 // When storing the web db we are out of the write lock. | 75 // When storing the web db we are out of the write lock. |
74 struct DataBundle; | 76 struct DataBundle; |
75 | 77 |
76 // Helper to query WebDatabase for the current autofill state. | 78 // Helper to query WebDatabase for the current autofill state. |
77 // Made virtual for ease of mocking in the unit-test. | 79 // Made virtual for ease of mocking in the unit-test. |
78 // Caller owns returned |profiles|. | 80 // Caller owns returned |profiles|. |
79 virtual bool LoadAutofillData(std::vector<AutofillProfile*>* profiles); | 81 virtual bool LoadAutofillData(std::vector<AutofillProfile*>* profiles); |
80 | 82 |
81 // Helper to persist any changes that occured during model association to | 83 // Helper to persist any changes that occured during model association to |
82 // the WebDatabase. | 84 // the WebDatabase. |
83 // Made virtual for ease of mocking in the unit-test. | 85 // Made virtual for ease of mocking in the unit-test. |
84 virtual bool SaveChangesToWebData(const DataBundle& bundle); | 86 virtual bool SaveChangesToWebData(const DataBundle& bundle); |
85 | 87 |
86 private: | 88 private: |
87 friend class ::ProfileSyncServiceAutofillTest; | 89 friend class ProfileSyncServiceAutofillTest; |
88 friend class MockAutofillProfileSyncableService; | 90 friend class MockAutofillProfileSyncableService; |
89 FRIEND_TEST_ALL_PREFIXES(AutofillProfileSyncableServiceTest, | 91 FRIEND_TEST_ALL_PREFIXES(AutofillProfileSyncableServiceTest, |
90 MergeDataAndStartSyncing); | 92 MergeDataAndStartSyncing); |
91 FRIEND_TEST_ALL_PREFIXES(AutofillProfileSyncableServiceTest, GetAllSyncData); | 93 FRIEND_TEST_ALL_PREFIXES(AutofillProfileSyncableServiceTest, GetAllSyncData); |
92 FRIEND_TEST_ALL_PREFIXES(AutofillProfileSyncableServiceTest, | 94 FRIEND_TEST_ALL_PREFIXES(AutofillProfileSyncableServiceTest, |
93 ProcessSyncChanges); | 95 ProcessSyncChanges); |
94 FRIEND_TEST_ALL_PREFIXES(AutofillProfileSyncableServiceTest, | 96 FRIEND_TEST_ALL_PREFIXES(AutofillProfileSyncableServiceTest, |
95 ActOnChange); | 97 ActOnChange); |
96 | 98 |
97 // The map of the guid to profiles owned by the |profiles_| vector. | 99 // The map of the guid to profiles owned by the |profiles_| vector. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 | |
160 | |
161 #endif // CHROME_BROWSER_WEBDATA_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_ | 161 #endif // CHROME_BROWSER_WEBDATA_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_ |
OLD | NEW |