| 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 "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/profiles/incognito_helpers.h" | 10 #include "chrome/browser/profiles/incognito_helpers.h" |
| 11 #include "chrome/browser/sync/glue/sync_start_util.h" | 11 #include "chrome/browser/sync/glue/sync_start_util.h" |
| 12 #include "chrome/browser/ui/profile_error_dialog.h" | 12 #include "chrome/browser/ui/profile_error_dialog.h" |
| 13 #include "chrome/browser/webdata/autocomplete_syncable_service.h" | 13 #include "chrome/browser/webdata/autocomplete_syncable_service.h" |
| 14 #include "chrome/browser/webdata/autofill_profile_syncable_service.h" | 14 #include "chrome/browser/webdata/autofill_profile_syncable_service.h" |
| 15 #include "chrome/browser/webdata/keyword_table.h" | 15 #include "chrome/browser/webdata/keyword_table.h" |
| 16 #include "chrome/browser/webdata/logins_table.h" | 16 #include "chrome/browser/webdata/logins_table.h" |
| 17 #include "chrome/browser/webdata/token_service_table.h" | 17 #include "chrome/browser/webdata/token_service_table.h" |
| 18 #include "chrome/browser/webdata/token_web_data.h" |
| 18 #include "chrome/browser/webdata/web_apps_table.h" | 19 #include "chrome/browser/webdata/web_apps_table.h" |
| 19 #include "chrome/browser/webdata/web_data_service.h" | 20 #include "chrome/browser/webdata/web_data_service.h" |
| 20 #include "chrome/browser/webdata/web_intents_table.h" | 21 #include "chrome/browser/webdata/web_intents_table.h" |
| 21 #include "components/autofill/browser/autofill_country.h" | 22 #include "components/autofill/browser/autofill_country.h" |
| 22 #include "components/autofill/browser/webdata/autofill_table.h" | 23 #include "components/autofill/browser/webdata/autofill_table.h" |
| 23 #include "components/autofill/browser/webdata/autofill_webdata_service.h" | 24 #include "components/autofill/browser/webdata/autofill_webdata_service.h" |
| 24 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" | 25 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" |
| 25 #include "components/webdata/common/webdata_constants.h" | 26 #include "components/webdata/common/webdata_constants.h" |
| 26 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 27 #include "grit/chromium_strings.h" | 28 #include "grit/chromium_strings.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 // WebIntentsTable, then remove this. | 89 // WebIntentsTable, then remove this. |
| 89 web_database_->AddTable( | 90 web_database_->AddTable( |
| 90 scoped_ptr<WebDatabaseTable>(new WebIntentsTable())); | 91 scoped_ptr<WebDatabaseTable>(new WebIntentsTable())); |
| 91 | 92 |
| 92 web_database_->LoadDatabase(); | 93 web_database_->LoadDatabase(); |
| 93 | 94 |
| 94 autofill_web_data_ = new AutofillWebDataService( | 95 autofill_web_data_ = new AutofillWebDataService( |
| 95 web_database_, base::Bind(&ProfileErrorCallback)); | 96 web_database_, base::Bind(&ProfileErrorCallback)); |
| 96 autofill_web_data_->Init(); | 97 autofill_web_data_->Init(); |
| 97 | 98 |
| 99 token_web_data_ = new TokenWebData( |
| 100 web_database_, base::Bind(&ProfileErrorCallback)); |
| 101 token_web_data_->Init(); |
| 102 |
| 98 web_data_ = new WebDataService( | 103 web_data_ = new WebDataService( |
| 99 web_database_, base::Bind(&ProfileErrorCallback)); | 104 web_database_, base::Bind(&ProfileErrorCallback)); |
| 100 web_data_->Init(); | 105 web_data_->Init(); |
| 101 | 106 |
| 102 BrowserThread::PostTask( | 107 BrowserThread::PostTask( |
| 103 BrowserThread::DB, FROM_HERE, | 108 BrowserThread::DB, FROM_HERE, |
| 104 base::Bind(&InitSyncableServicesOnDBThread, | 109 base::Bind(&InitSyncableServicesOnDBThread, |
| 105 autofill_web_data_, | 110 autofill_web_data_, |
| 106 profile_path, | 111 profile_path, |
| 107 g_browser_process->GetApplicationLocale())); | 112 g_browser_process->GetApplicationLocale())); |
| 108 } | 113 } |
| 109 | 114 |
| 110 WebDataServiceWrapper::~WebDataServiceWrapper() { | 115 WebDataServiceWrapper::~WebDataServiceWrapper() { |
| 111 } | 116 } |
| 112 | 117 |
| 113 void WebDataServiceWrapper::Shutdown() { | 118 void WebDataServiceWrapper::Shutdown() { |
| 114 autofill_web_data_->ShutdownOnUIThread(); | 119 autofill_web_data_->ShutdownOnUIThread(); |
| 120 token_web_data_->ShutdownOnUIThread(); |
| 115 web_data_->ShutdownOnUIThread(); | 121 web_data_->ShutdownOnUIThread(); |
| 116 web_database_->ShutdownDatabase(); | 122 web_database_->ShutdownDatabase(); |
| 117 } | 123 } |
| 118 | 124 |
| 119 scoped_refptr<AutofillWebDataService> | 125 scoped_refptr<AutofillWebDataService> |
| 120 WebDataServiceWrapper::GetAutofillWebData() { | 126 WebDataServiceWrapper::GetAutofillWebData() { |
| 121 return autofill_web_data_.get(); | 127 return autofill_web_data_.get(); |
| 122 } | 128 } |
| 123 | 129 |
| 124 scoped_refptr<WebDataService> WebDataServiceWrapper::GetWebData() { | 130 scoped_refptr<WebDataService> WebDataServiceWrapper::GetWebData() { |
| 125 return web_data_.get(); | 131 return web_data_.get(); |
| 126 } | 132 } |
| 127 | 133 |
| 134 scoped_refptr<TokenWebData> WebDataServiceWrapper::GetTokenWebData() { |
| 135 return token_web_data_.get(); |
| 136 } |
| 137 |
| 128 // static | 138 // static |
| 129 scoped_refptr<AutofillWebDataService> | 139 scoped_refptr<AutofillWebDataService> |
| 130 AutofillWebDataService::FromBrowserContext(content::BrowserContext* context) { | 140 AutofillWebDataService::FromBrowserContext(content::BrowserContext* context) { |
| 131 // For this service, the implicit/explicit distinction doesn't | 141 // For this service, the implicit/explicit distinction doesn't |
| 132 // really matter; it's just used for a DCHECK. So we currently | 142 // really matter; it's just used for a DCHECK. So we currently |
| 133 // cheat and always say EXPLICIT_ACCESS. | 143 // cheat and always say EXPLICIT_ACCESS. |
| 134 WebDataServiceWrapper* wrapper = | 144 WebDataServiceWrapper* wrapper = |
| 135 WebDataServiceFactory::GetForProfile( | 145 WebDataServiceFactory::GetForProfile( |
| 136 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS); | 146 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS); |
| 137 if (wrapper) | 147 if (wrapper) |
| 138 return wrapper->GetAutofillWebData(); | 148 return wrapper->GetAutofillWebData(); |
| 139 // |wrapper| can be NULL in Incognito mode. | 149 // |wrapper| can be NULL in Incognito mode. |
| 140 return scoped_refptr<AutofillWebDataService>(NULL); | 150 return scoped_refptr<AutofillWebDataService>(NULL); |
| 141 } | 151 } |
| 142 | 152 |
| 143 // static | 153 // static |
| 154 scoped_refptr<TokenWebData> TokenWebData::FromBrowserContext( |
| 155 content::BrowserContext* context) { |
| 156 // For this service, the implicit/explicit distinction doesn't |
| 157 // really matter; it's just used for a DCHECK. So we currently |
| 158 // cheat and always say EXPLICIT_ACCESS. |
| 159 WebDataServiceWrapper* wrapper = |
| 160 WebDataServiceFactory::GetForProfile( |
| 161 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS); |
| 162 if (wrapper) |
| 163 return wrapper->GetTokenWebData(); |
| 164 // |wrapper| can be NULL in Incognito mode. |
| 165 return scoped_refptr<TokenWebData>(NULL); |
| 166 } |
| 167 |
| 168 // static |
| 144 scoped_refptr<WebDataService> WebDataService::FromBrowserContext( | 169 scoped_refptr<WebDataService> WebDataService::FromBrowserContext( |
| 145 content::BrowserContext* context) { | 170 content::BrowserContext* context) { |
| 146 // For this service, the implicit/explicit distinction doesn't | 171 // For this service, the implicit/explicit distinction doesn't |
| 147 // really matter; it's just used for a DCHECK. So we currently | 172 // really matter; it's just used for a DCHECK. So we currently |
| 148 // cheat and always say EXPLICIT_ACCESS. | 173 // cheat and always say EXPLICIT_ACCESS. |
| 149 WebDataServiceWrapper* wrapper = | 174 WebDataServiceWrapper* wrapper = |
| 150 WebDataServiceFactory::GetForProfile( | 175 WebDataServiceFactory::GetForProfile( |
| 151 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS); | 176 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS); |
| 152 if (wrapper) | 177 if (wrapper) |
| 153 return wrapper->GetWebData(); | 178 return wrapper->GetWebData(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 221 } |
| 197 | 222 |
| 198 ProfileKeyedService* WebDataServiceFactory::BuildServiceInstanceFor( | 223 ProfileKeyedService* WebDataServiceFactory::BuildServiceInstanceFor( |
| 199 content::BrowserContext* profile) const { | 224 content::BrowserContext* profile) const { |
| 200 return new WebDataServiceWrapper(static_cast<Profile*>(profile)); | 225 return new WebDataServiceWrapper(static_cast<Profile*>(profile)); |
| 201 } | 226 } |
| 202 | 227 |
| 203 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const { | 228 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const { |
| 204 return true; | 229 return true; |
| 205 } | 230 } |
| OLD | NEW |