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

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: fix WIN paths 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 virtual bool IsDatabaseLoaded(); 143 virtual bool IsDatabaseLoaded();
dhollowa 2013/03/15 18:56:21 Doc please.
Cait (Slow) 2013/03/15 20:43:59 Done.
144 virtual WebDatabase* GetDatabase(); 144 virtual WebDatabase* GetDatabase();
dhollowa 2013/03/15 18:56:21 Doc please. When can/should this be called? Is c
Cait (Slow) 2013/03/15 20:43:59 Done.
145 145
146 ////////////////////////////////////////////////////////////////////////////// 146 //////////////////////////////////////////////////////////////////////////////
147 // 147 //
148 // Keywords 148 // Keywords
149 // 149 //
150 ////////////////////////////////////////////////////////////////////////////// 150 //////////////////////////////////////////////////////////////////////////////
151 151
152 // As the database processes requests at a later date, all deletion is 152 // As the database processes requests at a later date, all deletion is
153 // done on the background thread. 153 // done on the background thread.
154 // 154 //
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 // Returns the syncable service for Autofill addresses and credit cards stored 313 // Returns the syncable service for Autofill addresses and credit cards stored
314 // in this table. The returned service is owned by |this| object. 314 // in this table. The returned service is owned by |this| object.
315 virtual AutofillProfileSyncableService* 315 virtual AutofillProfileSyncableService*
316 GetAutofillProfileSyncableService() const; 316 GetAutofillProfileSyncableService() const;
317 317
318 // Returns the syncable service for field autocomplete stored in this table. 318 // Returns the syncable service for field autocomplete stored in this table.
319 // The returned service is owned by |this| object. 319 // The returned service is owned by |this| object.
320 virtual AutocompleteSyncableService* 320 virtual AutocompleteSyncableService*
321 GetAutocompleteSyncableService() const; 321 GetAutocompleteSyncableService() const;
322 322
323 // Testing
324 #ifdef UNIT_TEST
325 void set_failed_init(bool value) { failed_init_ = value; }
326 #endif
327
328 protected: 323 protected:
329 friend class TemplateURLServiceTest; 324 friend class TemplateURLServiceTest;
330 friend class TemplateURLServiceTestingProfile; 325 friend class TemplateURLServiceTestingProfile;
331 friend class WebDataServiceTest; 326 friend class WebDataServiceTest;
332 friend class WebDataRequest; 327 friend class WebDataRequest;
333 328
334 virtual ~WebDataService(); 329 virtual ~WebDataService();
335 330
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 ////////////////////////////////////////////////////////////////////////////// 331 //////////////////////////////////////////////////////////////////////////////
340 // 332 //
341 // The following methods are only invoked in the web data service thread. 333 // The following methods are only invoked in the web data service thread.
342 // 334 //
343 ////////////////////////////////////////////////////////////////////////////// 335 //////////////////////////////////////////////////////////////////////////////
344 private: 336 private:
345 friend struct content::BrowserThread::DeleteOnThread< 337 friend struct content::BrowserThread::DeleteOnThread<
346 content::BrowserThread::UI>; 338 content::BrowserThread::UI>;
347 friend class base::DeleteHelper<WebDataService>; 339 friend class base::DeleteHelper<WebDataService>;
348 340
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. 341 // Initialize any syncable services.
356 void InitializeSyncableServices(); 342 void InitializeSyncableServices();
357 343
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. 344 // Deletes the syncable services.
365 void ShutdownSyncableServices(); 345 void ShutdownSyncableServices();
366 346
367 // Commit the current transaction and creates a new one. 347 void DBInitFailed(sql::InitStatus sql_status);
368 void Commit(); 348 void NotifyDatabaseLoadedOnUIThread();
369 349 void OnDatabaseInit(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 350
391 ////////////////////////////////////////////////////////////////////////////// 351 //////////////////////////////////////////////////////////////////////////////
392 // 352 //
393 // Keywords. 353 // Keywords.
394 // 354 //
395 ////////////////////////////////////////////////////////////////////////////// 355 //////////////////////////////////////////////////////////////////////////////
396 void AddKeywordImpl(const TemplateURLData& data); 356 WebDatabase::State AddKeywordImpl(
397 void RemoveKeywordImpl(TemplateURLID id); 357 const TemplateURLData& data, WebDatabase* db);
398 void UpdateKeywordImpl(const TemplateURLData& data); 358 WebDatabase::State RemoveKeywordImpl(
399 scoped_ptr<WDTypedResult> GetKeywordsImpl(); 359 TemplateURLID id, WebDatabase* db);
400 void SetDefaultSearchProviderImpl(TemplateURLID r); 360 WebDatabase::State UpdateKeywordImpl(
401 void SetBuiltinKeywordVersionImpl(int version); 361 const TemplateURLData& data, WebDatabase* db);
362 scoped_ptr<WDTypedResult> GetKeywordsImpl(WebDatabase* db);
363 WebDatabase::State SetDefaultSearchProviderImpl(
364 TemplateURLID r, WebDatabase* db);
365 WebDatabase::State SetBuiltinKeywordVersionImpl(int version, WebDatabase* db);
402 366
403 ////////////////////////////////////////////////////////////////////////////// 367 //////////////////////////////////////////////////////////////////////////////
404 // 368 //
405 // Web Apps. 369 // Web Apps.
406 // 370 //
407 ////////////////////////////////////////////////////////////////////////////// 371 //////////////////////////////////////////////////////////////////////////////
408 372
409 void SetWebAppImageImpl(const GURL& app_url, const SkBitmap& image); 373 WebDatabase::State SetWebAppImageImpl(const GURL& app_url,
410 void SetWebAppHasAllImagesImpl(const GURL& app_url, bool has_all_images); 374 const SkBitmap& image, WebDatabase* db);
411 void RemoveWebAppImpl(const GURL& app_url); 375 WebDatabase::State SetWebAppHasAllImagesImpl(const GURL& app_url,
412 scoped_ptr<WDTypedResult> GetWebAppImagesImpl(const GURL& app_url); 376 bool has_all_images, WebDatabase* db);
377 WebDatabase::State RemoveWebAppImpl(const GURL& app_url, WebDatabase* db);
378 scoped_ptr<WDTypedResult> GetWebAppImagesImpl(
379 const GURL& app_url, WebDatabase* db);
413 380
414 #if defined(ENABLE_WEB_INTENTS) 381 #if defined(ENABLE_WEB_INTENTS)
415 ////////////////////////////////////////////////////////////////////////////// 382 //////////////////////////////////////////////////////////////////////////////
416 // 383 //
417 // Web Intents. 384 // Web Intents.
418 // 385 //
419 ////////////////////////////////////////////////////////////////////////////// 386 //////////////////////////////////////////////////////////////////////////////
420 void AddWebIntentServiceImpl( 387 WebDatabase::State AddWebIntentServiceImpl(
421 const webkit_glue::WebIntentServiceData& service); 388 const webkit_glue::WebIntentServiceData& service);
422 void RemoveWebIntentServiceImpl( 389 WebDatabase::State RemoveWebIntentServiceImpl(
423 const webkit_glue::WebIntentServiceData& service); 390 const webkit_glue::WebIntentServiceData& service);
424 scoped_ptr<WDTypedResult> GetWebIntentServicesImpl(const string16& action); 391 scoped_ptr<WDTypedResult> GetWebIntentServicesImpl(const string16& action);
425 scoped_ptr<WDTypedResult> GetWebIntentServicesForURLImpl( 392 scoped_ptr<WDTypedResult> GetWebIntentServicesForURLImpl(
426 const string16& service_url); 393 const string16& service_url);
427 scoped_ptr<WDTypedResult> GetAllWebIntentServicesImpl(); 394 scoped_ptr<WDTypedResult> GetAllWebIntentServicesImpl();
428 void AddDefaultWebIntentServiceImpl(const DefaultWebIntentService& service); 395 WebDatabase::State AddDefaultWebIntentServiceImpl(
429 void RemoveDefaultWebIntentServiceImpl(
430 const DefaultWebIntentService& service); 396 const DefaultWebIntentService& service);
431 void RemoveWebIntentServiceDefaultsImpl(const GURL& service_url); 397 WebDatabase::State RemoveDefaultWebIntentServiceImpl(
398 const DefaultWebIntentService& service);
399 WebDatabase::State RemoveWebIntentServiceDefaultsImpl(
400 const GURL& service_url);
432 scoped_ptr<WDTypedResult> GetDefaultWebIntentServicesForActionImpl( 401 scoped_ptr<WDTypedResult> GetDefaultWebIntentServicesForActionImpl(
433 const string16& action); 402 const string16& action);
434 scoped_ptr<WDTypedResult> GetAllDefaultWebIntentServicesImpl(); 403 scoped_ptr<WDTypedResult> GetAllDefaultWebIntentServicesImpl();
435 #endif 404 #endif
436 405
437 ////////////////////////////////////////////////////////////////////////////// 406 //////////////////////////////////////////////////////////////////////////////
438 // 407 //
439 // Token Service. 408 // Token Service.
440 // 409 //
441 ////////////////////////////////////////////////////////////////////////////// 410 //////////////////////////////////////////////////////////////////////////////
442 411
443 void RemoveAllTokensImpl(); 412 WebDatabase::State RemoveAllTokensImpl(WebDatabase* db);
444 void SetTokenForServiceImpl(const std::string& service, 413 WebDatabase::State SetTokenForServiceImpl(const std::string& service,
445 const std::string& token); 414 const std::string& token, WebDatabase* db);
446 scoped_ptr<WDTypedResult> GetAllTokensImpl(); 415 scoped_ptr<WDTypedResult> GetAllTokensImpl(WebDatabase* db);
447 416
448 #if defined(OS_WIN) 417 #if defined(OS_WIN)
449 ////////////////////////////////////////////////////////////////////////////// 418 //////////////////////////////////////////////////////////////////////////////
450 // 419 //
451 // Password manager. 420 // Password manager.
452 // 421 //
453 ////////////////////////////////////////////////////////////////////////////// 422 //////////////////////////////////////////////////////////////////////////////
454 void AddIE7LoginImpl(const IE7PasswordInfo& info); 423 WebDatabase::State AddIE7LoginImpl(
455 void RemoveIE7LoginImpl(const IE7PasswordInfo& info); 424 const IE7PasswordInfo& info, WebDatabase* db);
456 scoped_ptr<WDTypedResult> GetIE7LoginImpl(const IE7PasswordInfo& info); 425 WebDatabase::State RemoveIE7LoginImpl(
426 const IE7PasswordInfo& info, WebDatabase* db);
427 scoped_ptr<WDTypedResult> GetIE7LoginImpl(
428 const IE7PasswordInfo& info, WebDatabase* db);
457 #endif // defined(OS_WIN) 429 #endif // defined(OS_WIN)
458 430
459 ////////////////////////////////////////////////////////////////////////////// 431 //////////////////////////////////////////////////////////////////////////////
460 // 432 //
461 // Autofill. 433 // Autofill.
462 // 434 //
463 ////////////////////////////////////////////////////////////////////////////// 435 //////////////////////////////////////////////////////////////////////////////
464 void AddFormElementsImpl(const std::vector<FormFieldData>& fields); 436 WebDatabase::State AddFormElementsImpl(
437 const std::vector<FormFieldData>& fields, WebDatabase* db);
465 scoped_ptr<WDTypedResult> GetFormValuesForElementNameImpl( 438 scoped_ptr<WDTypedResult> GetFormValuesForElementNameImpl(
466 const string16& name, const string16& prefix, int limit); 439 const string16& name, const string16& prefix, int limit, WebDatabase* db);
467 void RemoveFormElementsAddedBetweenImpl( 440 WebDatabase::State RemoveFormElementsAddedBetweenImpl(
468 const base::Time& delete_begin, const base::Time& delete_end); 441 const base::Time& delete_begin, const base::Time& delete_end,
469 void RemoveExpiredFormElementsImpl(); 442 WebDatabase* db);
470 void RemoveFormValueForElementNameImpl(const string16& name, 443 WebDatabase::State RemoveExpiredFormElementsImpl(WebDatabase* db);
471 const string16& value); 444 WebDatabase::State RemoveFormValueForElementNameImpl(
472 void AddAutofillProfileImpl(const AutofillProfile& profile); 445 const string16& name, const string16& value, WebDatabase* db);
473 void UpdateAutofillProfileImpl(const AutofillProfile& profile); 446 WebDatabase::State AddAutofillProfileImpl(
474 void RemoveAutofillProfileImpl(const std::string& guid); 447 const AutofillProfile& profile, WebDatabase* db);
475 scoped_ptr<WDTypedResult> GetAutofillProfilesImpl(); 448 WebDatabase::State UpdateAutofillProfileImpl(
476 void AddCreditCardImpl(const CreditCard& credit_card); 449 const AutofillProfile& profile, WebDatabase* db);
477 void UpdateCreditCardImpl(const CreditCard& credit_card); 450 WebDatabase::State RemoveAutofillProfileImpl(
478 void RemoveCreditCardImpl(const std::string& guid); 451 const std::string& guid, WebDatabase* db);
479 scoped_ptr<WDTypedResult> GetCreditCardsImpl(); 452 scoped_ptr<WDTypedResult> GetAutofillProfilesImpl(WebDatabase* db);
480 void RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( 453 WebDatabase::State AddCreditCardImpl(
481 const base::Time& delete_begin, const base::Time& delete_end); 454 const CreditCard& credit_card, WebDatabase* db);
455 WebDatabase::State UpdateCreditCardImpl(
456 const CreditCard& credit_card, WebDatabase* db);
457 WebDatabase::State RemoveCreditCardImpl(
458 const std::string& guid, WebDatabase* db);
459 scoped_ptr<WDTypedResult> GetCreditCardsImpl(WebDatabase* db);
460 WebDatabase::State RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl(
461 const base::Time& delete_begin, const base::Time& delete_end,
462 WebDatabase* db);
482 463
483 // Callbacks to ensure that sensitive info is destroyed if request is 464 // Callbacks to ensure that sensitive info is destroyed if request is
484 // cancelled. 465 // cancelled.
485 void DestroyAutofillProfileResult(const WDTypedResult* result); 466 void DestroyAutofillProfileResult(const WDTypedResult* result);
486 void DestroyAutofillCreditCardResult(const WDTypedResult* result); 467 void DestroyAutofillCreditCardResult(const WDTypedResult* result);
487 468
488 // True once initialization has started. 469 // Our database service.
489 bool is_running_; 470 scoped_ptr<WebDatabaseService> wdbs_;
490 471
491 // The path with which to initialize the database. 472 // True if we've received a notification that the WebDatabase has loaded.
492 base::FilePath path_; 473 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 474
506 // Syncable services for the database data. We own the services, but don't 475 // 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 476 // use |scoped_ptr|s because the lifetimes must be managed on the database
508 // thread. 477 // thread.
509 // Currently only Autocomplete and Autofill profiles use the new Sync API, but 478 // Currently only Autocomplete and Autofill profiles use the new Sync API, but
510 // all the database data should migrate to this API over time. 479 // all the database data should migrate to this API over time.
511 AutocompleteSyncableService* autocomplete_syncable_service_; 480 AutocompleteSyncableService* autocomplete_syncable_service_;
512 AutofillProfileSyncableService* autofill_profile_syncable_service_; 481 AutofillProfileSyncableService* autofill_profile_syncable_service_;
513 482
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); 483 DISALLOW_COPY_AND_ASSIGN(WebDataService);
525 }; 484 };
526 485
527 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ 486 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698