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

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

Issue 12851008: Create a common base class for all the webdatas (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Override base methods so AutofillWebData properly delegates to WDS 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 #include "chrome/browser/webdata/web_data_service.h" 5 #include "chrome/browser/webdata/web_data_service.h"
6 6
7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/message_loop.h"
10 #include "base/stl_util.h"
11 #include "base/threading/thread.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/browser/search_engines/template_url.h" 7 #include "chrome/browser/search_engines/template_url.h"
15 #include "chrome/browser/ui/profile_error_dialog.h"
16 #include "chrome/browser/webdata/autocomplete_syncable_service.h" 8 #include "chrome/browser/webdata/autocomplete_syncable_service.h"
17 #include "chrome/browser/webdata/autofill_change.h" 9 #include "chrome/browser/webdata/autofill_change.h"
18 #include "chrome/browser/webdata/autofill_entry.h" 10 #include "chrome/browser/webdata/autofill_entry.h"
19 #include "chrome/browser/webdata/autofill_profile_syncable_service.h" 11 #include "chrome/browser/webdata/autofill_profile_syncable_service.h"
20 #include "chrome/browser/webdata/autofill_table.h" 12 #include "chrome/browser/webdata/autofill_table.h"
21 #include "chrome/browser/webdata/keyword_table.h" 13 #include "chrome/browser/webdata/keyword_table.h"
22 #include "chrome/browser/webdata/logins_table.h" 14 #include "chrome/browser/webdata/logins_table.h"
23 #include "chrome/browser/webdata/token_service_table.h" 15 #include "chrome/browser/webdata/token_service_table.h"
24 #include "chrome/browser/webdata/web_apps_table.h" 16 #include "chrome/browser/webdata/web_apps_table.h"
25 #include "chrome/browser/webdata/web_database_service.h" 17 #include "chrome/browser/webdata/web_database_service.h"
26 #include "chrome/browser/webdata/web_intents_table.h" 18 #include "chrome/browser/webdata/web_intents_table.h"
27 #include "chrome/common/chrome_constants.h"
28 #include "chrome/common/chrome_notification_types.h" 19 #include "chrome/common/chrome_notification_types.h"
29 #include "components/autofill/browser/autofill_country.h" 20 #include "components/autofill/browser/autofill_country.h"
30 #include "components/autofill/browser/autofill_profile.h" 21 #include "components/autofill/browser/autofill_profile.h"
31 #include "components/autofill/browser/credit_card.h" 22 #include "components/autofill/browser/credit_card.h"
32 #include "components/autofill/common/form_field_data.h" 23 #include "components/autofill/common/form_field_data.h"
33 #ifdef DEBUG
34 #include "content/public/browser/browser_thread.h"
35 #endif
36 #include "content/public/browser/notification_details.h" 24 #include "content/public/browser/notification_details.h"
37 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
38 #include "content/public/browser/notification_source.h" 26 #include "content/public/browser/notification_source.h"
39 #include "grit/chromium_strings.h"
40 #include "grit/generated_resources.h"
41 #include "third_party/skia/include/core/SkBitmap.h" 27 #include "third_party/skia/include/core/SkBitmap.h"
42 28
43 //////////////////////////////////////////////////////////////////////////////// 29 ////////////////////////////////////////////////////////////////////////////////
44 // 30 //
45 // WebDataService implementation. 31 // WebDataService implementation.
46 // 32 //
47 //////////////////////////////////////////////////////////////////////////////// 33 ////////////////////////////////////////////////////////////////////////////////
48 34
49 using base::Bind; 35 using base::Bind;
50 using base::Time; 36 using base::Time;
(...skipping 20 matching lines...) Expand all
71 WDAppImagesResult::~WDAppImagesResult() {} 57 WDAppImagesResult::~WDAppImagesResult() {}
72 58
73 WDKeywordsResult::WDKeywordsResult() 59 WDKeywordsResult::WDKeywordsResult()
74 : default_search_provider_id(0), 60 : default_search_provider_id(0),
75 builtin_keyword_version(0) { 61 builtin_keyword_version(0) {
76 } 62 }
77 63
78 WDKeywordsResult::~WDKeywordsResult() {} 64 WDKeywordsResult::~WDKeywordsResult() {}
79 65
80 WebDataService::WebDataService() 66 WebDataService::WebDataService()
81 : db_loaded_(false), 67 : autocomplete_syncable_service_(NULL),
82 autocomplete_syncable_service_(NULL),
83 autofill_profile_syncable_service_(NULL) { 68 autofill_profile_syncable_service_(NULL) {
84 // WebDataService requires DB thread if instantiated.
85 // Set WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile, NULL)
86 // if you do not want to instantiate WebDataService in your test.
87 DCHECK(BrowserThread::IsWellKnownThread(BrowserThread::DB));
88 } 69 }
89 70
90 // static 71 // static
91 void WebDataService::NotifyOfMultipleAutofillChanges( 72 void WebDataService::NotifyOfMultipleAutofillChanges(
92 WebDataService* web_data_service) { 73 WebDataService* web_data_service) {
93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
94 75
95 if (!web_data_service) 76 if (!web_data_service)
96 return; 77 return;
97 78
98 BrowserThread::PostTask( 79 BrowserThread::PostTask(
99 BrowserThread::UI, FROM_HERE, 80 BrowserThread::UI, FROM_HERE,
100 Bind(&NotifyOfMultipleAutofillChangesTask, 81 Bind(&NotifyOfMultipleAutofillChangesTask,
101 make_scoped_refptr(web_data_service))); 82 make_scoped_refptr(web_data_service)));
102 } 83 }
103 84
104 void WebDataService::ShutdownOnUIThread() { 85 void WebDataService::ShutdownOnUIThread() {
105 db_loaded_ = false;
106 ShutdownDatabase();
107 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 86 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
108 Bind(&WebDataService::ShutdownSyncableServices, this)); 87 Bind(&WebDataService::ShutdownSyncableServices, this));
88 WebDataServiceBase::ShutdownOnUIThread();
109 } 89 }
110 90
111 void WebDataService::Init(const base::FilePath& path) { 91 void WebDataService::Init(const base::FilePath& path) {
112 wdbs_.reset(new WebDatabaseService(path)); 92 WebDataServiceBase::Init(path);
113 wdbs_->LoadDatabase(Bind(&WebDataService::DatabaseInitOnDB, this));
114
115 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 93 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
116 Bind(&WebDataService::InitializeSyncableServices, this)); 94 Bind(&WebDataService::InitializeSyncableServices, this));
117 } 95 }
118 96
119 void WebDataService::UnloadDatabase() {
120 if (!wdbs_)
121 return;
122 wdbs_->UnloadDatabase();
123 }
124
125 void WebDataService::ShutdownDatabase() {
126 if (!wdbs_)
127 return;
128 wdbs_->ShutdownDatabase();
129 }
130
131 void WebDataService::CancelRequest(Handle h) {
132 if (!wdbs_)
133 return;
134 wdbs_->CancelRequest(h);
135 }
136
137 content::NotificationSource WebDataService::GetNotificationSource() {
138 return content::Source<WebDataService>(this);
139 }
140
141 bool WebDataService::IsDatabaseLoaded() {
142 return db_loaded_;
143 }
144
145 WebDatabase* WebDataService::GetDatabase() {
146 if (!wdbs_)
147 return NULL;
148 return wdbs_->GetDatabaseOnDB();
149 }
150
151 ////////////////////////////////////////////////////////////////////////////// 97 //////////////////////////////////////////////////////////////////////////////
152 // 98 //
153 // Keywords. 99 // Keywords.
154 // 100 //
155 ////////////////////////////////////////////////////////////////////////////// 101 //////////////////////////////////////////////////////////////////////////////
156 102
157 void WebDataService::AddKeyword(const TemplateURLData& data) { 103 void WebDataService::AddKeyword(const TemplateURLData& data) {
158 wdbs_->ScheduleDBTask( 104 wdbs_->ScheduleDBTask(
159 FROM_HERE, Bind(&WebDataService::AddKeywordImpl, this, data)); 105 FROM_HERE, Bind(&WebDataService::AddKeywordImpl, this, data));
160 } 106 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 269
324 void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetween( 270 void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetween(
325 const Time& delete_begin, 271 const Time& delete_begin,
326 const Time& delete_end) { 272 const Time& delete_end) {
327 wdbs_->ScheduleDBTask(FROM_HERE, Bind( 273 wdbs_->ScheduleDBTask(FROM_HERE, Bind(
328 &WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl, 274 &WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl,
329 this, delete_begin, delete_end)); 275 this, delete_begin, delete_end));
330 } 276 }
331 277
332 WebDataService::~WebDataService() { 278 WebDataService::~WebDataService() {
333 wdbs_.reset();
334 DCHECK(!autocomplete_syncable_service_); 279 DCHECK(!autocomplete_syncable_service_);
335 DCHECK(!autofill_profile_syncable_service_); 280 DCHECK(!autofill_profile_syncable_service_);
336 } 281 }
337 282
338 //////////////////////////////////////////////////////////////////////////////// 283 ////////////////////////////////////////////////////////////////////////////////
339 // 284 //
340 // The following methods are executed on the DB thread. 285 // The following methods are executed on the DB thread.
341 // 286 //
342 //////////////////////////////////////////////////////////////////////////////// 287 ////////////////////////////////////////////////////////////////////////////////
343 288
344 void WebDataService::DBInitFailed(sql::InitStatus sql_status) {
345 ShowProfileErrorDialog(
346 (sql_status == sql::INIT_FAILURE) ?
347 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR);
348 }
349
350 void WebDataService::NotifyDatabaseLoadedOnUIThread() {
351 db_loaded_ = true;
352 // Notify that the database has been initialized.
353 content::NotificationService::current()->Notify(
354 chrome::NOTIFICATION_WEB_DATABASE_LOADED,
355 content::Source<WebDataService>(this),
356 content::NotificationService::NoDetails());
357 }
358
359 void WebDataService::DatabaseInitOnDB(sql::InitStatus status) {
360 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
361 if (status == sql::INIT_OK) {
362 BrowserThread::PostTask(
363 BrowserThread::UI, FROM_HERE,
364 base::Bind(&WebDataService::NotifyDatabaseLoadedOnUIThread, this));
365 } else {
366 BrowserThread::PostTask(
367 BrowserThread::UI, FROM_HERE,
368 base::Bind(&WebDataService::DBInitFailed, this, status));
369 }
370 }
371
372 void WebDataService::InitializeSyncableServices() { 289 void WebDataService::InitializeSyncableServices() {
373 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
374 DCHECK(!autocomplete_syncable_service_); 291 DCHECK(!autocomplete_syncable_service_);
375 DCHECK(!autofill_profile_syncable_service_); 292 DCHECK(!autofill_profile_syncable_service_);
376 293
377 autocomplete_syncable_service_ = new AutocompleteSyncableService(this); 294 autocomplete_syncable_service_ = new AutocompleteSyncableService(this);
378 autofill_profile_syncable_service_ = new AutofillProfileSyncableService(this); 295 autofill_profile_syncable_service_ = new AutofillProfileSyncableService(this);
379 } 296 }
380 297
381 void WebDataService::ShutdownSyncableServices() { 298 void WebDataService::ShutdownSyncableServices() {
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 700
784 void WebDataService::DestroyAutofillCreditCardResult( 701 void WebDataService::DestroyAutofillCreditCardResult(
785 const WDTypedResult* result) { 702 const WDTypedResult* result) {
786 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); 703 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT);
787 const WDResult<std::vector<CreditCard*> >* r = 704 const WDResult<std::vector<CreditCard*> >* r =
788 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); 705 static_cast<const WDResult<std::vector<CreditCard*> >*>(result);
789 706
790 std::vector<CreditCard*> credit_cards = r->GetValue(); 707 std::vector<CreditCard*> credit_cards = r->GetValue();
791 STLDeleteElements(&credit_cards); 708 STLDeleteElements(&credit_cards);
792 } 709 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698