| 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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 //////////////////////////////////////////////////////////////////////////////// | 22 //////////////////////////////////////////////////////////////////////////////// |
| 23 // | 23 // |
| 24 // WebDataServiceBase implementation. | 24 // WebDataServiceBase implementation. |
| 25 // | 25 // |
| 26 //////////////////////////////////////////////////////////////////////////////// | 26 //////////////////////////////////////////////////////////////////////////////// |
| 27 | 27 |
| 28 using base::Bind; | 28 using base::Bind; |
| 29 using base::Time; | 29 using base::Time; |
| 30 using content::BrowserThread; | 30 using content::BrowserThread; |
| 31 | 31 |
| 32 WebDataServiceBase::WebDataServiceBase(const ProfileErrorCallback& callback) | 32 WebDataServiceBase::WebDataServiceBase(scoped_refptr<WebDatabaseService> wdbs, |
| 33 : db_loaded_(false), | 33 const ProfileErrorCallback& callback) |
| 34 : wdbs_(wdbs), |
| 35 db_loaded_(false), |
| 34 profile_error_callback_(callback) { | 36 profile_error_callback_(callback) { |
| 35 // WebDataService requires DB thread if instantiated. | 37 // WebDataService requires DB thread if instantiated. |
| 36 // Set WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile, NULL) | 38 // Set WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile, NULL) |
| 37 // if you do not want to instantiate WebDataService in your test. | 39 // if you do not want to instantiate WebDataService in your test. |
| 38 DCHECK(BrowserThread::IsWellKnownThread(BrowserThread::DB)); | 40 DCHECK(BrowserThread::IsWellKnownThread(BrowserThread::DB)); |
| 39 } | 41 } |
| 40 | 42 |
| 41 void WebDataServiceBase::ShutdownOnUIThread() { | 43 void WebDataServiceBase::ShutdownOnUIThread() { |
| 42 db_loaded_ = false; | 44 db_loaded_ = false; |
| 43 BrowserThread::PostTask( | 45 BrowserThread::PostTask( |
| 44 BrowserThread::DB, FROM_HERE, | 46 BrowserThread::DB, FROM_HERE, |
| 45 base::Bind(&WebDataServiceBase::ShutdownOnDBThread, this)); | 47 base::Bind(&WebDataServiceBase::ShutdownOnDBThread, this)); |
| 46 ShutdownDatabase(); | |
| 47 } | 48 } |
| 48 | 49 |
| 49 void WebDataServiceBase::Init(const base::FilePath& path) { | 50 void WebDataServiceBase::AddTable(scoped_ptr<WebDatabaseTable> table) { |
| 50 wdbs_.reset(new WebDatabaseService(path)); | 51 DCHECK(wdbs_.get()); |
| 52 wdbs_->AddTable(table.Pass()); |
| 53 } |
| 54 |
| 55 void WebDataServiceBase::Init() { |
| 56 DCHECK(wdbs_.get()); |
| 51 wdbs_->LoadDatabase(Bind(&WebDataServiceBase::DatabaseInitOnDB, this)); | 57 wdbs_->LoadDatabase(Bind(&WebDataServiceBase::DatabaseInitOnDB, this)); |
| 52 } | 58 } |
| 53 | 59 |
| 54 void WebDataServiceBase::UnloadDatabase() { | 60 void WebDataServiceBase::UnloadDatabase() { |
| 55 if (!wdbs_) | 61 if (!wdbs_) |
| 56 return; | 62 return; |
| 57 wdbs_->UnloadDatabase(); | 63 wdbs_->UnloadDatabase(); |
| 58 } | 64 } |
| 59 | 65 |
| 60 void WebDataServiceBase::ShutdownDatabase() { | 66 void WebDataServiceBase::ShutdownDatabase() { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 85 | 91 |
| 86 base::SupportsUserData* WebDataServiceBase::GetDBUserData() { | 92 base::SupportsUserData* WebDataServiceBase::GetDBUserData() { |
| 87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 88 if (!db_thread_user_data_) | 94 if (!db_thread_user_data_) |
| 89 db_thread_user_data_.reset(new SupportsUserDataAggregatable()); | 95 db_thread_user_data_.reset(new SupportsUserDataAggregatable()); |
| 90 return db_thread_user_data_.get(); | 96 return db_thread_user_data_.get(); |
| 91 } | 97 } |
| 92 | 98 |
| 93 WebDataServiceBase::~WebDataServiceBase() { | 99 WebDataServiceBase::~WebDataServiceBase() { |
| 94 DCHECK(!db_thread_user_data_.get()) << "Forgot to call ShutdownOnUIThread?"; | 100 DCHECK(!db_thread_user_data_.get()) << "Forgot to call ShutdownOnUIThread?"; |
| 95 wdbs_.reset(); | |
| 96 } | 101 } |
| 97 | 102 |
| 98 void WebDataServiceBase::ShutdownOnDBThread() { | 103 void WebDataServiceBase::ShutdownOnDBThread() { |
| 99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 100 db_thread_user_data_.reset(); | 105 db_thread_user_data_.reset(); |
| 101 } | 106 } |
| 102 | 107 |
| 103 //////////////////////////////////////////////////////////////////////////////// | 108 //////////////////////////////////////////////////////////////////////////////// |
| 104 // | 109 // |
| 105 // The following methods are executed on the DB thread. | 110 // The following methods are executed on the DB thread. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 126 BrowserThread::PostTask( | 131 BrowserThread::PostTask( |
| 127 BrowserThread::UI, FROM_HERE, | 132 BrowserThread::UI, FROM_HERE, |
| 128 base::Bind(&WebDataServiceBase::NotifyDatabaseLoadedOnUIThread, this)); | 133 base::Bind(&WebDataServiceBase::NotifyDatabaseLoadedOnUIThread, this)); |
| 129 } else { | 134 } else { |
| 130 BrowserThread::PostTask( | 135 BrowserThread::PostTask( |
| 131 BrowserThread::UI, FROM_HERE, | 136 BrowserThread::UI, FROM_HERE, |
| 132 base::Bind(&WebDataServiceBase::DBInitFailed, this, status)); | 137 base::Bind(&WebDataServiceBase::DBInitFailed, this, status)); |
| 133 } | 138 } |
| 134 } | 139 } |
| 135 | 140 |
| OLD | NEW |