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