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

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

Issue 12494020: Remove knowledge of Chrome-specific SyncableService classes from WebDataService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix a unit test bug, use safer keys for SupportsUserData. 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/stl_util.h"
dhollowa 2013/03/20 21:47:37 Why was this added?
Jói 2013/03/20 22:03:16 It became necessary when the two syncable service
7 #include "chrome/browser/search_engines/template_url.h" 8 #include "chrome/browser/search_engines/template_url.h"
8 #include "chrome/browser/webdata/autocomplete_syncable_service.h"
9 #include "chrome/browser/webdata/autofill_change.h" 9 #include "chrome/browser/webdata/autofill_change.h"
10 #include "chrome/browser/webdata/autofill_entry.h" 10 #include "chrome/browser/webdata/autofill_entry.h"
11 #include "chrome/browser/webdata/autofill_profile_syncable_service.h"
12 #include "chrome/browser/webdata/autofill_table.h" 11 #include "chrome/browser/webdata/autofill_table.h"
13 #include "chrome/browser/webdata/keyword_table.h" 12 #include "chrome/browser/webdata/keyword_table.h"
14 #include "chrome/browser/webdata/logins_table.h" 13 #include "chrome/browser/webdata/logins_table.h"
15 #include "chrome/browser/webdata/token_service_table.h" 14 #include "chrome/browser/webdata/token_service_table.h"
16 #include "chrome/browser/webdata/web_apps_table.h" 15 #include "chrome/browser/webdata/web_apps_table.h"
17 #include "chrome/browser/webdata/web_database_service.h" 16 #include "chrome/browser/webdata/web_database_service.h"
18 #include "chrome/browser/webdata/web_intents_table.h" 17 #include "chrome/browser/webdata/web_intents_table.h"
19 #include "chrome/common/chrome_notification_types.h" 18 #include "chrome/common/chrome_notification_types.h"
20 #include "components/autofill/browser/autofill_country.h" 19 #include "components/autofill/browser/autofill_country.h"
21 #include "components/autofill/browser/autofill_profile.h" 20 #include "components/autofill/browser/autofill_profile.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 WDAppImagesResult::~WDAppImagesResult() {} 56 WDAppImagesResult::~WDAppImagesResult() {}
58 57
59 WDKeywordsResult::WDKeywordsResult() 58 WDKeywordsResult::WDKeywordsResult()
60 : default_search_provider_id(0), 59 : default_search_provider_id(0),
61 builtin_keyword_version(0) { 60 builtin_keyword_version(0) {
62 } 61 }
63 62
64 WDKeywordsResult::~WDKeywordsResult() {} 63 WDKeywordsResult::~WDKeywordsResult() {}
65 64
66 WebDataService::WebDataService(const ProfileErrorCallback& callback) 65 WebDataService::WebDataService(const ProfileErrorCallback& callback)
67 : WebDataServiceBase(callback), 66 : WebDataServiceBase(callback) {
68 autocomplete_syncable_service_(NULL),
69 autofill_profile_syncable_service_(NULL) {
70 } 67 }
71 68
72 // static 69 // static
73 void WebDataService::NotifyOfMultipleAutofillChanges( 70 void WebDataService::NotifyOfMultipleAutofillChanges(
74 WebDataService* web_data_service) { 71 WebDataService* web_data_service) {
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
76 73
77 if (!web_data_service) 74 if (!web_data_service)
78 return; 75 return;
79 76
80 BrowserThread::PostTask( 77 BrowserThread::PostTask(
81 BrowserThread::UI, FROM_HERE, 78 BrowserThread::UI, FROM_HERE,
82 Bind(&NotifyOfMultipleAutofillChangesTask, 79 Bind(&NotifyOfMultipleAutofillChangesTask,
83 make_scoped_refptr(web_data_service))); 80 make_scoped_refptr(web_data_service)));
84 } 81 }
85 82
86 void WebDataService::ShutdownOnUIThread() {
87 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
88 Bind(&WebDataService::ShutdownSyncableServices, this));
89 WebDataServiceBase::ShutdownOnUIThread();
90 }
91
92 void WebDataService::Init(const base::FilePath& path) {
93 WebDataServiceBase::Init(path);
94 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
95 Bind(&WebDataService::InitializeSyncableServices, this));
96 }
97
98 ////////////////////////////////////////////////////////////////////////////// 83 //////////////////////////////////////////////////////////////////////////////
99 // 84 //
100 // Keywords. 85 // Keywords.
101 // 86 //
102 ////////////////////////////////////////////////////////////////////////////// 87 //////////////////////////////////////////////////////////////////////////////
103 88
104 void WebDataService::AddKeyword(const TemplateURLData& data) { 89 void WebDataService::AddKeyword(const TemplateURLData& data) {
105 wdbs_->ScheduleDBTask( 90 wdbs_->ScheduleDBTask(
106 FROM_HERE, Bind(&WebDataService::AddKeywordImpl, this, data)); 91 FROM_HERE, Bind(&WebDataService::AddKeywordImpl, this, data));
107 } 92 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 255
271 void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetween( 256 void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetween(
272 const Time& delete_begin, 257 const Time& delete_begin,
273 const Time& delete_end) { 258 const Time& delete_end) {
274 wdbs_->ScheduleDBTask(FROM_HERE, Bind( 259 wdbs_->ScheduleDBTask(FROM_HERE, Bind(
275 &WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl, 260 &WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl,
276 this, delete_begin, delete_end)); 261 this, delete_begin, delete_end));
277 } 262 }
278 263
279 WebDataService::WebDataService() 264 WebDataService::WebDataService()
280 : WebDataServiceBase(ProfileErrorCallback()), 265 : WebDataServiceBase(ProfileErrorCallback()) {
281 autocomplete_syncable_service_(NULL),
282 autofill_profile_syncable_service_(NULL) {
283 } 266 }
284 267
285 WebDataService::~WebDataService() { 268 WebDataService::~WebDataService() {
286 DCHECK(!autocomplete_syncable_service_);
287 DCHECK(!autofill_profile_syncable_service_);
288 } 269 }
289 270
290 //////////////////////////////////////////////////////////////////////////////// 271 ////////////////////////////////////////////////////////////////////////////////
291 //
292 // The following methods are executed on the DB thread.
293 //
294 ////////////////////////////////////////////////////////////////////////////////
295
296 void WebDataService::InitializeSyncableServices() {
297 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
298 DCHECK(!autocomplete_syncable_service_);
299 DCHECK(!autofill_profile_syncable_service_);
300
301 autocomplete_syncable_service_ = new AutocompleteSyncableService(this);
302 autofill_profile_syncable_service_ = new AutofillProfileSyncableService(this);
303 }
304
305 void WebDataService::ShutdownSyncableServices() {
306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
307
308 delete autocomplete_syncable_service_;
309 autocomplete_syncable_service_ = NULL;
310 delete autofill_profile_syncable_service_;
311 autofill_profile_syncable_service_ = NULL;
312 }
313
314 ////////////////////////////////////////////////////////////////////////////////
315 // 272 //
316 // Keywords implementation. 273 // Keywords implementation.
317 // 274 //
318 //////////////////////////////////////////////////////////////////////////////// 275 ////////////////////////////////////////////////////////////////////////////////
319 276
320 WebDatabase::State WebDataService::AddKeywordImpl( 277 WebDatabase::State WebDataService::AddKeywordImpl(
321 const TemplateURLData& data, WebDatabase* db) { 278 const TemplateURLData& data, WebDatabase* db) {
322 KeywordTable::FromWebDatabase(db)->AddKeyword(data); 279 KeywordTable::FromWebDatabase(db)->AddKeyword(data);
323 return WebDatabase::COMMIT_NEEDED; 280 return WebDatabase::COMMIT_NEEDED;
324 } 281 }
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 content::Source<WebDataService>(this), 635 content::Source<WebDataService>(this),
679 content::Details<AutofillProfileChange>(&change)); 636 content::Details<AutofillProfileChange>(&change));
680 } 637 }
681 // Note: It is the caller's responsibility to post notifications for any 638 // Note: It is the caller's responsibility to post notifications for any
682 // changes, e.g. by calling the Refresh() method of PersonalDataManager. 639 // changes, e.g. by calling the Refresh() method of PersonalDataManager.
683 return WebDatabase::COMMIT_NEEDED; 640 return WebDatabase::COMMIT_NEEDED;
684 } 641 }
685 return WebDatabase::COMMIT_NOT_NEEDED; 642 return WebDatabase::COMMIT_NOT_NEEDED;
686 } 643 }
687 644
688 AutofillProfileSyncableService*
689 WebDataService::GetAutofillProfileSyncableService() const {
690 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
691 DCHECK(autofill_profile_syncable_service_); // Make sure we're initialized.
692
693 return autofill_profile_syncable_service_;
694 }
695
696 AutocompleteSyncableService* WebDataService::GetAutocompleteSyncableService()
697 const {
698 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
699 DCHECK(autocomplete_syncable_service_); // Make sure we're initialized.
700
701 return autocomplete_syncable_service_;
702 }
703
704 void WebDataService::DestroyAutofillProfileResult(const WDTypedResult* result) { 645 void WebDataService::DestroyAutofillProfileResult(const WDTypedResult* result) {
705 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT); 646 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT);
706 const WDResult<std::vector<AutofillProfile*> >* r = 647 const WDResult<std::vector<AutofillProfile*> >* r =
707 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result); 648 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result);
708 std::vector<AutofillProfile*> profiles = r->GetValue(); 649 std::vector<AutofillProfile*> profiles = r->GetValue();
709 STLDeleteElements(&profiles); 650 STLDeleteElements(&profiles);
710 } 651 }
711 652
712 void WebDataService::DestroyAutofillCreditCardResult( 653 void WebDataService::DestroyAutofillCreditCardResult(
713 const WDTypedResult* result) { 654 const WDTypedResult* result) {
714 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); 655 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT);
715 const WDResult<std::vector<CreditCard*> >* r = 656 const WDResult<std::vector<CreditCard*> >* r =
716 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); 657 static_cast<const WDResult<std::vector<CreditCard*> >*>(result);
717 658
718 std::vector<CreditCard*> credit_cards = r->GetValue(); 659 std::vector<CreditCard*> credit_cards = r->GetValue();
719 STLDeleteElements(&credit_cards); 660 STLDeleteElements(&credit_cards);
720 } 661 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698