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

Unified Diff: components/offline_pages/offline_page_model_impl.cc

Issue 2503853004: Support getting offline pages also by original URL (Closed)
Patch Set: Make NTP redirect work per comment Created 4 years, 1 month 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_impl.cc
diff --git a/components/offline_pages/offline_page_model_impl.cc b/components/offline_pages/offline_page_model_impl.cc
index 094dab25e128153b166610e74db5f884e2a17c93..cc10c7611e244274b8243d8310a927c522d870ee 100644
--- a/components/offline_pages/offline_page_model_impl.cc
+++ b/components/offline_pages/offline_page_model_impl.cc
@@ -608,36 +608,43 @@ void OfflinePageModelImpl::GetPageByOfflineId(
multiple_callback));
}
-void OfflinePageModelImpl::GetPagesByOnlineURL(
- const GURL& online_url,
+void OfflinePageModelImpl::GetPagesByURL(
+ const GURL& url,
+ URLSearchMode url_search_mode,
const MultipleOfflinePageItemCallback& callback) {
RunWhenLoaded(
- base::Bind(&OfflinePageModelImpl::GetPagesByOnlineURLWhenLoadDone,
- weak_ptr_factory_.GetWeakPtr(), online_url, callback));
+ base::Bind(&OfflinePageModelImpl::GetPagesByURLWhenLoadDone,
+ weak_ptr_factory_.GetWeakPtr(), url,
+ url_search_mode, callback));
}
-void OfflinePageModelImpl::GetPagesByOnlineURLWhenLoadDone(
- const GURL& online_url,
+void OfflinePageModelImpl::GetPagesByURLWhenLoadDone(
+ const GURL& url,
+ URLSearchMode url_search_mode,
const MultipleOfflinePageItemCallback& callback) const {
std::vector<OfflinePageItem> result;
GURL::Replacements remove_params;
remove_params.ClearRef();
- GURL online_url_without_fragment =
- online_url.ReplaceComponents(remove_params);
+ GURL url_without_fragment =
+ url.ReplaceComponents(remove_params);
for (const auto& id_page_pair : offline_pages_) {
if (id_page_pair.second.IsExpired())
continue;
- if (online_url == id_page_pair.second.url) {
+ // First, search by last committed URL with fragment stripped.
+ if (url_without_fragment ==
+ id_page_pair.second.url.ReplaceComponents(remove_params)) {
result.push_back(id_page_pair.second);
continue;
}
- // If the full URL does not match, try with the fragment identifier
- // stripped.
- if (online_url_without_fragment ==
- id_page_pair.second.url.ReplaceComponents(remove_params)) {
+ // Then, search by original request URL if |url_search_mode| wants it.
+ // Note that we want to do the exact match with fragment included. This is
+ // because original URL is used for redirect purpose and it is always safer
+ // to support the exact redirect.
+ if (url_search_mode == URLSearchMode::SEARCH_BY_ALL_URLS &&
+ url == id_page_pair.second.original_url) {
result.push_back(id_page_pair.second);
}
}
@@ -877,8 +884,9 @@ void OfflinePageModelImpl::DeleteExistingPagesWithSameURL(
.pages_allowed_per_url;
if (pages_allowed == kUnlimitedPages)
return;
- GetPagesByOnlineURL(
+ GetPagesByURL(
offline_page.url,
+ URLSearchMode::SEARCH_BY_FINAL_URL_ONLY,
base::Bind(&OfflinePageModelImpl::OnPagesFoundWithSameURL,
weak_ptr_factory_.GetWeakPtr(), offline_page, pages_allowed));
}
« no previous file with comments | « components/offline_pages/offline_page_model_impl.h ('k') | components/offline_pages/offline_page_model_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698