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 23 matching lines...) Expand all Loading... | |
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, Profile::ServiceAccessType access_type) { |
200 // If |access_type| starts being used for anything other than this | 185 // If |access_type| starts being used for anything other than this |
201 // DCHECK, we need to start taking it as a parameter to | 186 // DCHECK, we need to start taking it as a parameter to |
202 // AutofillWebDataService::FromBrowserContext (see above). | 187 // WebDataServiceFactory::GetAutofillWebDataForProfile (see below). |
203 DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord()); | 188 DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord()); |
204 return static_cast<WebDataServiceWrapper*>( | 189 return static_cast<WebDataServiceWrapper*>( |
205 GetInstance()->GetServiceForBrowserContext(profile, true)); | 190 GetInstance()->GetServiceForBrowserContext(profile, true)); |
206 } | 191 } |
207 | 192 |
208 // static | 193 // static |
209 WebDataServiceWrapper* WebDataServiceFactory::GetForProfileIfExists( | 194 WebDataServiceWrapper* WebDataServiceFactory::GetForProfileIfExists( |
210 Profile* profile, Profile::ServiceAccessType access_type) { | 195 Profile* profile, Profile::ServiceAccessType access_type) { |
211 // If |access_type| starts being used for anything other than this | 196 // If |access_type| starts being used for anything other than this |
212 // DCHECK, we need to start taking it as a parameter to | 197 // DCHECK, we need to start taking it as a parameter to |
213 // AutofillWebDataService::FromBrowserContext (see above). | 198 // WebDataServiceFactory::GetAutofillWebDataForProfile (see below). |
214 DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord()); | 199 DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord()); |
215 return static_cast<WebDataServiceWrapper*>( | 200 return static_cast<WebDataServiceWrapper*>( |
216 GetInstance()->GetServiceForBrowserContext(profile, false)); | 201 GetInstance()->GetServiceForBrowserContext(profile, false)); |
217 } | 202 } |
218 | 203 |
219 // static | 204 // static |
205 scoped_refptr<AutofillWebDataService> | |
206 WebDataServiceFactory::GetAutofillWebDataForProfile(Profile* profile) { | |
Peter Kasting
2013/11/15 01:30:59
Nit: Indent 4
blundell
2013/11/19 14:05:37
No indentation after return type: http://google-st
| |
207 // For this service, the implicit/explicit distinction doesn't | |
208 // really matter; it's just used for a DCHECK. So we currently | |
209 // cheat and always say EXPLICIT_ACCESS. | |
Peter Kasting
2013/11/15 01:30:59
"Just a DCHECK" sounds kind of worrisome; DCHECKs
Jói
2013/11/15 13:25:34
It would be OK to bring back the parameter and DCH
blundell
2013/11/19 14:05:37
Added in the parameter.
On 2013/11/15 13:25:34, J
| |
210 WebDataServiceWrapper* wrapper = | |
211 WebDataServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); | |
212 if (wrapper) | |
213 return wrapper->GetAutofillWebData(); | |
214 // |wrapper| can be NULL in Incognito mode. | |
215 return scoped_refptr<AutofillWebDataService>(NULL); | |
Peter Kasting
2013/11/15 01:30:59
Nit: Simpler:
// |wrapper| can be NULL in Incog
blundell
2013/11/19 14:05:37
Done.
| |
216 } | |
217 | |
218 // static | |
220 WebDataServiceFactory* WebDataServiceFactory::GetInstance() { | 219 WebDataServiceFactory* WebDataServiceFactory::GetInstance() { |
221 return Singleton<WebDataServiceFactory>::get(); | 220 return Singleton<WebDataServiceFactory>::get(); |
222 } | 221 } |
223 | 222 |
224 content::BrowserContext* WebDataServiceFactory::GetBrowserContextToUse( | 223 content::BrowserContext* WebDataServiceFactory::GetBrowserContextToUse( |
225 content::BrowserContext* context) const { | 224 content::BrowserContext* context) const { |
226 return chrome::GetBrowserContextRedirectedInIncognito(context); | 225 return chrome::GetBrowserContextRedirectedInIncognito(context); |
227 } | 226 } |
228 | 227 |
229 BrowserContextKeyedService* WebDataServiceFactory::BuildServiceInstanceFor( | 228 BrowserContextKeyedService* WebDataServiceFactory::BuildServiceInstanceFor( |
230 content::BrowserContext* profile) const { | 229 content::BrowserContext* profile) const { |
231 return new WebDataServiceWrapper(static_cast<Profile*>(profile)); | 230 return new WebDataServiceWrapper(static_cast<Profile*>(profile)); |
232 } | 231 } |
233 | 232 |
234 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const { | 233 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const { |
235 return true; | 234 return true; |
236 } | 235 } |
OLD | NEW |