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

Unified Diff: components/offline_pages/snapshot_controller.cc

Issue 1936613002: Implementing recent pages snapshot capture. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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/snapshot_controller.cc
diff --git a/components/offline_pages/snapshot_controller.cc b/components/offline_pages/snapshot_controller.cc
index b086e486c34a505e5adbfb7711486d462f9ea652..247e193161889d6dba16dc33836bfe9b103e13db 100644
--- a/components/offline_pages/snapshot_controller.cc
+++ b/components/offline_pages/snapshot_controller.cc
@@ -25,12 +25,14 @@ SnapshotController::SnapshotController(
: task_runner_(task_runner),
client_(client),
state_(State::kReady),
+ session_counter_(0),
weak_ptr_factory_(this) {
}
SnapshotController::~SnapshotController() {}
void SnapshotController::Reset() {
+ session_counter_++;
state_ = State::kReady;
}
@@ -53,22 +55,26 @@ void SnapshotController::DocumentAvailableInMainFrame() {
task_runner_->PostDelayedTask(
FROM_HERE,
base::Bind(&SnapshotController::MaybeStartSnapshot,
- weak_ptr_factory_.GetWeakPtr()),
+ weak_ptr_factory_.GetWeakPtr(),
+ session_counter_),
base::TimeDelta::FromMilliseconds(kDelayAfterDocumentAvailable));
}
void SnapshotController::DocumentOnLoadCompletedInMainFrame() {
- MaybeStartSnapshot();
+ MaybeStartSnapshot(session_counter_);
// No more snapshots after onLoad (there still can be other events
// or delayed tasks that can try to start another snapshot)
Stop();
}
-void SnapshotController::MaybeStartSnapshot() {
+void SnapshotController::MaybeStartSnapshot(size_t session_id) {
if (state_ != State::kReady)
return;
- if (client_->StartSnapshot())
- state_ = State::kSnapshotPending;
+ // This task was posted for previous session, ignore it.
+ if (session_id != session_counter_)
+ return;
+ state_ = State::kSnapshotPending;
+ client_->StartSnapshot();
}
size_t SnapshotController::GetDelayAfterDocumentAvailableForTest() {

Powered by Google App Engine
This is Rietveld 408576698