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/web_data_service.h

Issue 10908065: Introduce a couple of abstract bases for WebDataService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 4
5 // Chromium settings and storage represent user-selected preferences and 5 // Chromium settings and storage represent user-selected preferences and
6 // information and MUST not be extracted, overwritten or modified except 6 // information and MUST not be extracted, overwritten or modified except
7 // through Chromium defined APIs. 7 // through Chromium defined APIs.
8 8
9 #ifndef CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ 9 #ifndef CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__
10 #define CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ 10 #define CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__
11 11
12 #include <map> 12 #include <map>
13 #include <string> 13 #include <string>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/callback_forward.h" 16 #include "base/callback_forward.h"
17 #include "base/file_path.h" 17 #include "base/file_path.h"
18 #include "base/location.h" 18 #include "base/location.h"
19 #include "base/memory/ref_counted.h" 19 #include "base/memory/ref_counted.h"
20 #include "base/sequenced_task_runner_helpers.h" 20 #include "base/sequenced_task_runner_helpers.h"
21 #include "base/synchronization/lock.h" 21 #include "base/synchronization/lock.h"
22 #include "chrome/browser/profiles/refcounted_profile_keyed_service.h" 22 #include "chrome/browser/api/webdata/autofill_web_data.h"
23 #include "chrome/browser/api/webdata/web_data_results.h"
24 #include "chrome/browser/api/webdata/web_data_service_base.h"
25 #include "chrome/browser/api/webdata/web_data_service_consumer.h"
23 #include "chrome/browser/search_engines/template_url.h" 26 #include "chrome/browser/search_engines/template_url.h"
24 #include "chrome/browser/search_engines/template_url_id.h" 27 #include "chrome/browser/search_engines/template_url_id.h"
25 #include "chrome/browser/webdata/keyword_table.h" 28 #include "chrome/browser/webdata/keyword_table.h"
26 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
27 #include "sql/init_status.h" 30 #include "sql/init_status.h"
28 31
29 class AutocompleteSyncableService; 32 class AutocompleteSyncableService;
30 class AutofillChange; 33 class AutofillChange;
31 class AutofillProfile;
32 class AutofillProfileSyncableService; 34 class AutofillProfileSyncableService;
33 class CreditCard;
34 struct DefaultWebIntentService; 35 struct DefaultWebIntentService;
35 class GURL; 36 class GURL;
36 #if defined(OS_WIN) 37 #if defined(OS_WIN)
37 struct IE7PasswordInfo; 38 struct IE7PasswordInfo;
38 #endif 39 #endif
39 class MessageLoop; 40 class MessageLoop;
40 class Profile; 41 class Profile;
41 class SkBitmap; 42 class SkBitmap;
42 class WebDatabase; 43 class WebDatabase;
43 44
44 namespace base { 45 namespace base {
45 class Thread; 46 class Thread;
46 } 47 }
47 48
48 namespace webkit {
49 namespace forms {
50 struct FormField;
51 }
52 }
53
54 namespace webkit_glue { 49 namespace webkit_glue {
55 struct WebIntentServiceData; 50 struct WebIntentServiceData;
56 } 51 }
57 52
58 //////////////////////////////////////////////////////////////////////////////// 53 ////////////////////////////////////////////////////////////////////////////////
59 // 54 //
60 // WebDataService is a generic data repository for meta data associated with 55 // WebDataService is a generic data repository for meta data associated with
61 // web pages. All data is retrieved and archived in an asynchronous way. 56 // web pages. All data is retrieved and archived in an asynchronous way.
62 // 57 //
63 // All requests return a handle. The handle can be used to cancel the request. 58 // All requests return a handle. The handle can be used to cancel the request.
64 // 59 //
65 //////////////////////////////////////////////////////////////////////////////// 60 ////////////////////////////////////////////////////////////////////////////////
66 61
67 62
68 //////////////////////////////////////////////////////////////////////////////// 63 ////////////////////////////////////////////////////////////////////////////////
69 // 64 //
70 // WebDataService results 65 // WebDataService results
71 // 66 //
72 //////////////////////////////////////////////////////////////////////////////// 67 ////////////////////////////////////////////////////////////////////////////////
73 68
74 //
75 // Result types
76 //
77 typedef enum {
78 BOOL_RESULT = 1, // WDResult<bool>
79 KEYWORDS_RESULT, // WDResult<WDKeywordsResult>
80 INT64_RESULT, // WDResult<int64>
81 #if defined(OS_WIN)
82 PASSWORD_IE7_RESULT, // WDResult<IE7PasswordInfo>
83 #endif
84 WEB_APP_IMAGES, // WDResult<WDAppImagesResult>
85 TOKEN_RESULT, // WDResult<std::vector<std::string>>
86 AUTOFILL_VALUE_RESULT, // WDResult<std::vector<string16>>
87 AUTOFILL_CHANGES, // WDResult<std::vector<AutofillChange>>
88 AUTOFILL_PROFILE_RESULT, // WDResult<AutofillProfile>
89 AUTOFILL_PROFILES_RESULT, // WDResult<std::vector<AutofillProfile*>>
90 AUTOFILL_CREDITCARD_RESULT, // WDResult<CreditCard>
91 AUTOFILL_CREDITCARDS_RESULT, // WDResult<std::vector<CreditCard*>>
92 WEB_INTENTS_RESULT, // WDResult<std::vector<WebIntentServiceData>>
93 WEB_INTENTS_DEFAULTS_RESULT, // WDResult<std::vector<DefaultWebIntentService>>
94 } WDResultType;
95
96 typedef std::vector<AutofillChange> AutofillChangeList; 69 typedef std::vector<AutofillChange> AutofillChangeList;
97 70
98 // Result from GetWebAppImages. 71 // Result from GetWebAppImages.
99 struct WDAppImagesResult { 72 struct WDAppImagesResult {
100 WDAppImagesResult(); 73 WDAppImagesResult();
101 ~WDAppImagesResult(); 74 ~WDAppImagesResult();
102 75
103 // True if SetWebAppHasAllImages(true) was invoked. 76 // True if SetWebAppHasAllImages(true) was invoked.
104 bool has_all_images; 77 bool has_all_images;
105 78
(...skipping 12 matching lines...) Expand all
118 // Version of the built-in keywords. A value of 0 indicates a first run. 91 // Version of the built-in keywords. A value of 0 indicates a first run.
119 int builtin_keyword_version; 92 int builtin_keyword_version;
120 // Backup of the default search provider, and whether the backup is valid. 93 // Backup of the default search provider, and whether the backup is valid.
121 bool backup_valid; 94 bool backup_valid;
122 TemplateURLData default_search_provider_backup; 95 TemplateURLData default_search_provider_backup;
123 // Indicates if default search provider has been changed by something 96 // Indicates if default search provider has been changed by something
124 // other than user's action in the browser. 97 // other than user's action in the browser.
125 bool did_default_search_provider_change; 98 bool did_default_search_provider_change;
126 }; 99 };
127 100
128 //
129 // The top level class for a result.
130 //
131 class WDTypedResult {
132 public:
133 virtual ~WDTypedResult() {}
134
135 // Return the result type.
136 WDResultType GetType() const {
137 return type_;
138 }
139
140 protected:
141 explicit WDTypedResult(WDResultType type) : type_(type) {
142 }
143
144 private:
145 WDResultType type_;
146 DISALLOW_COPY_AND_ASSIGN(WDTypedResult);
147 };
148
149 // A result containing one specific pointer or literal value.
150 template <class T> class WDResult : public WDTypedResult {
151 public:
152
153 WDResult(WDResultType type, const T& v) : WDTypedResult(type), value_(v) {
154 }
155
156 virtual ~WDResult() {
157 }
158
159 // Return a single value result.
160 T GetValue() const {
161 return value_;
162 }
163
164 private:
165 T value_;
166
167 DISALLOW_COPY_AND_ASSIGN(WDResult);
168 };
169
170 template <class T> class WDObjectResult : public WDTypedResult {
171 public:
172 explicit WDObjectResult(WDResultType type) : WDTypedResult(type) {
173 }
174
175 T* GetValue() const {
176 return &value_;
177 }
178
179 private:
180 // mutable to keep GetValue() const.
181 mutable T value_;
182 DISALLOW_COPY_AND_ASSIGN(WDObjectResult);
183 };
184
185 class WebDataServiceConsumer; 101 class WebDataServiceConsumer;
186 102
187 class WebDataService : public RefcountedProfileKeyedService { 103 class WebDataService
104 : public WebDataServiceBase,
105 public AutofillWebData {
dhollowa 2012/09/04 16:26:55 Instead of splitting out just the *interface* for
188 public: 106 public:
189 // All requests return an opaque handle of the following type.
190 typedef int Handle;
191
192 ////////////////////////////////////////////////////////////////////////////// 107 //////////////////////////////////////////////////////////////////////////////
193 // 108 //
194 // Internal requests 109 // Internal requests
195 // 110 //
196 // Every request is processed using a request object. The object contains 111 // Every request is processed using a request object. The object contains
197 // both the request parameters and the results. 112 // both the request parameters and the results.
198 ////////////////////////////////////////////////////////////////////////////// 113 //////////////////////////////////////////////////////////////////////////////
199 class WebDataRequest { 114 class WebDataRequest {
200 public: 115 public:
201 WebDataRequest(WebDataService* service, 116 WebDataRequest(WebDataService* service,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 199
285 const U& arg2() const { return arg2_; } 200 const U& arg2() const { return arg2_; }
286 201
287 private: 202 private:
288 T arg1_; 203 T arg1_;
289 U arg2_; 204 U arg2_;
290 }; 205 };
291 206
292 WebDataService(); 207 WebDataService();
293 208
209 // WebDataServiceBase implementation.
210 virtual void CancelRequest(Handle h) OVERRIDE;
211
294 // Notifies listeners on the UI thread that multiple changes have been made to 212 // Notifies listeners on the UI thread that multiple changes have been made to
295 // to Autofill records of the database. 213 // to Autofill records of the database.
296 // NOTE: This method is intended to be called from the DB thread. It 214 // NOTE: This method is intended to be called from the DB thread. It
297 // it asynchronously notifies listeners on the UI thread. 215 // it asynchronously notifies listeners on the UI thread.
298 // |web_data_service| may be NULL for testing purposes. 216 // |web_data_service| may be NULL for testing purposes.
299 static void NotifyOfMultipleAutofillChanges(WebDataService* web_data_service); 217 static void NotifyOfMultipleAutofillChanges(WebDataService* web_data_service);
300 218
301 // RefcountedProfileKeyedService override: 219 // RefcountedProfileKeyedService override:
302 // Shutdown the web data service. The service can no longer be used after this 220 // Shutdown the web data service. The service can no longer be used after this
303 // call. 221 // call.
304 virtual void ShutdownOnUIThread() OVERRIDE; 222 virtual void ShutdownOnUIThread() OVERRIDE;
305 223
306 // Initializes the web data service. Returns false on failure 224 // Initializes the web data service. Returns false on failure
307 // Takes the path of the profile directory as its argument. 225 // Takes the path of the profile directory as its argument.
308 bool Init(const FilePath& profile_path); 226 bool Init(const FilePath& profile_path);
309 227
310 // Returns false if Shutdown() has been called. 228 // Returns false if Shutdown() has been called.
311 bool IsRunning() const; 229 bool IsRunning() const;
312 230
313 // Unloads the database without actually shutting down the service. This can 231 // Unloads the database without actually shutting down the service. This can
314 // be used to temporarily reduce the browser process' memory footprint. 232 // be used to temporarily reduce the browser process' memory footprint.
315 void UnloadDatabase(); 233 void UnloadDatabase();
316 234
317 // Cancel any pending request. You need to call this method if your
318 // WebDataServiceConsumer is about to be deleted.
319 void CancelRequest(Handle h);
320
321 virtual bool IsDatabaseLoaded(); 235 virtual bool IsDatabaseLoaded();
322 virtual WebDatabase* GetDatabase(); 236 virtual WebDatabase* GetDatabase();
323 237
324 ////////////////////////////////////////////////////////////////////////////// 238 //////////////////////////////////////////////////////////////////////////////
325 // 239 //
326 // Keywords 240 // Keywords
327 // 241 //
328 ////////////////////////////////////////////////////////////////////////////// 242 //////////////////////////////////////////////////////////////////////////////
329 243
330 // As the database processes requests at a later date, all deletion is 244 // As the database processes requests at a later date, all deletion is
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 Handle GetIE7Login(const IE7PasswordInfo& info, 364 Handle GetIE7Login(const IE7PasswordInfo& info,
451 WebDataServiceConsumer* consumer); 365 WebDataServiceConsumer* consumer);
452 #endif // defined(OS_WIN) 366 #endif // defined(OS_WIN)
453 367
454 ////////////////////////////////////////////////////////////////////////////// 368 //////////////////////////////////////////////////////////////////////////////
455 // 369 //
456 // Autofill. 370 // Autofill.
457 // 371 //
458 ////////////////////////////////////////////////////////////////////////////// 372 //////////////////////////////////////////////////////////////////////////////
459 373
460 // Schedules a task to add form fields to the web database. 374 // AutofillWebData implementation.
461 virtual void AddFormFields( 375 virtual void AddFormFields(
462 const std::vector<webkit::forms::FormField>& fields); 376 const std::vector<webkit::forms::FormField>& fields) OVERRIDE;
463 377 virtual Handle GetFormValuesForElementName(
464 // Initiates the request for a vector of values which have been entered in 378 const string16& name,
465 // form input fields named |name|. The method OnWebDataServiceRequestDone of 379 const string16& prefix,
466 // |consumer| gets called back when the request is finished, with the vector 380 int limit,
467 // included in the argument |result|. 381 WebDataServiceConsumer* consumer) OVERRIDE;
468 Handle GetFormValuesForElementName(const string16& name, 382 virtual void RemoveExpiredFormElements() OVERRIDE;
469 const string16& prefix, 383 virtual void RemoveFormValueForElementName(const string16& name,
470 int limit, 384 const string16& value) OVERRIDE;
471 WebDataServiceConsumer* consumer); 385 virtual void AddAutofillProfile(const AutofillProfile& profile) OVERRIDE;
472 386 virtual void UpdateAutofillProfile(const AutofillProfile& profile) OVERRIDE;
473 // Removes form elements recorded for Autocomplete from the database. 387 virtual void RemoveAutofillProfile(const std::string& guid) OVERRIDE;
474 void RemoveFormElementsAddedBetween(const base::Time& delete_begin, 388 virtual Handle GetAutofillProfiles(WebDataServiceConsumer* consumer) OVERRIDE;
475 const base::Time& delete_end); 389 virtual void EmptyMigrationTrash(bool notify_sync) OVERRIDE;
476 void RemoveExpiredFormElements(); 390 virtual void AddCreditCard(const CreditCard& credit_card) OVERRIDE;
477 void RemoveFormValueForElementName(const string16& name, 391 virtual void UpdateCreditCard(const CreditCard& credit_card) OVERRIDE;
478 const string16& value); 392 virtual void RemoveCreditCard(const std::string& guid) OVERRIDE;
479 393 virtual Handle GetCreditCards(WebDataServiceConsumer* consumer) OVERRIDE;
480 // Schedules a task to add an Autofill profile to the web database.
481 void AddAutofillProfile(const AutofillProfile& profile);
482
483 // Schedules a task to update an Autofill profile in the web database.
484 void UpdateAutofillProfile(const AutofillProfile& profile);
485
486 // Schedules a task to remove an Autofill profile from the web database.
487 // |guid| is the identifer of the profile to remove.
488 void RemoveAutofillProfile(const std::string& guid);
489
490 // Initiates the request for all Autofill profiles. The method
491 // OnWebDataServiceRequestDone of |consumer| gets called when the request is
492 // finished, with the profiles included in the argument |result|. The
493 // consumer owns the profiles.
494 Handle GetAutofillProfiles(WebDataServiceConsumer* consumer);
495
496 // Remove "trashed" profile guids from the web database and optionally send
497 // notifications to tell Sync that the items have been removed.
498 void EmptyMigrationTrash(bool notify_sync);
499
500 // Schedules a task to add credit card to the web database.
501 void AddCreditCard(const CreditCard& credit_card);
502
503 // Schedules a task to update credit card in the web database.
504 void UpdateCreditCard(const CreditCard& credit_card);
505
506 // Schedules a task to remove a credit card from the web database.
507 // |guid| is identifer of the credit card to remove.
508 void RemoveCreditCard(const std::string& guid);
509
510 // Initiates the request for all credit cards. The method
511 // OnWebDataServiceRequestDone of |consumer| gets called when the request is
512 // finished, with the credit cards included in the argument |result|. The
513 // consumer owns the credit cards.
514 Handle GetCreditCards(WebDataServiceConsumer* consumer);
515 394
516 // Removes Autofill records from the database. 395 // Removes Autofill records from the database.
517 void RemoveAutofillProfilesAndCreditCardsModifiedBetween( 396 void RemoveAutofillProfilesAndCreditCardsModifiedBetween(
518 const base::Time& delete_begin, 397 const base::Time& delete_begin,
519 const base::Time& delete_end); 398 const base::Time& delete_end);
520 399
400 // Removes form elements recorded for Autocomplete from the database.
401 void RemoveFormElementsAddedBetween(const base::Time& delete_begin,
402 const base::Time& delete_end);
403
521 // Returns the syncable service for Autofill addresses and credit cards stored 404 // Returns the syncable service for Autofill addresses and credit cards stored
522 // in this table. The returned service is owned by |this| object. 405 // in this table. The returned service is owned by |this| object.
523 virtual AutofillProfileSyncableService* 406 virtual AutofillProfileSyncableService*
524 GetAutofillProfileSyncableService() const; 407 GetAutofillProfileSyncableService() const;
525 408
526 // Returns the syncable service for field autocomplete stored in this table. 409 // Returns the syncable service for field autocomplete stored in this table.
527 // The returned service is owned by |this| object. 410 // The returned service is owned by |this| object.
528 virtual AutocompleteSyncableService* 411 virtual AutocompleteSyncableService*
529 GetAutocompleteSyncableService() const; 412 GetAutocompleteSyncableService() const;
530 413
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 601
719 typedef std::map<Handle, WebDataRequest*> RequestMap; 602 typedef std::map<Handle, WebDataRequest*> RequestMap;
720 RequestMap pending_requests_; 603 RequestMap pending_requests_;
721 604
722 // MessageLoop the WebDataService is created on. 605 // MessageLoop the WebDataService is created on.
723 MessageLoop* main_loop_; 606 MessageLoop* main_loop_;
724 607
725 DISALLOW_COPY_AND_ASSIGN(WebDataService); 608 DISALLOW_COPY_AND_ASSIGN(WebDataService);
726 }; 609 };
727 610
728 ////////////////////////////////////////////////////////////////////////////////
729 //
730 // WebDataServiceConsumer.
731 //
732 // All requests to the web data service are asynchronous. When the request has
733 // been performed, the data consumer is notified using the following interface.
734 //
735 ////////////////////////////////////////////////////////////////////////////////
736
737 class WebDataServiceConsumer {
738 public:
739
740 // Called when a request is done. h uniquely identifies the request.
741 // result can be NULL, if no result is expected or if the database could
742 // not be opened. The result object is destroyed after this call.
743 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h,
744 const WDTypedResult* result) = 0;
745
746 protected:
747 virtual ~WebDataServiceConsumer() {}
748 };
749
750 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ 611 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698