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