Chromium Code Reviews| 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 OfflinePageModel::Observer, | |
| 33 public SnapshotController::Client { | |
| 20 public: | 34 public: |
| 21 ~RecentTabHelper() override; | 35 ~RecentTabHelper() override; |
| 22 | 36 |
| 37 // content::WebContentsObserver | |
| 38 void DidFinishNavigation( | |
| 39 content::NavigationHandle* navigation_handle) override; | |
| 40 void DocumentAvailableInMainFrame() override; | |
| 41 void DocumentOnLoadCompletedInMainFrame() override; | |
| 42 | |
| 43 // OfflinePageModel::Observer | |
| 44 void OfflinePageModelLoaded(OfflinePageModel* model) override; | |
| 45 void OfflinePageModelChanged(offline_pages::OfflinePageModel*) override {}; | |
| 46 void OfflinePageDeleted(int64_t, const offline_pages::ClientId&) override {}; | |
| 47 | |
| 48 // SnapshotController::Client | |
| 49 void StartSnapshot() override; | |
| 50 | |
| 51 // Test support. | |
| 52 // A factory that supplies the instances of an OfflienPageArchiver. | |
|
dewittj
2016/05/02 19:54:27
nit: spelling offlien
| |
| 53 // This is used for testing, where we want to use a specific mock. | |
| 54 class TestArchiveFactory { | |
| 55 public: | |
| 56 virtual ~TestArchiveFactory() {} | |
| 57 virtual std::unique_ptr<OfflinePageArchiver> CreateArchiver( | |
| 58 content::WebContents* web_contents) = 0; | |
| 59 }; | |
| 60 // Test method, overrides the normally used MHTML Archivers with a test | |
| 61 // mocks created by specified function. | |
| 62 void SetArchiveFactoryForTest( | |
| 63 std::unique_ptr<TestArchiveFactory> test_archive_factory); | |
| 64 // Test method, overrides the task_runner_ so FastForwardBy() can be used. | |
| 65 void SetTaskRunnerForTest( | |
| 66 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | |
| 67 | |
| 23 private: | 68 private: |
| 24 explicit RecentTabHelper(content::WebContents* web_contents); | 69 explicit RecentTabHelper(content::WebContents* web_contents); |
| 25 friend class content::WebContentsUserData<RecentTabHelper>; | 70 friend class content::WebContentsUserData<RecentTabHelper>; |
| 26 | 71 |
| 72 void ContinueSnapshotWithModel(); | |
| 73 void ContinueSnapshotAfterPurge(OfflinePageModel::DeletePageResult result); | |
| 74 void SavePageCallback(OfflinePageModel::SavePageResult result, | |
| 75 int64_t offline_id); | |
| 76 OfflinePageModel* GetPageModel(); | |
| 77 std::vector<int64_t> GetPagesToPurge() const; | |
| 78 void ReportSnapshotCompleted(); | |
| 79 bool IsSamePage() const; | |
| 80 ClientId client_id() const; | |
| 81 | |
| 82 // Page model is a service, no ownership. | |
| 83 OfflinePageModel* page_model_; | |
| 84 bool page_model_is_loaded_; | |
| 85 | |
| 86 // If true, never make snapshots off the attached WebContents. | |
| 87 bool never_do_snapshots_; | |
| 88 | |
| 89 // The URL of the page that is currently being snapshotted. Used to check, | |
| 90 // during async operations, that WebContents still contains the same page. | |
| 91 GURL snapshot_url_; | |
| 92 std::unique_ptr<SnapshotController> snapshot_controller_; | |
| 93 std::unique_ptr<TestArchiveFactory> test_archive_factory_; | |
| 94 | |
| 95 base::WeakPtrFactory<RecentTabHelper> weak_ptr_factory_; | |
| 96 | |
| 27 DISALLOW_COPY_AND_ASSIGN(RecentTabHelper); | 97 DISALLOW_COPY_AND_ASSIGN(RecentTabHelper); |
| 28 }; | 98 }; |
| 29 | 99 |
| 30 } // namespace offline_pages | 100 } // namespace offline_pages |
| 31 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_RECENT_TAB_HELPER_H_ | 101 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_RECENT_TAB_HELPER_H_ |
| OLD | NEW |