| 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/profile_dependency_manager.h" | 10 #include "chrome/browser/profiles/profile_dependency_manager.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 scoped_refptr<AutofillWebDataService> | 111 scoped_refptr<AutofillWebDataService> |
| 112 WebDataServiceWrapper::GetAutofillWebData() { | 112 WebDataServiceWrapper::GetAutofillWebData() { |
| 113 return autofill_web_data_.get(); | 113 return autofill_web_data_.get(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 scoped_refptr<WebDataService> WebDataServiceWrapper::GetWebData() { | 116 scoped_refptr<WebDataService> WebDataServiceWrapper::GetWebData() { |
| 117 return web_data_.get(); | 117 return web_data_.get(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 // static | 120 // static |
| 121 scoped_refptr<WebDataService> |
| 122 WebDataServiceFactory::GetWebDataServiceForProfile( |
| 123 Profile* profile) { |
| 124 // For this service, the implicit/explicit distinction doesn't |
| 125 // really matter; it's just used for a DCHECK. So we currently |
| 126 // cheat and always say EXPLICIT_ACCESS. |
| 127 WebDataServiceWrapper* wds_wrapper = |
| 128 WebDataServiceFactory::GetForProfile( |
| 129 profile, Profile::EXPLICIT_ACCESS, true); |
| 130 if (wds_wrapper) |
| 131 return wds_wrapper->GetWebData(); |
| 132 return NULL; |
| 133 } |
| 134 |
| 135 // static |
| 136 scoped_refptr<WebDataService> |
| 137 WebDataServiceFactory::GetWebDataServiceForProfileIfExists(Profile* profile) { |
| 138 // For this service, the implicit/explicit distinction doesn't |
| 139 // really matter; it's just used for a DCHECK. So we currently |
| 140 // cheat and always say EXPLICIT_ACCESS. |
| 141 WebDataServiceWrapper* wds_wrapper = |
| 142 WebDataServiceFactory::GetForProfile( |
| 143 profile, Profile::EXPLICIT_ACCESS, false); |
| 144 if (wds_wrapper) |
| 145 return wds_wrapper->GetWebData(); |
| 146 return NULL; |
| 147 } |
| 148 |
| 149 // static |
| 121 scoped_refptr<AutofillWebDataService> | 150 scoped_refptr<AutofillWebDataService> |
| 122 AutofillWebDataService::FromBrowserContext(content::BrowserContext* context) { | 151 WebDataServiceFactory::GetAutofillWebDataServiceForProfile(Profile* profile) { |
| 123 // For this service, the implicit/explicit distinction doesn't | 152 // For this service, the implicit/explicit distinction doesn't |
| 124 // really matter; it's just used for a DCHECK. So we currently | 153 // really matter; it's just used for a DCHECK. So we currently |
| 125 // cheat and always say EXPLICIT_ACCESS. | 154 // cheat and always say EXPLICIT_ACCESS. |
| 126 WebDataServiceWrapper* wrapper = | 155 WebDataServiceWrapper* wds_wrapper = |
| 127 WebDataServiceFactory::GetForProfile( | 156 WebDataServiceFactory::GetForProfile( |
| 128 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS); | 157 profile, Profile::EXPLICIT_ACCESS, true); |
| 129 if (wrapper) | 158 if (wds_wrapper) |
| 130 return wrapper->GetAutofillWebData(); | 159 return wds_wrapper->GetAutofillWebData(); |
| 131 // |wrapper| can be NULL in Incognito mode. | 160 return NULL; |
| 132 return scoped_refptr<AutofillWebDataService>(NULL); | |
| 133 } | |
| 134 | |
| 135 // static | |
| 136 scoped_refptr<WebDataService> WebDataService::FromBrowserContext( | |
| 137 content::BrowserContext* context) { | |
| 138 // For this service, the implicit/explicit distinction doesn't | |
| 139 // really matter; it's just used for a DCHECK. So we currently | |
| 140 // cheat and always say EXPLICIT_ACCESS. | |
| 141 WebDataServiceWrapper* wrapper = | |
| 142 WebDataServiceFactory::GetForProfile( | |
| 143 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS); | |
| 144 if (wrapper) | |
| 145 return wrapper->GetWebData(); | |
| 146 // |wrapper| can be NULL in Incognito mode. | |
| 147 return scoped_refptr<WebDataService>(NULL); | |
| 148 } | 161 } |
| 149 | 162 |
| 150 WebDataServiceFactory::WebDataServiceFactory() | 163 WebDataServiceFactory::WebDataServiceFactory() |
| 151 : ProfileKeyedServiceFactory("WebDataService", | 164 : ProfileKeyedServiceFactory("WebDataService", |
| 152 ProfileDependencyManager::GetInstance()) { | 165 ProfileDependencyManager::GetInstance()) { |
| 153 // WebDataServiceFactory has no dependecies. | 166 // WebDataServiceFactory has no dependecies. |
| 154 } | 167 } |
| 155 | 168 |
| 156 WebDataServiceFactory::~WebDataServiceFactory() {} | 169 WebDataServiceFactory::~WebDataServiceFactory() {} |
| 157 | 170 |
| 158 // static | 171 // static |
| 159 WebDataServiceWrapper* WebDataServiceFactory::GetForProfile( | |
| 160 Profile* profile, Profile::ServiceAccessType access_type) { | |
| 161 // If |access_type| starts being used for anything other than this | |
| 162 // DCHECK, we need to start taking it as a parameter to | |
| 163 // AutofillWebDataService::FromBrowserContext (see above). | |
| 164 DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord()); | |
| 165 return static_cast<WebDataServiceWrapper*>( | |
| 166 GetInstance()->GetServiceForProfile(profile, true)); | |
| 167 } | |
| 168 | |
| 169 // static | |
| 170 WebDataServiceWrapper* WebDataServiceFactory::GetForProfileIfExists( | |
| 171 Profile* profile, Profile::ServiceAccessType access_type) { | |
| 172 // If |access_type| starts being used for anything other than this | |
| 173 // DCHECK, we need to start taking it as a parameter to | |
| 174 // AutofillWebDataService::FromBrowserContext (see above). | |
| 175 DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord()); | |
| 176 return static_cast<WebDataServiceWrapper*>( | |
| 177 GetInstance()->GetServiceForProfile(profile, false)); | |
| 178 } | |
| 179 | |
| 180 // static | |
| 181 WebDataServiceFactory* WebDataServiceFactory::GetInstance() { | 172 WebDataServiceFactory* WebDataServiceFactory::GetInstance() { |
| 182 return Singleton<WebDataServiceFactory>::get(); | 173 return Singleton<WebDataServiceFactory>::get(); |
| 183 } | 174 } |
| 184 | 175 |
| 176 // static |
| 177 WebDataServiceWrapper* WebDataServiceFactory::GetForProfile( |
| 178 Profile* profile, |
| 179 Profile::ServiceAccessType access_type, |
| 180 bool create_if_not_exist) { |
| 181 // If |access_type| starts being used for anything other than this DCHECK, we |
| 182 // need to start taking it as a parameter to GetXXXForProfile functions (see |
| 183 // above). |
| 184 DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord()); |
| 185 return static_cast<WebDataServiceWrapper*>( |
| 186 GetInstance()->GetServiceForProfile(profile, create_if_not_exist)); |
| 187 } |
| 188 |
| 185 bool WebDataServiceFactory::ServiceRedirectedInIncognito() const { | 189 bool WebDataServiceFactory::ServiceRedirectedInIncognito() const { |
| 186 return true; | 190 return true; |
| 187 } | 191 } |
| 188 | 192 |
| 189 ProfileKeyedService* | 193 ProfileKeyedService* |
| 190 WebDataServiceFactory::BuildServiceInstanceFor(Profile* profile) const { | 194 WebDataServiceFactory::BuildServiceInstanceFor(Profile* profile) const { |
| 191 return new WebDataServiceWrapper(profile); | 195 return new WebDataServiceWrapper(profile); |
| 192 } | 196 } |
| 193 | 197 |
| 194 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const { | 198 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const { |
| 195 return true; | 199 return true; |
| 196 } | 200 } |
| OLD | NEW |