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

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

Issue 2773273002: Last_n: do not save snapshot of custom tabs. (Closed)
Patch Set: Created 3 years, 9 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 std::unique_ptr<offline_pages::OfflinePageArchiver> CreatePageArchiver( 42 std::unique_ptr<offline_pages::OfflinePageArchiver> CreatePageArchiver(
43 content::WebContents* web_contents) override { 43 content::WebContents* web_contents) override {
44 return base::MakeUnique<offline_pages::OfflinePageMHTMLArchiver>( 44 return base::MakeUnique<offline_pages::OfflinePageMHTMLArchiver>(
45 web_contents); 45 web_contents);
46 } 46 }
47 bool GetTabId(content::WebContents* web_contents, int* tab_id) override { 47 bool GetTabId(content::WebContents* web_contents, int* tab_id) override {
48 return offline_pages::OfflinePageUtils::GetTabId(web_contents, tab_id); 48 return offline_pages::OfflinePageUtils::GetTabId(web_contents, tab_id);
49 } 49 }
50 bool IsLowEndDevice() override { return is_low_end_device_; } 50 bool IsLowEndDevice() override { return is_low_end_device_; }
51 51
52 bool IsCustomTab(content::WebContents* web_contents) override {
53 return offline_pages::OfflinePageUtils::IsCurrentlyACustomTab(web_contents);
54 }
55
52 private: 56 private:
53 // Cached value of whether low end device. 57 // Cached value of whether low end device.
54 bool is_low_end_device_; 58 bool is_low_end_device_;
55 }; 59 };
56 } // namespace 60 } // namespace
57 61
58 namespace offline_pages { 62 namespace offline_pages {
59 63
60 using PageQuality = SnapshotController::PageQuality; 64 using PageQuality = SnapshotController::PageQuality;
61 65
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 downloads_ongoing_snapshot_info_.get(), false); 263 downloads_ongoing_snapshot_info_.get(), false);
260 } 264 }
261 // And cancel any ongoing snapshots. 265 // And cancel any ongoing snapshots.
262 CancelInFlightSnapshots(); 266 CancelInFlightSnapshots();
263 } 267 }
264 268
265 void RecentTabHelper::WasHidden() { 269 void RecentTabHelper::WasHidden() {
266 if (!IsOffliningRecentPagesEnabled()) 270 if (!IsOffliningRecentPagesEnabled())
267 return; 271 return;
268 272
269 // Return immediately if last_n is not listening to tab hidden events, if a 273 // Do not save a snapshots if any of these are true:
270 // last_n snapshot is currently being saved or if the tab is closing. 274 // - Last_n is not listening to tab hidden events.
275 // - A last_n snapshot is currently being saved.
276 // - The tab is in the process of being closed.
277 // - The tab is currently presented as a custom tab.
271 if (!last_n_listen_to_tab_hidden_ || last_n_ongoing_snapshot_info_ || 278 if (!last_n_listen_to_tab_hidden_ || last_n_ongoing_snapshot_info_ ||
272 tab_is_closing_) { 279 tab_is_closing_ || delegate_->IsCustomTab(web_contents())) {
273 DVLOG(1) << "Will not snapshot for last_n (reasons: " 280 DVLOG(1) << "Will not snapshot for last_n (reasons: "
274 << !last_n_listen_to_tab_hidden_ << ", " 281 << !last_n_listen_to_tab_hidden_ << ", "
275 << !!last_n_ongoing_snapshot_info_ << ", " << tab_is_closing_ 282 << !!last_n_ongoing_snapshot_info_ << ", " << tab_is_closing_
283 << ", " << delegate_->IsCustomTab(web_contents())
276 << ") for: " << web_contents()->GetLastCommittedURL().spec(); 284 << ") for: " << web_contents()->GetLastCommittedURL().spec();
277 return; 285 return;
278 } 286 }
279 287
280 // Do not save if page quality is too low. 288 // Do not save if page quality is too low.
281 // Note: we assume page quality for a page can only increase. 289 // Note: we assume page quality for a page can only increase.
282 if (snapshot_controller_->current_page_quality() == PageQuality::POOR) { 290 if (snapshot_controller_->current_page_quality() == PageQuality::POOR) {
283 DVLOG(1) << "Will not snapshot for last_n (page quality too low) for: " 291 DVLOG(1) << "Will not snapshot for last_n (page quality too low) for: "
284 << web_contents()->GetLastCommittedURL().spec(); 292 << web_contents()->GetLastCommittedURL().spec();
285 return; 293 return;
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 } 485 }
478 486
479 void RecentTabHelper::CancelInFlightSnapshots() { 487 void RecentTabHelper::CancelInFlightSnapshots() {
480 weak_ptr_factory_.InvalidateWeakPtrs(); 488 weak_ptr_factory_.InvalidateWeakPtrs();
481 downloads_ongoing_snapshot_info_.reset(); 489 downloads_ongoing_snapshot_info_.reset();
482 downloads_latest_saved_snapshot_info_.reset(); 490 downloads_latest_saved_snapshot_info_.reset();
483 last_n_ongoing_snapshot_info_.reset(); 491 last_n_ongoing_snapshot_info_.reset();
484 } 492 }
485 493
486 } // namespace offline_pages 494 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698