Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(413)

Unified Diff: components/offline_pages/background/request_queue_store_sql.cc

Issue 2379353003: [Offline pages] Applying StoreState to track RequestQueueStore state (Closed)
Patch Set: Addressing feedback Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/offline_pages/background/request_queue_store_sql.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..d83c1ebdfa7dcd404572933cb710dae506d46826 100644
--- a/components/offline_pages/background/request_queue_store_sql.cc
+++ b/components/offline_pages/background/request_queue_store_sql.cc
@@ -23,6 +23,7 @@ template class StoreUpdateResult<SavePageRequest>;
namespace {
using UpdateStatus = RequestQueueStore::UpdateStatus;
+using StoreStateCallback = base::Callback<void(StoreState)>;
// This is a macro instead of a const so that
// it can be used inline in other SQL statements below.
@@ -402,21 +403,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 StoreStateCallback& 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 StoreStateCallback& callback) {
// 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 +553,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
« no previous file with comments | « components/offline_pages/background/request_queue_store_sql.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698