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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 134 |
135 scoped_refptr<WebDataService> WebDataServiceWrapper::GetWebData() { | 135 scoped_refptr<WebDataService> WebDataServiceWrapper::GetWebData() { |
136 return web_data_.get(); | 136 return web_data_.get(); |
137 } | 137 } |
138 | 138 |
139 scoped_refptr<TokenWebData> WebDataServiceWrapper::GetTokenWebData() { | 139 scoped_refptr<TokenWebData> WebDataServiceWrapper::GetTokenWebData() { |
140 return token_web_data_.get(); | 140 return token_web_data_.get(); |
141 } | 141 } |
142 | 142 |
143 // static | 143 // static |
144 scoped_refptr<AutofillWebDataService> | |
145 AutofillWebDataService::FromBrowserContext(content::BrowserContext* context) { | |
146 // For this service, the implicit/explicit distinction doesn't | |
147 // really matter; it's just used for a DCHECK. So we currently | |
148 // cheat and always say EXPLICIT_ACCESS. | |
149 WebDataServiceWrapper* wrapper = | |
150 WebDataServiceFactory::GetForProfile( | |
151 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS); | |
152 if (wrapper) | |
153 return wrapper->GetAutofillWebData(); | |
154 // |wrapper| can be NULL in Incognito mode. | |
155 return scoped_refptr<AutofillWebDataService>(NULL); | |
156 } | |
157 | |
158 // static | |
159 scoped_refptr<TokenWebData> TokenWebData::FromBrowserContext( | 144 scoped_refptr<TokenWebData> TokenWebData::FromBrowserContext( |
160 content::BrowserContext* context) { | 145 content::BrowserContext* context) { |
161 // For this service, the implicit/explicit distinction doesn't | 146 // For this service, the implicit/explicit distinction doesn't |
162 // really matter; it's just used for a DCHECK. So we currently | 147 // really matter; it's just used for a DCHECK. So we currently |
163 // cheat and always say EXPLICIT_ACCESS. | 148 // cheat and always say EXPLICIT_ACCESS. |
164 WebDataServiceWrapper* wrapper = | 149 WebDataServiceWrapper* wrapper = |
165 WebDataServiceFactory::GetForProfile( | 150 WebDataServiceFactory::GetForProfile( |
166 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS); | 151 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS); |
167 if (wrapper) | 152 if (wrapper) |
168 return wrapper->GetTokenWebData(); | 153 return wrapper->GetTokenWebData(); |
(...skipping 20 matching lines...) Expand all Loading... |
189 : BrowserContextKeyedServiceFactory( | 174 : BrowserContextKeyedServiceFactory( |
190 "WebDataService", | 175 "WebDataService", |
191 BrowserContextDependencyManager::GetInstance()) { | 176 BrowserContextDependencyManager::GetInstance()) { |
192 // WebDataServiceFactory has no dependecies. | 177 // WebDataServiceFactory has no dependecies. |
193 } | 178 } |
194 | 179 |
195 WebDataServiceFactory::~WebDataServiceFactory() {} | 180 WebDataServiceFactory::~WebDataServiceFactory() {} |
196 | 181 |
197 // static | 182 // static |
198 WebDataServiceWrapper* WebDataServiceFactory::GetForProfile( | 183 WebDataServiceWrapper* WebDataServiceFactory::GetForProfile( |
199 Profile* profile, Profile::ServiceAccessType access_type) { | 184 Profile* profile, |
| 185 Profile::ServiceAccessType access_type) { |
200 // If |access_type| starts being used for anything other than this | 186 // If |access_type| starts being used for anything other than this |
201 // DCHECK, we need to start taking it as a parameter to | 187 // DCHECK, we need to start taking it as a parameter to |
202 // AutofillWebDataService::FromBrowserContext (see above). | 188 // the *WebDataService::FromBrowserContext() functions (see above). |
203 DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord()); | 189 DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord()); |
204 return static_cast<WebDataServiceWrapper*>( | 190 return static_cast<WebDataServiceWrapper*>( |
205 GetInstance()->GetServiceForBrowserContext(profile, true)); | 191 GetInstance()->GetServiceForBrowserContext(profile, true)); |
206 } | 192 } |
207 | 193 |
208 // static | 194 // static |
209 WebDataServiceWrapper* WebDataServiceFactory::GetForProfileIfExists( | 195 WebDataServiceWrapper* WebDataServiceFactory::GetForProfileIfExists( |
210 Profile* profile, Profile::ServiceAccessType access_type) { | 196 Profile* profile, |
| 197 Profile::ServiceAccessType access_type) { |
211 // If |access_type| starts being used for anything other than this | 198 // If |access_type| starts being used for anything other than this |
212 // DCHECK, we need to start taking it as a parameter to | 199 // DCHECK, we need to start taking it as a parameter to |
213 // AutofillWebDataService::FromBrowserContext (see above). | 200 // the *WebDataService::FromBrowserContext() functions (see above). |
214 DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord()); | 201 DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord()); |
215 return static_cast<WebDataServiceWrapper*>( | 202 return static_cast<WebDataServiceWrapper*>( |
216 GetInstance()->GetServiceForBrowserContext(profile, false)); | 203 GetInstance()->GetServiceForBrowserContext(profile, false)); |
217 } | 204 } |
218 | 205 |
219 // static | 206 // static |
| 207 scoped_refptr<AutofillWebDataService> |
| 208 WebDataServiceFactory::GetAutofillWebDataForProfile( |
| 209 Profile* profile, |
| 210 Profile::ServiceAccessType access_type) { |
| 211 WebDataServiceWrapper* wrapper = |
| 212 WebDataServiceFactory::GetForProfile(profile, access_type); |
| 213 // |wrapper| can be NULL in Incognito mode. |
| 214 return wrapper ? |
| 215 wrapper->GetAutofillWebData() : |
| 216 scoped_refptr<AutofillWebDataService>(NULL); |
| 217 } |
| 218 |
| 219 // static |
220 WebDataServiceFactory* WebDataServiceFactory::GetInstance() { | 220 WebDataServiceFactory* WebDataServiceFactory::GetInstance() { |
221 return Singleton<WebDataServiceFactory>::get(); | 221 return Singleton<WebDataServiceFactory>::get(); |
222 } | 222 } |
223 | 223 |
224 content::BrowserContext* WebDataServiceFactory::GetBrowserContextToUse( | 224 content::BrowserContext* WebDataServiceFactory::GetBrowserContextToUse( |
225 content::BrowserContext* context) const { | 225 content::BrowserContext* context) const { |
226 return chrome::GetBrowserContextRedirectedInIncognito(context); | 226 return chrome::GetBrowserContextRedirectedInIncognito(context); |
227 } | 227 } |
228 | 228 |
229 BrowserContextKeyedService* WebDataServiceFactory::BuildServiceInstanceFor( | 229 BrowserContextKeyedService* WebDataServiceFactory::BuildServiceInstanceFor( |
230 content::BrowserContext* profile) const { | 230 content::BrowserContext* profile) const { |
231 return new WebDataServiceWrapper(static_cast<Profile*>(profile)); | 231 return new WebDataServiceWrapper(static_cast<Profile*>(profile)); |
232 } | 232 } |
233 | 233 |
234 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const { | 234 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const { |
235 return true; | 235 return true; |
236 } | 236 } |
OLD | NEW |