| 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_SNAPSHOT_CONTROLLER_H_ | 5 #ifndef COMPONENTS_OFFLINE_PAGES_SNAPSHOT_CONTROLLER_H_ |
| 6 #define COMPONENTS_OFFLINE_PAGES_SNAPSHOT_CONTROLLER_H_ | 6 #define COMPONENTS_OFFLINE_PAGES_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 30 matching lines...) Expand all Loading... |
| 41 // it is assumed that later snapshots are better then previous. | 41 // it is assumed that later snapshots are better then previous. |
| 42 virtual void StartSnapshot() = 0; | 42 virtual void StartSnapshot() = 0; |
| 43 | 43 |
| 44 protected: | 44 protected: |
| 45 virtual ~Client() {} | 45 virtual ~Client() {} |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 SnapshotController( | 48 SnapshotController( |
| 49 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 49 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 50 SnapshotController::Client* client); | 50 SnapshotController::Client* client); |
| 51 SnapshotController( |
| 52 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 53 SnapshotController::Client* client, |
| 54 size_t delay_after_document_available_ms, |
| 55 size_t delay_after_document_on_load_completed_ms); |
| 51 virtual ~SnapshotController(); | 56 virtual ~SnapshotController(); |
| 52 | 57 |
| 53 // Resets the 'session', returning controller to initial state. | 58 // Resets the 'session', returning controller to initial state. |
| 54 void Reset(); | 59 void Reset(); |
| 55 | 60 |
| 56 // Stops current session, no more Client::StartSnapshot calls will be | 61 // Stops current session, no more Client::StartSnapshot calls will be |
| 57 // invoked from the SnapshotController until current session is Reset(). | 62 // invoked from the SnapshotController until current session is Reset(). |
| 58 // Called by Client, for example when it encounters an error loading the page. | 63 // Called by Client, for example when it encounters an error loading the page. |
| 59 void Stop(); | 64 void Stop(); |
| 60 | 65 |
| 61 // The way for Client to report that previously started snapshot is | 66 // The way for Client to report that previously started snapshot is |
| 62 // now completed (so the next one can be started). | 67 // now completed (so the next one can be started). |
| 63 void PendingSnapshotCompleted(); | 68 void PendingSnapshotCompleted(); |
| 64 | 69 |
| 65 // Invoked from WebContentObserver::DocumentAvailableInMainFrame | 70 // Invoked from WebContentObserver::DocumentAvailableInMainFrame |
| 66 void DocumentAvailableInMainFrame(); | 71 void DocumentAvailableInMainFrame(); |
| 67 | 72 |
| 68 // Invoked from WebContentObserver::DocumentOnLoadCompletedInMainFrame | 73 // Invoked from WebContentObserver::DocumentOnLoadCompletedInMainFrame |
| 69 void DocumentOnLoadCompletedInMainFrame(); | 74 void DocumentOnLoadCompletedInMainFrame(); |
| 70 | 75 |
| 71 size_t GetDelayAfterDocumentAvailableForTest(); | 76 size_t GetDelayAfterDocumentAvailableForTest(); |
| 77 size_t GetDelayAfterDocumentOnLoadCompletedForTest(); |
| 72 | 78 |
| 73 private: | 79 private: |
| 74 void MaybeStartSnapshot(); | 80 void MaybeStartSnapshot(); |
| 81 void MaybeStartSnapshotThenStop(); |
| 75 | 82 |
| 76 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 83 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 77 // Client owns this class. | 84 // Client owns this class. |
| 78 SnapshotController::Client* client_; | 85 SnapshotController::Client* client_; |
| 79 SnapshotController::State state_; | 86 SnapshotController::State state_; |
| 87 size_t delay_after_document_available_ms_; |
| 88 size_t delay_after_document_on_load_completed_ms_; |
| 80 | 89 |
| 81 base::WeakPtrFactory<SnapshotController> weak_ptr_factory_; | 90 base::WeakPtrFactory<SnapshotController> weak_ptr_factory_; |
| 82 | 91 |
| 83 DISALLOW_COPY_AND_ASSIGN(SnapshotController); | 92 DISALLOW_COPY_AND_ASSIGN(SnapshotController); |
| 84 }; | 93 }; |
| 85 | 94 |
| 86 } // namespace offline_pages | 95 } // namespace offline_pages |
| 87 | 96 |
| 88 #endif // COMPONENTS_OFFLINE_PAGES_SNAPSHOT_CONTROLLER_H_ | 97 #endif // COMPONENTS_OFFLINE_PAGES_SNAPSHOT_CONTROLLER_H_ |
| OLD | NEW |