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

Unified Diff: chrome/browser/android/offline_pages/offline_page_utils.cc

Issue 2225213002: Make GetBestPageForOnlineURL async (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback Created 4 years, 4 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: chrome/browser/android/offline_pages/offline_page_utils.cc
diff --git a/chrome/browser/android/offline_pages/offline_page_utils.cc b/chrome/browser/android/offline_pages/offline_page_utils.cc
index aa787a894110ccd7c5f5a419828dae677b5d6bde..acb9b73ab96d92fb0189ea1255905c3bd0b810c9 100644
--- a/chrome/browser/android/offline_pages/offline_page_utils.cc
+++ b/chrome/browser/android/offline_pages/offline_page_utils.cc
@@ -14,6 +14,7 @@
#include "chrome/browser/android/offline_pages/offline_page_model_factory.h"
#include "chrome/browser/android/offline_pages/offline_page_tab_helper.h"
#include "chrome/browser/android/tab_android.h"
+#include "components/offline_pages/client_namespace_constants.h"
#include "components/offline_pages/offline_page_feature.h"
#include "components/offline_pages/offline_page_item.h"
#include "components/offline_pages/offline_page_model.h"
@@ -73,6 +74,26 @@ void OnGetPageByOfflineURLDone(
callback.Run(result_url);
}
+void OnGetPagesByOnlineURLDone(
+ int tab_id,
+ const base::Callback<void(const OfflinePageItem*)>& callback,
+ const MultipleOfflinePageItemResult& pages) {
+ const OfflinePageItem* selected_page = nullptr;
+ std::string tab_id_str = base::IntToString(tab_id);
+ for (const auto& offline_page : pages) {
+ if ((offline_page.client_id.name_space == kBookmarkNamespace) ||
+ (offline_page.client_id.name_space == kAsyncNamespace) ||
+ (offline_page.client_id.name_space == kLastNNamespace &&
+ offline_page.client_id.id == tab_id_str)) {
+ if (!selected_page ||
+ offline_page.creation_time > selected_page->creation_time) {
+ selected_page = &offline_page;
+ }
+ }
+ }
+ callback.Run(selected_page);
+}
+
} // namespace
// static
@@ -97,6 +118,24 @@ GURL OfflinePageUtils::MaybeGetOnlineURLForOfflineURL(
}
// static
+void OfflinePageUtils::SelectPageForOnlineURL(
+ content::BrowserContext* browser_context,
+ const GURL& online_url,
+ int tab_id,
+ const base::Callback<void(const OfflinePageItem*)>& callback) {
+ OfflinePageModel* offline_page_model =
+ OfflinePageModelFactory::GetForBrowserContext(browser_context);
+ if (!offline_page_model) {
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(callback, nullptr));
+ return;
+ }
+
+ offline_page_model->GetPagesByOnlineURL(
+ online_url, base::Bind(&OnGetPagesByOnlineURLDone, tab_id, callback));
+}
+
+// static
void OfflinePageUtils::GetOnlineURLForOfflineURL(
content::BrowserContext* browser_context,
const GURL& offline_url,
« no previous file with comments | « chrome/browser/android/offline_pages/offline_page_utils.h ('k') | components/offline_pages/offline_page_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698