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" |
| 11 #include "chrome/browser/webdata/autocomplete_syncable_service.h" |
| 12 #include "chrome/browser/webdata/autofill_profile_syncable_service.h" |
11 #include "chrome/browser/webdata/autofill_web_data_service_impl.h" | 13 #include "chrome/browser/webdata/autofill_web_data_service_impl.h" |
12 #include "chrome/common/chrome_constants.h" | 14 #include "chrome/common/chrome_constants.h" |
| 15 #include "content/public/browser/browser_thread.h" |
13 #include "grit/chromium_strings.h" | 16 #include "grit/chromium_strings.h" |
14 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
15 | 18 |
| 19 using content::BrowserThread; |
| 20 |
16 namespace { | 21 namespace { |
17 | 22 |
18 // Callback to show error dialog on profile load error. | 23 // Callback to show error dialog on profile load error. |
19 void ProfileErrorCallback(sql::InitStatus status) { | 24 void ProfileErrorCallback(sql::InitStatus status) { |
20 ShowProfileErrorDialog( | 25 ShowProfileErrorDialog( |
21 (status == sql::INIT_FAILURE) ? | 26 (status == sql::INIT_FAILURE) ? |
22 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR); | 27 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR); |
23 } | 28 } |
24 | 29 |
| 30 void InitSyncableServicesOnDBThread(scoped_refptr<WebDataService> web_data) { |
| 31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 32 |
| 33 // Currently only Autocomplete and Autofill profiles use the new Sync API, but |
| 34 // all the database data should migrate to this API over time. |
| 35 AutocompleteSyncableService::CreateForWebDataService(web_data); |
| 36 AutofillProfileSyncableService::CreateForWebDataService(web_data); |
| 37 } |
| 38 |
25 } // namespace | 39 } // namespace |
26 | 40 |
27 WebDataServiceWrapper::WebDataServiceWrapper(Profile* profile){ | 41 WebDataServiceWrapper::WebDataServiceWrapper(Profile* profile) { |
28 base::FilePath path = profile->GetPath(); | 42 base::FilePath path = profile->GetPath(); |
29 path = path.Append(chrome::kWebDataFilename); | 43 path = path.Append(chrome::kWebDataFilename); |
30 web_data_service_ = new WebDataService(base::Bind(&ProfileErrorCallback)); | 44 web_data_service_ = new WebDataService(base::Bind(&ProfileErrorCallback)); |
31 web_data_service_->Init(path); | 45 web_data_service_->Init(path); |
| 46 |
| 47 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 48 base::Bind(&InitSyncableServicesOnDBThread, |
| 49 web_data_service_)); |
32 } | 50 } |
33 | 51 |
34 // For testing. | 52 // For testing. |
35 WebDataServiceWrapper::WebDataServiceWrapper() { | 53 WebDataServiceWrapper::WebDataServiceWrapper() { |
36 } | 54 } |
37 | 55 |
38 WebDataServiceWrapper::~WebDataServiceWrapper() { | 56 WebDataServiceWrapper::~WebDataServiceWrapper() { |
39 web_data_service_ = NULL; | 57 web_data_service_ = NULL; |
40 } | 58 } |
41 | 59 |
42 void WebDataServiceWrapper::Shutdown() { | 60 void WebDataServiceWrapper::Shutdown() { |
43 web_data_service_->ShutdownOnUIThread(); | 61 web_data_service_->ShutdownOnUIThread(); |
44 } | 62 } |
45 | 63 |
46 scoped_refptr<WebDataService> WebDataServiceWrapper::GetWebData() { | 64 scoped_refptr<WebDataService> WebDataServiceWrapper::GetWebData() { |
47 return web_data_service_.get(); | 65 return web_data_service_.get(); |
48 } | 66 } |
49 | 67 |
50 // static | 68 // static |
51 scoped_refptr<AutofillWebDataService> AutofillWebDataService::FromBrowserContext
( | 69 scoped_refptr<AutofillWebDataService> |
52 content::BrowserContext* context) { | 70 AutofillWebDataService::FromBrowserContext(content::BrowserContext* context) { |
53 // For this service, the implicit/explicit distinction doesn't | 71 // For this service, the implicit/explicit distinction doesn't |
54 // really matter; it's just used for a DCHECK. So we currently | 72 // really matter; it's just used for a DCHECK. So we currently |
55 // cheat and always say EXPLICIT_ACCESS. | 73 // cheat and always say EXPLICIT_ACCESS. |
56 scoped_refptr<WebDataService> service = WebDataServiceFactory::GetForProfile( | 74 scoped_refptr<WebDataService> service = WebDataServiceFactory::GetForProfile( |
57 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS); | 75 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS); |
58 | 76 |
59 if (service.get()) { | 77 if (service.get()) { |
60 return scoped_refptr<AutofillWebDataService>( | 78 return scoped_refptr<AutofillWebDataService>( |
61 new AutofillWebDataServiceImpl(service)); | 79 new AutofillWebDataServiceImpl(service)); |
62 } else { | 80 } else { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 } | 143 } |
126 | 144 |
127 ProfileKeyedService* | 145 ProfileKeyedService* |
128 WebDataServiceFactory::BuildServiceInstanceFor(Profile* profile) const { | 146 WebDataServiceFactory::BuildServiceInstanceFor(Profile* profile) const { |
129 return new WebDataServiceWrapper(profile); | 147 return new WebDataServiceWrapper(profile); |
130 } | 148 } |
131 | 149 |
132 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const { | 150 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const { |
133 return true; | 151 return true; |
134 } | 152 } |
OLD | NEW |