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 | 4 |
5 #ifndef COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_SERVICE_H_ | 5 #ifndef COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_SERVICE_H_ |
6 #define COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_SERVICE_H_ | 6 #define COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_SERVICE_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/weak_ptr.h" |
11 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
12 #include "base/supports_user_data.h" | 13 #include "base/supports_user_data.h" |
13 #include "components/autofill/browser/webdata/autofill_webdata.h" | 14 #include "components/autofill/browser/webdata/autofill_webdata.h" |
14 #include "components/autofill/common/form_field_data.h" | 15 #include "components/autofill/common/form_field_data.h" |
15 #include "components/webdata/common/web_data_results.h" | 16 #include "components/webdata/common/web_data_results.h" |
16 #include "components/webdata/common/web_data_service_base.h" | 17 #include "components/webdata/common/web_data_service_base.h" |
17 #include "components/webdata/common/web_data_service_consumer.h" | 18 #include "components/webdata/common/web_data_service_consumer.h" |
18 #include "components/webdata/common/web_database.h" | 19 #include "components/webdata/common/web_database.h" |
19 | 20 |
20 class WebDatabaseService; | 21 class WebDatabaseService; |
21 | 22 |
22 namespace content { | 23 namespace content { |
23 class BrowserContext; | 24 class BrowserContext; |
24 } | 25 } |
25 | 26 |
26 namespace autofill { | 27 namespace autofill { |
27 | 28 |
28 class AutofillChange; | 29 class AutofillChange; |
29 class AutofillProfile; | 30 class AutofillProfile; |
30 class AutofillWebDataBackend; | 31 class AutofillWebDataBackend; |
| 32 class AutofillWebDataBackendImpl; |
31 class AutofillWebDataServiceObserverOnDBThread; | 33 class AutofillWebDataServiceObserverOnDBThread; |
32 class AutofillWebDataServiceObserverOnUIThread; | 34 class AutofillWebDataServiceObserverOnUIThread; |
33 class CreditCard; | 35 class CreditCard; |
34 | 36 |
35 // API for Autofill web data. | 37 // API for Autofill web data. |
36 class AutofillWebDataService : public AutofillWebData, | 38 class AutofillWebDataService : public AutofillWebData, |
37 public WebDataServiceBase { | 39 public WebDataServiceBase { |
38 public: | 40 public: |
39 AutofillWebDataService(); | 41 AutofillWebDataService(); |
40 | 42 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 91 |
90 void AddObserver(AutofillWebDataServiceObserverOnUIThread* observer); | 92 void AddObserver(AutofillWebDataServiceObserverOnUIThread* observer); |
91 void RemoveObserver(AutofillWebDataServiceObserverOnUIThread* observer); | 93 void RemoveObserver(AutofillWebDataServiceObserverOnUIThread* observer); |
92 | 94 |
93 // Returns a SupportsUserData objects that may be used to store data | 95 // Returns a SupportsUserData objects that may be used to store data |
94 // owned by the DB thread on this object. Should be called only from | 96 // owned by the DB thread on this object. Should be called only from |
95 // the DB thread, and will be destroyed on the DB thread soon after | 97 // the DB thread, and will be destroyed on the DB thread soon after |
96 // |ShutdownOnUIThread()| is called. | 98 // |ShutdownOnUIThread()| is called. |
97 base::SupportsUserData* GetDBUserData(); | 99 base::SupportsUserData* GetDBUserData(); |
98 | 100 |
| 101 // Takes a callback which will be called on the DB thread with a pointer to an |
| 102 // |AutofillWebdataBackend|. This backend can be used to access or update the |
| 103 // WebDatabase directly on the DB thread. |
| 104 void GetAutofillBackend( |
| 105 const base::Callback<void(AutofillWebDataBackend*)>& callback); |
| 106 |
99 protected: | 107 protected: |
100 virtual ~AutofillWebDataService(); | 108 virtual ~AutofillWebDataService(); |
101 | 109 |
102 virtual void ShutdownOnDBThread(); | 110 virtual void ShutdownOnDBThread(); |
103 | 111 |
104 private: | 112 private: |
105 // This makes the destructor public, and thus allows us to aggregate | 113 // This makes the destructor public, and thus allows us to aggregate |
106 // SupportsUserData. It is private by default to prevent incorrect | 114 // SupportsUserData. It is private by default to prevent incorrect |
107 // usage in class hierarchies where it is inherited by | 115 // usage in class hierarchies where it is inherited by |
108 // reference-counted objects. | 116 // reference-counted objects. |
109 class SupportsUserDataAggregatable : public base::SupportsUserData { | 117 class SupportsUserDataAggregatable : public base::SupportsUserData { |
110 public: | 118 public: |
111 SupportsUserDataAggregatable() {} | 119 SupportsUserDataAggregatable() {} |
112 virtual ~SupportsUserDataAggregatable() {} | 120 virtual ~SupportsUserDataAggregatable() {} |
113 private: | 121 private: |
114 DISALLOW_COPY_AND_ASSIGN(SupportsUserDataAggregatable); | 122 DISALLOW_COPY_AND_ASSIGN(SupportsUserDataAggregatable); |
115 }; | 123 }; |
116 | 124 |
117 void NotifyAutofillMultipleChangedOnUIThread(); | 125 void NotifyAutofillMultipleChangedOnUIThread(); |
118 | 126 |
119 // Storage for user data to be accessed only on the DB thread. May | 127 // Storage for user data to be accessed only on the DB thread. May |
120 // be used e.g. for SyncableService subclasses that need to be owned | 128 // be used e.g. for SyncableService subclasses that need to be owned |
121 // by this object. Is created on first call to |GetDBUserData()|. | 129 // by this object. Is created on first call to |GetDBUserData()|. |
122 scoped_ptr<SupportsUserDataAggregatable> db_thread_user_data_; | 130 scoped_ptr<SupportsUserDataAggregatable> db_thread_user_data_; |
123 | 131 |
124 ObserverList<AutofillWebDataServiceObserverOnUIThread> ui_observer_list_; | 132 ObserverList<AutofillWebDataServiceObserverOnUIThread> ui_observer_list_; |
125 | 133 |
126 scoped_refptr<AutofillWebDataBackend> autofill_backend_; | 134 // This factory is used on the UI thread. All vended weak pointers are |
| 135 // invalidated in ShutdownOnUIThread(). |
| 136 base::WeakPtrFactory<AutofillWebDataService> weak_ptr_factory_; |
| 137 |
| 138 scoped_refptr<AutofillWebDataBackendImpl> autofill_backend_; |
127 | 139 |
128 DISALLOW_COPY_AND_ASSIGN(AutofillWebDataService); | 140 DISALLOW_COPY_AND_ASSIGN(AutofillWebDataService); |
129 }; | 141 }; |
130 | 142 |
131 } // namespace autofill | 143 } // namespace autofill |
132 | 144 |
133 #endif // COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_SERVICE_H_ | 145 #endif // COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_SERVICE_H_ |
OLD | NEW |