| 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 "components/offline_pages/client_namespace_constants.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 { |
| 29 const char* kClientNamespace = "last_n"; | |
| 30 | 30 |
| 31 // Max number of pages to keep. The oldest pages that are over this count are | 31 // Max number of pages to keep. The oldest pages that are over this count are |
| 32 // deleted before the next one is saved. | 32 // deleted before the next one is saved. |
| 33 const size_t kMaxPagesToKeep = 50; | 33 const size_t kMaxPagesToKeep = 50; |
| 34 | 34 |
| 35 // Predicate for priority_queue used to compute the oldest pages. | 35 // Predicate for priority_queue used to compute the oldest pages. |
| 36 struct ComparePagesForPurge { | 36 struct ComparePagesForPurge { |
| 37 bool operator()(const offline_pages::OfflinePageItem* left, | 37 bool operator()(const offline_pages::OfflinePageItem* left, |
| 38 const offline_pages::OfflinePageItem* right) const { | 38 const offline_pages::OfflinePageItem* right) const { |
| 39 return left->creation_time > right->creation_time; | 39 return left->creation_time > right->creation_time; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 void RecentTabHelper::ReportSnapshotCompleted() { | 188 void RecentTabHelper::ReportSnapshotCompleted() { |
| 189 snapshot_controller_->PendingSnapshotCompleted(); | 189 snapshot_controller_->PendingSnapshotCompleted(); |
| 190 } | 190 } |
| 191 | 191 |
| 192 bool RecentTabHelper::IsSamePage() const { | 192 bool RecentTabHelper::IsSamePage() const { |
| 193 return web_contents() && | 193 return web_contents() && |
| 194 (web_contents()->GetLastCommittedURL() == snapshot_url_); | 194 (web_contents()->GetLastCommittedURL() == snapshot_url_); |
| 195 } | 195 } |
| 196 | 196 |
| 197 ClientId RecentTabHelper::client_id() const { | 197 ClientId RecentTabHelper::client_id() const { |
| 198 return ClientId(kClientNamespace, ""); | 198 return ClientId(kLastNNamespace, ""); |
| 199 } | 199 } |
| 200 | 200 |
| 201 void RecentTabHelper::SetArchiveFactoryForTest( | 201 void RecentTabHelper::SetArchiveFactoryForTest( |
| 202 std::unique_ptr<TestArchiveFactory> test_archive_factory) { | 202 std::unique_ptr<TestArchiveFactory> test_archive_factory) { |
| 203 test_archive_factory_ = std::move(test_archive_factory); | 203 test_archive_factory_ = std::move(test_archive_factory); |
| 204 } | 204 } |
| 205 | 205 |
| 206 void RecentTabHelper::SetTaskRunnerForTest( | 206 void RecentTabHelper::SetTaskRunnerForTest( |
| 207 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { | 207 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { |
| 208 snapshot_controller_.reset(new SnapshotController(task_runner, this)); | 208 snapshot_controller_.reset(new SnapshotController(task_runner, this)); |
| 209 } | 209 } |
| 210 | 210 |
| 211 } // namespace offline_pages | 211 } // namespace offline_pages |
| OLD | NEW |