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

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

Issue 2824623002: Last_n: Delete previously saved snapshot when navigating. (Closed)
Patch Set: Created 3 years, 8 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 (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.
216 if (last_n_latest_saved_snapshot_info_) {
dewittj 2017/04/17 21:17:42 This is an interesting strategy, I wonder if there
carlosk 2017/04/18 17:56:19 There is a very small window of time between the p
217 std::vector<int64_t> id{last_n_latest_saved_snapshot_info_->request_id};
218 page_model_->DeletePagesByOfflineId(id, DeletePageCallback());
219 }
220
215 // Cancel any and all in flight snapshot tasks from the previous page. 221 // Cancel any and all in flight snapshot tasks from the previous page.
216 DVLOG_IF(1, last_n_ongoing_snapshot_info_)
217 << " - Canceling ongoing last_n snapshot";
218 CancelInFlightSnapshots(); 222 CancelInFlightSnapshots();
219 downloads_snapshot_on_hold_ = false; 223 downloads_snapshot_on_hold_ = false;
220 224
221 // Always reset so that posted tasks get canceled. 225 // Always reset so that posted tasks get canceled.
222 snapshot_controller_->Reset(); 226 snapshot_controller_->Reset();
223 227
224 // Check for conditions that would cause us not to snapshot. 228 // Check for conditions that would cause us not to snapshot.
225 bool can_save = 229 bool can_save =
226 !navigation_handle->IsErrorPage() && 230 !navigation_handle->IsErrorPage() &&
227 OfflinePageModel::CanSaveURL(web_contents()->GetLastCommittedURL()) && 231 OfflinePageModel::CanSaveURL(web_contents()->GetLastCommittedURL()) &&
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 OfflinePageUtils::GetOriginalURLFromWebContents(web_contents()); 416 OfflinePageUtils::GetOriginalURLFromWebContents(web_contents());
413 page_model_->SavePage( 417 page_model_->SavePage(
414 save_page_params, delegate_->CreatePageArchiver(web_contents()), 418 save_page_params, delegate_->CreatePageArchiver(web_contents()),
415 base::Bind(&RecentTabHelper::SavePageCallback, 419 base::Bind(&RecentTabHelper::SavePageCallback,
416 weak_ptr_factory_.GetWeakPtr(), snapshot_info)); 420 weak_ptr_factory_.GetWeakPtr(), snapshot_info));
417 } 421 }
418 422
419 void RecentTabHelper::SavePageCallback(SnapshotProgressInfo* snapshot_info, 423 void RecentTabHelper::SavePageCallback(SnapshotProgressInfo* snapshot_info,
420 OfflinePageModel::SavePageResult result, 424 OfflinePageModel::SavePageResult result,
421 int64_t offline_id) { 425 int64_t offline_id) {
422 DCHECK(snapshot_info->IsForLastN() || 426 DCHECK((snapshot_info->IsForLastN() &&
427 snapshot_info->request_id == OfflinePageModel::kInvalidOfflineId) ||
423 snapshot_info->request_id == offline_id); 428 snapshot_info->request_id == offline_id);
429 // Store the assigned offline_id (for downloads case it will already contain
430 // the same value).
431 snapshot_info->request_id = offline_id;
424 ReportSnapshotCompleted(snapshot_info, result == SavePageResult::SUCCESS); 432 ReportSnapshotCompleted(snapshot_info, result == SavePageResult::SUCCESS);
425 } 433 }
426 434
427 // Note: this is the final step in the chain of callbacks and it's where the 435 // Note: this is the final step in the chain of callbacks and it's where the
428 // behavior is different depending on this being a last_n or downloads snapshot. 436 // behavior is different depending on this being a last_n or downloads snapshot.
429 void RecentTabHelper::ReportSnapshotCompleted( 437 void RecentTabHelper::ReportSnapshotCompleted(
430 SnapshotProgressInfo* snapshot_info, 438 SnapshotProgressInfo* snapshot_info,
431 bool success) { 439 bool success) {
432 DVLOG(1) << (snapshot_info->IsForLastN() ? "Last_n" : "Downloads") 440 DVLOG(1) << (snapshot_info->IsForLastN() ? "Last_n" : "Downloads")
433 << " snapshot " << (success ? "succeeded" : "failed") 441 << " snapshot " << (success ? "succeeded" : "failed")
434 << " for: " << web_contents()->GetLastCommittedURL().spec(); 442 << " for: " << web_contents()->GetLastCommittedURL().spec();
435 if (snapshot_info->IsForLastN()) { 443 if (snapshot_info->IsForLastN()) {
436 DCHECK_EQ(snapshot_info, last_n_ongoing_snapshot_info_.get()); 444 DCHECK_EQ(snapshot_info, last_n_ongoing_snapshot_info_.get());
437 last_n_ongoing_snapshot_info_.reset(); 445 if (success) {
446 last_n_latest_saved_snapshot_info_ =
447 std::move(last_n_ongoing_snapshot_info_);
448 } else {
449 last_n_ongoing_snapshot_info_.reset();
450 }
438 return; 451 return;
439 } 452 }
440 453
441 DCHECK_EQ(snapshot_info, downloads_ongoing_snapshot_info_.get()); 454 DCHECK_EQ(snapshot_info, downloads_ongoing_snapshot_info_.get());
442 snapshot_controller_->PendingSnapshotCompleted(); 455 snapshot_controller_->PendingSnapshotCompleted();
443 // Tell RequestCoordinator how the request should be processed further. 456 // Tell RequestCoordinator how the request should be processed further.
444 ReportDownloadStatusToRequestCoordinator(snapshot_info, success); 457 ReportDownloadStatusToRequestCoordinator(snapshot_info, success);
445 if (success) { 458 if (success) {
446 downloads_latest_saved_snapshot_info_ = 459 downloads_latest_saved_snapshot_info_ =
447 std::move(downloads_ongoing_snapshot_info_); 460 std::move(downloads_ongoing_snapshot_info_);
(...skipping 26 matching lines...) Expand all
474 request_coordinator->EnableForOffliner(snapshot_info->request_id, 487 request_coordinator->EnableForOffliner(snapshot_info->request_id,
475 snapshot_info->client_id); 488 snapshot_info->client_id);
476 } 489 }
477 } 490 }
478 491
479 ClientId RecentTabHelper::GetRecentPagesClientId() const { 492 ClientId RecentTabHelper::GetRecentPagesClientId() const {
480 return ClientId(kLastNNamespace, tab_id_); 493 return ClientId(kLastNNamespace, tab_id_);
481 } 494 }
482 495
483 void RecentTabHelper::CancelInFlightSnapshots() { 496 void RecentTabHelper::CancelInFlightSnapshots() {
497 DVLOG_IF(1, last_n_ongoing_snapshot_info_)
498 << " - Canceling ongoing last_n snapshot";
499 DVLOG_IF(1, downloads_ongoing_snapshot_info_)
500 << " - Canceling ongoing downloads snapshot";
484 weak_ptr_factory_.InvalidateWeakPtrs(); 501 weak_ptr_factory_.InvalidateWeakPtrs();
485 downloads_ongoing_snapshot_info_.reset(); 502 downloads_ongoing_snapshot_info_.reset();
486 downloads_latest_saved_snapshot_info_.reset(); 503 downloads_latest_saved_snapshot_info_.reset();
487 last_n_ongoing_snapshot_info_.reset(); 504 last_n_ongoing_snapshot_info_.reset();
505 last_n_latest_saved_snapshot_info_.reset();
488 } 506 }
489 507
490 } // namespace offline_pages 508 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698