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

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

Issue 2854213005: Last_n: do not delete the currently loading offline snapshot. (Closed)
Patch Set: Created 3 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
« no previous file with comments | « chrome/browser/android/offline_pages/recent_tab_helper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #include "chrome/browser/android/offline_pages/recent_tab_helper.h" 5 #include "chrome/browser/android/offline_pages/recent_tab_helper.h"
6 6
7 #include <queue> 7 #include <queue>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 << web_contents()->GetLastCommittedURL().spec(); 205 << web_contents()->GetLastCommittedURL().spec();
206 206
207 // If there is an ongoing downloads request, lets make Background Offliner 207 // If there is an ongoing downloads request, lets make Background Offliner
208 // take over downloading that page. 208 // take over downloading that page.
209 if (downloads_ongoing_snapshot_info_) { 209 if (downloads_ongoing_snapshot_info_) {
210 DVLOG(1) << " - Passing ongoing downloads request to Background Offliner"; 210 DVLOG(1) << " - Passing ongoing downloads request to Background Offliner";
211 ReportDownloadStatusToRequestCoordinator( 211 ReportDownloadStatusToRequestCoordinator(
212 downloads_ongoing_snapshot_info_.get(), false); 212 downloads_ongoing_snapshot_info_.get(), false);
213 } 213 }
214 214
215 // If the previous page was saved, delete it now. 215 // If currently loading an offline page get a pointer to it. It will be null
216 if (last_n_latest_saved_snapshot_info_) { 216 // otherwise.
217 const OfflinePageItem* current_offline_page =
218 OfflinePageUtils::GetOfflinePageFromWebContents(web_contents());
219
220 // If the previous page was saved, delete it now unless we are currently
221 // loading that very snapshot.
222 if (last_n_latest_saved_snapshot_info_ &&
223 (!current_offline_page ||
224 current_offline_page->offline_id !=
225 last_n_latest_saved_snapshot_info_->request_id)) {
226 DVLOG(1) << " - Deleting previous last_n snapshot with offline_id "
227 << last_n_latest_saved_snapshot_info_->request_id;
217 std::vector<int64_t> id{last_n_latest_saved_snapshot_info_->request_id}; 228 std::vector<int64_t> id{last_n_latest_saved_snapshot_info_->request_id};
218 page_model_->DeletePagesByOfflineId(id, DeletePageCallback()); 229 page_model_->DeletePagesByOfflineId(id, DeletePageCallback());
230 last_n_latest_saved_snapshot_info_.reset();
219 } 231 }
220 232
221 // Cancel any and all in flight snapshot tasks from the previous page. 233 // Cancel any and all in flight snapshot tasks from the previous page.
222 CancelInFlightSnapshots(); 234 CancelInFlightSnapshots();
223 downloads_snapshot_on_hold_ = false; 235 downloads_snapshot_on_hold_ = false;
224 236
225 // Always reset so that posted tasks get canceled. 237 // Always reset so that posted tasks get canceled.
226 snapshot_controller_->Reset(); 238 snapshot_controller_->Reset();
227 239
228 // Check for conditions that should stop last_n from creating snapshots of 240 // Check for conditions that should stop last_n from creating snapshots of
229 // this page: 241 // this page:
230 // - It is an error page. 242 // - It is an error page.
231 // - The navigation is a POST as offline pages are never loaded for them. 243 // - The navigation is a POST as offline pages are never loaded for them.
232 // - The navigated URL is not supported. 244 // - The navigated URL is not supported.
233 // - The page being loaded is already an offline page. 245 // - The page being loaded is already an offline page.
234 bool can_save = 246 bool can_save =
235 !navigation_handle->IsErrorPage() && !navigation_handle->IsPost() && 247 !navigation_handle->IsErrorPage() && !navigation_handle->IsPost() &&
236 OfflinePageModel::CanSaveURL(web_contents()->GetLastCommittedURL()) && 248 OfflinePageModel::CanSaveURL(web_contents()->GetLastCommittedURL()) &&
237 OfflinePageUtils::GetOfflinePageFromWebContents(web_contents()) == 249 current_offline_page == nullptr;
238 nullptr; 250 DVLOG_IF(1, !can_save)
239 DVLOG_IF(1, !can_save) << " - Page can not be saved for offline usage"; 251 << " - Page can not be saved for offline usage (reasons: "
252 << !navigation_handle->IsErrorPage() << ", "
253 << !navigation_handle->IsPost() << ", "
254 << OfflinePageModel::CanSaveURL(web_contents()->GetLastCommittedURL())
255 << ", " << (current_offline_page == nullptr) << ")";
240 256
241 UMA_HISTOGRAM_BOOLEAN("OfflinePages.CanSaveRecentPage", can_save); 257 UMA_HISTOGRAM_BOOLEAN("OfflinePages.CanSaveRecentPage", can_save);
242 258
243 if (!can_save) 259 if (!can_save)
244 snapshot_controller_->Stop(); 260 snapshot_controller_->Stop();
245 last_n_listen_to_tab_hidden_ = can_save && !delegate_->IsLowEndDevice() && 261 last_n_listen_to_tab_hidden_ = can_save && !delegate_->IsLowEndDevice() &&
246 IsOffliningRecentPagesEnabled(); 262 IsOffliningRecentPagesEnabled();
247 DVLOG_IF(1, can_save && !last_n_listen_to_tab_hidden_) 263 DVLOG_IF(1, can_save && !last_n_listen_to_tab_hidden_)
248 << " - Page can not be saved by last_n"; 264 << " - Page can not be saved by last_n";
249 } 265 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 last_n_ongoing_snapshot_info_ = 319 last_n_ongoing_snapshot_info_ =
304 base::MakeUnique<SnapshotProgressInfo>(GetRecentPagesClientId()); 320 base::MakeUnique<SnapshotProgressInfo>(GetRecentPagesClientId());
305 DCHECK(last_n_ongoing_snapshot_info_->IsForLastN()); 321 DCHECK(last_n_ongoing_snapshot_info_->IsForLastN());
306 DCHECK(snapshots_enabled_); 322 DCHECK(snapshots_enabled_);
307 // Remove previously captured pages for this tab. 323 // Remove previously captured pages for this tab.
308 page_model_->GetOfflineIdsForClientId( 324 page_model_->GetOfflineIdsForClientId(
309 GetRecentPagesClientId(), 325 GetRecentPagesClientId(),
310 base::Bind(&RecentTabHelper::ContinueSnapshotWithIdsToPurge, 326 base::Bind(&RecentTabHelper::ContinueSnapshotWithIdsToPurge,
311 weak_ptr_factory_.GetWeakPtr(), 327 weak_ptr_factory_.GetWeakPtr(),
312 last_n_ongoing_snapshot_info_.get())); 328 last_n_ongoing_snapshot_info_.get()));
329 last_n_latest_saved_snapshot_info_.reset();
313 } 330 }
314 331
315 void RecentTabHelper::WasShown() { 332 void RecentTabHelper::WasShown() {
316 // If the tab was closing and is now being shown, the closure was reverted. 333 // If the tab was closing and is now being shown, the closure was reverted.
317 DVLOG_IF(0, tab_is_closing_) << "Tab is not closing anymore: " 334 DVLOG_IF(0, tab_is_closing_) << "Tab is not closing anymore: "
318 << web_contents()->GetLastCommittedURL().spec(); 335 << web_contents()->GetLastCommittedURL().spec();
319 tab_is_closing_ = false; 336 tab_is_closing_ = false;
320 } 337 }
321 338
322 void RecentTabHelper::WillCloseTab() { 339 void RecentTabHelper::WillCloseTab() {
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 517
501 void RecentTabHelper::CancelInFlightSnapshots() { 518 void RecentTabHelper::CancelInFlightSnapshots() {
502 DVLOG_IF(1, last_n_ongoing_snapshot_info_) 519 DVLOG_IF(1, last_n_ongoing_snapshot_info_)
503 << " - Canceling ongoing last_n snapshot"; 520 << " - Canceling ongoing last_n snapshot";
504 DVLOG_IF(1, downloads_ongoing_snapshot_info_) 521 DVLOG_IF(1, downloads_ongoing_snapshot_info_)
505 << " - Canceling ongoing downloads snapshot"; 522 << " - Canceling ongoing downloads snapshot";
506 weak_ptr_factory_.InvalidateWeakPtrs(); 523 weak_ptr_factory_.InvalidateWeakPtrs();
507 downloads_ongoing_snapshot_info_.reset(); 524 downloads_ongoing_snapshot_info_.reset();
508 downloads_latest_saved_snapshot_info_.reset(); 525 downloads_latest_saved_snapshot_info_.reset();
509 last_n_ongoing_snapshot_info_.reset(); 526 last_n_ongoing_snapshot_info_.reset();
510 last_n_latest_saved_snapshot_info_.reset();
511 } 527 }
512 528
513 } // namespace offline_pages 529 } // namespace offline_pages
OLDNEW
« no previous file with comments | « chrome/browser/android/offline_pages/recent_tab_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698