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

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

Issue 2655273003: Adds a first integration test for the Recent Tabs feature. (Closed)
Patch Set: Fix wrapping of comment text. Created 3 years, 10 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"
11 #include "components/offline_pages/core/offline_page_feature.h"
11 12
12 namespace { 13 namespace {
13 // Default delay, in milliseconds, between the main document parsed event and 14 // Default delay, in milliseconds, between the main document parsed event and
14 // snapshot. Note: this snapshot might not occur if the OnLoad event and 15 // snapshot. Note: this snapshot might not occur if the OnLoad event and
15 // OnLoad delay elapses first to trigger a final snapshot. 16 // OnLoad delay elapses first to trigger a final snapshot.
16 const size_t kDefaultDelayAfterDocumentAvailableMs = 7000; 17 const int64_t kDefaultDelayAfterDocumentAvailableMs = 7000;
17 18
18 // Default delay, in milliseconds, between the main document OnLoad event and 19 // Default delay, in milliseconds, between the main document OnLoad event and
19 // snapshot. 20 // snapshot.
20 const size_t kDelayAfterDocumentOnLoadCompletedMs = 1000; 21 const int64_t kDelayAfterDocumentOnLoadCompletedMs = 1000;
22
23 // Delay for testing to keep polling times reasonable.
24 const int64_t kDelayForTests = 0;
21 25
22 } // namespace 26 } // namespace
23 27
24 namespace offline_pages { 28 namespace offline_pages {
25 29
26 SnapshotController::SnapshotController( 30 SnapshotController::SnapshotController(
27 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 31 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
28 SnapshotController::Client* client) 32 SnapshotController::Client* client)
29 : task_runner_(task_runner), 33 : SnapshotController(task_runner,
30 client_(client), 34 client,
31 state_(State::READY), 35 kDefaultDelayAfterDocumentAvailableMs,
32 delay_after_document_available_ms_(kDefaultDelayAfterDocumentAvailableMs), 36 kDelayAfterDocumentOnLoadCompletedMs) {}
33 delay_after_document_on_load_completed_ms_(
34 kDelayAfterDocumentOnLoadCompletedMs),
35 weak_ptr_factory_(this) {}
36 37
37 SnapshotController::SnapshotController( 38 SnapshotController::SnapshotController(
38 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 39 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
39 SnapshotController::Client* client, 40 SnapshotController::Client* client,
40 size_t delay_after_document_available_ms, 41 int64_t delay_after_document_available_ms,
41 size_t delay_after_document_on_load_completed_ms) 42 int64_t delay_after_document_on_load_completed_ms)
42 : task_runner_(task_runner), 43 : task_runner_(task_runner),
43 client_(client), 44 client_(client),
44 state_(State::READY), 45 state_(State::READY),
45 delay_after_document_available_ms_(delay_after_document_available_ms), 46 delay_after_document_available_ms_(delay_after_document_available_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 delay_after_document_on_load_completed_ms),
48 weak_ptr_factory_(this) {} 49 weak_ptr_factory_(this) {
50 if (offline_pages::ShouldUseTestingSnapshotDelay()) {
51 delay_after_document_available_ms_ = kDelayForTests;
52 delay_after_document_on_load_completed_ms_ = kDelayForTests;
53 }
54 }
49 55
50 SnapshotController::~SnapshotController() {} 56 SnapshotController::~SnapshotController() {}
51 57
52 void SnapshotController::Reset() { 58 void SnapshotController::Reset() {
53 // Cancel potentially delayed tasks that relate to the previous 'session'. 59 // Cancel potentially delayed tasks that relate to the previous 'session'.
54 weak_ptr_factory_.InvalidateWeakPtrs(); 60 weak_ptr_factory_.InvalidateWeakPtrs();
55 state_ = State::READY; 61 state_ = State::READY;
56 current_page_quality_ = PageQuality::POOR; 62 current_page_quality_ = PageQuality::POOR;
57 } 63 }
58 64
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 current_page_quality_ = updated_page_quality; 100 current_page_quality_ = updated_page_quality;
95 state_ = State::SNAPSHOT_PENDING; 101 state_ = State::SNAPSHOT_PENDING;
96 client_->StartSnapshot(); 102 client_->StartSnapshot();
97 } 103 }
98 104
99 void SnapshotController::MaybeStartSnapshotThenStop() { 105 void SnapshotController::MaybeStartSnapshotThenStop() {
100 MaybeStartSnapshot(PageQuality::HIGH); 106 MaybeStartSnapshot(PageQuality::HIGH);
101 Stop(); 107 Stop();
102 } 108 }
103 109
104 size_t SnapshotController::GetDelayAfterDocumentAvailableForTest() { 110 int64_t SnapshotController::GetDelayAfterDocumentAvailableForTest() {
105 return delay_after_document_available_ms_; 111 return delay_after_document_available_ms_;
106 } 112 }
107 113
108 size_t SnapshotController::GetDelayAfterDocumentOnLoadCompletedForTest() { 114 int64_t SnapshotController::GetDelayAfterDocumentOnLoadCompletedForTest() {
109 return delay_after_document_on_load_completed_ms_; 115 return delay_after_document_on_load_completed_ms_;
110 } 116 }
111 117
112 } // namespace offline_pages 118 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698