Chromium Code Reviews| Index: chrome/browser/android/offline_pages/recent_tab_helper.h |
| diff --git a/chrome/browser/android/offline_pages/recent_tab_helper.h b/chrome/browser/android/offline_pages/recent_tab_helper.h |
| index 00e1d24d2776485c4f71427d4b32c87714c8865b..73119ae6e4abd0bdc8c55f59ec66a1b76d7f4542 100644 |
| --- a/chrome/browser/android/offline_pages/recent_tab_helper.h |
| +++ b/chrome/browser/android/offline_pages/recent_tab_helper.h |
| @@ -5,8 +5,20 @@ |
| #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_RECENT_TAB_HELPER_H_ |
| #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_RECENT_TAB_HELPER_H_ |
| +#include <memory> |
| +#include <vector> |
| + |
| +#include "base/memory/weak_ptr.h" |
| +#include "components/offline_pages/offline_page_model.h" |
| +#include "components/offline_pages/snapshot_controller.h" |
| #include "content/public/browser/web_contents_observer.h" |
| #include "content/public/browser/web_contents_user_data.h" |
| +#include "url/gurl.h" |
| + |
| +namespace content { |
| +class NavigationEntry; |
| +class NavigationHandle; |
| +} |
| namespace offline_pages { |
| @@ -16,14 +28,72 @@ namespace offline_pages { |
| // snapshots of recent pages on the device. |
| class RecentTabHelper |
| : public content::WebContentsObserver, |
| - public content::WebContentsUserData<RecentTabHelper> { |
| + public content::WebContentsUserData<RecentTabHelper>, |
| + public OfflinePageModel::Observer, |
| + public SnapshotController::Client { |
| public: |
| ~RecentTabHelper() override; |
| + // content::WebContentsObserver |
| + void DidFinishNavigation( |
| + content::NavigationHandle* navigation_handle) override; |
| + void DocumentAvailableInMainFrame() override; |
| + void DocumentOnLoadCompletedInMainFrame() override; |
| + |
| + // OfflinePageModel::Observer |
| + void OfflinePageModelLoaded(OfflinePageModel* model) override; |
| + void OfflinePageModelChanged(offline_pages::OfflinePageModel*) override {}; |
| + void OfflinePageDeleted(int64_t, const offline_pages::ClientId&) override {}; |
| + |
| + // SnapshotController::Client |
| + void StartSnapshot() override; |
| + |
| + // Test support. |
| + // A factory that supplies the instances of an OfflienPageArchiver. |
|
dewittj
2016/05/02 19:54:27
nit: spelling offlien
|
| + // This is used for testing, where we want to use a specific mock. |
| + class TestArchiveFactory { |
| + public: |
| + virtual ~TestArchiveFactory() {} |
| + virtual std::unique_ptr<OfflinePageArchiver> CreateArchiver( |
| + content::WebContents* web_contents) = 0; |
| + }; |
| + // Test method, overrides the normally used MHTML Archivers with a test |
| + // mocks created by specified function. |
| + void SetArchiveFactoryForTest( |
| + std::unique_ptr<TestArchiveFactory> test_archive_factory); |
| + // Test method, overrides the task_runner_ so FastForwardBy() can be used. |
| + void SetTaskRunnerForTest( |
| + const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); |
| + |
| private: |
| explicit RecentTabHelper(content::WebContents* web_contents); |
| friend class content::WebContentsUserData<RecentTabHelper>; |
| + void ContinueSnapshotWithModel(); |
| + void ContinueSnapshotAfterPurge(OfflinePageModel::DeletePageResult result); |
| + void SavePageCallback(OfflinePageModel::SavePageResult result, |
| + int64_t offline_id); |
| + OfflinePageModel* GetPageModel(); |
| + std::vector<int64_t> GetPagesToPurge() const; |
| + void ReportSnapshotCompleted(); |
| + bool IsSamePage() const; |
| + ClientId client_id() const; |
| + |
| + // Page model is a service, no ownership. |
| + OfflinePageModel* page_model_; |
| + bool page_model_is_loaded_; |
| + |
| + // If true, never make snapshots off the attached WebContents. |
| + bool never_do_snapshots_; |
| + |
| + // The URL of the page that is currently being snapshotted. Used to check, |
| + // during async operations, that WebContents still contains the same page. |
| + GURL snapshot_url_; |
| + std::unique_ptr<SnapshotController> snapshot_controller_; |
| + std::unique_ptr<TestArchiveFactory> test_archive_factory_; |
| + |
| + base::WeakPtrFactory<RecentTabHelper> weak_ptr_factory_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(RecentTabHelper); |
| }; |