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

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

Issue 2040163003: Refactors offline page tab helper to stash the offline page item on redirect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@single-result
Patch Set: Add a dedicated test. 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 25d49cb9ea128b373f25b2b7136fabddd158a178..9145296dbde4ed87840c6e0ae68356490597e34f 100644
--- a/chrome/browser/android/offline_pages/offline_page_utils.cc
+++ b/chrome/browser/android/offline_pages/offline_page_utils.cc
@@ -16,11 +16,14 @@
#include "components/offline_pages/offline_page_item.h"
#include "components/offline_pages/offline_page_model.h"
#include "content/public/browser/browser_context.h"
+#include "content/public/browser/web_contents.h"
#include "url/gurl.h"
namespace offline_pages {
namespace {
+const char kWebContentsUserDataKey[] = "OfflinePageForTab";
+
// Returns an offline page originated from the |online_url|.
const OfflinePageItem* MaybeGetBestOfflinePageForOnlineURL(
content::BrowserContext* browser_context,
@@ -179,4 +182,23 @@ void OfflinePageUtils::MarkPageAccessed(
offline_page_model->MarkPageAccessed(offline_page->offline_id);
}
+const OfflinePageItem* OfflinePageUtils::GetCurrentOfflinePage(
+ content::WebContents* web_contents) {
+ return static_cast<const OfflinePageItem*>(
+ web_contents->GetUserData(kWebContentsUserDataKey));
+}
+
+void OfflinePageUtils::SetCurrentOfflinePage(
+ content::WebContents* web_contents,
+ const OfflinePageItem* offline_page) {
+ if (!offline_page) {
+ web_contents->RemoveUserData(kWebContentsUserDataKey);
+ return;
+ }
+
+ // |SetUserData| takes ownership of the data object, so we need to make a copy
+ // here.
+ web_contents->SetUserData(kWebContentsUserDataKey,
+ new OfflinePageItem(*offline_page));
+}
} // namespace offline_pages

Powered by Google App Engine
This is Rietveld 408576698