Chromium Code Reviews| Index: components/offline_pages/background/request_queue_store_sql.cc |
| diff --git a/components/offline_pages/background/request_queue_store_sql.cc b/components/offline_pages/background/request_queue_store_sql.cc |
| index 4b7309a754408ab9a572d2b99a0bed7a5f343abb..76daa95ecb8fcf8441e05add9283c01002d8aaf7 100644 |
| --- a/components/offline_pages/background/request_queue_store_sql.cc |
| +++ b/components/offline_pages/background/request_queue_store_sql.cc |
| @@ -402,21 +402,28 @@ void ChangeRequestsStateSync( |
| void OpenConnectionSync(sql::Connection* db, |
| scoped_refptr<base::SingleThreadTaskRunner> runner, |
| const base::FilePath& path, |
| - const base::Callback<void(bool)>& callback) { |
| - bool success = InitDatabase(db, path); |
| - runner->PostTask(FROM_HERE, base::Bind(callback, success)); |
| + const base::Callback<void(StoreState)>& callback) { |
| + StoreState state = |
| + InitDatabase(db, path) ? StoreState::LOADED : StoreState::FAILED_LOADING; |
| + runner->PostTask(FROM_HERE, base::Bind(callback, state)); |
| } |
| void ResetSync(sql::Connection* db, |
| const base::FilePath& db_file_path, |
| scoped_refptr<base::SingleThreadTaskRunner> runner, |
| - const RequestQueueStore::ResetCallback& callback) { |
| + const base::Callback<void(StoreState)>& callback) { |
|
Pete Williamson
2016/09/30 18:34:14
Should we have a more descriptive name for this ty
fgorski
2016/09/30 22:51:23
Done.
|
| // This method deletes the content of the whole store and reinitializes it. |
| bool success = db->Raze(); |
| db->Close(); |
| - if (success) |
| - success = InitDatabase(db, db_file_path); |
| - runner->PostTask(FROM_HERE, base::Bind(callback, success)); |
| + StoreState state; |
| + if (!success) |
| + state = StoreState::FAILED_RESET; |
| + if (InitDatabase(db, db_file_path)) |
| + state = StoreState::LOADED; |
| + else |
| + state = StoreState::FAILED_LOADING; |
| + |
| + runner->PostTask(FROM_HERE, base::Bind(callback, state)); |
| } |
| } // anonymous namespace |
| @@ -545,19 +552,25 @@ void RequestQueueStoreSQL::OpenConnection() { |
| weak_ptr_factory_.GetWeakPtr()))); |
| } |
| -void RequestQueueStoreSQL::OnOpenConnectionDone(bool success) { |
| +void RequestQueueStoreSQL::OnOpenConnectionDone(StoreState state) { |
| DCHECK(db_.get()); |
| + state_ = state; |
| + |
| // Unfortunately we were not able to open DB connection. |
| - if (!success) |
| + if (state_ != StoreState::LOADED) |
| db_.reset(); |
| } |
| void RequestQueueStoreSQL::OnResetDone(const ResetCallback& callback, |
| - bool success) { |
| + StoreState state) { |
| // Complete connection initialization post reset. |
| - OnOpenConnectionDone(success); |
| - callback.Run(success); |
| + OnOpenConnectionDone(state); |
| + callback.Run(state == StoreState::LOADED); |
| +} |
| + |
| +StoreState RequestQueueStoreSQL::state() const { |
| + return state_; |
| } |
| } // namespace offline_pages |