| 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> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // 4. If capture is successful, this tab helper removes the suspended request. | 64 // 4. If capture is successful, this tab helper removes the suspended request. |
| 65 // Otherwise (navigation to other page, close tab) tab helper un-suspends | 65 // Otherwise (navigation to other page, close tab) tab helper un-suspends |
| 66 // the request so the Background Offliner starts working on it. | 66 // the request so the Background Offliner starts working on it. |
| 67 // 5. If Chrome is killed at any point, next time Background Offliner loads | 67 // 5. If Chrome is killed at any point, next time Background Offliner loads |
| 68 // it converts all suspended requests from last session into active. | 68 // it converts all suspended requests from last session into active. |
| 69 void ObserveAndDownloadCurrentPage(const ClientId& client_id, | 69 void ObserveAndDownloadCurrentPage(const ClientId& client_id, |
| 70 int64_t request_id); | 70 int64_t request_id); |
| 71 | 71 |
| 72 private: | 72 private: |
| 73 // Keeps client_id/request_id that will be used for the offline snapshot. | 73 // Keeps client_id/request_id that will be used for the offline snapshot. |
| 74 struct DownloadPageInfo { | 74 struct SnapshotProgressInfo { |
| 75 public: | 75 public: |
| 76 DownloadPageInfo(const ClientId& client_id, | 76 // For a downloads snapshot request, where the |request_id| is defined. |
| 77 int64_t request_id) | 77 SnapshotProgressInfo(const ClientId& client_id, int64_t request_id) |
| 78 : client_id_(client_id), | 78 : client_id(client_id), request_id(request_id) {} |
| 79 request_id_(request_id), | 79 |
| 80 page_snapshot_completed_(false) {} | 80 // For a last_n snapshot request. |
| 81 explicit SnapshotProgressInfo(const ClientId& client_id) |
| 82 : client_id(client_id) {} |
| 83 |
| 84 bool IsForLastN(); |
| 81 | 85 |
| 82 // The ClientID to go with the offline page. | 86 // The ClientID to go with the offline page. |
| 83 ClientId client_id_; | 87 ClientId client_id; |
| 88 |
| 84 // Id of the suspended request in Background Offliner. Used to un-suspend | 89 // Id of the suspended request in Background Offliner. Used to un-suspend |
| 85 // the request if the capture of the current page was not possible (e.g. | 90 // the request if the capture of the current page was not possible (e.g. |
| 86 // the user navigated to another page before current one was loaded). | 91 // the user navigated to another page before current one was loaded). |
| 87 // 0 if this is a "last_1" info. | 92 // 0 if this is a "last_n" info. |
| 88 int64_t request_id_; | 93 int64_t request_id = OfflinePageModel::kInvalidOfflineId; |
| 94 |
| 89 // True if there was at least one snapshot successfully completed. | 95 // True if there was at least one snapshot successfully completed. |
| 90 bool page_snapshot_completed_; | 96 bool page_snapshot_completed = false; |
| 91 }; | 97 }; |
| 92 | 98 |
| 93 explicit RecentTabHelper(content::WebContents* web_contents); | 99 explicit RecentTabHelper(content::WebContents* web_contents); |
| 94 friend class content::WebContentsUserData<RecentTabHelper>; | 100 friend class content::WebContentsUserData<RecentTabHelper>; |
| 95 | 101 |
| 96 void EnsureInitialized(); | 102 void EnsureInitialized(); |
| 97 void ContinueSnapshotWithIdsToPurge(const std::vector<int64_t>& page_ids); | 103 void ContinueSnapshotWithIdsToPurge(const std::vector<int64_t>& page_ids); |
| 98 void ContinueSnapshotAfterPurge(OfflinePageModel::DeletePageResult result); | 104 void ContinueSnapshotAfterPurge(OfflinePageModel::DeletePageResult result); |
| 99 void SavePageCallback(OfflinePageModel::SavePageResult result, | 105 void SavePageCallback(OfflinePageModel::SavePageResult result, |
| 100 int64_t offline_id); | 106 int64_t offline_id); |
| 101 void ReportSnapshotCompleted(); | 107 void ReportSnapshotCompleted(); |
| 102 void ReportDownloadStatusToRequestCoordinator(); | 108 void ReportDownloadStatusToRequestCoordinator(); |
| 103 bool IsSamePage() const; | 109 bool IsSamePage() const; |
| 104 ClientId GetRecentPagesClientId() const; | 110 ClientId GetRecentPagesClientId() const; |
| 105 | 111 |
| 106 // Page model is a service, no ownership. Can be null - for example, in | 112 // Page model is a service, no ownership. Can be null - for example, in |
| 107 // case when tab is in incognito profile. | 113 // case when tab is in incognito profile. |
| 108 OfflinePageModel* page_model_; | 114 OfflinePageModel* page_model_ = nullptr; |
| 109 | 115 |
| 110 // If false, never make snapshots off the attached WebContents. | 116 // If false, never make snapshots off the attached WebContents. |
| 111 // Not page-specific. | 117 // Not page-specific. |
| 112 bool snapshots_enabled_; | 118 bool snapshots_enabled_ = false; |
| 113 | 119 |
| 114 // Becomes true during navigation if the page is ready for snapshot as | 120 // Becomes true during navigation if the page is ready for snapshot as |
| 115 // indicated by at least one callback from SnapshotController. | 121 // indicated by at least one callback from SnapshotController. |
| 116 bool is_page_ready_for_snapshot_; | 122 bool is_page_ready_for_snapshot_ = false; |
| 117 | 123 |
| 118 // Info for the offline page to capture. Null if the tab is not capturing | 124 // Info for the offline page to capture. Null if the tab is not capturing |
| 119 // current page. | 125 // current page. |
| 120 std::unique_ptr<DownloadPageInfo> download_info_; | 126 std::unique_ptr<SnapshotProgressInfo> snapshot_info_; |
| 121 | 127 |
| 122 // If empty, the tab does not have AndroidId and can not capture pages. | 128 // If empty, the tab does not have AndroidId and can not capture pages. |
| 123 std::string tab_id_; | 129 std::string tab_id_; |
| 124 | 130 |
| 125 // The URL of the page that is currently being snapshotted. Used to check, | 131 // The URL of the page that is currently being snapshotted. Used to check, |
| 126 // during async operations, that WebContents still contains the same page. | 132 // during async operations, that WebContents still contains the same page. |
| 127 GURL snapshot_url_; | 133 GURL snapshot_url_; |
| 128 // This starts out null and used as a flag for EnsureInitialized() to do the | 134 // This starts out null and used as a flag for EnsureInitialized() to do the |
| 129 // initialization only once. | 135 // initialization only once. |
| 130 std::unique_ptr<SnapshotController> snapshot_controller_; | 136 std::unique_ptr<SnapshotController> snapshot_controller_; |
| 131 | 137 |
| 132 std::unique_ptr<Delegate> delegate_; | 138 std::unique_ptr<Delegate> delegate_; |
| 133 | 139 |
| 134 base::WeakPtrFactory<RecentTabHelper> weak_ptr_factory_; | 140 base::WeakPtrFactory<RecentTabHelper> weak_ptr_factory_; |
| 135 | 141 |
| 136 DISALLOW_COPY_AND_ASSIGN(RecentTabHelper); | 142 DISALLOW_COPY_AND_ASSIGN(RecentTabHelper); |
| 137 }; | 143 }; |
| 138 | 144 |
| 139 } // namespace offline_pages | 145 } // namespace offline_pages |
| 146 |
| 140 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_RECENT_TAB_HELPER_H_ | 147 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_RECENT_TAB_HELPER_H_ |
| OLD | NEW |