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

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

Issue 2040573002: [Offlining] Updates the tab helper to use the async OfflinePageModel API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address jianli's nits. Created 4 years, 6 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 e53d52440a79732ef9929bf96a6737f86c1aca09..ac75cfa615373639d1540968f7fa85849c83bffc 100644
--- a/chrome/browser/android/offline_pages/offline_page_utils.cc
+++ b/chrome/browser/android/offline_pages/offline_page_utils.cc
@@ -4,9 +4,13 @@
#include "chrome/browser/android/offline_pages/offline_page_utils.h"
+#include "base/bind.h"
+#include "base/location.h"
+#include "base/optional.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
+#include "base/threading/thread_task_runner_handle.h"
#include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h"
#include "chrome/browser/android/offline_pages/offline_page_model_factory.h"
#include "components/offline_pages/offline_page_feature.h"
@@ -58,6 +62,24 @@ const OfflinePageItem* GetOfflinePageForOfflineURL(
return offline_page_model->MaybeGetPageByOfflineURL(offline_url);
}
+void OnGetPageByOfflineURLDone(
+ const base::Callback<void(const GURL&)>& callback,
+ const base::Optional<OfflinePageItem>& item) {
+ GURL result_url;
+ if (item)
+ result_url = item->url;
+ callback.Run(result_url);
+}
+
+void OnGetBestPageForOnlineURLDone(
+ const base::Callback<void(const GURL&)>& callback,
+ const base::Optional<OfflinePageItem>& item) {
+ GURL result_url;
+ if (item)
+ result_url = item->GetOfflineURL();
+ callback.Run(result_url);
+}
+
} // namespace
// static
@@ -70,7 +92,7 @@ bool OfflinePageUtils::MightBeOfflineURL(const GURL& url) {
}
// static
-GURL OfflinePageUtils::GetOfflineURLForOnlineURL(
+GURL OfflinePageUtils::MaybeGetOfflineURLForOnlineURL(
content::BrowserContext* browser_context,
const GURL& online_url) {
const OfflinePageItem* offline_page =
@@ -82,7 +104,25 @@ GURL OfflinePageUtils::GetOfflineURLForOnlineURL(
}
// static
-GURL OfflinePageUtils::GetOnlineURLForOfflineURL(
+void OfflinePageUtils::GetOfflineURLForOnlineURL(
+ content::BrowserContext* browser_context,
+ const GURL& online_url,
+ const base::Callback<void(const GURL&)>& callback) {
+ OfflinePageModel* offline_page_model =
+ OfflinePageModelFactory::GetForBrowserContext(browser_context);
+ if (!offline_page_model) {
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE,
+ base::Bind(&OnGetPageByOfflineURLDone, callback, base::nullopt));
+ return;
+ }
+
+ offline_page_model->GetBestPageForOnlineURL(
+ online_url, base::Bind(&OnGetBestPageForOnlineURLDone, callback));
+}
+
+// static
+GURL OfflinePageUtils::MaybeGetOnlineURLForOfflineURL(
content::BrowserContext* browser_context,
const GURL& offline_url) {
const OfflinePageItem* offline_page =
@@ -94,6 +134,24 @@ GURL OfflinePageUtils::GetOnlineURLForOfflineURL(
}
// static
+void OfflinePageUtils::GetOnlineURLForOfflineURL(
+ content::BrowserContext* browser_context,
+ const GURL& offline_url,
+ const base::Callback<void(const GURL&)>& callback) {
+ OfflinePageModel* offline_page_model =
+ OfflinePageModelFactory::GetForBrowserContext(browser_context);
+ if (!offline_page_model) {
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE,
+ base::Bind(&OnGetPageByOfflineURLDone, callback, base::nullopt));
+ return;
+ }
+
+ offline_page_model->GetPageByOfflineURL(
+ offline_url, base::Bind(&OnGetPageByOfflineURLDone, callback));
+}
+
+// static
bool OfflinePageUtils::IsOfflinePage(content::BrowserContext* browser_context,
const GURL& offline_url) {
return GetOfflinePageForOfflineURL(browser_context, offline_url) != nullptr;

Powered by Google App Engine
This is Rietveld 408576698