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

Side by Side Diff: chrome/browser/webdata/web_data_service.h

Issue 12851008: Create a common base class for all the webdatas (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase on trunk and comments Created 7 years, 9 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/files/file_path.h" 17 #include "base/files/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/api/webdata/autofill_web_data_service.h" 22 #include "chrome/browser/api/webdata/autofill_web_data_service.h"
23 #include "chrome/browser/api/webdata/web_data_results.h" 23 #include "chrome/browser/api/webdata/web_data_results.h"
24 #include "chrome/browser/api/webdata/web_data_service_base.h" 24 #include "chrome/browser/api/webdata/web_data_service_base.h"
25 #include "chrome/browser/api/webdata/web_data_service_consumer.h" 25 #include "chrome/browser/api/webdata/web_data_service_consumer.h"
26 #include "chrome/browser/profiles/refcounted_profile_keyed_service.h"
27 #include "chrome/browser/search_engines/template_url.h" 26 #include "chrome/browser/search_engines/template_url.h"
28 #include "chrome/browser/search_engines/template_url_id.h" 27 #include "chrome/browser/search_engines/template_url_id.h"
29 #include "chrome/browser/webdata/keyword_table.h" 28 #include "chrome/browser/webdata/keyword_table.h"
30 #include "chrome/browser/webdata/web_data_request_manager.h" 29 #include "chrome/browser/webdata/web_database.h"
31 #include "content/public/browser/browser_thread.h"
32 #include "sql/init_status.h"
33 30
34 class AutocompleteSyncableService; 31 class AutocompleteSyncableService;
35 class AutofillChange; 32 class AutofillChange;
36 class AutofillProfileSyncableService; 33 class AutofillProfileSyncableService;
37 struct DefaultWebIntentService; 34 struct DefaultWebIntentService;
38 class GURL; 35 class GURL;
39 #if defined(OS_WIN) 36 #if defined(OS_WIN)
40 struct IE7PasswordInfo; 37 struct IE7PasswordInfo;
41 #endif 38 #endif
42 class MessageLoop; 39 class MessageLoop;
43 class Profile; 40 class Profile;
44 class SkBitmap; 41 class SkBitmap;
45 class WebDatabase; 42 class WebDatabaseService;
46 43
47 namespace base { 44 namespace base {
48 class Thread; 45 class Thread;
49 } 46 }
50 47
51 namespace content { 48 namespace content {
52 class BrowserContext; 49 class BrowserContext;
53 } 50 }
54 51
55 namespace webkit_glue { 52 namespace webkit_glue {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 // 0 indicates there is no default search provider. 94 // 0 indicates there is no default search provider.
98 int64 default_search_provider_id; 95 int64 default_search_provider_id;
99 // Version of the built-in keywords. A value of 0 indicates a first run. 96 // Version of the built-in keywords. A value of 0 indicates a first run.
100 int builtin_keyword_version; 97 int builtin_keyword_version;
101 }; 98 };
102 99
103 class WebDataServiceConsumer; 100 class WebDataServiceConsumer;
104 101
105 class WebDataService 102 class WebDataService
106 : public WebDataServiceBase, 103 : public WebDataServiceBase,
107 public AutofillWebData, 104 public AutofillWebData {
108 public RefcountedProfileKeyedService {
109 public: 105 public:
110 // Retrieve a WebDataService for the given context. 106 // Retrieve a WebDataService for the given context.
111 static scoped_refptr<WebDataService> FromBrowserContext( 107 static scoped_refptr<WebDataService> FromBrowserContext(
112 content::BrowserContext* context); 108 content::BrowserContext* context);
113 109
114 WebDataService(); 110 WebDataService();
115 111
116 // WebDataServiceBase implementation. 112 // WebDataServiceBase implementation.
117 virtual void CancelRequest(Handle h) OVERRIDE; 113 virtual void ShutdownOnUIThread() OVERRIDE;
118 virtual content::NotificationSource GetNotificationSource() OVERRIDE; 114 virtual void Init(const base::FilePath& path) OVERRIDE;
119 115
120 // Notifies listeners on the UI thread that multiple changes have been made to 116 // Notifies listeners on the UI thread that multiple changes have been made to
121 // to Autofill records of the database. 117 // to Autofill records of the database.
122 // NOTE: This method is intended to be called from the DB thread. It 118 // NOTE: This method is intended to be called from the DB thread. It
123 // it asynchronously notifies listeners on the UI thread. 119 // it asynchronously notifies listeners on the UI thread.
124 // |web_data_service| may be NULL for testing purposes. 120 // |web_data_service| may be NULL for testing purposes.
125 static void NotifyOfMultipleAutofillChanges(WebDataService* web_data_service); 121 static void NotifyOfMultipleAutofillChanges(WebDataService* web_data_service);
126 122
127 // RefcountedProfileKeyedService override:
128 // Shutdown the web data service. The service can no longer be used after this
129 // call.
130 virtual void ShutdownOnUIThread() OVERRIDE;
131 123
132 // Initializes the web data service. Returns false on failure
133 // Takes the path of the profile directory as its argument.
134 bool Init(const base::FilePath& profile_path);
135
136 // Returns false if Shutdown() has been called.
137 bool IsRunning() const;
138
139 // Unloads the database without actually shutting down the service. This can
140 // be used to temporarily reduce the browser process' memory footprint.
141 void UnloadDatabase();
142
143 virtual bool IsDatabaseLoaded();
144 virtual WebDatabase* GetDatabase();
145 124
146 ////////////////////////////////////////////////////////////////////////////// 125 //////////////////////////////////////////////////////////////////////////////
147 // 126 //
148 // Keywords 127 // Keywords
149 // 128 //
150 ////////////////////////////////////////////////////////////////////////////// 129 //////////////////////////////////////////////////////////////////////////////
151 130
152 // As the database processes requests at a later date, all deletion is 131 // As the database processes requests at a later date, all deletion is
153 // done on the background thread. 132 // done on the background thread.
154 // 133 //
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 // Returns the syncable service for Autofill addresses and credit cards stored 292 // Returns the syncable service for Autofill addresses and credit cards stored
314 // in this table. The returned service is owned by |this| object. 293 // in this table. The returned service is owned by |this| object.
315 virtual AutofillProfileSyncableService* 294 virtual AutofillProfileSyncableService*
316 GetAutofillProfileSyncableService() const; 295 GetAutofillProfileSyncableService() const;
317 296
318 // Returns the syncable service for field autocomplete stored in this table. 297 // Returns the syncable service for field autocomplete stored in this table.
319 // The returned service is owned by |this| object. 298 // The returned service is owned by |this| object.
320 virtual AutocompleteSyncableService* 299 virtual AutocompleteSyncableService*
321 GetAutocompleteSyncableService() const; 300 GetAutocompleteSyncableService() const;
322 301
323 // Testing
324 #ifdef UNIT_TEST
325 void set_failed_init(bool value) { failed_init_ = value; }
326 #endif
327
328 protected: 302 protected:
303 // TODO(caitkp): We probably don't need these anymore.
329 friend class TemplateURLServiceTest; 304 friend class TemplateURLServiceTest;
330 friend class TemplateURLServiceTestingProfile; 305 friend class TemplateURLServiceTestingProfile;
331 friend class WebDataServiceTest; 306 friend class WebDataServiceTest;
332 friend class WebDataRequest; 307 friend class WebDataRequest;
333 308
334 virtual ~WebDataService(); 309 virtual ~WebDataService();
335 310
336 // This is invoked by the unit test; path is the path of the Web Data file.
337 bool InitWithPath(const base::FilePath& path);
338
339 ////////////////////////////////////////////////////////////////////////////// 311 //////////////////////////////////////////////////////////////////////////////
340 // 312 //
341 // The following methods are only invoked in the web data service thread. 313 // The following methods are only invoked in the web data service thread.
342 // 314 //
343 ////////////////////////////////////////////////////////////////////////////// 315 //////////////////////////////////////////////////////////////////////////////
344 private: 316 private:
345 friend struct content::BrowserThread::DeleteOnThread<
346 content::BrowserThread::UI>;
347 friend class base::DeleteHelper<WebDataService>;
348
349 // Invoked on the main thread if initializing the db fails.
350 void DBInitFailed(sql::InitStatus init_status);
351
352 // Initialize the database, if it hasn't already been initialized.
353 void InitializeDatabaseIfNecessary();
354
355 // Initialize any syncable services. 317 // Initialize any syncable services.
356 void InitializeSyncableServices(); 318 void InitializeSyncableServices();
357 319
358 // The notification method.
359 void NotifyDatabaseLoadedOnUIThread();
360
361 // Commit any pending transaction and deletes the database.
362 void ShutdownDatabase();
363
364 // Deletes the syncable services. 320 // Deletes the syncable services.
365 void ShutdownSyncableServices(); 321 void ShutdownSyncableServices();
366 322
367 // Commit the current transaction and creates a new one.
368 void Commit();
369
370 // Schedule a task on our worker thread.
371 void ScheduleTask(const tracked_objects::Location& from_here,
372 const base::Closure& task);
373
374 void ScheduleDBTask(const tracked_objects::Location& from_here,
375 const base::Closure& task);
376
377 WebDataService::Handle ScheduleDBTaskWithResult(
378 const tracked_objects::Location& from_here,
379 const ResultTask& task,
380 WebDataServiceConsumer* consumer);
381
382 void DBTaskWrapper(const base::Closure& task,
383 scoped_ptr<WebDataRequest> request);
384
385 void DBResultTaskWrapper(const ResultTask& task,
386 scoped_ptr<WebDataRequest> request);
387
388 // Schedule a commit if one is not already pending.
389 void ScheduleCommit();
390
391 ////////////////////////////////////////////////////////////////////////////// 323 //////////////////////////////////////////////////////////////////////////////
392 // 324 //
393 // Keywords. 325 // Keywords.
394 // 326 //
395 ////////////////////////////////////////////////////////////////////////////// 327 //////////////////////////////////////////////////////////////////////////////
396 void AddKeywordImpl(const TemplateURLData& data); 328 WebDatabase::State AddKeywordImpl(
397 void RemoveKeywordImpl(TemplateURLID id); 329 const TemplateURLData& data, WebDatabase* db);
398 void UpdateKeywordImpl(const TemplateURLData& data); 330 WebDatabase::State RemoveKeywordImpl(
399 scoped_ptr<WDTypedResult> GetKeywordsImpl(); 331 TemplateURLID id, WebDatabase* db);
400 void SetDefaultSearchProviderImpl(TemplateURLID r); 332 WebDatabase::State UpdateKeywordImpl(
401 void SetBuiltinKeywordVersionImpl(int version); 333 const TemplateURLData& data, WebDatabase* db);
334 scoped_ptr<WDTypedResult> GetKeywordsImpl(WebDatabase* db);
335 WebDatabase::State SetDefaultSearchProviderImpl(
336 TemplateURLID r, WebDatabase* db);
337 WebDatabase::State SetBuiltinKeywordVersionImpl(int version, WebDatabase* db);
402 338
403 ////////////////////////////////////////////////////////////////////////////// 339 //////////////////////////////////////////////////////////////////////////////
404 // 340 //
405 // Web Apps. 341 // Web Apps.
406 // 342 //
407 ////////////////////////////////////////////////////////////////////////////// 343 //////////////////////////////////////////////////////////////////////////////
408 344
409 void SetWebAppImageImpl(const GURL& app_url, const SkBitmap& image); 345 WebDatabase::State SetWebAppImageImpl(const GURL& app_url,
410 void SetWebAppHasAllImagesImpl(const GURL& app_url, bool has_all_images); 346 const SkBitmap& image, WebDatabase* db);
411 void RemoveWebAppImpl(const GURL& app_url); 347 WebDatabase::State SetWebAppHasAllImagesImpl(const GURL& app_url,
412 scoped_ptr<WDTypedResult> GetWebAppImagesImpl(const GURL& app_url); 348 bool has_all_images, WebDatabase* db);
349 WebDatabase::State RemoveWebAppImpl(const GURL& app_url, WebDatabase* db);
350 scoped_ptr<WDTypedResult> GetWebAppImagesImpl(
351 const GURL& app_url, WebDatabase* db);
413 352
414 #if defined(ENABLE_WEB_INTENTS) 353 #if defined(ENABLE_WEB_INTENTS)
415 ////////////////////////////////////////////////////////////////////////////// 354 //////////////////////////////////////////////////////////////////////////////
416 // 355 //
417 // Web Intents. 356 // Web Intents.
418 // 357 //
419 ////////////////////////////////////////////////////////////////////////////// 358 //////////////////////////////////////////////////////////////////////////////
420 void AddWebIntentServiceImpl( 359 WebDatabase::State AddWebIntentServiceImpl(
421 const webkit_glue::WebIntentServiceData& service); 360 const webkit_glue::WebIntentServiceData& service);
422 void RemoveWebIntentServiceImpl( 361 WebDatabase::State RemoveWebIntentServiceImpl(
423 const webkit_glue::WebIntentServiceData& service); 362 const webkit_glue::WebIntentServiceData& service);
424 scoped_ptr<WDTypedResult> GetWebIntentServicesImpl(const string16& action); 363 scoped_ptr<WDTypedResult> GetWebIntentServicesImpl(const string16& action);
425 scoped_ptr<WDTypedResult> GetWebIntentServicesForURLImpl( 364 scoped_ptr<WDTypedResult> GetWebIntentServicesForURLImpl(
426 const string16& service_url); 365 const string16& service_url);
427 scoped_ptr<WDTypedResult> GetAllWebIntentServicesImpl(); 366 scoped_ptr<WDTypedResult> GetAllWebIntentServicesImpl();
428 void AddDefaultWebIntentServiceImpl(const DefaultWebIntentService& service); 367 WebDatabase::State AddDefaultWebIntentServiceImpl(
429 void RemoveDefaultWebIntentServiceImpl(
430 const DefaultWebIntentService& service); 368 const DefaultWebIntentService& service);
431 void RemoveWebIntentServiceDefaultsImpl(const GURL& service_url); 369 WebDatabase::State RemoveDefaultWebIntentServiceImpl(
370 const DefaultWebIntentService& service);
371 WebDatabase::State RemoveWebIntentServiceDefaultsImpl(
372 const GURL& service_url);
432 scoped_ptr<WDTypedResult> GetDefaultWebIntentServicesForActionImpl( 373 scoped_ptr<WDTypedResult> GetDefaultWebIntentServicesForActionImpl(
433 const string16& action); 374 const string16& action);
434 scoped_ptr<WDTypedResult> GetAllDefaultWebIntentServicesImpl(); 375 scoped_ptr<WDTypedResult> GetAllDefaultWebIntentServicesImpl();
435 #endif 376 #endif
436 377
437 ////////////////////////////////////////////////////////////////////////////// 378 //////////////////////////////////////////////////////////////////////////////
438 // 379 //
439 // Token Service. 380 // Token Service.
440 // 381 //
441 ////////////////////////////////////////////////////////////////////////////// 382 //////////////////////////////////////////////////////////////////////////////
442 383
443 void RemoveAllTokensImpl(); 384 WebDatabase::State RemoveAllTokensImpl(WebDatabase* db);
444 void SetTokenForServiceImpl(const std::string& service, 385 WebDatabase::State SetTokenForServiceImpl(const std::string& service,
445 const std::string& token); 386 const std::string& token, WebDatabase* db);
446 scoped_ptr<WDTypedResult> GetAllTokensImpl(); 387 scoped_ptr<WDTypedResult> GetAllTokensImpl(WebDatabase* db);
447 388
448 #if defined(OS_WIN) 389 #if defined(OS_WIN)
449 ////////////////////////////////////////////////////////////////////////////// 390 //////////////////////////////////////////////////////////////////////////////
450 // 391 //
451 // Password manager. 392 // Password manager.
452 // 393 //
453 ////////////////////////////////////////////////////////////////////////////// 394 //////////////////////////////////////////////////////////////////////////////
454 void AddIE7LoginImpl(const IE7PasswordInfo& info); 395 WebDatabase::State AddIE7LoginImpl(
455 void RemoveIE7LoginImpl(const IE7PasswordInfo& info); 396 const IE7PasswordInfo& info, WebDatabase* db);
456 scoped_ptr<WDTypedResult> GetIE7LoginImpl(const IE7PasswordInfo& info); 397 WebDatabase::State RemoveIE7LoginImpl(
398 const IE7PasswordInfo& info, WebDatabase* db);
399 scoped_ptr<WDTypedResult> GetIE7LoginImpl(
400 const IE7PasswordInfo& info, WebDatabase* db);
457 #endif // defined(OS_WIN) 401 #endif // defined(OS_WIN)
458 402
459 ////////////////////////////////////////////////////////////////////////////// 403 //////////////////////////////////////////////////////////////////////////////
460 // 404 //
461 // Autofill. 405 // Autofill.
462 // 406 //
463 ////////////////////////////////////////////////////////////////////////////// 407 //////////////////////////////////////////////////////////////////////////////
464 void AddFormElementsImpl(const std::vector<FormFieldData>& fields); 408 WebDatabase::State AddFormElementsImpl(
409 const std::vector<FormFieldData>& fields, WebDatabase* db);
465 scoped_ptr<WDTypedResult> GetFormValuesForElementNameImpl( 410 scoped_ptr<WDTypedResult> GetFormValuesForElementNameImpl(
466 const string16& name, const string16& prefix, int limit); 411 const string16& name, const string16& prefix, int limit, WebDatabase* db);
467 void RemoveFormElementsAddedBetweenImpl( 412 WebDatabase::State RemoveFormElementsAddedBetweenImpl(
468 const base::Time& delete_begin, const base::Time& delete_end); 413 const base::Time& delete_begin, const base::Time& delete_end,
469 void RemoveExpiredFormElementsImpl(); 414 WebDatabase* db);
470 void RemoveFormValueForElementNameImpl(const string16& name, 415 WebDatabase::State RemoveExpiredFormElementsImpl(WebDatabase* db);
471 const string16& value); 416 WebDatabase::State RemoveFormValueForElementNameImpl(
472 void AddAutofillProfileImpl(const AutofillProfile& profile); 417 const string16& name, const string16& value, WebDatabase* db);
473 void UpdateAutofillProfileImpl(const AutofillProfile& profile); 418 WebDatabase::State AddAutofillProfileImpl(
474 void RemoveAutofillProfileImpl(const std::string& guid); 419 const AutofillProfile& profile, WebDatabase* db);
475 scoped_ptr<WDTypedResult> GetAutofillProfilesImpl(); 420 WebDatabase::State UpdateAutofillProfileImpl(
476 void AddCreditCardImpl(const CreditCard& credit_card); 421 const AutofillProfile& profile, WebDatabase* db);
477 void UpdateCreditCardImpl(const CreditCard& credit_card); 422 WebDatabase::State RemoveAutofillProfileImpl(
478 void RemoveCreditCardImpl(const std::string& guid); 423 const std::string& guid, WebDatabase* db);
479 scoped_ptr<WDTypedResult> GetCreditCardsImpl(); 424 scoped_ptr<WDTypedResult> GetAutofillProfilesImpl(WebDatabase* db);
480 void RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( 425 WebDatabase::State AddCreditCardImpl(
481 const base::Time& delete_begin, const base::Time& delete_end); 426 const CreditCard& credit_card, WebDatabase* db);
427 WebDatabase::State UpdateCreditCardImpl(
428 const CreditCard& credit_card, WebDatabase* db);
429 WebDatabase::State RemoveCreditCardImpl(
430 const std::string& guid, WebDatabase* db);
431 scoped_ptr<WDTypedResult> GetCreditCardsImpl(WebDatabase* db);
432 WebDatabase::State RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl(
433 const base::Time& delete_begin, const base::Time& delete_end,
434 WebDatabase* db);
482 435
483 // Callbacks to ensure that sensitive info is destroyed if request is 436 // Callbacks to ensure that sensitive info is destroyed if request is
484 // cancelled. 437 // cancelled.
485 void DestroyAutofillProfileResult(const WDTypedResult* result); 438 void DestroyAutofillProfileResult(const WDTypedResult* result);
486 void DestroyAutofillCreditCardResult(const WDTypedResult* result); 439 void DestroyAutofillCreditCardResult(const WDTypedResult* result);
487 440
488 // True once initialization has started.
489 bool is_running_;
490
491 // The path with which to initialize the database.
492 base::FilePath path_;
493
494 // Our database. We own the |db_|, but don't use a |scoped_ptr| because the
495 // |db_| lifetime must be managed on the database thread.
496 WebDatabase* db_;
497
498 // Keeps track of all pending requests made to the db.
499 scoped_refptr<WebDataRequestManager> request_manager_;
500
501 // The application locale. The locale is needed for some database migrations,
502 // and must be read on the UI thread. It's cached here so that we can pass it
503 // to the migration code on the DB thread.
504 const std::string app_locale_;
505
506 // Syncable services for the database data. We own the services, but don't 441 // Syncable services for the database data. We own the services, but don't
507 // use |scoped_ptr|s because the lifetimes must be managed on the database 442 // use |scoped_ptr|s because the lifetimes must be managed on the database
508 // thread. 443 // thread.
509 // Currently only Autocomplete and Autofill profiles use the new Sync API, but 444 // Currently only Autocomplete and Autofill profiles use the new Sync API, but
510 // all the database data should migrate to this API over time. 445 // all the database data should migrate to this API over time.
511 AutocompleteSyncableService* autocomplete_syncable_service_; 446 AutocompleteSyncableService* autocomplete_syncable_service_;
512 AutofillProfileSyncableService* autofill_profile_syncable_service_; 447 AutofillProfileSyncableService* autofill_profile_syncable_service_;
513 448
514 // Whether the database failed to initialize. We use this to avoid
515 // continually trying to reinit.
516 bool failed_init_;
517
518 // Whether we should commit the database.
519 bool should_commit_;
520
521 // MessageLoop the WebDataService is created on.
522 MessageLoop* main_loop_;
523
524 DISALLOW_COPY_AND_ASSIGN(WebDataService); 449 DISALLOW_COPY_AND_ASSIGN(WebDataService);
525 }; 450 };
526 451
527 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ 452 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698