| 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 CHROME_BROWSER_ANDROID_OFFLINE_PAGES_RECENT_TAB_HELPER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_RECENT_TAB_HELPER_H_ |
| 6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_RECENT_TAB_HELPER_H_ | 6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_RECENT_TAB_HELPER_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "components/offline_pages/offline_page_model.h" |
| 13 #include "components/offline_pages/snapshot_controller.h" |
| 8 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
| 9 #include "content/public/browser/web_contents_user_data.h" | 15 #include "content/public/browser/web_contents_user_data.h" |
| 16 #include "url/gurl.h" |
| 17 |
| 18 namespace content { |
| 19 class NavigationEntry; |
| 20 class NavigationHandle; |
| 21 } |
| 10 | 22 |
| 11 namespace offline_pages { | 23 namespace offline_pages { |
| 12 | 24 |
| 13 // Attaches to every WebContent shown in a tab. Waits until the WebContent is | 25 // Attaches to every WebContent shown in a tab. Waits until the WebContent is |
| 14 // loaded to proper degree and then makes a snapshot of the page. Removes the | 26 // loaded to proper degree and then makes a snapshot of the page. Removes the |
| 15 // oldest snapshot in the 'ring buffer'. As a result, there is always up to N | 27 // oldest snapshot in the 'ring buffer'. As a result, there is always up to N |
| 16 // snapshots of recent pages on the device. | 28 // snapshots of recent pages on the device. |
| 17 class RecentTabHelper | 29 class RecentTabHelper |
| 18 : public content::WebContentsObserver, | 30 : public content::WebContentsObserver, |
| 19 public content::WebContentsUserData<RecentTabHelper> { | 31 public content::WebContentsUserData<RecentTabHelper>, |
| 32 public SnapshotController::Client { |
| 20 public: | 33 public: |
| 21 ~RecentTabHelper() override; | 34 ~RecentTabHelper() override; |
| 22 | 35 |
| 36 // content::WebContentsObserver |
| 37 void DidFinishNavigation( |
| 38 content::NavigationHandle* navigation_handle) override; |
| 39 void DocumentAvailableInMainFrame() override; |
| 40 void DocumentOnLoadCompletedInMainFrame() override; |
| 41 |
| 42 // SnapshotController::Client |
| 43 void StartSnapshot() override; |
| 44 |
| 45 // Test support. |
| 46 // A factory that supplies the instances of an OfflienPageArchiver. |
| 47 // This is used for testing, where we want to use a specific mock. |
| 48 class TestArchiveFactory { |
| 49 public: |
| 50 virtual ~TestArchiveFactory() {} |
| 51 virtual std::unique_ptr<OfflinePageArchiver> CreateArchiver( |
| 52 content::WebContents* web_contents) = 0; |
| 53 }; |
| 54 // Test method, overrides the normally used MHTML Archivers with a test |
| 55 // mocks created by specified function. |
| 56 void SetArchiveFactoryForTest( |
| 57 std::unique_ptr<TestArchiveFactory> test_archive_factory); |
| 58 // Test method, overrides the task_runner_ so FastForwardBy() can be used. |
| 59 void SetTaskRunnerForTest( |
| 60 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); |
| 61 |
| 23 private: | 62 private: |
| 24 explicit RecentTabHelper(content::WebContents* web_contents); | 63 explicit RecentTabHelper(content::WebContents* web_contents); |
| 25 friend class content::WebContentsUserData<RecentTabHelper>; | 64 friend class content::WebContentsUserData<RecentTabHelper>; |
| 26 | 65 |
| 66 |
| 67 void ContinueSnapshotWithIdsToPurge(const std::vector<int64_t>& page_ids); |
| 68 void ContinueSnapshotAfterPurge(OfflinePageModel::DeletePageResult result); |
| 69 void SavePageCallback(OfflinePageModel::SavePageResult result, |
| 70 int64_t offline_id); |
| 71 |
| 72 void ReportSnapshotCompleted(); |
| 73 bool IsSamePage() const; |
| 74 ClientId client_id() const; |
| 75 |
| 76 // Page model is a service, no ownership. |
| 77 OfflinePageModel* page_model_; |
| 78 |
| 79 // If true, never make snapshots off the attached WebContents. |
| 80 bool never_do_snapshots_; |
| 81 |
| 82 // The URL of the page that is currently being snapshotted. Used to check, |
| 83 // during async operations, that WebContents still contains the same page. |
| 84 GURL snapshot_url_; |
| 85 std::unique_ptr<SnapshotController> snapshot_controller_; |
| 86 std::unique_ptr<TestArchiveFactory> test_archive_factory_; |
| 87 |
| 88 base::WeakPtrFactory<RecentTabHelper> weak_ptr_factory_; |
| 89 |
| 27 DISALLOW_COPY_AND_ASSIGN(RecentTabHelper); | 90 DISALLOW_COPY_AND_ASSIGN(RecentTabHelper); |
| 28 }; | 91 }; |
| 29 | 92 |
| 30 } // namespace offline_pages | 93 } // namespace offline_pages |
| 31 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_RECENT_TAB_HELPER_H_ | 94 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_RECENT_TAB_HELPER_H_ |
| OLD | NEW |