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

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

Issue 2278773002: Modify RecentTabHelper to be always-on and observe the loading of the pages. (Closed)
Patch Set: Created 4 years, 4 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> 8 #include <memory>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 16 matching lines...) Expand all
27 // 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
28 // snapshots of recent pages on the device. 28 // snapshots of recent pages on the device.
29 class RecentTabHelper 29 class RecentTabHelper
30 : public content::WebContentsObserver, 30 : public content::WebContentsObserver,
31 public content::WebContentsUserData<RecentTabHelper>, 31 public content::WebContentsUserData<RecentTabHelper>,
32 public SnapshotController::Client { 32 public SnapshotController::Client {
33 public: 33 public:
34 ~RecentTabHelper() override; 34 ~RecentTabHelper() override;
35 35
36 // content::WebContentsObserver 36 // content::WebContentsObserver
37 void DidStartNavigation(
38 content::NavigationHandle* navigation_handle) override;
37 void DidFinishNavigation( 39 void DidFinishNavigation(
38 content::NavigationHandle* navigation_handle) override; 40 content::NavigationHandle* navigation_handle) override;
39 void DocumentAvailableInMainFrame() override; 41 void DocumentAvailableInMainFrame() override;
40 void DocumentOnLoadCompletedInMainFrame() override; 42 void DocumentOnLoadCompletedInMainFrame() override;
41 43
42 // SnapshotController::Client 44 // SnapshotController::Client
43 void StartSnapshot() override; 45 void StartSnapshot() override;
44 46
45 // Delegate that is used by RecentTabHelper to get external dependencies. 47 // Delegate that is used by RecentTabHelper to get external dependencies.
46 // Default implementation lives in .cc file, while tests provide an override. 48 // Default implementation lives in .cc file, while tests provide an override.
47 class Delegate { 49 class Delegate {
48 public: 50 public:
49 virtual ~Delegate() {} 51 virtual ~Delegate() {}
50 virtual std::unique_ptr<OfflinePageArchiver> CreatePageArchiver( 52 virtual std::unique_ptr<OfflinePageArchiver> CreatePageArchiver(
51 content::WebContents* web_contents) = 0; 53 content::WebContents* web_contents) = 0;
52 virtual scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() = 0; 54 virtual scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() = 0;
53 // There is no expectations that tab_id is always present. 55 // There is no expectations that tab_id is always present.
54 virtual bool GetTabId(content::WebContents* web_contents, int* tab_id) = 0; 56 virtual bool GetTabId(content::WebContents* web_contents, int* tab_id) = 0;
55 }; 57 };
56 void SetDelegate(std::unique_ptr<RecentTabHelper::Delegate> delegate); 58 void SetDelegate(std::unique_ptr<RecentTabHelper::Delegate> delegate);
57 59
60 bool is_page_ready_for_snapshot() const {
61 return is_page_ready_for_snapshot_;
62 }
63
58 private: 64 private:
59 explicit RecentTabHelper(content::WebContents* web_contents); 65 explicit RecentTabHelper(content::WebContents* web_contents);
60 friend class content::WebContentsUserData<RecentTabHelper>; 66 friend class content::WebContentsUserData<RecentTabHelper>;
61 67
62 68
63 void LazyInitialize(); 69 void EnsureInitialized();
64 void ContinueSnapshotWithIdsToPurge(const std::vector<int64_t>& page_ids); 70 void ContinueSnapshotWithIdsToPurge(const std::vector<int64_t>& page_ids);
65 void ContinueSnapshotAfterPurge(OfflinePageModel::DeletePageResult result); 71 void ContinueSnapshotAfterPurge(OfflinePageModel::DeletePageResult result);
66 void SavePageCallback(OfflinePageModel::SavePageResult result, 72 void SavePageCallback(OfflinePageModel::SavePageResult result,
67 int64_t offline_id); 73 int64_t offline_id);
68 74
69 void ReportSnapshotCompleted(); 75 void ReportSnapshotCompleted();
70 bool IsSamePage() const; 76 bool IsSamePage() const;
71 ClientId client_id() const; 77 ClientId client_id() const;
72 78
73 // Page model is a service, no ownership. 79 // Page model is a service, no ownership.
74 OfflinePageModel* page_model_; 80 OfflinePageModel* page_model_;
dewittj 2016/08/24 23:01:39 please document that page_model_ can be null even
Dmitry Titov 2016/08/25 00:36:09 Done.
75 // If false, never make snapshots off the attached WebContents. 81 // If false, never make snapshots off the attached WebContents.
82 // Not page-specific.
76 bool snapshots_enabled_; 83 bool snapshots_enabled_;
84 // Becomes true during navigation if the page is ready for snapshot as
85 // indicated by at least one callback from SnapshotController.
86 bool is_page_ready_for_snapshot_;
77 // If empty, the tab does not have AndroidId and can not capture pages. 87 // If empty, the tab does not have AndroidId and can not capture pages.
78 std::string tab_id_; 88 std::string tab_id_;
79 89
80 // The URL of the page that is currently being snapshotted. Used to check, 90 // The URL of the page that is currently being snapshotted. Used to check,
81 // during async operations, that WebContents still contains the same page. 91 // during async operations, that WebContents still contains the same page.
82 GURL snapshot_url_; 92 GURL snapshot_url_;
83 std::unique_ptr<SnapshotController> snapshot_controller_; 93 std::unique_ptr<SnapshotController> snapshot_controller_;
dewittj 2016/08/24 23:01:39 also document that this starts out null but then l
Dmitry Titov 2016/08/25 00:36:09 Done.
84 94
85 std::unique_ptr<Delegate> delegate_; 95 std::unique_ptr<Delegate> delegate_;
86 96
87 base::WeakPtrFactory<RecentTabHelper> weak_ptr_factory_; 97 base::WeakPtrFactory<RecentTabHelper> weak_ptr_factory_;
88 98
89 DISALLOW_COPY_AND_ASSIGN(RecentTabHelper); 99 DISALLOW_COPY_AND_ASSIGN(RecentTabHelper);
90 }; 100 };
91 101
92 } // namespace offline_pages 102 } // namespace offline_pages
93 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_RECENT_TAB_HELPER_H_ 103 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_RECENT_TAB_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698