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

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

Issue 12871006: Second try at splitting WebDataService (minus ownership changes) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head for commit. 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__
(...skipping 10 matching lines...) Expand all
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" 26 #include "chrome/browser/profiles/refcounted_profile_keyed_service.h"
27 #include "chrome/browser/search_engines/template_url.h" 27 #include "chrome/browser/search_engines/template_url.h"
28 #include "chrome/browser/search_engines/template_url_id.h" 28 #include "chrome/browser/search_engines/template_url_id.h"
29 #include "chrome/browser/webdata/keyword_table.h" 29 #include "chrome/browser/webdata/keyword_table.h"
30 #include "chrome/browser/webdata/web_data_request_manager.h" 30 #include "chrome/browser/webdata/web_data_request_manager.h"
31 #include "chrome/browser/webdata/web_database.h"
31 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
32 #include "sql/init_status.h" 33 #include "sql/init_status.h"
33 34
34 class AutocompleteSyncableService; 35 class AutocompleteSyncableService;
35 class AutofillChange; 36 class AutofillChange;
36 class AutofillProfileSyncableService; 37 class AutofillProfileSyncableService;
37 struct DefaultWebIntentService; 38 struct DefaultWebIntentService;
38 class GURL; 39 class GURL;
39 #if defined(OS_WIN) 40 #if defined(OS_WIN)
40 struct IE7PasswordInfo; 41 struct IE7PasswordInfo;
41 #endif 42 #endif
42 class MessageLoop; 43 class MessageLoop;
43 class Profile; 44 class Profile;
44 class SkBitmap; 45 class SkBitmap;
45 class WebDatabase; 46 class WebDatabaseService;
46 47
47 namespace base { 48 namespace base {
48 class Thread; 49 class Thread;
49 } 50 }
50 51
51 namespace content { 52 namespace content {
52 class BrowserContext; 53 class BrowserContext;
53 } 54 }
54 55
55 namespace webkit_glue { 56 namespace webkit_glue {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 // NOTE: This method is intended to be called from the DB thread. It 123 // NOTE: This method is intended to be called from the DB thread. It
123 // it asynchronously notifies listeners on the UI thread. 124 // it asynchronously notifies listeners on the UI thread.
124 // |web_data_service| may be NULL for testing purposes. 125 // |web_data_service| may be NULL for testing purposes.
125 static void NotifyOfMultipleAutofillChanges(WebDataService* web_data_service); 126 static void NotifyOfMultipleAutofillChanges(WebDataService* web_data_service);
126 127
127 // RefcountedProfileKeyedService override: 128 // RefcountedProfileKeyedService override:
128 // Shutdown the web data service. The service can no longer be used after this 129 // Shutdown the web data service. The service can no longer be used after this
129 // call. 130 // call.
130 virtual void ShutdownOnUIThread() OVERRIDE; 131 virtual void ShutdownOnUIThread() OVERRIDE;
131 132
132 // Initializes the web data service. Returns false on failure 133 // Initializes the web data service.
133 // Takes the path of the profile directory as its argument. 134 void Init(const base::FilePath& path);
134 bool Init(const base::FilePath& profile_path);
135
136 // Returns false if Shutdown() has been called.
137 bool IsRunning() const;
138 135
139 // Unloads the database without actually shutting down the service. This can 136 // Unloads the database without actually shutting down the service. This can
140 // be used to temporarily reduce the browser process' memory footprint. 137 // be used to temporarily reduce the browser process' memory footprint.
141 void UnloadDatabase(); 138 void UnloadDatabase();
142 139
140 // Unloads the database permanently and shuts down service.
141 void ShutdownDatabase();
142
143 // Returns true if the database load has completetd successfully, and
144 // ShutdownOnUIThread has not yet been called.
143 virtual bool IsDatabaseLoaded(); 145 virtual bool IsDatabaseLoaded();
146
147 // Returns a pointer to the DB (used by SyncableServices). May return NULL if
148 // the database is not loaded or otherwise unavailable. Must be called on
149 // DBThread.
144 virtual WebDatabase* GetDatabase(); 150 virtual WebDatabase* GetDatabase();
145 151
146 ////////////////////////////////////////////////////////////////////////////// 152 //////////////////////////////////////////////////////////////////////////////
147 // 153 //
148 // Keywords 154 // Keywords
149 // 155 //
150 ////////////////////////////////////////////////////////////////////////////// 156 //////////////////////////////////////////////////////////////////////////////
151 157
152 // As the database processes requests at a later date, all deletion is 158 // As the database processes requests at a later date, all deletion is
153 // done on the background thread. 159 // done on the background thread.
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 // Returns the syncable service for Autofill addresses and credit cards stored 319 // Returns the syncable service for Autofill addresses and credit cards stored
314 // in this table. The returned service is owned by |this| object. 320 // in this table. The returned service is owned by |this| object.
315 virtual AutofillProfileSyncableService* 321 virtual AutofillProfileSyncableService*
316 GetAutofillProfileSyncableService() const; 322 GetAutofillProfileSyncableService() const;
317 323
318 // Returns the syncable service for field autocomplete stored in this table. 324 // Returns the syncable service for field autocomplete stored in this table.
319 // The returned service is owned by |this| object. 325 // The returned service is owned by |this| object.
320 virtual AutocompleteSyncableService* 326 virtual AutocompleteSyncableService*
321 GetAutocompleteSyncableService() const; 327 GetAutocompleteSyncableService() const;
322 328
323 // Testing
324 #ifdef UNIT_TEST
325 void set_failed_init(bool value) { failed_init_ = value; }
326 #endif
327
328 protected: 329 protected:
329 friend class TemplateURLServiceTest; 330 friend class TemplateURLServiceTest;
330 friend class TemplateURLServiceTestingProfile; 331 friend class TemplateURLServiceTestingProfile;
331 friend class WebDataServiceTest; 332 friend class WebDataServiceTest;
332 friend class WebDataRequest; 333 friend class WebDataRequest;
333 334
334 virtual ~WebDataService(); 335 virtual ~WebDataService();
335 336
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 ////////////////////////////////////////////////////////////////////////////// 337 //////////////////////////////////////////////////////////////////////////////
340 // 338 //
341 // The following methods are only invoked in the web data service thread. 339 // The following methods are only invoked in the web data service thread.
342 // 340 //
343 ////////////////////////////////////////////////////////////////////////////// 341 //////////////////////////////////////////////////////////////////////////////
344 private: 342 private:
345 friend struct content::BrowserThread::DeleteOnThread< 343 friend struct content::BrowserThread::DeleteOnThread<
346 content::BrowserThread::UI>; 344 content::BrowserThread::UI>;
347 friend class base::DeleteHelper<WebDataService>; 345 friend class base::DeleteHelper<WebDataService>;
348 346
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. 347 // Initialize any syncable services.
356 void InitializeSyncableServices(); 348 void InitializeSyncableServices();
357 349
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. 350 // Deletes the syncable services.
365 void ShutdownSyncableServices(); 351 void ShutdownSyncableServices();
366 352
367 // Commit the current transaction and creates a new one. 353 void DBInitFailed(sql::InitStatus sql_status);
368 void Commit(); 354 void NotifyDatabaseLoadedOnUIThread();
369 355 void DatabaseInitOnDB(sql::InitStatus status);
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 356
391 ////////////////////////////////////////////////////////////////////////////// 357 //////////////////////////////////////////////////////////////////////////////
392 // 358 //
393 // Keywords. 359 // Keywords.
394 // 360 //
395 ////////////////////////////////////////////////////////////////////////////// 361 //////////////////////////////////////////////////////////////////////////////
396 void AddKeywordImpl(const TemplateURLData& data); 362 WebDatabase::State AddKeywordImpl(
397 void RemoveKeywordImpl(TemplateURLID id); 363 const TemplateURLData& data, WebDatabase* db);
398 void UpdateKeywordImpl(const TemplateURLData& data); 364 WebDatabase::State RemoveKeywordImpl(
399 scoped_ptr<WDTypedResult> GetKeywordsImpl(); 365 TemplateURLID id, WebDatabase* db);
400 void SetDefaultSearchProviderImpl(TemplateURLID r); 366 WebDatabase::State UpdateKeywordImpl(
401 void SetBuiltinKeywordVersionImpl(int version); 367 const TemplateURLData& data, WebDatabase* db);
368 scoped_ptr<WDTypedResult> GetKeywordsImpl(WebDatabase* db);
369 WebDatabase::State SetDefaultSearchProviderImpl(
370 TemplateURLID r, WebDatabase* db);
371 WebDatabase::State SetBuiltinKeywordVersionImpl(int version, WebDatabase* db);
402 372
403 ////////////////////////////////////////////////////////////////////////////// 373 //////////////////////////////////////////////////////////////////////////////
404 // 374 //
405 // Web Apps. 375 // Web Apps.
406 // 376 //
407 ////////////////////////////////////////////////////////////////////////////// 377 //////////////////////////////////////////////////////////////////////////////
408 378
409 void SetWebAppImageImpl(const GURL& app_url, const SkBitmap& image); 379 WebDatabase::State SetWebAppImageImpl(const GURL& app_url,
410 void SetWebAppHasAllImagesImpl(const GURL& app_url, bool has_all_images); 380 const SkBitmap& image, WebDatabase* db);
411 void RemoveWebAppImpl(const GURL& app_url); 381 WebDatabase::State SetWebAppHasAllImagesImpl(const GURL& app_url,
412 scoped_ptr<WDTypedResult> GetWebAppImagesImpl(const GURL& app_url); 382 bool has_all_images, WebDatabase* db);
383 WebDatabase::State RemoveWebAppImpl(const GURL& app_url, WebDatabase* db);
384 scoped_ptr<WDTypedResult> GetWebAppImagesImpl(
385 const GURL& app_url, WebDatabase* db);
413 386
414 #if defined(ENABLE_WEB_INTENTS) 387 #if defined(ENABLE_WEB_INTENTS)
415 ////////////////////////////////////////////////////////////////////////////// 388 //////////////////////////////////////////////////////////////////////////////
416 // 389 //
417 // Web Intents. 390 // Web Intents.
418 // 391 //
419 ////////////////////////////////////////////////////////////////////////////// 392 //////////////////////////////////////////////////////////////////////////////
420 void AddWebIntentServiceImpl( 393 WebDatabase::State AddWebIntentServiceImpl(
421 const webkit_glue::WebIntentServiceData& service); 394 const webkit_glue::WebIntentServiceData& service);
422 void RemoveWebIntentServiceImpl( 395 WebDatabase::State RemoveWebIntentServiceImpl(
423 const webkit_glue::WebIntentServiceData& service); 396 const webkit_glue::WebIntentServiceData& service);
424 scoped_ptr<WDTypedResult> GetWebIntentServicesImpl(const string16& action); 397 scoped_ptr<WDTypedResult> GetWebIntentServicesImpl(const string16& action);
425 scoped_ptr<WDTypedResult> GetWebIntentServicesForURLImpl( 398 scoped_ptr<WDTypedResult> GetWebIntentServicesForURLImpl(
426 const string16& service_url); 399 const string16& service_url);
427 scoped_ptr<WDTypedResult> GetAllWebIntentServicesImpl(); 400 scoped_ptr<WDTypedResult> GetAllWebIntentServicesImpl();
428 void AddDefaultWebIntentServiceImpl(const DefaultWebIntentService& service); 401 WebDatabase::State AddDefaultWebIntentServiceImpl(
429 void RemoveDefaultWebIntentServiceImpl(
430 const DefaultWebIntentService& service); 402 const DefaultWebIntentService& service);
431 void RemoveWebIntentServiceDefaultsImpl(const GURL& service_url); 403 WebDatabase::State RemoveDefaultWebIntentServiceImpl(
404 const DefaultWebIntentService& service);
405 WebDatabase::State RemoveWebIntentServiceDefaultsImpl(
406 const GURL& service_url);
432 scoped_ptr<WDTypedResult> GetDefaultWebIntentServicesForActionImpl( 407 scoped_ptr<WDTypedResult> GetDefaultWebIntentServicesForActionImpl(
433 const string16& action); 408 const string16& action);
434 scoped_ptr<WDTypedResult> GetAllDefaultWebIntentServicesImpl(); 409 scoped_ptr<WDTypedResult> GetAllDefaultWebIntentServicesImpl();
435 #endif 410 #endif
436 411
437 ////////////////////////////////////////////////////////////////////////////// 412 //////////////////////////////////////////////////////////////////////////////
438 // 413 //
439 // Token Service. 414 // Token Service.
440 // 415 //
441 ////////////////////////////////////////////////////////////////////////////// 416 //////////////////////////////////////////////////////////////////////////////
442 417
443 void RemoveAllTokensImpl(); 418 WebDatabase::State RemoveAllTokensImpl(WebDatabase* db);
444 void SetTokenForServiceImpl(const std::string& service, 419 WebDatabase::State SetTokenForServiceImpl(const std::string& service,
445 const std::string& token); 420 const std::string& token, WebDatabase* db);
446 scoped_ptr<WDTypedResult> GetAllTokensImpl(); 421 scoped_ptr<WDTypedResult> GetAllTokensImpl(WebDatabase* db);
447 422
448 #if defined(OS_WIN) 423 #if defined(OS_WIN)
449 ////////////////////////////////////////////////////////////////////////////// 424 //////////////////////////////////////////////////////////////////////////////
450 // 425 //
451 // Password manager. 426 // Password manager.
452 // 427 //
453 ////////////////////////////////////////////////////////////////////////////// 428 //////////////////////////////////////////////////////////////////////////////
454 void AddIE7LoginImpl(const IE7PasswordInfo& info); 429 WebDatabase::State AddIE7LoginImpl(
455 void RemoveIE7LoginImpl(const IE7PasswordInfo& info); 430 const IE7PasswordInfo& info, WebDatabase* db);
456 scoped_ptr<WDTypedResult> GetIE7LoginImpl(const IE7PasswordInfo& info); 431 WebDatabase::State RemoveIE7LoginImpl(
432 const IE7PasswordInfo& info, WebDatabase* db);
433 scoped_ptr<WDTypedResult> GetIE7LoginImpl(
434 const IE7PasswordInfo& info, WebDatabase* db);
457 #endif // defined(OS_WIN) 435 #endif // defined(OS_WIN)
458 436
459 ////////////////////////////////////////////////////////////////////////////// 437 //////////////////////////////////////////////////////////////////////////////
460 // 438 //
461 // Autofill. 439 // Autofill.
462 // 440 //
463 ////////////////////////////////////////////////////////////////////////////// 441 //////////////////////////////////////////////////////////////////////////////
464 void AddFormElementsImpl(const std::vector<FormFieldData>& fields); 442 WebDatabase::State AddFormElementsImpl(
443 const std::vector<FormFieldData>& fields, WebDatabase* db);
465 scoped_ptr<WDTypedResult> GetFormValuesForElementNameImpl( 444 scoped_ptr<WDTypedResult> GetFormValuesForElementNameImpl(
466 const string16& name, const string16& prefix, int limit); 445 const string16& name, const string16& prefix, int limit, WebDatabase* db);
467 void RemoveFormElementsAddedBetweenImpl( 446 WebDatabase::State RemoveFormElementsAddedBetweenImpl(
468 const base::Time& delete_begin, const base::Time& delete_end); 447 const base::Time& delete_begin, const base::Time& delete_end,
469 void RemoveExpiredFormElementsImpl(); 448 WebDatabase* db);
470 void RemoveFormValueForElementNameImpl(const string16& name, 449 WebDatabase::State RemoveExpiredFormElementsImpl(WebDatabase* db);
471 const string16& value); 450 WebDatabase::State RemoveFormValueForElementNameImpl(
472 void AddAutofillProfileImpl(const AutofillProfile& profile); 451 const string16& name, const string16& value, WebDatabase* db);
473 void UpdateAutofillProfileImpl(const AutofillProfile& profile); 452 WebDatabase::State AddAutofillProfileImpl(
474 void RemoveAutofillProfileImpl(const std::string& guid); 453 const AutofillProfile& profile, WebDatabase* db);
475 scoped_ptr<WDTypedResult> GetAutofillProfilesImpl(); 454 WebDatabase::State UpdateAutofillProfileImpl(
476 void AddCreditCardImpl(const CreditCard& credit_card); 455 const AutofillProfile& profile, WebDatabase* db);
477 void UpdateCreditCardImpl(const CreditCard& credit_card); 456 WebDatabase::State RemoveAutofillProfileImpl(
478 void RemoveCreditCardImpl(const std::string& guid); 457 const std::string& guid, WebDatabase* db);
479 scoped_ptr<WDTypedResult> GetCreditCardsImpl(); 458 scoped_ptr<WDTypedResult> GetAutofillProfilesImpl(WebDatabase* db);
480 void RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( 459 WebDatabase::State AddCreditCardImpl(
481 const base::Time& delete_begin, const base::Time& delete_end); 460 const CreditCard& credit_card, WebDatabase* db);
461 WebDatabase::State UpdateCreditCardImpl(
462 const CreditCard& credit_card, WebDatabase* db);
463 WebDatabase::State RemoveCreditCardImpl(
464 const std::string& guid, WebDatabase* db);
465 scoped_ptr<WDTypedResult> GetCreditCardsImpl(WebDatabase* db);
466 WebDatabase::State RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl(
467 const base::Time& delete_begin, const base::Time& delete_end,
468 WebDatabase* db);
482 469
483 // Callbacks to ensure that sensitive info is destroyed if request is 470 // Callbacks to ensure that sensitive info is destroyed if request is
484 // cancelled. 471 // cancelled.
485 void DestroyAutofillProfileResult(const WDTypedResult* result); 472 void DestroyAutofillProfileResult(const WDTypedResult* result);
486 void DestroyAutofillCreditCardResult(const WDTypedResult* result); 473 void DestroyAutofillCreditCardResult(const WDTypedResult* result);
487 474
488 // True once initialization has started. 475 // Our database service.
489 bool is_running_; 476 scoped_ptr<WebDatabaseService> wdbs_;
490 477
491 // The path with which to initialize the database. 478 // True if we've received a notification that the WebDatabase has loaded.
492 base::FilePath path_; 479 bool db_loaded_;
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 480
506 // Syncable services for the database data. We own the services, but don't 481 // 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 482 // use |scoped_ptr|s because the lifetimes must be managed on the database
508 // thread. 483 // thread.
509 // Currently only Autocomplete and Autofill profiles use the new Sync API, but 484 // Currently only Autocomplete and Autofill profiles use the new Sync API, but
510 // all the database data should migrate to this API over time. 485 // all the database data should migrate to this API over time.
511 AutocompleteSyncableService* autocomplete_syncable_service_; 486 AutocompleteSyncableService* autocomplete_syncable_service_;
512 AutofillProfileSyncableService* autofill_profile_syncable_service_; 487 AutofillProfileSyncableService* autofill_profile_syncable_service_;
513 488
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); 489 DISALLOW_COPY_AND_ASSIGN(WebDataService);
525 }; 490 };
526 491
527 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ 492 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc ('k') | chrome/browser/webdata/web_data_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698