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

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

Issue 12494020: Remove knowledge of Chrome-specific SyncableService classes from WebDataService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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_factory.h" 5 #include "chrome/browser/webdata/web_data_service_factory.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "chrome/browser/profiles/profile_dependency_manager.h" 9 #include "chrome/browser/profiles/profile_dependency_manager.h"
10 #include "chrome/browser/ui/profile_error_dialog.h" 10 #include "chrome/browser/ui/profile_error_dialog.h"
11 #include "chrome/browser/webdata/autocomplete_syncable_service.h"
12 #include "chrome/browser/webdata/autofill_profile_syncable_service.h"
11 #include "chrome/browser/webdata/autofill_web_data_service_impl.h" 13 #include "chrome/browser/webdata/autofill_web_data_service_impl.h"
12 #include "chrome/common/chrome_constants.h" 14 #include "chrome/common/chrome_constants.h"
15 #include "content/public/browser/browser_thread.h"
13 #include "grit/chromium_strings.h" 16 #include "grit/chromium_strings.h"
14 #include "grit/generated_resources.h" 17 #include "grit/generated_resources.h"
15 18
19 using content::BrowserThread;
20
16 namespace { 21 namespace {
17 22
18 // Callback to show error dialog on profile load error. 23 // Callback to show error dialog on profile load error.
19 void ProfileErrorCallback(sql::InitStatus status) { 24 void ProfileErrorCallback(sql::InitStatus status) {
20 ShowProfileErrorDialog( 25 ShowProfileErrorDialog(
21 (status == sql::INIT_FAILURE) ? 26 (status == sql::INIT_FAILURE) ?
22 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR); 27 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR);
23 } 28 }
24 29
30 void InitSyncableServicesOnDBThread(scoped_refptr<WebDataService> web_data) {
31 // Currently only Autocomplete and Autofill profiles use the new Sync API, but
32 // all the database data should migrate to this API over time.
33 AutocompleteSyncableService::AttachToWebData(
34 make_scoped_ptr(new AutocompleteSyncableService(web_data)),
35 web_data);
36 AutofillProfileSyncableService::AttachToWebData(
37 make_scoped_ptr(new AutofillProfileSyncableService(web_data)),
38 web_data);
39 }
40
25 } // namespace 41 } // namespace
26 42
27 WebDataServiceWrapper::WebDataServiceWrapper(Profile* profile){ 43 WebDataServiceWrapper::WebDataServiceWrapper(Profile* profile) {
28 base::FilePath path = profile->GetPath(); 44 base::FilePath path = profile->GetPath();
29 path = path.Append(chrome::kWebDataFilename); 45 path = path.Append(chrome::kWebDataFilename);
30 web_data_service_ = new WebDataService(base::Bind(&ProfileErrorCallback)); 46 web_data_service_ = new WebDataService(base::Bind(&ProfileErrorCallback));
31 web_data_service_->Init(path); 47 web_data_service_->Init(path);
48
49 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
50 base::Bind(&InitSyncableServicesOnDBThread,
51 web_data_service_));
32 } 52 }
33 53
34 // For testing. 54 // For testing.
35 WebDataServiceWrapper::WebDataServiceWrapper() { 55 WebDataServiceWrapper::WebDataServiceWrapper() {
36 } 56 }
37 57
38 WebDataServiceWrapper::~WebDataServiceWrapper() { 58 WebDataServiceWrapper::~WebDataServiceWrapper() {
39 web_data_service_ = NULL; 59 web_data_service_ = NULL;
40 } 60 }
41 61
42 void WebDataServiceWrapper::Shutdown() { 62 void WebDataServiceWrapper::Shutdown() {
43 web_data_service_->ShutdownOnUIThread(); 63 web_data_service_->ShutdownOnUIThread();
44 } 64 }
45 65
46 scoped_refptr<WebDataService> WebDataServiceWrapper::GetWebData() { 66 scoped_refptr<WebDataService> WebDataServiceWrapper::GetWebData() {
47 return web_data_service_.get(); 67 return web_data_service_.get();
48 } 68 }
49 69
50 // static 70 // static
51 scoped_refptr<AutofillWebDataService> AutofillWebDataService::FromBrowserContext ( 71 scoped_refptr<AutofillWebDataService>
52 content::BrowserContext* context) { 72 AutofillWebDataService::FromBrowserContext(content::BrowserContext* context) {
53 // For this service, the implicit/explicit distinction doesn't 73 // For this service, the implicit/explicit distinction doesn't
54 // really matter; it's just used for a DCHECK. So we currently 74 // really matter; it's just used for a DCHECK. So we currently
55 // cheat and always say EXPLICIT_ACCESS. 75 // cheat and always say EXPLICIT_ACCESS.
56 scoped_refptr<WebDataService> service = WebDataServiceFactory::GetForProfile( 76 scoped_refptr<WebDataService> service = WebDataServiceFactory::GetForProfile(
57 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS); 77 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS);
58 78
59 if (service.get()) { 79 if (service.get()) {
60 return scoped_refptr<AutofillWebDataService>( 80 return scoped_refptr<AutofillWebDataService>(
61 new AutofillWebDataServiceImpl(service)); 81 new AutofillWebDataServiceImpl(service));
62 } else { 82 } else {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 145 }
126 146
127 ProfileKeyedService* 147 ProfileKeyedService*
128 WebDataServiceFactory::BuildServiceInstanceFor(Profile* profile) const { 148 WebDataServiceFactory::BuildServiceInstanceFor(Profile* profile) const {
129 return new WebDataServiceWrapper(profile); 149 return new WebDataServiceWrapper(profile);
130 } 150 }
131 151
132 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const { 152 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const {
133 return true; 153 return true;
134 } 154 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698