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

Unified Diff: chrome/browser/android/offline_pages/offline_page_tab_helper.h

Issue 2362033002: Showing previews UI for Offline Previews (Closed)
Patch Set: megjablon comments rebase Created 4 years, 2 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_tab_helper.h
diff --git a/chrome/browser/android/offline_pages/offline_page_tab_helper.h b/chrome/browser/android/offline_pages/offline_page_tab_helper.h
index 8ded15dff9f73a0f2da25095d9520ed0315bb29d..df7fed1717907b722f6f771e69430ad489c6a0dd 100644
--- a/chrome/browser/android/offline_pages/offline_page_tab_helper.h
+++ b/chrome/browser/android/offline_pages/offline_page_tab_helper.h
@@ -1,101 +1,73 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_
#define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_
+#include <memory>
+
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
+#include "components/offline_pages/loaded_offline_page_info.h"
#include "components/offline_pages/request_header/offline_page_header.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
#include "url/gurl.h"
namespace content {
class WebContents;
}
namespace offline_pages {
-
struct OfflinePageItem;
// Per-tab class that monitors the navigations and stores the necessary info
// to facilitate the synchronous access to offline information.
class OfflinePageTabHelper :
public content::WebContentsObserver,
public content::WebContentsUserData<OfflinePageTabHelper> {
public:
~OfflinePageTabHelper() override;
- void SetOfflinePage(const OfflinePageItem& offline_page,
- const OfflinePageHeader& offline_header,
- bool is_offline_preview);
-
- const OfflinePageItem* offline_page() {
- return offline_info_.offline_page.get();
+ const OfflinePageItem* offline_page() const {
+ if (!offline_info_ || !offline_info_->offline_page())
+ return nullptr;
+ return offline_info_->offline_page();
}
- const OfflinePageHeader& offline_header() const {
- return offline_info_.offline_header;
+ const OfflinePageHeader* offline_header() const {
+ if (!offline_info_ || !offline_info_->offline_header()) {
+ return nullptr;
+ }
+ return offline_info_->offline_header();
}
- // Whether the page is an offline preview.
- bool is_offline_preview() const { return offline_info_.is_offline_preview; }
-
- // Returns provisional offline page since actual navigation does not happen
- // during unit tests.
- const OfflinePageItem* GetOfflinePageForTest() const;
-
private:
friend class content::WebContentsUserData<OfflinePageTabHelper>;
- // Contains the info about the offline page being loaded.
- struct LoadedOfflinePageInfo {
- LoadedOfflinePageInfo();
- ~LoadedOfflinePageInfo();
-
- // The cached copy of OfflinePageItem.
- std::unique_ptr<OfflinePageItem> offline_page;
-
- // The offline header that is provided when offline page is loaded.
- OfflinePageHeader offline_header;
-
- // Whether the page is an offline preview. Offline page previews are shown
- // when a user's effective connection type is prohibitively slow.
- bool is_offline_preview;
-
- void Clear();
- };
-
explicit OfflinePageTabHelper(content::WebContents* web_contents);
// Overridden from content::WebContentsObserver:
void DidStartNavigation(
content::NavigationHandle* navigation_handle) override;
void DidFinishNavigation(
content::NavigationHandle* navigation_handle) override;
void SelectPageForOnlineURLDone(const OfflinePageItem* offline_page);
- // The provisional info about the offline page being loaded. This is set when
- // the offline interceptor decides to serve the offline page and it will be
- // moved to |offline_info_| once the navigation is committed without error.
- LoadedOfflinePageInfo provisional_offline_info_;
-
- // The info about offline page being loaded. This is set from
- // |provisional_offline_info_| when the navigation is committed without error.
- // This can be used to by the Tab to synchronously ask about the offline
- // info.
- LoadedOfflinePageInfo offline_info_;
+ // The info about offline page being loaded. This is set when the navigation
+ // is committed without error. This can be used to by the Tab to synchronously
+ // ask about the offline info.
+ std::unique_ptr<LoadedOfflinePageInfo> offline_info_;
bool reloading_url_on_net_error_ = false;
base::WeakPtrFactory<OfflinePageTabHelper> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(OfflinePageTabHelper);
};
} // namespace offline_pages

Powered by Google App Engine
This is Rietveld 408576698