| 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" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" | 17 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" |
| 18 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" | 18 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" |
| 19 #include "chrome/browser/android/offline_pages/offline_page_utils.h" |
| 19 #include "components/offline_pages/offline_page_item.h" | 20 #include "components/offline_pages/offline_page_item.h" |
| 20 #include "components/offline_pages/offline_page_model.h" | 21 #include "components/offline_pages/offline_page_model.h" |
| 21 #include "content/public/browser/browser_context.h" | 22 #include "content/public/browser/browser_context.h" |
| 22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 23 #include "content/public/browser/navigation_entry.h" | 24 #include "content/public/browser/navigation_entry.h" |
| 24 #include "content/public/browser/navigation_handle.h" | 25 #include "content/public/browser/navigation_handle.h" |
| 25 | 26 |
| 26 DEFINE_WEB_CONTENTS_USER_DATA_KEY(offline_pages::RecentTabHelper); | 27 DEFINE_WEB_CONTENTS_USER_DATA_KEY(offline_pages::RecentTabHelper); |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // - compute the set of old 'last_n' pages that have to be purged | 86 // - compute the set of old 'last_n' pages that have to be purged |
| 86 // - delete the pages found in the previous step | 87 // - delete the pages found in the previous step |
| 87 // - snapshot the current web contents | 88 // - snapshot the current web contents |
| 88 // Along the chain, the original URL is passed and compared, to detect | 89 // Along the chain, the original URL is passed and compared, to detect |
| 89 // possible navigation and cancel snapshot in that case. | 90 // possible navigation and cancel snapshot in that case. |
| 90 void RecentTabHelper::StartSnapshot() { | 91 void RecentTabHelper::StartSnapshot() { |
| 91 if (never_do_snapshots_) | 92 if (never_do_snapshots_) |
| 92 return; | 93 return; |
| 93 | 94 |
| 94 GURL url = web_contents()->GetLastCommittedURL(); | 95 GURL url = web_contents()->GetLastCommittedURL(); |
| 95 bool can_save = page_model_->CanSavePage(url); | 96 bool can_save = OfflinePageUtils::CanSaveURL(url); |
| 96 UMA_HISTOGRAM_BOOLEAN("OfflinePages.CanSaveRecentPage", can_save); | 97 UMA_HISTOGRAM_BOOLEAN("OfflinePages.CanSaveRecentPage", can_save); |
| 97 if (!can_save) | 98 if (!can_save) |
| 98 return; | 99 return; |
| 99 | 100 |
| 100 snapshot_url_ = url; | 101 snapshot_url_ = url; |
| 101 | 102 |
| 102 // TODO(dimich): Implement automatic cleanup as per design doc, based on | 103 // TODO(dimich): Implement automatic cleanup as per design doc, based on |
| 103 // storage limits and page age. | 104 // storage limits and page age. |
| 104 // This algorithm (remove pages before making sure the save was successful) | 105 // This algorithm (remove pages before making sure the save was successful) |
| 105 // prefers keeping the storage use low and under control by potentially | 106 // prefers keeping the storage use low and under control by potentially |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 std::unique_ptr<TestArchiveFactory> test_archive_factory) { | 202 std::unique_ptr<TestArchiveFactory> test_archive_factory) { |
| 202 test_archive_factory_ = std::move(test_archive_factory); | 203 test_archive_factory_ = std::move(test_archive_factory); |
| 203 } | 204 } |
| 204 | 205 |
| 205 void RecentTabHelper::SetTaskRunnerForTest( | 206 void RecentTabHelper::SetTaskRunnerForTest( |
| 206 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { | 207 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { |
| 207 snapshot_controller_.reset(new SnapshotController(task_runner, this)); | 208 snapshot_controller_.reset(new SnapshotController(task_runner, this)); |
| 208 } | 209 } |
| 209 | 210 |
| 210 } // namespace offline_pages | 211 } // namespace offline_pages |
| OLD | NEW |