| 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 #ifndef COMPONENTS_OFFLINE_PAGES_CORE_SNAPSHOT_CONTROLLER_H_ | 5 #ifndef COMPONENTS_OFFLINE_PAGES_CORE_SNAPSHOT_CONTROLLER_H_ |
| 6 #define COMPONENTS_OFFLINE_PAGES_CORE_SNAPSHOT_CONTROLLER_H_ | 6 #define COMPONENTS_OFFLINE_PAGES_CORE_SNAPSHOT_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // OnLoad is currently such signal. | 23 // OnLoad is currently such signal. |
| 24 // - Once Reset() is called on the SnapshotController, the delayed tasks are | 24 // - Once Reset() is called on the SnapshotController, the delayed tasks are |
| 25 // reset so no StartSnapshot calls is made 'cross-session'. | 25 // reset so no StartSnapshot calls is made 'cross-session'. |
| 26 class SnapshotController { | 26 class SnapshotController { |
| 27 public: | 27 public: |
| 28 enum class State { | 28 enum class State { |
| 29 READY, // Listening to input, will start snapshot when needed. | 29 READY, // Listening to input, will start snapshot when needed. |
| 30 SNAPSHOT_PENDING, // Snapshot is in progress, don't start another. | 30 SNAPSHOT_PENDING, // Snapshot is in progress, don't start another. |
| 31 STOPPED, // Terminal state, no snapshots until reset. | 31 STOPPED, // Terminal state, no snapshots until reset. |
| 32 }; | 32 }; |
| 33 // The expected quality of a page based on its current loading progress. |
| 34 enum class PageQuality { |
| 35 // Not loaded enough to reach a minimum level of quality. Snapshots taken at |
| 36 // this point are expected to be useless. |
| 37 POOR = 0, |
| 38 // A minimal level of quality has been attained but the page is still |
| 39 // loading so its quality is continuously increasing. One or more snapshots |
| 40 // could be taken at this stage as later ones are expected to have higher |
| 41 // quality. |
| 42 FAIR_AND_IMPROVING, |
| 43 // The page is loaded enough and has attained its peak expected quality. |
| 44 // Snapshots taken at this point are not expected to increase in quality |
| 45 // after the first one. |
| 46 HIGH, |
| 47 }; |
| 33 | 48 |
| 34 // Client of the SnapshotController. | 49 // Client of the SnapshotController. |
| 35 class Client { | 50 class Client { |
| 36 public: | 51 public: |
| 37 // Invoked at a good moment to start a snapshot. May be invoked multiple | 52 // Invoked at a good moment to start a snapshot. May be invoked multiple |
| 38 // times, but not in overlapping manner - waits until | 53 // times, but not in overlapping manner - waits until |
| 39 // PreviousSnapshotCompleted() before the next StatrSnapshot(). | 54 // PreviousSnapshotCompleted() before the next StatrSnapshot(). |
| 40 // Client should overwrite the result of previous snapshot with the new one, | 55 // Client should overwrite the result of previous snapshot with the new one, |
| 41 // it is assumed that later snapshots are better then previous. | 56 // it is assumed that later snapshots are better then previous. |
| 42 virtual void StartSnapshot() = 0; | 57 virtual void StartSnapshot() = 0; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 69 | 84 |
| 70 // Invoked from WebContentObserver::DocumentAvailableInMainFrame | 85 // Invoked from WebContentObserver::DocumentAvailableInMainFrame |
| 71 void DocumentAvailableInMainFrame(); | 86 void DocumentAvailableInMainFrame(); |
| 72 | 87 |
| 73 // Invoked from WebContentObserver::DocumentOnLoadCompletedInMainFrame | 88 // Invoked from WebContentObserver::DocumentOnLoadCompletedInMainFrame |
| 74 void DocumentOnLoadCompletedInMainFrame(); | 89 void DocumentOnLoadCompletedInMainFrame(); |
| 75 | 90 |
| 76 size_t GetDelayAfterDocumentAvailableForTest(); | 91 size_t GetDelayAfterDocumentAvailableForTest(); |
| 77 size_t GetDelayAfterDocumentOnLoadCompletedForTest(); | 92 size_t GetDelayAfterDocumentOnLoadCompletedForTest(); |
| 78 | 93 |
| 94 PageQuality current_page_quality() const { return current_page_quality_; } |
| 95 |
| 79 private: | 96 private: |
| 80 void MaybeStartSnapshot(); | 97 void MaybeStartSnapshot(PageQuality updated_page_quality); |
| 81 void MaybeStartSnapshotThenStop(); | 98 void MaybeStartSnapshotThenStop(); |
| 82 | 99 |
| 83 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 100 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 84 // Client owns this class. | 101 // Client owns this class. |
| 85 SnapshotController::Client* client_; | 102 SnapshotController::Client* client_; |
| 86 SnapshotController::State state_; | 103 SnapshotController::State state_; |
| 87 size_t delay_after_document_available_ms_; | 104 size_t delay_after_document_available_ms_; |
| 88 size_t delay_after_document_on_load_completed_ms_; | 105 size_t delay_after_document_on_load_completed_ms_; |
| 89 | 106 |
| 107 // The expected quality of a snapshot taken at the moment this value is |
| 108 // queried. |
| 109 PageQuality current_page_quality_ = PageQuality::POOR; |
| 110 |
| 90 base::WeakPtrFactory<SnapshotController> weak_ptr_factory_; | 111 base::WeakPtrFactory<SnapshotController> weak_ptr_factory_; |
| 91 | 112 |
| 92 DISALLOW_COPY_AND_ASSIGN(SnapshotController); | 113 DISALLOW_COPY_AND_ASSIGN(SnapshotController); |
| 93 }; | 114 }; |
| 94 | 115 |
| 95 } // namespace offline_pages | 116 } // namespace offline_pages |
| 96 | 117 |
| 97 #endif // COMPONENTS_OFFLINE_PAGES_CORE_SNAPSHOT_CONTROLLER_H_ | 118 #endif // COMPONENTS_OFFLINE_PAGES_CORE_SNAPSHOT_CONTROLLER_H_ |
| OLD | NEW |