| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 // times, but not in overlapping manner - waits until | 53 // times, but not in overlapping manner - waits until |
| 54 // PreviousSnapshotCompleted() before the next StatrSnapshot(). | 54 // PreviousSnapshotCompleted() before the next StatrSnapshot(). |
| 55 // 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, |
| 56 // it is assumed that later snapshots are better then previous. | 56 // it is assumed that later snapshots are better then previous. |
| 57 virtual void StartSnapshot() = 0; | 57 virtual void StartSnapshot() = 0; |
| 58 | 58 |
| 59 protected: | 59 protected: |
| 60 virtual ~Client() {} | 60 virtual ~Client() {} |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 SnapshotController( | 63 // Creates a SnapshotController with document available delay = 7s, |
| 64 // document on load delay = 1s and triggers snapshot on document available. |
| 65 static std::unique_ptr<SnapshotController> CreateForForegroundOfflining( |
| 64 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 66 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 65 SnapshotController::Client* client); | 67 SnapshotController::Client* client); |
| 68 // Creates a SnapshotController with document on load delay = 2s |
| 69 // and ignores document available signal. |
| 70 static std::unique_ptr<SnapshotController> CreateForBackgroundOfflining( |
| 71 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 72 SnapshotController::Client* client); |
| 73 |
| 66 SnapshotController( | 74 SnapshotController( |
| 67 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 75 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 68 SnapshotController::Client* client, | 76 SnapshotController::Client* client, |
| 69 int64_t delay_after_document_available_ms, | 77 int64_t delay_after_document_available_ms, |
| 70 int64_t delay_after_document_on_load_completed_ms); | 78 int64_t delay_after_document_on_load_completed_ms, |
| 79 bool document_available_triggers_snapshot); |
| 71 virtual ~SnapshotController(); | 80 virtual ~SnapshotController(); |
| 72 | 81 |
| 73 // Resets the 'session', returning controller to initial state. | 82 // Resets the 'session', returning controller to initial state. |
| 74 void Reset(); | 83 void Reset(); |
| 75 | 84 |
| 76 // Stops current session, no more Client::StartSnapshot calls will be | 85 // Stops current session, no more Client::StartSnapshot calls will be |
| 77 // invoked from the SnapshotController until current session is Reset(). | 86 // invoked from the SnapshotController until current session is Reset(). |
| 78 // Called by Client, for example when it encounters an error loading the page. | 87 // Called by Client, for example when it encounters an error loading the page. |
| 79 void Stop(); | 88 void Stop(); |
| 80 | 89 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 96 private: | 105 private: |
| 97 void MaybeStartSnapshot(PageQuality updated_page_quality); | 106 void MaybeStartSnapshot(PageQuality updated_page_quality); |
| 98 void MaybeStartSnapshotThenStop(); | 107 void MaybeStartSnapshotThenStop(); |
| 99 | 108 |
| 100 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 109 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 101 // Client owns this class. | 110 // Client owns this class. |
| 102 SnapshotController::Client* client_; | 111 SnapshotController::Client* client_; |
| 103 SnapshotController::State state_; | 112 SnapshotController::State state_; |
| 104 int64_t delay_after_document_available_ms_; | 113 int64_t delay_after_document_available_ms_; |
| 105 int64_t delay_after_document_on_load_completed_ms_; | 114 int64_t delay_after_document_on_load_completed_ms_; |
| 115 bool document_available_triggers_snapshot_; |
| 106 | 116 |
| 107 // The expected quality of a snapshot taken at the moment this value is | 117 // The expected quality of a snapshot taken at the moment this value is |
| 108 // queried. | 118 // queried. |
| 109 PageQuality current_page_quality_ = PageQuality::POOR; | 119 PageQuality current_page_quality_ = PageQuality::POOR; |
| 110 | 120 |
| 111 base::WeakPtrFactory<SnapshotController> weak_ptr_factory_; | 121 base::WeakPtrFactory<SnapshotController> weak_ptr_factory_; |
| 112 | 122 |
| 113 DISALLOW_COPY_AND_ASSIGN(SnapshotController); | 123 DISALLOW_COPY_AND_ASSIGN(SnapshotController); |
| 114 }; | 124 }; |
| 115 | 125 |
| 116 } // namespace offline_pages | 126 } // namespace offline_pages |
| 117 | 127 |
| 118 #endif // COMPONENTS_OFFLINE_PAGES_CORE_SNAPSHOT_CONTROLLER_H_ | 128 #endif // COMPONENTS_OFFLINE_PAGES_CORE_SNAPSHOT_CONTROLLER_H_ |
| OLD | NEW |