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

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

Issue 2705323006: Last_n: Do not save a snapshot of a closing tab. (Closed)
Patch Set: Minor comment changes. Created 3 years, 10 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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 CancelInFlightSnapshots(); 240 CancelInFlightSnapshots();
241 } 241 }
242 242
243 // TODO(carlosk): this method is also called when the tab is being closed, when 243 // TODO(carlosk): this method is also called when the tab is being closed, when
244 // saving a snapshot is probably useless (low probability of the user undoing 244 // saving a snapshot is probably useless (low probability of the user undoing
245 // the close). We should detect that and avoid the saving. 245 // the close). We should detect that and avoid the saving.
246 void RecentTabHelper::WasHidden() { 246 void RecentTabHelper::WasHidden() {
247 if (!IsOffliningRecentPagesEnabled()) 247 if (!IsOffliningRecentPagesEnabled())
248 return; 248 return;
249 249
250 // Return immediately if last_n is not listening to tab hidden events or if a 250 // Return immediately if last_n is not listening to tab hidden events, if a
251 // last_n snapshot is currently being saved. 251 // last_n snapshot is currently being saved or if the tab is closing.
252 if (!last_n_listen_to_tab_hidden_ || last_n_ongoing_snapshot_info_) 252 if (!last_n_listen_to_tab_hidden_ || last_n_ongoing_snapshot_info_ ||
253 tab_is_closing) {
254 DVLOG(1) << "Will not snapshot for last_n (reasons: "
255 << !last_n_listen_to_tab_hidden_ << ", "
256 << !!last_n_ongoing_snapshot_info_ << ", " << tab_is_closing
257 << ") for: " << web_contents()->GetLastCommittedURL().spec();
253 return; 258 return;
259 }
254 260
255 // Do not save if page quality is too low. 261 // Do not save if page quality is too low.
256 // Note: we assume page quality for a page can only increase. 262 // Note: we assume page quality for a page can only increase.
257 if (snapshot_controller_->current_page_quality() == PageQuality::POOR) 263 if (snapshot_controller_->current_page_quality() == PageQuality::POOR)
258 return; 264 return;
259 265
260 last_n_ongoing_snapshot_info_ = 266 last_n_ongoing_snapshot_info_ =
261 base::MakeUnique<SnapshotProgressInfo>(GetRecentPagesClientId()); 267 base::MakeUnique<SnapshotProgressInfo>(GetRecentPagesClientId());
262 DCHECK(last_n_ongoing_snapshot_info_->IsForLastN()); 268 DCHECK(last_n_ongoing_snapshot_info_->IsForLastN());
263 DCHECK(snapshots_enabled_); 269 DCHECK(snapshots_enabled_);
264 // Remove previously captured pages for this tab. 270 // Remove previously captured pages for this tab.
265 page_model_->GetOfflineIdsForClientId( 271 page_model_->GetOfflineIdsForClientId(
266 GetRecentPagesClientId(), 272 GetRecentPagesClientId(),
267 base::Bind(&RecentTabHelper::ContinueSnapshotWithIdsToPurge, 273 base::Bind(&RecentTabHelper::ContinueSnapshotWithIdsToPurge,
268 weak_ptr_factory_.GetWeakPtr(), 274 weak_ptr_factory_.GetWeakPtr(),
269 last_n_ongoing_snapshot_info_.get())); 275 last_n_ongoing_snapshot_info_.get()));
270 } 276 }
271 277
278 void RecentTabHelper::WasShown() {
279 // If the tab was closing and is now being shown, the closure was reverted.
280 DVLOG_IF(0, tab_is_closing) << "Tab is not closing anymore: "
281 << web_contents()->GetLastCommittedURL().spec();
282 tab_is_closing = false;
283 }
284
285 void RecentTabHelper::WillCloseTab() {
286 DVLOG(1) << "Tab is now closing: "
287 << web_contents()->GetLastCommittedURL().spec();
288 tab_is_closing = true;
289 }
290
272 // TODO(carlosk): rename this to RequestSnapshot and make it return a bool 291 // TODO(carlosk): rename this to RequestSnapshot and make it return a bool
273 // representing the acceptance of the snapshot request. 292 // representing the acceptance of the snapshot request.
274 void RecentTabHelper::StartSnapshot() { 293 void RecentTabHelper::StartSnapshot() {
275 DCHECK_NE(PageQuality::POOR, snapshot_controller_->current_page_quality()); 294 DCHECK_NE(PageQuality::POOR, snapshot_controller_->current_page_quality());
276 295
277 // As long as snapshots are enabled for this tab, there are two situations 296 // As long as snapshots are enabled for this tab, there are two situations
278 // that allow for a navigation event to start a snapshot: 297 // that allow for a navigation event to start a snapshot:
279 // 1) There is a request on hold waiting for the page to be minimally loaded. 298 // 1) There is a request on hold waiting for the page to be minimally loaded.
280 if (snapshots_enabled_ && downloads_snapshot_on_hold_) { 299 if (snapshots_enabled_ && downloads_snapshot_on_hold_) {
281 downloads_snapshot_on_hold_ = false; 300 downloads_snapshot_on_hold_ = false;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 } 442 }
424 443
425 void RecentTabHelper::CancelInFlightSnapshots() { 444 void RecentTabHelper::CancelInFlightSnapshots() {
426 weak_ptr_factory_.InvalidateWeakPtrs(); 445 weak_ptr_factory_.InvalidateWeakPtrs();
427 downloads_ongoing_snapshot_info_.reset(); 446 downloads_ongoing_snapshot_info_.reset();
428 downloads_latest_saved_snapshot_info_.reset(); 447 downloads_latest_saved_snapshot_info_.reset();
429 last_n_ongoing_snapshot_info_.reset(); 448 last_n_ongoing_snapshot_info_.reset();
430 } 449 }
431 450
432 } // namespace offline_pages 451 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698