| 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() {} | 41 WebDataServiceWrapper::WebDataServiceWrapper() {} |
| 28 | 42 |
| 29 WebDataServiceWrapper::WebDataServiceWrapper(Profile* profile) { | 43 WebDataServiceWrapper::WebDataServiceWrapper(Profile* profile) { |
| 30 base::FilePath path = profile->GetPath(); | 44 base::FilePath path = profile->GetPath(); |
| 31 path = path.Append(chrome::kWebDataFilename); | 45 path = path.Append(chrome::kWebDataFilename); |
| 32 web_data_service_ = new WebDataService(base::Bind(&ProfileErrorCallback)); | 46 web_data_service_ = new WebDataService(base::Bind(&ProfileErrorCallback)); |
| 33 web_data_service_->Init(path); | 47 web_data_service_->Init(path); |
| 48 |
| 49 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 50 base::Bind(&InitSyncableServicesOnDBThread, |
| 51 web_data_service_)); |
| 34 } | 52 } |
| 35 | 53 |
| 36 WebDataServiceWrapper::~WebDataServiceWrapper() { | 54 WebDataServiceWrapper::~WebDataServiceWrapper() { |
| 37 } | 55 } |
| 38 | 56 |
| 39 void WebDataServiceWrapper::Shutdown() { | 57 void WebDataServiceWrapper::Shutdown() { |
| 40 web_data_service_->ShutdownOnUIThread(); | 58 web_data_service_->ShutdownOnUIThread(); |
| 41 web_data_service_ = NULL; | 59 web_data_service_ = NULL; |
| 42 } | 60 } |
| 43 | 61 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } | 141 } |
| 124 | 142 |
| 125 ProfileKeyedService* | 143 ProfileKeyedService* |
| 126 WebDataServiceFactory::BuildServiceInstanceFor(Profile* profile) const { | 144 WebDataServiceFactory::BuildServiceInstanceFor(Profile* profile) const { |
| 127 return new WebDataServiceWrapper(profile); | 145 return new WebDataServiceWrapper(profile); |
| 128 } | 146 } |
| 129 | 147 |
| 130 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const { | 148 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const { |
| 131 return true; | 149 return true; |
| 132 } | 150 } |
| OLD | NEW |