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

Side by Side Diff: components/offline_pages/core/snapshot_controller.cc

Issue 2602473004: Offline Page Cache uses user interaction triggers for saving pages. (Closed)
Patch Set: Minor changes. Created 3 years, 11 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/core/snapshot_controller.h" 5 #include "components/offline_pages/core/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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 delay_after_document_on_load_completed_ms_( 46 delay_after_document_on_load_completed_ms_(
47 delay_after_document_on_load_completed_ms), 47 delay_after_document_on_load_completed_ms),
48 weak_ptr_factory_(this) {} 48 weak_ptr_factory_(this) {}
49 49
50 SnapshotController::~SnapshotController() {} 50 SnapshotController::~SnapshotController() {}
51 51
52 void SnapshotController::Reset() { 52 void SnapshotController::Reset() {
53 // Cancel potentially delayed tasks that relate to the previous 'session'. 53 // Cancel potentially delayed tasks that relate to the previous 'session'.
54 weak_ptr_factory_.InvalidateWeakPtrs(); 54 weak_ptr_factory_.InvalidateWeakPtrs();
55 state_ = State::READY; 55 state_ = State::READY;
56 current_page_quality_ = PageQuality::POOR;
56 } 57 }
57 58
58 void SnapshotController::Stop() { 59 void SnapshotController::Stop() {
59 state_ = State::STOPPED; 60 state_ = State::STOPPED;
60 } 61 }
61 62
62 void SnapshotController::PendingSnapshotCompleted() { 63 void SnapshotController::PendingSnapshotCompleted() {
63 // Unless the controller is "stopped", enable the subsequent snapshots. 64 // Unless the controller is "stopped", enable the subsequent snapshots.
64 // Stopped state prevents any further snapshots form being started. 65 // Stopped state prevents any further snapshots form being started.
65 if (state_ == State::STOPPED) 66 if (state_ == State::STOPPED)
66 return; 67 return;
67 state_ = State::READY; 68 state_ = State::READY;
68 } 69 }
69 70
70 void SnapshotController::DocumentAvailableInMainFrame() { 71 void SnapshotController::DocumentAvailableInMainFrame() {
72 DCHECK_EQ(PageQuality::POOR, current_page_quality_);
71 // Post a delayed task to snapshot. 73 // Post a delayed task to snapshot.
72 task_runner_->PostDelayedTask( 74 task_runner_->PostDelayedTask(
73 FROM_HERE, base::Bind(&SnapshotController::MaybeStartSnapshot, 75 FROM_HERE, base::Bind(&SnapshotController::MaybeStartSnapshot,
74 weak_ptr_factory_.GetWeakPtr()), 76 weak_ptr_factory_.GetWeakPtr(),
77 PageQuality::FAIR_AND_IMPROVING),
75 base::TimeDelta::FromMilliseconds(delay_after_document_available_ms_)); 78 base::TimeDelta::FromMilliseconds(delay_after_document_available_ms_));
76 } 79 }
77 80
78 void SnapshotController::DocumentOnLoadCompletedInMainFrame() { 81 void SnapshotController::DocumentOnLoadCompletedInMainFrame() {
79 // Post a delayed task to snapshot and then stop this controller. 82 // Post a delayed task to snapshot and then stop this controller.
80 task_runner_->PostDelayedTask( 83 task_runner_->PostDelayedTask(
81 FROM_HERE, base::Bind(&SnapshotController::MaybeStartSnapshotThenStop, 84 FROM_HERE, base::Bind(&SnapshotController::MaybeStartSnapshotThenStop,
82 weak_ptr_factory_.GetWeakPtr()), 85 weak_ptr_factory_.GetWeakPtr()),
83 base::TimeDelta::FromMilliseconds( 86 base::TimeDelta::FromMilliseconds(
84 delay_after_document_on_load_completed_ms_)); 87 delay_after_document_on_load_completed_ms_));
85 } 88 }
86 89
87 void SnapshotController::MaybeStartSnapshot() { 90 void SnapshotController::MaybeStartSnapshot(PageQuality updated_page_quality) {
88 if (state_ != State::READY) 91 if (state_ != State::READY)
89 return; 92 return;
93 DCHECK_LT(current_page_quality_, updated_page_quality);
94 current_page_quality_ = updated_page_quality;
90 state_ = State::SNAPSHOT_PENDING; 95 state_ = State::SNAPSHOT_PENDING;
91 client_->StartSnapshot(); 96 client_->StartSnapshot();
92 } 97 }
93 98
94 void SnapshotController::MaybeStartSnapshotThenStop() { 99 void SnapshotController::MaybeStartSnapshotThenStop() {
95 MaybeStartSnapshot(); 100 MaybeStartSnapshot(PageQuality::HIGH);
96 Stop(); 101 Stop();
97 } 102 }
98 103
99 size_t SnapshotController::GetDelayAfterDocumentAvailableForTest() { 104 size_t SnapshotController::GetDelayAfterDocumentAvailableForTest() {
100 return delay_after_document_available_ms_; 105 return delay_after_document_available_ms_;
101 } 106 }
102 107
103 size_t SnapshotController::GetDelayAfterDocumentOnLoadCompletedForTest() { 108 size_t SnapshotController::GetDelayAfterDocumentOnLoadCompletedForTest() {
104 return delay_after_document_on_load_completed_ms_; 109 return delay_after_document_on_load_completed_ms_;
105 } 110 }
106 111
107 } // namespace offline_pages 112 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698