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

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

Issue 12897009: Autofill Webdata Split TRY ONLY (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Try again 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" 11 #include "chrome/browser/webdata/autocomplete_syncable_service.h"
12 #include "chrome/browser/webdata/autofill_profile_syncable_service.h" 12 #include "chrome/browser/webdata/autofill_profile_syncable_service.h"
13 #include "chrome/browser/webdata/autofill_table.h"
13 #include "chrome/browser/webdata/autofill_web_data_service_impl.h" 14 #include "chrome/browser/webdata/autofill_web_data_service_impl.h"
15 #include "chrome/browser/webdata/keyword_table.h"
16 #include "chrome/browser/webdata/logins_table.h"
17 #include "chrome/browser/webdata/token_service_table.h"
18 #include "chrome/browser/webdata/web_apps_table.h"
19 #include "chrome/browser/webdata/web_data_service.h"
20 #include "chrome/browser/webdata/web_intents_table.h"
14 #include "chrome/common/chrome_constants.h" 21 #include "chrome/common/chrome_constants.h"
15 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
16 #include "grit/chromium_strings.h" 23 #include "grit/chromium_strings.h"
17 #include "grit/generated_resources.h" 24 #include "grit/generated_resources.h"
18 25
19 using content::BrowserThread; 26 using content::BrowserThread;
20 27
21 namespace { 28 namespace {
22 29
23 // Callback to show error dialog on profile load error. 30 // Callback to show error dialog on profile load error.
24 void ProfileErrorCallback(sql::InitStatus status) { 31 void ProfileErrorCallback(sql::InitStatus status) {
25 ShowProfileErrorDialog( 32 ShowProfileErrorDialog(
26 (status == sql::INIT_FAILURE) ? 33 (status == sql::INIT_FAILURE) ?
27 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR); 34 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR);
28 } 35 }
29 36
30 void InitSyncableServicesOnDBThread(scoped_refptr<WebDataService> web_data) { 37 void InitSyncableServicesOnDBThread(
38 scoped_refptr<AutofillWebDataService> autofill_web_data) {
31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
32 40
33 // Currently only Autocomplete and Autofill profiles use the new Sync API, but 41 // Currently only Autocomplete and Autofill profiles use the new Sync API, but
34 // all the database data should migrate to this API over time. 42 // all the database data should migrate to this API over time.
35 AutocompleteSyncableService::CreateForWebDataService(web_data); 43 AutocompleteSyncableService::CreateForWebDataService(autofill_web_data);
36 AutofillProfileSyncableService::CreateForWebDataService(web_data); 44 AutofillProfileSyncableService::CreateForWebDataService(autofill_web_data);
37 } 45 }
38 46
39 } // namespace 47 } // namespace
40 48
41 WebDataServiceWrapper::WebDataServiceWrapper() {} 49 WebDataServiceWrapper::WebDataServiceWrapper() {}
42 50
43 WebDataServiceWrapper::WebDataServiceWrapper(Profile* profile) { 51 WebDataServiceWrapper::WebDataServiceWrapper(Profile* profile) {
44 base::FilePath path = profile->GetPath(); 52 base::FilePath path = profile->GetPath();
45 path = path.Append(chrome::kWebDataFilename); 53 path = path.Append(chrome::kWebDataFilename);
46 web_data_service_ = new WebDataService(base::Bind(&ProfileErrorCallback)); 54
47 web_data_service_->Init(path); 55 // TODO (caitkp): Rework the callbacks here. They're ugly.
56
57 web_database_ = new WebDatabaseService(path);
58
59 // All tables objects that participate in managing the database must
60 // be added here.
61 web_database_->AddTable(
62 scoped_ptr<WebDatabaseTable>(new AutofillTable()));
63 web_database_->AddTable(
64 scoped_ptr<WebDatabaseTable>(new KeywordTable()));
65 // TODO(mdm): We only really need the LoginsTable on Windows for IE7 password
66 // access, but for now, we still create it on all platforms since it deletes
67 // the old logins table. We can remove this after a while, e.g. in M22 or so.
68 web_database_->AddTable(
69 scoped_ptr<WebDatabaseTable>(new LoginsTable()));
70 web_database_->AddTable(
71 scoped_ptr<WebDatabaseTable>(new TokenServiceTable()));
72 web_database_->AddTable(
73 scoped_ptr<WebDatabaseTable>(new WebAppsTable()));
74 // TODO(thakis): Add a migration to delete the SQL table used by
75 // WebIntentsTable, then remove this.
76 web_database_->AddTable(
77 scoped_ptr<WebDatabaseTable>(new WebIntentsTable()));
78
79 web_database_->LoadDatabase(WebDatabaseService::InitCallback());
80
81 autofill_web_data_ = new AutofillWebDataServiceImpl(
82 web_database_, base::Bind(&ProfileErrorCallback));
83 autofill_web_data_->Init();
84
85 web_data_ = new WebDataService(
86 web_database_, base::Bind(&ProfileErrorCallback));
87 web_data_->Init();
48 88
49 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 89 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
50 base::Bind(&InitSyncableServicesOnDBThread, 90 base::Bind(&InitSyncableServicesOnDBThread,
51 web_data_service_)); 91 autofill_web_data_));
52 } 92 }
53 93
54 WebDataServiceWrapper::~WebDataServiceWrapper() { 94 WebDataServiceWrapper::~WebDataServiceWrapper() {
55 } 95 }
56 96
57 void WebDataServiceWrapper::Shutdown() { 97 void WebDataServiceWrapper::Shutdown() {
58 web_data_service_->ShutdownOnUIThread(); 98 autofill_web_data_->ShutdownOnUIThread();
59 web_data_service_ = NULL; 99 web_data_->ShutdownOnUIThread();
100 web_database_->ShutdownDatabase();
101 }
102
103 scoped_refptr<AutofillWebDataService>
104 WebDataServiceWrapper::GetAutofillWebData() {
105 return autofill_web_data_.get();
60 } 106 }
61 107
62 scoped_refptr<WebDataService> WebDataServiceWrapper::GetWebData() { 108 scoped_refptr<WebDataService> WebDataServiceWrapper::GetWebData() {
63 return web_data_service_.get(); 109 return web_data_.get();
64 } 110 }
65 111
112
66 // static 113 // static
67 scoped_refptr<AutofillWebDataService> 114 scoped_refptr<AutofillWebDataService>
68 AutofillWebDataService::FromBrowserContext(content::BrowserContext* context) { 115 AutofillWebDataService::FromBrowserContext(content::BrowserContext* context) {
69 // For this service, the implicit/explicit distinction doesn't 116 // For this service, the implicit/explicit distinction doesn't
70 // really matter; it's just used for a DCHECK. So we currently 117 // really matter; it's just used for a DCHECK. So we currently
71 // cheat and always say EXPLICIT_ACCESS. 118 // cheat and always say EXPLICIT_ACCESS.
72 scoped_refptr<WebDataService> service = WebDataServiceFactory::GetForProfile( 119 WebDataServiceWrapper* wrapper =
73 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS); 120 WebDataServiceFactory::GetForProfile(
74 121 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS);
75 if (service.get()) { 122 if (wrapper)
76 return scoped_refptr<AutofillWebDataService>( 123 return wrapper->GetAutofillWebData();
77 new AutofillWebDataServiceImpl(service)); 124 // |wrapper| can be NULL in Incognito mode.
78 } else { 125 return scoped_refptr<AutofillWebDataService>(NULL);
79 return scoped_refptr<AutofillWebDataService>(NULL);
80 }
81 } 126 }
82 127
83 // static 128 // static
84 scoped_refptr<WebDataService> WebDataService::FromBrowserContext( 129 scoped_refptr<WebDataService> WebDataService::FromBrowserContext(
85 content::BrowserContext* context) { 130 content::BrowserContext* context) {
86 // For this service, the implicit/explicit distinction doesn't 131 // For this service, the implicit/explicit distinction doesn't
87 // really matter; it's just used for a DCHECK. So we currently 132 // really matter; it's just used for a DCHECK. So we currently
88 // cheat and always say EXPLICIT_ACCESS. 133 // cheat and always say EXPLICIT_ACCESS.
89 return WebDataServiceFactory::GetForProfile( 134 WebDataServiceWrapper* wrapper =
90 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS); 135 WebDataServiceFactory::GetForProfile(
136 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS);
137 if (wrapper)
138 return wrapper->GetWebData();
139 // |wrapper| can be NULL in Incognito mode.
140 return scoped_refptr<WebDataService>(NULL);
91 } 141 }
92 142
93 WebDataServiceFactory::WebDataServiceFactory() 143 WebDataServiceFactory::WebDataServiceFactory()
94 : ProfileKeyedServiceFactory( 144 : ProfileKeyedServiceFactory(
95 "WebDataService", 145 "WebDataService",
96 ProfileDependencyManager::GetInstance()) { 146 ProfileDependencyManager::GetInstance()) {
97 // WebDataServiceFactory has no dependecies. 147 // WebDataServiceFactory has no dependecies.
98 } 148 }
99 149
100 WebDataServiceFactory::~WebDataServiceFactory() {} 150 WebDataServiceFactory::~WebDataServiceFactory() {}
101 151
102 // static 152 // static
103 scoped_refptr<WebDataService> WebDataServiceFactory::GetForProfile( 153 WebDataServiceWrapper* WebDataServiceFactory::GetForProfile(
104 Profile* profile, Profile::ServiceAccessType access_type) { 154 Profile* profile, Profile::ServiceAccessType access_type) {
105 // If |access_type| starts being used for anything other than this 155 // If |access_type| starts being used for anything other than this
106 // DCHECK, we need to start taking it as a parameter to 156 // DCHECK, we need to start taking it as a parameter to
107 // AutofillWebDataServiceImpl::FromBrowserContext (see above). 157 // AutofillWebDataServiceImpl::FromBrowserContext (see above).
108 DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord()); 158 DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord());
109 WebDataServiceWrapper* wrapper = 159 return static_cast<WebDataServiceWrapper*>(
110 static_cast<WebDataServiceWrapper*>(
111 GetInstance()->GetServiceForProfile(profile, true)); 160 GetInstance()->GetServiceForProfile(profile, true));
112 if (wrapper)
113 return wrapper->GetWebData();
114 // |wrapper| can be NULL in Incognito mode.
115 return NULL;
116 } 161 }
117 162
118 // static 163 // static
119 scoped_refptr<WebDataService> WebDataServiceFactory::GetForProfileIfExists( 164 WebDataServiceWrapper* WebDataServiceFactory::GetForProfileIfExists(
120 Profile* profile, Profile::ServiceAccessType access_type) { 165 Profile* profile, Profile::ServiceAccessType access_type) {
121 // If |access_type| starts being used for anything other than this 166 // If |access_type| starts being used for anything other than this
122 // DCHECK, we need to start taking it as a parameter to 167 // DCHECK, we need to start taking it as a parameter to
123 // AutofillWebDataServiceImpl::FromBrowserContext (see above). 168 // AutofillWebDataServiceImpl::FromBrowserContext (see above).
124 DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord()); 169 DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord());
125 WebDataServiceWrapper* wrapper = 170 return static_cast<WebDataServiceWrapper*>(
126 static_cast<WebDataServiceWrapper*>( 171 GetInstance()->GetServiceForProfile(profile, false));
127 GetInstance()->GetServiceForProfile(profile, true));
128 if (wrapper)
129 return wrapper->GetWebData();
130 // |wrapper| can be NULL in Incognito mode.
131 return NULL;
132 } 172 }
133 173
134 // static 174 // static
135 WebDataServiceFactory* WebDataServiceFactory::GetInstance() { 175 WebDataServiceFactory* WebDataServiceFactory::GetInstance() {
136 return Singleton<WebDataServiceFactory>::get(); 176 return Singleton<WebDataServiceFactory>::get();
137 } 177 }
138 178
139 bool WebDataServiceFactory::ServiceRedirectedInIncognito() const { 179 bool WebDataServiceFactory::ServiceRedirectedInIncognito() const {
140 return true; 180 return true;
141 } 181 }
142 182
143 ProfileKeyedService* 183 ProfileKeyedService*
144 WebDataServiceFactory::BuildServiceInstanceFor(Profile* profile) const { 184 WebDataServiceFactory::BuildServiceInstanceFor(Profile* profile) const {
145 return new WebDataServiceWrapper(profile); 185 return new WebDataServiceWrapper(profile);
146 } 186 }
147 187
148 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const { 188 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const {
149 return true; 189 return true;
150 } 190 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/web_data_service_factory.h ('k') | chrome/browser/webdata/web_data_service_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698