| OLD | NEW |
| 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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 if (downloads_ongoing_snapshot_info_) { | 254 if (downloads_ongoing_snapshot_info_) { |
| 255 DVLOG(1) << "WebContents destroyed; passing ongoing downloads request to " | 255 DVLOG(1) << "WebContents destroyed; passing ongoing downloads request to " |
| 256 "Background Offliner"; | 256 "Background Offliner"; |
| 257 ReportDownloadStatusToRequestCoordinator( | 257 ReportDownloadStatusToRequestCoordinator( |
| 258 downloads_ongoing_snapshot_info_.get(), false); | 258 downloads_ongoing_snapshot_info_.get(), false); |
| 259 } | 259 } |
| 260 // And cancel any ongoing snapshots. | 260 // And cancel any ongoing snapshots. |
| 261 CancelInFlightSnapshots(); | 261 CancelInFlightSnapshots(); |
| 262 } | 262 } |
| 263 | 263 |
| 264 // TODO(carlosk): this method is also called when the tab is being closed, when | |
| 265 // saving a snapshot is probably useless (low probability of the user undoing | |
| 266 // the close). We should detect that and avoid the saving. | |
| 267 void RecentTabHelper::WasHidden() { | 264 void RecentTabHelper::WasHidden() { |
| 268 if (!IsOffliningRecentPagesEnabled()) | 265 if (!IsOffliningRecentPagesEnabled()) |
| 269 return; | 266 return; |
| 270 | 267 |
| 271 // Return immediately if last_n is not listening to tab hidden events, if a | 268 // Return immediately if last_n is not listening to tab hidden events, if a |
| 272 // last_n snapshot is currently being saved or if the tab is closing. | 269 // last_n snapshot is currently being saved or if the tab is closing. |
| 273 if (!last_n_listen_to_tab_hidden_ || last_n_ongoing_snapshot_info_ || | 270 if (!last_n_listen_to_tab_hidden_ || last_n_ongoing_snapshot_info_ || |
| 274 tab_is_closing_) { | 271 tab_is_closing_) { |
| 275 DVLOG(1) << "Will not snapshot for last_n (reasons: " | 272 DVLOG(1) << "Will not snapshot for last_n (reasons: " |
| 276 << !last_n_listen_to_tab_hidden_ << ", " | 273 << !last_n_listen_to_tab_hidden_ << ", " |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 } | 476 } |
| 480 | 477 |
| 481 void RecentTabHelper::CancelInFlightSnapshots() { | 478 void RecentTabHelper::CancelInFlightSnapshots() { |
| 482 weak_ptr_factory_.InvalidateWeakPtrs(); | 479 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 483 downloads_ongoing_snapshot_info_.reset(); | 480 downloads_ongoing_snapshot_info_.reset(); |
| 484 downloads_latest_saved_snapshot_info_.reset(); | 481 downloads_latest_saved_snapshot_info_.reset(); |
| 485 last_n_ongoing_snapshot_info_.reset(); | 482 last_n_ongoing_snapshot_info_.reset(); |
| 486 } | 483 } |
| 487 | 484 |
| 488 } // namespace offline_pages | 485 } // namespace offline_pages |
| OLD | NEW |