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

Unified Diff: components/offline_pages/offline_page_model.cc

Issue 1959393002: Choose the best offline page when given an online URL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nits. Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: components/offline_pages/offline_page_model.cc
diff --git a/components/offline_pages/offline_page_model.cc b/components/offline_pages/offline_page_model.cc
index 8c2e652c5f8e192094ba0a239e5d1891e32e6151..25b2016b02d4840da002015c3a906e6570247d92 100644
--- a/components/offline_pages/offline_page_model.cc
+++ b/components/offline_pages/offline_page_model.cc
@@ -429,6 +429,26 @@ const OfflinePageItem* OfflinePageModel::MaybeGetPageByOfflineURL(
return nullptr;
}
+void OfflinePageModel::GetBestPageForOnlineURL(
+ const GURL& online_url,
+ const SingleOfflinePageItemCallback callback) {
+ RunWhenLoaded(
+ base::Bind(&OfflinePageModel::GetBestPageForOnlineURLWhenLoadDone,
+ weak_ptr_factory_.GetWeakPtr(), online_url, callback));
+}
+
+void OfflinePageModel::GetBestPageForOnlineURLWhenLoadDone(
+ const GURL& online_url,
+ const SingleOfflinePageItemCallback& callback) const {
+ SingleOfflinePageItemResult result;
+
+ const OfflinePageItem* best_page = MaybeGetBestPageForOnlineURL(online_url);
+ if (best_page != nullptr)
+ result = *best_page;
+
+ callback.Run(result);
+}
+
void OfflinePageModel::GetPagesByOnlineURL(
const GURL& online_url,
const MultipleOfflinePageItemCallback& callback) {
@@ -450,13 +470,16 @@ void OfflinePageModel::GetPagesByOnlineURLWhenLoadDone(
callback.Run(result);
}
-const OfflinePageItem* OfflinePageModel::MaybeGetPageByOnlineURL(
+const OfflinePageItem* OfflinePageModel::MaybeGetBestPageForOnlineURL(
const GURL& online_url) const {
+ const OfflinePageItem* result = nullptr;
for (const auto& id_page_pair : offline_pages_) {
- if (id_page_pair.second.url == online_url)
- return &(id_page_pair.second);
+ if (id_page_pair.second.url == online_url) {
+ if (!result || id_page_pair.second.creation_time > result->creation_time)
+ result = &(id_page_pair.second);
+ }
}
- return nullptr;
+ return result;
}
void OfflinePageModel::CheckForExternalFileDeletion() {
« no previous file with comments | « components/offline_pages/offline_page_model.h ('k') | components/offline_pages/offline_page_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698