| 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" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 // Callback to show error dialog on profile load error. | 36 // Callback to show error dialog on profile load error. |
| 37 void ProfileErrorCallback(sql::InitStatus status) { | 37 void ProfileErrorCallback(sql::InitStatus status) { |
| 38 ShowProfileErrorDialog( | 38 ShowProfileErrorDialog( |
| 39 (status == sql::INIT_FAILURE) ? | 39 (status == sql::INIT_FAILURE) ? |
| 40 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR); | 40 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void InitSyncableServicesOnDBThread( | 43 void InitSyncableServicesOnDBThread( |
| 44 scoped_refptr<AutofillWebDataService> autofill_web_data, | 44 AutofillWebDataService* autofill_web_data, |
| 45 const base::FilePath& profile_path, | 45 const base::FilePath& profile_path, |
| 46 const std::string& app_locale, | 46 const std::string& app_locale, |
| 47 autofill::AutofillWebDataBackend* autofill_backend) { | 47 autofill::AutofillWebDataBackend* autofill_backend) { |
| 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 49 | 49 |
| 50 // Currently only Autocomplete and Autofill profiles use the new Sync API, but | 50 // Currently only Autocomplete and Autofill profiles use the new Sync API, but |
| 51 // all the database data should migrate to this API over time. | 51 // all the database data should migrate to this API over time. |
| 52 AutocompleteSyncableService::CreateForWebDataServiceAndBackend( | 52 AutocompleteSyncableService::CreateForWebDataServiceAndBackend( |
| 53 autofill_web_data.get(), autofill_backend); | 53 autofill_web_data, autofill_backend); |
| 54 AutocompleteSyncableService::FromWebDataService(autofill_web_data.get()) | 54 AutocompleteSyncableService::FromWebDataService(autofill_web_data) |
| 55 ->InjectStartSyncFlare( | 55 ->InjectStartSyncFlare( |
| 56 sync_start_util::GetFlareForSyncableService(profile_path)); | 56 sync_start_util::GetFlareForSyncableService(profile_path)); |
| 57 AutofillProfileSyncableService::CreateForWebDataServiceAndBackend( | 57 AutofillProfileSyncableService::CreateForWebDataServiceAndBackend( |
| 58 autofill_web_data.get(), autofill_backend, app_locale); | 58 autofill_web_data, autofill_backend, app_locale); |
| 59 AutofillProfileSyncableService::FromWebDataService(autofill_web_data.get()) | 59 AutofillProfileSyncableService::FromWebDataService(autofill_web_data) |
| 60 ->InjectStartSyncFlare( | 60 ->InjectStartSyncFlare( |
| 61 sync_start_util::GetFlareForSyncableService(profile_path)); | 61 sync_start_util::GetFlareForSyncableService(profile_path)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 } // namespace | 64 } // namespace |
| 65 | 65 |
| 66 WebDataServiceWrapper::WebDataServiceWrapper() {} | 66 WebDataServiceWrapper::WebDataServiceWrapper() {} |
| 67 | 67 |
| 68 WebDataServiceWrapper::WebDataServiceWrapper(Profile* profile) { | 68 WebDataServiceWrapper::WebDataServiceWrapper(Profile* profile) { |
| 69 base::FilePath profile_path = profile->GetPath(); | 69 base::FilePath profile_path = profile->GetPath(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 87 scoped_ptr<WebDatabaseTable>(new TokenServiceTable())); | 87 scoped_ptr<WebDatabaseTable>(new TokenServiceTable())); |
| 88 web_database_->AddTable( | 88 web_database_->AddTable( |
| 89 scoped_ptr<WebDatabaseTable>(new WebAppsTable())); | 89 scoped_ptr<WebDatabaseTable>(new WebAppsTable())); |
| 90 // TODO(thakis): Add a migration to delete the SQL table used by | 90 // TODO(thakis): Add a migration to delete the SQL table used by |
| 91 // WebIntentsTable, then remove this. | 91 // WebIntentsTable, then remove this. |
| 92 web_database_->AddTable( | 92 web_database_->AddTable( |
| 93 scoped_ptr<WebDatabaseTable>(new WebIntentsTable())); | 93 scoped_ptr<WebDatabaseTable>(new WebIntentsTable())); |
| 94 | 94 |
| 95 web_database_->LoadDatabase(); | 95 web_database_->LoadDatabase(); |
| 96 | 96 |
| 97 autofill_web_data_ = new AutofillWebDataService( | 97 autofill_web_data_.reset(new AutofillWebDataService( |
| 98 web_database_, base::Bind(&ProfileErrorCallback)); | 98 web_database_, base::Bind(&ProfileErrorCallback))); |
| 99 autofill_web_data_->Init(); | 99 autofill_web_data_->Init(); |
| 100 | 100 |
| 101 token_web_data_ = new TokenWebData( | 101 token_web_data_.reset(new TokenWebData( |
| 102 web_database_, base::Bind(&ProfileErrorCallback)); | 102 web_database_, base::Bind(&ProfileErrorCallback))); |
| 103 token_web_data_->Init(); | 103 token_web_data_->Init(); |
| 104 | 104 |
| 105 web_data_ = new WebDataService( | 105 web_data_ = new WebDataService( |
| 106 web_database_, base::Bind(&ProfileErrorCallback)); | 106 web_database_, base::Bind(&ProfileErrorCallback)); |
| 107 web_data_->Init(); | 107 web_data_->Init(); |
| 108 | 108 |
| 109 autofill_web_data_->GetAutofillBackend( | 109 autofill_web_data_->GetAutofillBackend( |
| 110 base::Bind(&InitSyncableServicesOnDBThread, | 110 base::Bind(&InitSyncableServicesOnDBThread, |
| 111 autofill_web_data_, | 111 autofill_web_data_.get(), |
| 112 profile_path, | 112 profile_path, |
| 113 g_browser_process->GetApplicationLocale())); | 113 g_browser_process->GetApplicationLocale())); |
| 114 } | 114 } |
| 115 | 115 |
| 116 WebDataServiceWrapper::~WebDataServiceWrapper() { | 116 WebDataServiceWrapper::~WebDataServiceWrapper() { |
| 117 } | 117 } |
| 118 | 118 |
| 119 void WebDataServiceWrapper::Shutdown() { | 119 void WebDataServiceWrapper::Shutdown() { |
| 120 autofill_web_data_->ShutdownOnUIThread(); | 120 autofill_web_data_->ShutdownOnUIThread(); |
| 121 token_web_data_->ShutdownOnUIThread(); | 121 token_web_data_->ShutdownOnUIThread(); |
| 122 web_data_->ShutdownOnUIThread(); | 122 web_data_->ShutdownOnUIThread(); |
| 123 web_database_->ShutdownDatabase(); | 123 web_database_->ShutdownDatabase(); |
| 124 } | 124 } |
| 125 | 125 |
| 126 scoped_refptr<AutofillWebDataService> | 126 AutofillWebDataService* WebDataServiceWrapper::GetAutofillWebData() { |
| 127 WebDataServiceWrapper::GetAutofillWebData() { | |
| 128 return autofill_web_data_.get(); | 127 return autofill_web_data_.get(); |
| 129 } | 128 } |
| 130 | 129 |
| 131 scoped_refptr<WebDataService> WebDataServiceWrapper::GetWebData() { | 130 scoped_refptr<WebDataService> WebDataServiceWrapper::GetWebData() { |
| 132 return web_data_.get(); | 131 return web_data_.get(); |
| 133 } | 132 } |
| 134 | 133 |
| 135 scoped_refptr<TokenWebData> WebDataServiceWrapper::GetTokenWebData() { | 134 TokenWebData* WebDataServiceWrapper::GetTokenWebData() { |
| 136 return token_web_data_.get(); | 135 return token_web_data_.get(); |
| 137 } | 136 } |
| 138 | 137 |
| 139 // static | 138 // static |
| 140 scoped_refptr<AutofillWebDataService> | 139 AutofillWebDataService* |
| 141 AutofillWebDataService::FromBrowserContext(content::BrowserContext* context) { | 140 AutofillWebDataService::FromBrowserContext(content::BrowserContext* context) { |
| 142 // For this service, the implicit/explicit distinction doesn't | 141 // For this service, the implicit/explicit distinction doesn't |
| 143 // 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 |
| 144 // cheat and always say EXPLICIT_ACCESS. | 143 // cheat and always say EXPLICIT_ACCESS. |
| 145 WebDataServiceWrapper* wrapper = | 144 WebDataServiceWrapper* wrapper = |
| 146 WebDataServiceFactory::GetForProfile( | 145 WebDataServiceFactory::GetForProfile( |
| 147 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS); | 146 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS); |
| 148 if (wrapper) | 147 if (wrapper) |
| 149 return wrapper->GetAutofillWebData(); | 148 return wrapper->GetAutofillWebData(); |
| 150 // |wrapper| can be NULL in Incognito mode. | 149 // |wrapper| can be NULL in Incognito mode. |
| 151 return scoped_refptr<AutofillWebDataService>(NULL); | 150 return NULL; |
| 152 } | 151 } |
| 153 | 152 |
| 154 // static | 153 // static |
| 155 scoped_refptr<TokenWebData> TokenWebData::FromBrowserContext( | 154 TokenWebData* TokenWebData::FromBrowserContext( |
| 156 content::BrowserContext* context) { | 155 content::BrowserContext* context) { |
| 157 // For this service, the implicit/explicit distinction doesn't | 156 // For this service, the implicit/explicit distinction doesn't |
| 158 // really matter; it's just used for a DCHECK. So we currently | 157 // really matter; it's just used for a DCHECK. So we currently |
| 159 // cheat and always say EXPLICIT_ACCESS. | 158 // cheat and always say EXPLICIT_ACCESS. |
| 160 WebDataServiceWrapper* wrapper = | 159 WebDataServiceWrapper* wrapper = |
| 161 WebDataServiceFactory::GetForProfile( | 160 WebDataServiceFactory::GetForProfile( |
| 162 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS); | 161 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS); |
| 163 if (wrapper) | 162 if (wrapper) |
| 164 return wrapper->GetTokenWebData(); | 163 return wrapper->GetTokenWebData(); |
| 165 // |wrapper| can be NULL in Incognito mode. | 164 // |wrapper| can be NULL in Incognito mode. |
| 166 return scoped_refptr<TokenWebData>(NULL); | 165 return NULL; |
| 167 } | 166 } |
| 168 | 167 |
| 169 // static | 168 // static |
| 170 scoped_refptr<WebDataService> WebDataService::FromBrowserContext( | 169 scoped_refptr<WebDataService> WebDataService::FromBrowserContext( |
| 171 content::BrowserContext* context) { | 170 content::BrowserContext* context) { |
| 172 // For this service, the implicit/explicit distinction doesn't | 171 // For this service, the implicit/explicit distinction doesn't |
| 173 // 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 |
| 174 // cheat and always say EXPLICIT_ACCESS. | 173 // cheat and always say EXPLICIT_ACCESS. |
| 175 WebDataServiceWrapper* wrapper = | 174 WebDataServiceWrapper* wrapper = |
| 176 WebDataServiceFactory::GetForProfile( | 175 WebDataServiceFactory::GetForProfile( |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 } | 222 } |
| 224 | 223 |
| 225 BrowserContextKeyedService* WebDataServiceFactory::BuildServiceInstanceFor( | 224 BrowserContextKeyedService* WebDataServiceFactory::BuildServiceInstanceFor( |
| 226 content::BrowserContext* profile) const { | 225 content::BrowserContext* profile) const { |
| 227 return new WebDataServiceWrapper(static_cast<Profile*>(profile)); | 226 return new WebDataServiceWrapper(static_cast<Profile*>(profile)); |
| 228 } | 227 } |
| 229 | 228 |
| 230 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const { | 229 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const { |
| 231 return true; | 230 return true; |
| 232 } | 231 } |
| OLD | NEW |