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