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

Side by Side Diff: chrome/browser/android/offline_pages/offline_page_tab_helper.h

Issue 2337363002: Load live version when reloading an offline page on connected network (Closed)
Patch Set: Rebase again Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_ 5 #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_
6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_ 6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "components/offline_pages/request_header/offline_page_header.h"
11 #include "content/public/browser/web_contents_observer.h" 12 #include "content/public/browser/web_contents_observer.h"
12 #include "content/public/browser/web_contents_user_data.h" 13 #include "content/public/browser/web_contents_user_data.h"
13 #include "url/gurl.h" 14 #include "url/gurl.h"
14 15
15 namespace content { 16 namespace content {
16 class WebContents; 17 class WebContents;
17 } 18 }
18 19
19 namespace offline_pages { 20 namespace offline_pages {
20 21
21 struct OfflinePageItem; 22 struct OfflinePageItem;
22 23
23 // Per-tab class that monitors the navigations and stores the necessary info 24 // Per-tab class that monitors the navigations and stores the necessary info
24 // to facilitate the synchronous access to offline information. 25 // to facilitate the synchronous access to offline information.
25 class OfflinePageTabHelper : 26 class OfflinePageTabHelper :
26 public content::WebContentsObserver, 27 public content::WebContentsObserver,
27 public content::WebContentsUserData<OfflinePageTabHelper> { 28 public content::WebContentsUserData<OfflinePageTabHelper> {
28 public: 29 public:
29 ~OfflinePageTabHelper() override; 30 ~OfflinePageTabHelper() override;
30 31
32 void SetOfflinePage(const OfflinePageItem& offline_page,
33 const OfflinePageHeader& offline_header,
34 bool is_offline_preview);
35
31 const OfflinePageItem* offline_page() { return offline_page_.get(); } 36 const OfflinePageItem* offline_page() { return offline_page_.get(); }
32 void SetOfflinePage(const OfflinePageItem& offline_page, 37
33 bool is_offline_preview); 38 const OfflinePageHeader& offline_header() const { return offline_header_; }
34 39
35 // Whether the page is an offline preview. 40 // Whether the page is an offline preview.
36 bool is_offline_preview() const { return is_offline_preview_; } 41 bool is_offline_preview() const { return is_offline_preview_; }
37 42
38 // Returns provisional offline page since actual navigation does not happen 43 // Returns provisional offline page since actual navigation does not happen
39 // during unit tests. 44 // during unit tests.
40 const OfflinePageItem* GetOfflinePageForTest() const; 45 const OfflinePageItem* GetOfflinePageForTest() const;
41 46
42 private: 47 private:
43 friend class content::WebContentsUserData<OfflinePageTabHelper>; 48 friend class content::WebContentsUserData<OfflinePageTabHelper>;
(...skipping 11 matching lines...) Expand all
55 // The cached copy of OfflinePageItem if offline page is loaded for current 60 // The cached copy of OfflinePageItem if offline page is loaded for current
56 // tab. This can be used to by the Tab to synchronously ask about the offline 61 // tab. This can be used to by the Tab to synchronously ask about the offline
57 // info. 62 // info.
58 std::unique_ptr<OfflinePageItem> offline_page_; 63 std::unique_ptr<OfflinePageItem> offline_page_;
59 // Potential new offline page copy. This is reset to nullptr at the start 64 // Potential new offline page copy. This is reset to nullptr at the start
60 // of every navigation and set by network request interceptor. If the 65 // of every navigation and set by network request interceptor. If the
61 // interceptor decided to not use offline page for the navigation or was not 66 // interceptor decided to not use offline page for the navigation or was not
62 // even invoked (as in case with fragment navigation), this stays nullptr. 67 // even invoked (as in case with fragment navigation), this stays nullptr.
63 std::unique_ptr<OfflinePageItem> provisional_offline_page_; 68 std::unique_ptr<OfflinePageItem> provisional_offline_page_;
64 69
70 // The offline header that is provided when offline page is loaded for current
71 // tab.
72 OfflinePageHeader offline_header_;
73
65 bool reloading_url_on_net_error_ = false; 74 bool reloading_url_on_net_error_ = false;
66 75
67 // Whether the page is an offline preview. Offline page previews are shown 76 // Whether the page is an offline preview. Offline page previews are shown
68 // when a user's effective connection type is prohibitively slow. 77 // when a user's effective connection type is prohibitively slow.
69 bool is_offline_preview_; 78 bool is_offline_preview_;
70 79
71 base::WeakPtrFactory<OfflinePageTabHelper> weak_ptr_factory_; 80 base::WeakPtrFactory<OfflinePageTabHelper> weak_ptr_factory_;
72 81
73 DISALLOW_COPY_AND_ASSIGN(OfflinePageTabHelper); 82 DISALLOW_COPY_AND_ASSIGN(OfflinePageTabHelper);
74 }; 83 };
75 84
76 } // namespace offline_pages 85 } // namespace offline_pages
77 86
78 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_ 87 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698