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/web_data_service_factory.h" | 5 #include "chrome/browser/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 "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/profiles/incognito_helpers.h" | 12 #include "chrome/browser/profiles/incognito_helpers.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/profiles/sql_init_error_message_ids.h" | 14 #include "chrome/browser/profiles/sql_init_error_message_ids.h" |
15 #include "chrome/browser/sync/glue/sync_start_util.h" | 15 #include "chrome/browser/sync/glue/sync_start_util.h" |
16 #include "chrome/browser/ui/profile_error_dialog.h" | 16 #include "chrome/browser/ui/profile_error_dialog.h" |
17 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 17 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
18 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 18 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
19 #include "components/search_engines/keyword_web_data_service.h" | 19 #include "components/search_engines/keyword_web_data_service.h" |
20 #include "components/signin/core/browser/webdata/token_web_data.h" | 20 #include "components/signin/core/browser/webdata/token_web_data.h" |
21 #include "components/webdata_services/web_data_service_wrapper.h" | 21 #include "components/webdata_services/web_data_service_wrapper.h" |
22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
23 | 23 |
24 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
25 #include "components/password_manager/core/browser/webdata/password_web_data_ser
vice_win.h" | 25 #include "components/password_manager/core/browser/webdata/password_web_data_ser
vice_win.h" |
26 #endif | 26 #endif |
27 | 27 |
| 28 #if defined(OS_ANDROID) |
| 29 #include "components/payments/android/payment_manifest_web_data_service.h" |
| 30 #endif |
| 31 |
28 using content::BrowserThread; | 32 using content::BrowserThread; |
29 | 33 |
30 namespace { | 34 namespace { |
31 | 35 |
32 // Converts a WebDataServiceWrapper::ErrorType to ProfileErrorType. | 36 // Converts a WebDataServiceWrapper::ErrorType to ProfileErrorType. |
33 ProfileErrorType ProfileErrorFromWebDataServiceWrapperError( | 37 ProfileErrorType ProfileErrorFromWebDataServiceWrapperError( |
34 WebDataServiceWrapper::ErrorType error_type) { | 38 WebDataServiceWrapper::ErrorType error_type) { |
35 switch (error_type) { | 39 switch (error_type) { |
36 case WebDataServiceWrapper::ERROR_LOADING_AUTOFILL: | 40 case WebDataServiceWrapper::ERROR_LOADING_AUTOFILL: |
37 return ProfileErrorType::DB_AUTOFILL_WEB_DATA; | 41 return ProfileErrorType::DB_AUTOFILL_WEB_DATA; |
38 | 42 |
39 case WebDataServiceWrapper::ERROR_LOADING_KEYWORD: | 43 case WebDataServiceWrapper::ERROR_LOADING_KEYWORD: |
40 return ProfileErrorType::DB_KEYWORD_WEB_DATA; | 44 return ProfileErrorType::DB_KEYWORD_WEB_DATA; |
41 | 45 |
42 case WebDataServiceWrapper::ERROR_LOADING_TOKEN: | 46 case WebDataServiceWrapper::ERROR_LOADING_TOKEN: |
43 return ProfileErrorType::DB_TOKEN_WEB_DATA; | 47 return ProfileErrorType::DB_TOKEN_WEB_DATA; |
44 | 48 |
45 case WebDataServiceWrapper::ERROR_LOADING_PASSWORD: | 49 case WebDataServiceWrapper::ERROR_LOADING_PASSWORD: |
46 return ProfileErrorType::DB_WEB_DATA; | 50 return ProfileErrorType::DB_WEB_DATA; |
47 | 51 |
| 52 case WebDataServiceWrapper::ERROR_LOADING_PAYMENT_MANIFEST: |
| 53 return ProfileErrorType::DB_PAYMENT_MANIFEST_WEB_DATA; |
| 54 |
48 default: | 55 default: |
49 NOTREACHED() | 56 NOTREACHED() |
50 << "Unknown WebDataServiceWrapper::ErrorType: " << error_type; | 57 << "Unknown WebDataServiceWrapper::ErrorType: " << error_type; |
51 return ProfileErrorType::DB_WEB_DATA; | 58 return ProfileErrorType::DB_WEB_DATA; |
52 } | 59 } |
53 } | 60 } |
54 | 61 |
55 // Callback to show error dialog on profile load error. | 62 // Callback to show error dialog on profile load error. |
56 void ProfileErrorCallback(WebDataServiceWrapper::ErrorType error_type, | 63 void ProfileErrorCallback(WebDataServiceWrapper::ErrorType error_type, |
57 sql::InitStatus status, | 64 sql::InitStatus status, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 ServiceAccessType access_type) { | 150 ServiceAccessType access_type) { |
144 WebDataServiceWrapper* wrapper = | 151 WebDataServiceWrapper* wrapper = |
145 WebDataServiceFactory::GetForProfile(profile, access_type); | 152 WebDataServiceFactory::GetForProfile(profile, access_type); |
146 // |wrapper| can be null in Incognito mode. | 153 // |wrapper| can be null in Incognito mode. |
147 return wrapper ? | 154 return wrapper ? |
148 wrapper->GetPasswordWebData() : | 155 wrapper->GetPasswordWebData() : |
149 scoped_refptr<PasswordWebDataService>(nullptr); | 156 scoped_refptr<PasswordWebDataService>(nullptr); |
150 } | 157 } |
151 #endif | 158 #endif |
152 | 159 |
| 160 #if defined(OS_ANDROID) |
| 161 // static |
| 162 scoped_refptr<payments::PaymentManifestWebDataService> |
| 163 WebDataServiceFactory::GetPaymentManifestWebDataForProfile( |
| 164 Profile* profile, |
| 165 ServiceAccessType access_type) { |
| 166 WebDataServiceWrapper* wrapper = |
| 167 WebDataServiceFactory::GetForProfile(profile, access_type); |
| 168 // |wrapper| can be null in Incognito mode. |
| 169 return wrapper |
| 170 ? wrapper->GetPaymentManifestWebData() |
| 171 : scoped_refptr<payments::PaymentManifestWebDataService>(nullptr); |
| 172 } |
| 173 #endif |
| 174 |
153 // static | 175 // static |
154 WebDataServiceFactory* WebDataServiceFactory::GetInstance() { | 176 WebDataServiceFactory* WebDataServiceFactory::GetInstance() { |
155 return base::Singleton<WebDataServiceFactory>::get(); | 177 return base::Singleton<WebDataServiceFactory>::get(); |
156 } | 178 } |
157 | 179 |
158 content::BrowserContext* WebDataServiceFactory::GetBrowserContextToUse( | 180 content::BrowserContext* WebDataServiceFactory::GetBrowserContextToUse( |
159 content::BrowserContext* context) const { | 181 content::BrowserContext* context) const { |
160 return chrome::GetBrowserContextRedirectedInIncognito(context); | 182 return chrome::GetBrowserContextRedirectedInIncognito(context); |
161 } | 183 } |
162 | 184 |
163 KeyedService* WebDataServiceFactory::BuildServiceInstanceFor( | 185 KeyedService* WebDataServiceFactory::BuildServiceInstanceFor( |
164 content::BrowserContext* context) const { | 186 content::BrowserContext* context) const { |
165 const base::FilePath& profile_path = context->GetPath(); | 187 const base::FilePath& profile_path = context->GetPath(); |
166 return new WebDataServiceWrapper( | 188 return new WebDataServiceWrapper( |
167 profile_path, g_browser_process->GetApplicationLocale(), | 189 profile_path, g_browser_process->GetApplicationLocale(), |
168 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), | 190 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), |
169 BrowserThread::GetTaskRunnerForThread(BrowserThread::DB), | 191 BrowserThread::GetTaskRunnerForThread(BrowserThread::DB), |
170 sync_start_util::GetFlareForSyncableService(profile_path), | 192 sync_start_util::GetFlareForSyncableService(profile_path), |
171 &ProfileErrorCallback); | 193 &ProfileErrorCallback); |
172 } | 194 } |
173 | 195 |
174 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const { | 196 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const { |
175 return true; | 197 return true; |
176 } | 198 } |
OLD | NEW |