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

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,
dhollowa 2012/09/07 16:04:01 nit: Common pattern is unwrapped style. I.e. line
105 public AutofillWebData,
106 public RefcountedProfileKeyedService {
188 public: 107 public:
189 // All requests return an opaque handle of the following type.
190 typedef int Handle;
191
192 ////////////////////////////////////////////////////////////////////////////// 108 //////////////////////////////////////////////////////////////////////////////
193 // 109 //
194 // Internal requests 110 // Internal requests
195 // 111 //
196 // Every request is processed using a request object. The object contains 112 // Every request is processed using a request object. The object contains
197 // both the request parameters and the results. 113 // both the request parameters and the results.
198 ////////////////////////////////////////////////////////////////////////////// 114 //////////////////////////////////////////////////////////////////////////////
199 class WebDataRequest { 115 class WebDataRequest {
200 public: 116 public:
201 WebDataRequest(WebDataService* service, 117 WebDataRequest(WebDataService* service,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 200
285 const U& arg2() const { return arg2_; } 201 const U& arg2() const { return arg2_; }
286 202
287 private: 203 private:
288 T arg1_; 204 T arg1_;
289 U arg2_; 205 U arg2_;
290 }; 206 };
291 207
292 WebDataService(); 208 WebDataService();
293 209
210 // WebDataServiceBase implementation.
211 virtual void CancelRequest(Handle h) OVERRIDE;
212
294 // Notifies listeners on the UI thread that multiple changes have been made to 213 // Notifies listeners on the UI thread that multiple changes have been made to
295 // to Autofill records of the database. 214 // to Autofill records of the database.
296 // NOTE: This method is intended to be called from the DB thread. It 215 // NOTE: This method is intended to be called from the DB thread. It
297 // it asynchronously notifies listeners on the UI thread. 216 // it asynchronously notifies listeners on the UI thread.
298 // |web_data_service| may be NULL for testing purposes. 217 // |web_data_service| may be NULL for testing purposes.
299 static void NotifyOfMultipleAutofillChanges(WebDataService* web_data_service); 218 static void NotifyOfMultipleAutofillChanges(WebDataService* web_data_service);
300 219
301 // RefcountedProfileKeyedService override: 220 // RefcountedProfileKeyedService override:
302 // Shutdown the web data service. The service can no longer be used after this 221 // Shutdown the web data service. The service can no longer be used after this
303 // call. 222 // call.
304 virtual void ShutdownOnUIThread() OVERRIDE; 223 virtual void ShutdownOnUIThread() OVERRIDE;
305 224
306 // Initializes the web data service. Returns false on failure 225 // Initializes the web data service. Returns false on failure
307 // Takes the path of the profile directory as its argument. 226 // Takes the path of the profile directory as its argument.
308 bool Init(const FilePath& profile_path); 227 bool Init(const FilePath& profile_path);
309 228
310 // Returns false if Shutdown() has been called. 229 // Returns false if Shutdown() has been called.
311 bool IsRunning() const; 230 bool IsRunning() const;
312 231
313 // Unloads the database without actually shutting down the service. This can 232 // Unloads the database without actually shutting down the service. This can
314 // be used to temporarily reduce the browser process' memory footprint. 233 // be used to temporarily reduce the browser process' memory footprint.
315 void UnloadDatabase(); 234 void UnloadDatabase();
316 235
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(); 236 virtual bool IsDatabaseLoaded();
322 virtual WebDatabase* GetDatabase(); 237 virtual WebDatabase* GetDatabase();
323 238
324 ////////////////////////////////////////////////////////////////////////////// 239 //////////////////////////////////////////////////////////////////////////////
325 // 240 //
326 // Keywords 241 // Keywords
327 // 242 //
328 ////////////////////////////////////////////////////////////////////////////// 243 //////////////////////////////////////////////////////////////////////////////
329 244
330 // As the database processes requests at a later date, all deletion is 245 // 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, 365 Handle GetIE7Login(const IE7PasswordInfo& info,
451 WebDataServiceConsumer* consumer); 366 WebDataServiceConsumer* consumer);
452 #endif // defined(OS_WIN) 367 #endif // defined(OS_WIN)
453 368
454 ////////////////////////////////////////////////////////////////////////////// 369 //////////////////////////////////////////////////////////////////////////////
455 // 370 //
456 // Autofill. 371 // Autofill.
457 // 372 //
458 ////////////////////////////////////////////////////////////////////////////// 373 //////////////////////////////////////////////////////////////////////////////
459 374
460 // Schedules a task to add form fields to the web database. 375 // AutofillWebData implementation.
461 virtual void AddFormFields( 376 virtual void AddFormFields(
462 const std::vector<webkit::forms::FormField>& fields); 377 const std::vector<webkit::forms::FormField>& fields) OVERRIDE;
463 378 virtual Handle GetFormValuesForElementName(
464 // Initiates the request for a vector of values which have been entered in 379 const string16& name,
465 // form input fields named |name|. The method OnWebDataServiceRequestDone of 380 const string16& prefix,
466 // |consumer| gets called back when the request is finished, with the vector 381 int limit,
467 // included in the argument |result|. 382 WebDataServiceConsumer* consumer) OVERRIDE;
468 Handle GetFormValuesForElementName(const string16& name, 383 virtual void RemoveExpiredFormElements() OVERRIDE;
469 const string16& prefix, 384 virtual void RemoveFormValueForElementName(const string16& name,
470 int limit, 385 const string16& value) OVERRIDE;
471 WebDataServiceConsumer* consumer); 386 virtual void AddAutofillProfile(const AutofillProfile& profile) OVERRIDE;
472 387 virtual void UpdateAutofillProfile(const AutofillProfile& profile) OVERRIDE;
473 // Removes form elements recorded for Autocomplete from the database. 388 virtual void RemoveAutofillProfile(const std::string& guid) OVERRIDE;
474 void RemoveFormElementsAddedBetween(const base::Time& delete_begin, 389 virtual Handle GetAutofillProfiles(WebDataServiceConsumer* consumer) OVERRIDE;
475 const base::Time& delete_end); 390 virtual void EmptyMigrationTrash(bool notify_sync) OVERRIDE;
476 void RemoveExpiredFormElements(); 391 virtual void AddCreditCard(const CreditCard& credit_card) OVERRIDE;
477 void RemoveFormValueForElementName(const string16& name, 392 virtual void UpdateCreditCard(const CreditCard& credit_card) OVERRIDE;
478 const string16& value); 393 virtual void RemoveCreditCard(const std::string& guid) OVERRIDE;
479 394 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 395
516 // Removes Autofill records from the database. 396 // Removes Autofill records from the database.
517 void RemoveAutofillProfilesAndCreditCardsModifiedBetween( 397 void RemoveAutofillProfilesAndCreditCardsModifiedBetween(
518 const base::Time& delete_begin, 398 const base::Time& delete_begin,
519 const base::Time& delete_end); 399 const base::Time& delete_end);
520 400
401 // Removes form elements recorded for Autocomplete from the database.
402 void RemoveFormElementsAddedBetween(const base::Time& delete_begin,
403 const base::Time& delete_end);
404
521 // Returns the syncable service for Autofill addresses and credit cards stored 405 // Returns the syncable service for Autofill addresses and credit cards stored
522 // in this table. The returned service is owned by |this| object. 406 // in this table. The returned service is owned by |this| object.
523 virtual AutofillProfileSyncableService* 407 virtual AutofillProfileSyncableService*
524 GetAutofillProfileSyncableService() const; 408 GetAutofillProfileSyncableService() const;
525 409
526 // Returns the syncable service for field autocomplete stored in this table. 410 // Returns the syncable service for field autocomplete stored in this table.
527 // The returned service is owned by |this| object. 411 // The returned service is owned by |this| object.
528 virtual AutocompleteSyncableService* 412 virtual AutocompleteSyncableService*
529 GetAutocompleteSyncableService() const; 413 GetAutocompleteSyncableService() const;
530 414
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 602
719 typedef std::map<Handle, WebDataRequest*> RequestMap; 603 typedef std::map<Handle, WebDataRequest*> RequestMap;
720 RequestMap pending_requests_; 604 RequestMap pending_requests_;
721 605
722 // MessageLoop the WebDataService is created on. 606 // MessageLoop the WebDataService is created on.
723 MessageLoop* main_loop_; 607 MessageLoop* main_loop_;
724 608
725 DISALLOW_COPY_AND_ASSIGN(WebDataService); 609 DISALLOW_COPY_AND_ASSIGN(WebDataService);
726 }; 610 };
727 611
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__ 612 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698