Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: chrome/browser/android/offline_pages/recent_tab_helper.h

Issue 1936613002: Implementing recent pages snapshot capture. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 method, overrides the normally used MHTML Archiver with a test one.
52 void SetArchiverForTest(std::unique_ptr<OfflinePageArchiver> test_archiver);
53 // Test method, overrides the task_runner_ so FastForwardBy() can be used.
54 void SetTaskRunnerForTest(
55 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
56
23 private: 57 private:
24 explicit RecentTabHelper(content::WebContents* web_contents); 58 explicit RecentTabHelper(content::WebContents* web_contents);
25 friend class content::WebContentsUserData<RecentTabHelper>; 59 friend class content::WebContentsUserData<RecentTabHelper>;
26 60
61 void ContinueSnapshotWithModel();
62 void ContinueSnapshotAfterPurge(OfflinePageModel::DeletePageResult result);
63 void SavePageCallback(OfflinePageModel::SavePageResult result,
64 int64_t offline_id);
65 OfflinePageModel* GetPageModel();
66 std::vector<int64_t> GetPagesToPurge() const;
67 void ReportSnapshotCompleted();
68 bool IsSamePage() const;
69 ClientId client_id() const;
70
71 // Page model is a service, no ownership.
72 OfflinePageModel* page_model_;
73 bool page_model_is_loaded_;
74
75 // If true, never make snapshots off the attached WebContents.
76 bool never_do_snapshots_;
77
78 // The URL of the page that is currently being snapshotted. Used to check,
79 // during async operations, that WebContents still contains the same page.
80 GURL snapshot_url_;
81 std::unique_ptr<SnapshotController> snapshot_controller_;
82 std::unique_ptr<OfflinePageArchiver> test_archiver_; // Only used in tests;
83 base::WeakPtrFactory<RecentTabHelper> weak_ptr_factory_;
84
27 DISALLOW_COPY_AND_ASSIGN(RecentTabHelper); 85 DISALLOW_COPY_AND_ASSIGN(RecentTabHelper);
28 }; 86 };
29 87
30 } // namespace offline_pages 88 } // namespace offline_pages
31 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_RECENT_TAB_HELPER_H_ 89 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_RECENT_TAB_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698