| 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 22 matching lines...) Expand all Loading... |
| 33 : db_loaded_(false), | 33 : db_loaded_(false), |
| 34 profile_error_callback_(callback) { | 34 profile_error_callback_(callback) { |
| 35 // WebDataService requires DB thread if instantiated. | 35 // WebDataService requires DB thread if instantiated. |
| 36 // Set WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile, NULL) | 36 // Set WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile, NULL) |
| 37 // if you do not want to instantiate WebDataService in your test. | 37 // if you do not want to instantiate WebDataService in your test. |
| 38 DCHECK(BrowserThread::IsWellKnownThread(BrowserThread::DB)); | 38 DCHECK(BrowserThread::IsWellKnownThread(BrowserThread::DB)); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void WebDataServiceBase::ShutdownOnUIThread() { | 41 void WebDataServiceBase::ShutdownOnUIThread() { |
| 42 db_loaded_ = false; | 42 db_loaded_ = false; |
| 43 BrowserThread::PostTask( |
| 44 BrowserThread::DB, FROM_HERE, |
| 45 base::Bind(&WebDataServiceBase::ShutdownOnDBThread, this)); |
| 43 ShutdownDatabase(); | 46 ShutdownDatabase(); |
| 44 } | 47 } |
| 45 | 48 |
| 46 void WebDataServiceBase::Init(const base::FilePath& path) { | 49 void WebDataServiceBase::Init(const base::FilePath& path) { |
| 47 wdbs_.reset(new WebDatabaseService(path)); | 50 wdbs_.reset(new WebDatabaseService(path)); |
| 48 wdbs_->LoadDatabase(Bind(&WebDataServiceBase::DatabaseInitOnDB, this)); | 51 wdbs_->LoadDatabase(Bind(&WebDataServiceBase::DatabaseInitOnDB, this)); |
| 49 } | 52 } |
| 50 | 53 |
| 51 void WebDataServiceBase::UnloadDatabase() { | 54 void WebDataServiceBase::UnloadDatabase() { |
| 52 if (!wdbs_) | 55 if (!wdbs_) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 73 bool WebDataServiceBase::IsDatabaseLoaded() { | 76 bool WebDataServiceBase::IsDatabaseLoaded() { |
| 74 return db_loaded_; | 77 return db_loaded_; |
| 75 } | 78 } |
| 76 | 79 |
| 77 WebDatabase* WebDataServiceBase::GetDatabase() { | 80 WebDatabase* WebDataServiceBase::GetDatabase() { |
| 78 if (!wdbs_) | 81 if (!wdbs_) |
| 79 return NULL; | 82 return NULL; |
| 80 return wdbs_->GetDatabaseOnDB(); | 83 return wdbs_->GetDatabaseOnDB(); |
| 81 } | 84 } |
| 82 | 85 |
| 86 base::SupportsUserData* WebDataServiceBase::GetDBUserData() { |
| 87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 88 if (!db_thread_user_data_) |
| 89 db_thread_user_data_.reset(new base::SupportsUserData()); |
| 90 return db_thread_user_data_.get(); |
| 91 } |
| 92 |
| 83 WebDataServiceBase::~WebDataServiceBase() { | 93 WebDataServiceBase::~WebDataServiceBase() { |
| 84 wdbs_.reset(); | 94 wdbs_.reset(); |
| 85 } | 95 } |
| 86 | 96 |
| 97 void WebDataServiceBase::ShutdownOnDBThread() { |
| 98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 99 db_thread_user_data_.reset(); |
| 100 } |
| 101 |
| 87 //////////////////////////////////////////////////////////////////////////////// | 102 //////////////////////////////////////////////////////////////////////////////// |
| 88 // | 103 // |
| 89 // The following methods are executed on the DB thread. | 104 // The following methods are executed on the DB thread. |
| 90 // | 105 // |
| 91 //////////////////////////////////////////////////////////////////////////////// | 106 //////////////////////////////////////////////////////////////////////////////// |
| 92 | 107 |
| 93 void WebDataServiceBase::DBInitFailed(sql::InitStatus sql_status) { | 108 void WebDataServiceBase::DBInitFailed(sql::InitStatus sql_status) { |
| 94 if (!profile_error_callback_.is_null()) | 109 if (!profile_error_callback_.is_null()) |
| 95 profile_error_callback_.Run(sql_status); | 110 profile_error_callback_.Run(sql_status); |
| 96 } | 111 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 110 BrowserThread::PostTask( | 125 BrowserThread::PostTask( |
| 111 BrowserThread::UI, FROM_HERE, | 126 BrowserThread::UI, FROM_HERE, |
| 112 base::Bind(&WebDataServiceBase::NotifyDatabaseLoadedOnUIThread, this)); | 127 base::Bind(&WebDataServiceBase::NotifyDatabaseLoadedOnUIThread, this)); |
| 113 } else { | 128 } else { |
| 114 BrowserThread::PostTask( | 129 BrowserThread::PostTask( |
| 115 BrowserThread::UI, FROM_HERE, | 130 BrowserThread::UI, FROM_HERE, |
| 116 base::Bind(&WebDataServiceBase::DBInitFailed, this, status)); | 131 base::Bind(&WebDataServiceBase::DBInitFailed, this, status)); |
| 117 } | 132 } |
| 118 } | 133 } |
| 119 | 134 |
| OLD | NEW |