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

Side by Side 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: clang is my friend Created 4 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/offline_pages/snapshot_controller.h" 5 #include "components/offline_pages/snapshot_controller.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 13 matching lines...) Expand all
24 SnapshotController::Client* client) 24 SnapshotController::Client* client)
25 : task_runner_(task_runner), 25 : task_runner_(task_runner),
26 client_(client), 26 client_(client),
27 state_(State::kReady), 27 state_(State::kReady),
28 weak_ptr_factory_(this) { 28 weak_ptr_factory_(this) {
29 } 29 }
30 30
31 SnapshotController::~SnapshotController() {} 31 SnapshotController::~SnapshotController() {}
32 32
33 void SnapshotController::Reset() { 33 void SnapshotController::Reset() {
34 // Cancel potentially delayed tasks that relate to the previous 'session'.
35 weak_ptr_factory_.InvalidateWeakPtrs();
34 state_ = State::kReady; 36 state_ = State::kReady;
35 } 37 }
36 38
37 void SnapshotController::Stop() { 39 void SnapshotController::Stop() {
38 state_ = State::kStopped; 40 state_ = State::kStopped;
39 } 41 }
40 42
41 void SnapshotController::PendingSnapshotCompleted() { 43 void SnapshotController::PendingSnapshotCompleted() {
42 // Unless the controller is "stopped", enable the subsequent snapshots. 44 // Unless the controller is "stopped", enable the subsequent snapshots.
43 // Stopped state prevents any further snapshots form being started. 45 // Stopped state prevents any further snapshots form being started.
(...skipping 16 matching lines...) Expand all
60 void SnapshotController::DocumentOnLoadCompletedInMainFrame() { 62 void SnapshotController::DocumentOnLoadCompletedInMainFrame() {
61 MaybeStartSnapshot(); 63 MaybeStartSnapshot();
62 // No more snapshots after onLoad (there still can be other events 64 // No more snapshots after onLoad (there still can be other events
63 // or delayed tasks that can try to start another snapshot) 65 // or delayed tasks that can try to start another snapshot)
64 Stop(); 66 Stop();
65 } 67 }
66 68
67 void SnapshotController::MaybeStartSnapshot() { 69 void SnapshotController::MaybeStartSnapshot() {
68 if (state_ != State::kReady) 70 if (state_ != State::kReady)
69 return; 71 return;
70 if (client_->StartSnapshot()) 72 state_ = State::kSnapshotPending;
71 state_ = State::kSnapshotPending; 73 client_->StartSnapshot();
72 } 74 }
73 75
74 size_t SnapshotController::GetDelayAfterDocumentAvailableForTest() { 76 size_t SnapshotController::GetDelayAfterDocumentAvailableForTest() {
75 return kDelayAfterDocumentAvailable; 77 return kDelayAfterDocumentAvailable;
76 } 78 }
77 79
78 80
79 } // namespace offline_pages 81 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/snapshot_controller.h ('k') | components/offline_pages/snapshot_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698