| OLD | NEW |
| 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 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 void SnapshotController::Stop() { | 39 void SnapshotController::Stop() { |
| 40 state_ = State::kStopped; | 40 state_ = State::kStopped; |
| 41 } | 41 } |
| 42 | 42 |
| 43 void SnapshotController::PendingSnapshotCompleted() { | 43 void SnapshotController::PendingSnapshotCompleted() { |
| 44 // Unless the controller is "stopped", enable the subsequent snapshots. | 44 // Unless the controller is "stopped", enable the subsequent snapshots. |
| 45 // Stopped state prevents any further snapshots form being started. | 45 // Stopped state prevents any further snapshots form being started. |
| 46 if (state_ == State::kStopped) | 46 if (state_ == State::kStopped) |
| 47 return; | 47 return; |
| 48 DCHECK(state_ == State::kSnapshotPending); | |
| 49 state_ = State::kReady; | 48 state_ = State::kReady; |
| 50 } | 49 } |
| 51 | 50 |
| 52 void SnapshotController::DocumentAvailableInMainFrame() { | 51 void SnapshotController::DocumentAvailableInMainFrame() { |
| 53 // Post a delayed task. The snapshot will happen either when the delay | 52 // Post a delayed task. The snapshot will happen either when the delay |
| 54 // is up, or if the "load" event is dispatched in the main frame. | 53 // is up, or if the "load" event is dispatched in the main frame. |
| 55 task_runner_->PostDelayedTask( | 54 task_runner_->PostDelayedTask( |
| 56 FROM_HERE, | 55 FROM_HERE, |
| 57 base::Bind(&SnapshotController::MaybeStartSnapshot, | 56 base::Bind(&SnapshotController::MaybeStartSnapshot, |
| 58 weak_ptr_factory_.GetWeakPtr()), | 57 weak_ptr_factory_.GetWeakPtr()), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 72 state_ = State::kSnapshotPending; | 71 state_ = State::kSnapshotPending; |
| 73 client_->StartSnapshot(); | 72 client_->StartSnapshot(); |
| 74 } | 73 } |
| 75 | 74 |
| 76 size_t SnapshotController::GetDelayAfterDocumentAvailableForTest() { | 75 size_t SnapshotController::GetDelayAfterDocumentAvailableForTest() { |
| 77 return kDelayAfterDocumentAvailable; | 76 return kDelayAfterDocumentAvailable; |
| 78 } | 77 } |
| 79 | 78 |
| 80 | 79 |
| 81 } // namespace offline_pages | 80 } // namespace offline_pages |
| OLD | NEW |