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

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

Issue 2218403002: Change database scheme - add state and start tracking (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Delete old database if any Created 4 years, 4 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
Index: components/offline_pages/background/save_page_request.cc
diff --git a/components/offline_pages/background/save_page_request.cc b/components/offline_pages/background/save_page_request.cc
index 2ed90bd8d5ae8c8ae102f8fa39e66f4a66a57cff..fefcebeb043ea3d178a0bc1155e5a0d80d000845 100644
--- a/components/offline_pages/background/save_page_request.cc
+++ b/components/offline_pages/background/save_page_request.cc
@@ -16,8 +16,10 @@ SavePageRequest::SavePageRequest(int64_t request_id,
client_id_(client_id),
creation_time_(creation_time),
activation_time_(creation_time),
- attempt_count_(0),
- user_requested_(was_user_requested) {}
+ started_attempt_count_(0),
+ completed_attempt_count_(0),
+ user_requested_(was_user_requested),
+ state_(RequestState::AVAILABLE) {}
SavePageRequest::SavePageRequest(int64_t request_id,
const GURL& url,
@@ -30,8 +32,10 @@ SavePageRequest::SavePageRequest(int64_t request_id,
client_id_(client_id),
creation_time_(creation_time),
activation_time_(activation_time),
- attempt_count_(0),
- user_requested_(user_requested) {}
+ started_attempt_count_(0),
+ completed_attempt_count_(0),
+ user_requested_(user_requested),
+ state_(RequestState::AVAILABLE) {}
SavePageRequest::SavePageRequest(const SavePageRequest& other)
: request_id_(other.request_id_),
@@ -39,9 +43,11 @@ SavePageRequest::SavePageRequest(const SavePageRequest& other)
client_id_(other.client_id_),
creation_time_(other.creation_time_),
activation_time_(other.activation_time_),
- attempt_count_(other.attempt_count_),
+ started_attempt_count_(other.started_attempt_count_),
+ completed_attempt_count_(other.completed_attempt_count_),
last_attempt_time_(other.last_attempt_time_),
- user_requested_(other.user_requested_) {}
+ user_requested_(other.user_requested_),
+ state_(other.state_) {}
SavePageRequest::~SavePageRequest() {}
@@ -51,19 +57,28 @@ void SavePageRequest::MarkAttemptStarted(const base::Time& start_time) {
// check here to ensure we only start tasks in status pending, and bail out in
// other cases.
last_attempt_time_ = start_time;
- ++attempt_count_;
+ ++started_attempt_count_;
+ state_ = RequestState::PRERENDERING;
}
void SavePageRequest::MarkAttemptCompleted() {
last_attempt_time_ = base::Time();
+ ++completed_attempt_count_;
+ state_ = RequestState::AVAILABLE;
}
void SavePageRequest::MarkAttemptAborted() {
- DCHECK_GT(attempt_count_, 0);
+ DCHECK_GT(started_attempt_count_, 0);
+ // We intentinally do not increment the completed_attempt_count_, since this
fgorski 2016/08/08 17:48:05 typo in: intentinally extra space after "intentio
Pete Williamson 2016/08/08 18:44:29 Done.
+ // was killed before it had a chance to run to completion so we could use the
fgorski 2016/08/08 17:48:05 how about: chance to complete. Phone was used for
chili 2016/08/08 18:17:01 even shorter: "since this was killed before it com
Pete Williamson 2016/08/08 18:44:29 Done.
Pete Williamson 2016/08/08 18:44:29 Done.
+ // phone or browser for other things.
last_attempt_time_ = base::Time();
- // TODO(dougarnett): Would be safer if we had two persisted counters
- // (attempts_started and attempts_completed) rather just one with decrement.
- --attempt_count_;
+ state_ = RequestState::AVAILABLE;
+}
+
+void SavePageRequest::MarkAttemptPaused() {
+ DCHECK_GT(started_attempt_count_, 0);
fgorski 2016/08/08 17:48:05 Would it not be possible to pause a task before it
Pete Williamson 2016/08/08 18:44:28 Good catch, removed DCHECK
+ state_ = RequestState::PAUSED;
fgorski 2016/08/08 17:48:05 can we mark last_attempt_time_ = base::Time(), sin
Pete Williamson 2016/08/08 18:44:28 In the normal case the request has not been attemp
fgorski 2016/08/08 22:35:33 Then why clearing it in cases where the attempt wa
Pete Williamson 2016/08/08 22:56:56 OK, I chose to stop clearing it and rely solely on
}
} // namespace offline_pages

Powered by Google App Engine
This is Rietveld 408576698