Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/memory/singleton.h" | |
| 9 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/profiles/incognito_helpers.h" | 11 #include "chrome/browser/profiles/incognito_helpers.h" |
| 11 #include "chrome/browser/sync/glue/sync_start_util.h" | 12 #include "chrome/browser/sync/glue/sync_start_util.h" |
| 12 #include "chrome/browser/ui/profile_error_dialog.h" | 13 #include "chrome/browser/ui/profile_error_dialog.h" |
| 13 #include "chrome/browser/webdata/autocomplete_syncable_service.h" | 14 #include "chrome/browser/webdata/autocomplete_syncable_service.h" |
| 14 #include "chrome/grit/chromium_strings.h" | 15 #include "chrome/grit/chromium_strings.h" |
| 15 #include "chrome/grit/generated_resources.h" | 16 #include "chrome/grit/generated_resources.h" |
| 16 #include "components/autofill/core/browser/autofill_country.h" | |
| 17 #include "components/autofill/core/browser/webdata/autofill_profile_syncable_ser vice.h" | 17 #include "components/autofill/core/browser/webdata/autofill_profile_syncable_ser vice.h" |
| 18 #include "components/autofill/core/browser/webdata/autofill_table.h" | |
| 19 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | |
| 20 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 18 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 21 #include "components/password_manager/core/browser/webdata/logins_table.h" | |
| 22 #include "components/search_engines/keyword_table.h" | |
| 23 #include "components/search_engines/keyword_web_data_service.h" | 19 #include "components/search_engines/keyword_web_data_service.h" |
| 24 #include "components/signin/core/browser/webdata/token_service_table.h" | |
| 25 #include "components/signin/core/browser/webdata/token_web_data.h" | 20 #include "components/signin/core/browser/webdata/token_web_data.h" |
| 26 #include "components/webdata/common/webdata_constants.h" | 21 #include "components/webdata_services/web_data_service_wrapper.h" |
| 27 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 28 | 23 |
| 29 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
| 30 #include "components/password_manager/core/browser/webdata/password_web_data_ser vice_win.h" | 25 #include "components/password_manager/core/browser/webdata/password_web_data_ser vice_win.h" |
| 31 #endif | 26 #endif |
| 32 | 27 |
| 28 using autofill::AutofillWebDataBackend; | |
|
Peter Kasting
2014/12/05 21:47:56
Nit: Avoid using directives unless they noticeably
sdefresne
2014/12/08 10:54:42
Done.
| |
| 33 using autofill::AutofillWebDataService; | 29 using autofill::AutofillWebDataService; |
| 34 using autofill::AutofillProfileSyncableService; | 30 using autofill::AutofillProfileSyncableService; |
| 35 using content::BrowserThread; | 31 using content::BrowserThread; |
| 36 | 32 |
| 37 namespace { | 33 namespace { |
| 38 | 34 |
| 35 // Converts a WebDataServiceWrapper::ErrorType to ProfileErrorType. | |
| 36 ProfileErrorType ProfileErrorFromWebDataServiceWrapperError( | |
| 37 WebDataServiceWrapper::ErrorType error_type) { | |
| 38 switch (error_type) { | |
| 39 case WebDataServiceWrapper::ERROR_DB_AUTOFILL_WEB_DATA: | |
| 40 return PROFILE_ERROR_DB_AUTOFILL_WEB_DATA; | |
| 41 | |
| 42 case WebDataServiceWrapper::ERROR_DB_KEYWORD_WEB_DATA: | |
| 43 return PROFILE_ERROR_DB_KEYWORD_WEB_DATA; | |
| 44 | |
| 45 case WebDataServiceWrapper::ERROR_DB_TOKEN_WEB_DATA: | |
| 46 return PROFILE_ERROR_DB_TOKEN_WEB_DATA; | |
| 47 | |
| 48 case WebDataServiceWrapper::ERROR_DB_PASSWORD_WEB_DATA: | |
| 49 return PROFILE_ERROR_DB_WEB_DATA; | |
| 50 } | |
| 51 NOTREACHED() << "Unknown WebDataServiceWrapper::ErrorType: " << error_type; | |
|
Peter Kasting
2014/12/05 21:47:55
Nit: Please move these two lines to a default clau
sdefresne
2014/12/08 10:54:42
Done.
| |
| 52 return PROFILE_ERROR_DB_WEB_DATA; | |
| 53 } | |
| 54 | |
| 39 // Callback to show error dialog on profile load error. | 55 // Callback to show error dialog on profile load error. |
| 40 void ProfileErrorCallback(ProfileErrorType type, sql::InitStatus status) { | 56 void ProfileErrorCallback(WebDataServiceWrapper::ErrorType error_type, |
| 41 ShowProfileErrorDialog( | 57 sql::InitStatus status) { |
| 42 type, | 58 ShowProfileErrorDialog(ProfileErrorFromWebDataServiceWrapperError(error_type), |
|
Peter Kasting
2014/12/05 21:47:55
Nit: Don't change the wrapping of this call; the o
sdefresne
2014/12/08 10:54:42
This was formatted by clang-format. Reverted.
| |
| 43 (status == sql::INIT_FAILURE) ? | 59 (status == sql::INIT_FAILURE) |
| 44 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR); | 60 ? IDS_COULDNT_OPEN_PROFILE_ERROR |
| 61 : IDS_PROFILE_TOO_NEW_ERROR); | |
| 45 } | 62 } |
| 46 | 63 |
| 64 } // namespace | |
| 65 | |
| 47 void InitSyncableServicesOnDBThread( | 66 void InitSyncableServicesOnDBThread( |
| 48 scoped_refptr<AutofillWebDataService> autofill_web_data, | 67 scoped_refptr<AutofillWebDataService> autofill_web_data, |
| 49 const base::FilePath& profile_path, | 68 const base::FilePath& profile_path, |
| 50 const std::string& app_locale, | 69 const std::string& app_locale, |
| 51 autofill::AutofillWebDataBackend* autofill_backend) { | 70 AutofillWebDataBackend* autofill_backend) { |
| 52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 53 | 72 |
| 54 // Currently only Autocomplete and Autofill profiles use the new Sync API, but | 73 // Currently only Autocomplete and Autofill profiles use the new Sync API, but |
| 55 // all the database data should migrate to this API over time. | 74 // all the database data should migrate to this API over time. |
| 56 AutocompleteSyncableService::CreateForWebDataServiceAndBackend( | 75 AutocompleteSyncableService::CreateForWebDataServiceAndBackend( |
| 57 autofill_web_data.get(), autofill_backend); | 76 autofill_web_data.get(), autofill_backend); |
| 58 AutocompleteSyncableService::FromWebDataService(autofill_web_data.get()) | 77 AutocompleteSyncableService::FromWebDataService(autofill_web_data.get()) |
| 59 ->InjectStartSyncFlare( | 78 ->InjectStartSyncFlare( |
| 60 sync_start_util::GetFlareForSyncableService(profile_path)); | 79 sync_start_util::GetFlareForSyncableService(profile_path)); |
| 61 AutofillProfileSyncableService::CreateForWebDataServiceAndBackend( | 80 AutofillProfileSyncableService::CreateForWebDataServiceAndBackend( |
| 62 autofill_web_data.get(), autofill_backend, app_locale); | 81 autofill_web_data.get(), autofill_backend, app_locale); |
| 63 AutofillProfileSyncableService::FromWebDataService(autofill_web_data.get()) | 82 AutofillProfileSyncableService::FromWebDataService(autofill_web_data.get()) |
| 64 ->InjectStartSyncFlare( | 83 ->InjectStartSyncFlare( |
| 65 sync_start_util::GetFlareForSyncableService(profile_path)); | 84 sync_start_util::GetFlareForSyncableService(profile_path)); |
| 66 } | 85 } |
| 67 | 86 |
| 68 } // namespace | |
| 69 | |
| 70 WebDataServiceWrapper::WebDataServiceWrapper() { | |
| 71 } | |
| 72 | |
| 73 WebDataServiceWrapper::WebDataServiceWrapper(Profile* profile) { | |
| 74 base::FilePath profile_path = profile->GetPath(); | |
| 75 base::FilePath path = profile_path.Append(kWebDataFilename); | |
| 76 | |
| 77 scoped_refptr<base::MessageLoopProxy> ui_thread = | |
| 78 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); | |
| 79 scoped_refptr<base::MessageLoopProxy> db_thread = | |
| 80 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB); | |
| 81 web_database_ = new WebDatabaseService(path, ui_thread, db_thread); | |
| 82 | |
| 83 // All tables objects that participate in managing the database must | |
| 84 // be added here. | |
| 85 web_database_->AddTable(scoped_ptr<WebDatabaseTable>( | |
| 86 new autofill::AutofillTable(g_browser_process->GetApplicationLocale()))); | |
| 87 web_database_->AddTable(scoped_ptr<WebDatabaseTable>(new KeywordTable())); | |
| 88 // TODO(mdm): We only really need the LoginsTable on Windows for IE7 password | |
| 89 // access, but for now, we still create it on all platforms since it deletes | |
| 90 // the old logins table. We can remove this after a while, e.g. in M22 or so. | |
| 91 web_database_->AddTable(scoped_ptr<WebDatabaseTable>(new LoginsTable())); | |
| 92 web_database_->AddTable( | |
| 93 scoped_ptr<WebDatabaseTable>(new TokenServiceTable())); | |
| 94 | |
| 95 web_database_->LoadDatabase(); | |
| 96 | |
| 97 autofill_web_data_ = new AutofillWebDataService( | |
| 98 web_database_, | |
| 99 ui_thread, | |
| 100 db_thread, | |
| 101 base::Bind(&ProfileErrorCallback, PROFILE_ERROR_DB_AUTOFILL_WEB_DATA)); | |
| 102 autofill_web_data_->Init(); | |
| 103 | |
| 104 keyword_web_data_ = new KeywordWebDataService( | |
| 105 web_database_, | |
| 106 ui_thread, | |
| 107 base::Bind(&ProfileErrorCallback, PROFILE_ERROR_DB_KEYWORD_WEB_DATA)); | |
| 108 keyword_web_data_->Init(); | |
| 109 | |
| 110 token_web_data_ = new TokenWebData( | |
| 111 web_database_, | |
| 112 ui_thread, | |
| 113 db_thread, | |
| 114 base::Bind(&ProfileErrorCallback, PROFILE_ERROR_DB_TOKEN_WEB_DATA)); | |
| 115 token_web_data_->Init(); | |
| 116 | |
| 117 #if defined(OS_WIN) | |
| 118 password_web_data_ = new PasswordWebDataService( | |
| 119 web_database_, | |
| 120 ui_thread, | |
| 121 base::Bind(&ProfileErrorCallback, PROFILE_ERROR_DB_WEB_DATA)); | |
| 122 password_web_data_->Init(); | |
| 123 #endif | |
| 124 | |
| 125 autofill_web_data_->GetAutofillBackend( | |
| 126 base::Bind(&InitSyncableServicesOnDBThread, | |
| 127 autofill_web_data_, | |
| 128 profile_path, | |
| 129 g_browser_process->GetApplicationLocale())); | |
| 130 } | |
| 131 | |
| 132 WebDataServiceWrapper::~WebDataServiceWrapper() { | |
| 133 } | |
| 134 | |
| 135 void WebDataServiceWrapper::Shutdown() { | |
| 136 autofill_web_data_->ShutdownOnUIThread(); | |
| 137 keyword_web_data_->ShutdownOnUIThread(); | |
| 138 token_web_data_->ShutdownOnUIThread(); | |
| 139 | |
| 140 #if defined(OS_WIN) | |
| 141 password_web_data_->ShutdownOnUIThread(); | |
| 142 #endif | |
| 143 web_database_->ShutdownDatabase(); | |
| 144 } | |
| 145 | |
| 146 scoped_refptr<AutofillWebDataService> | |
| 147 WebDataServiceWrapper::GetAutofillWebData() { | |
| 148 return autofill_web_data_.get(); | |
| 149 } | |
| 150 | |
| 151 scoped_refptr<KeywordWebDataService> | |
| 152 WebDataServiceWrapper::GetKeywordWebData() { | |
| 153 return keyword_web_data_.get(); | |
| 154 } | |
| 155 | |
| 156 scoped_refptr<TokenWebData> WebDataServiceWrapper::GetTokenWebData() { | |
| 157 return token_web_data_.get(); | |
| 158 } | |
| 159 | |
| 160 #if defined(OS_WIN) | |
| 161 scoped_refptr<PasswordWebDataService> | |
| 162 WebDataServiceWrapper::GetPasswordWebData() { | |
| 163 return password_web_data_.get(); | |
| 164 } | |
| 165 #endif | |
| 166 | |
| 167 WebDataServiceFactory::WebDataServiceFactory() | 87 WebDataServiceFactory::WebDataServiceFactory() |
| 168 : BrowserContextKeyedServiceFactory( | 88 : BrowserContextKeyedServiceFactory( |
| 169 "WebDataService", | 89 "WebDataService", |
| 170 BrowserContextDependencyManager::GetInstance()) { | 90 BrowserContextDependencyManager::GetInstance()) { |
| 171 // WebDataServiceFactory has no dependecies. | 91 // WebDataServiceFactory has no dependecies. |
| 172 } | 92 } |
| 173 | 93 |
| 174 WebDataServiceFactory::~WebDataServiceFactory() { | 94 WebDataServiceFactory::~WebDataServiceFactory() { |
| 175 } | 95 } |
| 176 | 96 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 198 GetInstance()->GetServiceForBrowserContext(profile, false)); | 118 GetInstance()->GetServiceForBrowserContext(profile, false)); |
| 199 } | 119 } |
| 200 | 120 |
| 201 // static | 121 // static |
| 202 scoped_refptr<AutofillWebDataService> | 122 scoped_refptr<AutofillWebDataService> |
| 203 WebDataServiceFactory::GetAutofillWebDataForProfile( | 123 WebDataServiceFactory::GetAutofillWebDataForProfile( |
| 204 Profile* profile, | 124 Profile* profile, |
| 205 Profile::ServiceAccessType access_type) { | 125 Profile::ServiceAccessType access_type) { |
| 206 WebDataServiceWrapper* wrapper = | 126 WebDataServiceWrapper* wrapper = |
| 207 WebDataServiceFactory::GetForProfile(profile, access_type); | 127 WebDataServiceFactory::GetForProfile(profile, access_type); |
| 208 // |wrapper| can be NULL in Incognito mode. | 128 // |wrapper| can be nullptr in Incognito mode. |
|
Peter Kasting
2014/12/05 21:47:56
Nit: Say "null" instead of "nullptr" in these comm
sdefresne
2014/12/08 10:54:42
Done.
| |
| 209 return wrapper ? | 129 return wrapper ? wrapper->GetAutofillWebData() |
| 210 wrapper->GetAutofillWebData() : | 130 : scoped_refptr<AutofillWebDataService>(nullptr); |
|
Peter Kasting
2014/12/05 21:47:55
Nit: Don't change the wrapping of these expression
sdefresne
2014/12/08 10:54:42
This was formatted by clang-format. Reverted.
| |
| 211 scoped_refptr<AutofillWebDataService>(NULL); | |
| 212 } | 131 } |
| 213 | 132 |
| 214 // static | 133 // static |
| 215 scoped_refptr<KeywordWebDataService> | 134 scoped_refptr<KeywordWebDataService> |
| 216 WebDataServiceFactory::GetKeywordWebDataForProfile( | 135 WebDataServiceFactory::GetKeywordWebDataForProfile( |
| 217 Profile* profile, | 136 Profile* profile, |
| 218 Profile::ServiceAccessType access_type) { | 137 Profile::ServiceAccessType access_type) { |
| 219 WebDataServiceWrapper* wrapper = | 138 WebDataServiceWrapper* wrapper = |
| 220 WebDataServiceFactory::GetForProfile(profile, access_type); | 139 WebDataServiceFactory::GetForProfile(profile, access_type); |
| 221 // |wrapper| can be NULL in Incognito mode. | 140 // |wrapper| can be nullptr in Incognito mode. |
| 222 return wrapper ? | 141 return wrapper ? wrapper->GetKeywordWebData() |
| 223 wrapper->GetKeywordWebData() : scoped_refptr<KeywordWebDataService>(NULL); | 142 : scoped_refptr<KeywordWebDataService>(nullptr); |
| 224 } | 143 } |
| 225 | 144 |
| 226 // static | 145 // static |
| 227 scoped_refptr<TokenWebData> WebDataServiceFactory::GetTokenWebDataForProfile( | 146 scoped_refptr<TokenWebData> WebDataServiceFactory::GetTokenWebDataForProfile( |
| 228 Profile* profile, | 147 Profile* profile, |
| 229 Profile::ServiceAccessType access_type) { | 148 Profile::ServiceAccessType access_type) { |
| 230 WebDataServiceWrapper* wrapper = | 149 WebDataServiceWrapper* wrapper = |
| 231 WebDataServiceFactory::GetForProfile(profile, access_type); | 150 WebDataServiceFactory::GetForProfile(profile, access_type); |
| 232 // |wrapper| can be NULL in Incognito mode. | 151 // |wrapper| can be nullptr in Incognito mode. |
| 233 return wrapper ? | 152 return wrapper ? wrapper->GetTokenWebData() |
| 234 wrapper->GetTokenWebData() : scoped_refptr<TokenWebData>(NULL); | 153 : scoped_refptr<TokenWebData>(nullptr); |
| 235 } | 154 } |
| 236 | 155 |
| 237 #if defined(OS_WIN) | 156 #if defined(OS_WIN) |
| 238 // static | 157 // static |
| 239 scoped_refptr<PasswordWebDataService> | 158 scoped_refptr<PasswordWebDataService> |
| 240 WebDataServiceFactory::GetPasswordWebDataForProfile( | 159 WebDataServiceFactory::GetPasswordWebDataForProfile( |
| 241 Profile* profile, | 160 Profile* profile, |
| 242 Profile::ServiceAccessType access_type) { | 161 Profile::ServiceAccessType access_type) { |
| 243 WebDataServiceWrapper* wrapper = | 162 WebDataServiceWrapper* wrapper = |
| 244 WebDataServiceFactory::GetForProfile(profile, access_type); | 163 WebDataServiceFactory::GetForProfile(profile, access_type); |
| 245 // |wrapper| can be NULL in Incognito mode. | 164 // |wrapper| can be nullptr in Incognito mode. |
| 246 return wrapper ? | 165 return wrapper ? wrapper->GetPasswordWebData() |
| 247 wrapper->GetPasswordWebData() : | 166 : scoped_refptr<PasswordWebDataService>(nullptr); |
| 248 scoped_refptr<PasswordWebDataService>(NULL); | |
| 249 } | 167 } |
| 250 #endif | 168 #endif |
| 251 | 169 |
| 252 // static | 170 // static |
| 253 WebDataServiceFactory* WebDataServiceFactory::GetInstance() { | 171 WebDataServiceFactory* WebDataServiceFactory::GetInstance() { |
| 254 return Singleton<WebDataServiceFactory>::get(); | 172 return Singleton<WebDataServiceFactory>::get(); |
| 255 } | 173 } |
| 256 | 174 |
| 257 content::BrowserContext* WebDataServiceFactory::GetBrowserContextToUse( | 175 content::BrowserContext* WebDataServiceFactory::GetBrowserContextToUse( |
| 258 content::BrowserContext* context) const { | 176 content::BrowserContext* context) const { |
| 259 return chrome::GetBrowserContextRedirectedInIncognito(context); | 177 return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 260 } | 178 } |
| 261 | 179 |
| 262 KeyedService* WebDataServiceFactory::BuildServiceInstanceFor( | 180 KeyedService* WebDataServiceFactory::BuildServiceInstanceFor( |
| 263 content::BrowserContext* profile) const { | 181 content::BrowserContext* profile) const { |
| 264 return new WebDataServiceWrapper(static_cast<Profile*>(profile)); | 182 WebDataServiceWrapper* web_data_service_wrapper = new WebDataServiceWrapper( |
| 183 static_cast<Profile*>(profile)->GetPath(), | |
| 184 g_browser_process->GetApplicationLocale(), | |
| 185 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), | |
| 186 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), | |
| 187 &ProfileErrorCallback); | |
| 188 web_data_service_wrapper->GetAutofillWebData()->GetAutofillBackend( | |
| 189 base::Bind(&InitSyncableServicesOnDBThread, | |
| 190 web_data_service_wrapper->GetAutofillWebData(), | |
| 191 static_cast<Profile*>(profile)->GetPath(), | |
| 192 g_browser_process->GetApplicationLocale())); | |
| 193 return web_data_service_wrapper; | |
| 265 } | 194 } |
| 266 | 195 |
| 267 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const { | 196 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const { |
| 268 return true; | 197 return true; |
| 269 } | 198 } |
| OLD | NEW |