| 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/api/webdata/web_data_service_base.h" | 5 #include "chrome/browser/api/webdata/web_data_service_base.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| 11 #include "chrome/browser/webdata/web_database_service.h" | 11 #include "chrome/browser/webdata/web_database_service.h" |
| 12 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
| 13 #ifdef DEBUG | 13 #ifdef DEBUG |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #endif | 15 #endif |
| 16 #include "content/public/browser/notification_details.h" | 16 #include "content/public/browser/notification_details.h" |
| 17 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 18 #include "content/public/browser/notification_source.h" | 18 #include "content/public/browser/notification_source.h" |
| 19 | 19 |
| 20 //////////////////////////////////////////////////////////////////////////////// | 20 //////////////////////////////////////////////////////////////////////////////// |
| 21 // | 21 // |
| 22 // WebDataServiceBase implementation. | 22 // WebDataServiceBase implementation. |
| 23 // | 23 // |
| 24 //////////////////////////////////////////////////////////////////////////////// | 24 //////////////////////////////////////////////////////////////////////////////// |
| 25 | 25 |
| 26 using base::Bind; | 26 using base::Bind; |
| 27 using base::Time; | 27 using base::Time; |
| 28 using content::BrowserThread; | 28 using content::BrowserThread; |
| 29 | 29 |
| 30 WebDataServiceBase::WebDataServiceBase(const ProfileErrorCallback& callback) | 30 WebDataServiceBase::WebDataServiceBase(const base::FilePath& path, |
| 31 const ProfileErrorCallback& callback) |
| 31 : db_loaded_(false), | 32 : db_loaded_(false), |
| 33 path_(path), |
| 32 profile_error_callback_(callback) { | 34 profile_error_callback_(callback) { |
| 33 // WebDataService requires DB thread if instantiated. | 35 // WebDataService requires DB thread if instantiated. |
| 34 // Set WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile, NULL) | 36 // Set WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile, NULL) |
| 35 // if you do not want to instantiate WebDataService in your test. | 37 // if you do not want to instantiate WebDataService in your test. |
| 36 DCHECK(BrowserThread::IsWellKnownThread(BrowserThread::DB)); | 38 DCHECK(BrowserThread::IsWellKnownThread(BrowserThread::DB)); |
| 37 } | 39 } |
| 38 | 40 |
| 39 void WebDataServiceBase::ShutdownOnUIThread() { | 41 void WebDataServiceBase::ShutdownOnUIThread() { |
| 40 db_loaded_ = false; | 42 db_loaded_ = false; |
| 41 BrowserThread::PostTask( | 43 BrowserThread::PostTask( |
| 42 BrowserThread::DB, FROM_HERE, | 44 BrowserThread::DB, FROM_HERE, |
| 43 base::Bind(&WebDataServiceBase::ShutdownOnDBThread, this)); | 45 base::Bind(&WebDataServiceBase::ShutdownOnDBThread, this)); |
| 44 ShutdownDatabase(); | 46 ShutdownDatabase(); |
| 45 } | 47 } |
| 46 | 48 |
| 47 void WebDataServiceBase::Init(const base::FilePath& path) { | 49 void WebDataServiceBase::AddTable(scoped_ptr<WebDatabaseTable> table) { |
| 48 wdbs_.reset(new WebDatabaseService(path)); | 50 if (!wdbs_.get()) |
| 51 wdbs_.reset(new WebDatabaseService(path_)); |
| 52 wdbs_->AddTable(table.Pass()); |
| 53 } |
| 54 |
| 55 void WebDataServiceBase::Init() { |
| 56 DCHECK(wdbs_.get()); |
| 49 wdbs_->LoadDatabase(Bind(&WebDataServiceBase::DatabaseInitOnDB, this)); | 57 wdbs_->LoadDatabase(Bind(&WebDataServiceBase::DatabaseInitOnDB, this)); |
| 50 } | 58 } |
| 51 | 59 |
| 52 void WebDataServiceBase::UnloadDatabase() { | 60 void WebDataServiceBase::UnloadDatabase() { |
| 53 if (!wdbs_) | 61 if (!wdbs_) |
| 54 return; | 62 return; |
| 55 wdbs_->UnloadDatabase(); | 63 wdbs_->UnloadDatabase(); |
| 56 } | 64 } |
| 57 | 65 |
| 58 void WebDataServiceBase::ShutdownDatabase() { | 66 void WebDataServiceBase::ShutdownDatabase() { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 BrowserThread::PostTask( | 132 BrowserThread::PostTask( |
| 125 BrowserThread::UI, FROM_HERE, | 133 BrowserThread::UI, FROM_HERE, |
| 126 base::Bind(&WebDataServiceBase::NotifyDatabaseLoadedOnUIThread, this)); | 134 base::Bind(&WebDataServiceBase::NotifyDatabaseLoadedOnUIThread, this)); |
| 127 } else { | 135 } else { |
| 128 BrowserThread::PostTask( | 136 BrowserThread::PostTask( |
| 129 BrowserThread::UI, FROM_HERE, | 137 BrowserThread::UI, FROM_HERE, |
| 130 base::Bind(&WebDataServiceBase::DBInitFailed, this, status)); | 138 base::Bind(&WebDataServiceBase::DBInitFailed, this, status)); |
| 131 } | 139 } |
| 132 } | 140 } |
| 133 | 141 |
| OLD | NEW |