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

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

Issue 2166363003: Offline pages using NQE 2G Slow (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tbansal nits (switching to consuming previews component) 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 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 "components/offline_pages/offline_page_types.h" 10 #include "components/offline_pages/offline_page_types.h"
11 #include "content/public/browser/web_contents_observer.h" 11 #include "content/public/browser/web_contents_observer.h"
12 #include "content/public/browser/web_contents_user_data.h" 12 #include "content/public/browser/web_contents_user_data.h"
13 #include "url/gurl.h" 13 #include "url/gurl.h"
14 14
15 namespace base {
16 class Clock;
17 }
18
15 namespace content { 19 namespace content {
16 class WebContents; 20 class WebContents;
17 } 21 }
18 22
19 namespace offline_pages { 23 namespace offline_pages {
20 24
21 struct OfflinePageItem; 25 struct OfflinePageItem;
22 26
23 // Per-tab class to manage switch between online version and offline version. 27 // Per-tab class to manage switch between online version and offline version.
24 class OfflinePageTabHelper : 28 class OfflinePageTabHelper :
(...skipping 14 matching lines...) Expand all
39 // The fringe errors (like no OfflinePageModel, etc.) are not reported due 43 // The fringe errors (like no OfflinePageModel, etc.) are not reported due
40 // to their low probability. 44 // to their low probability.
41 // NOTE: because this is used for UMA reporting, these values should not be 45 // NOTE: because this is used for UMA reporting, these values should not be
42 // changed or reused; new values should be ended immediately before the MAX 46 // changed or reused; new values should be ended immediately before the MAX
43 // value. Make sure to update the histogram enum 47 // value. Make sure to update the histogram enum
44 // (OfflinePagesRedirectResult in histograms.xml) accordingly. 48 // (OfflinePagesRedirectResult in histograms.xml) accordingly.
45 // Public for testing. 49 // Public for testing.
46 enum class RedirectResult { 50 enum class RedirectResult {
47 REDIRECTED_ON_DISCONNECTED_NETWORK = 0, 51 REDIRECTED_ON_DISCONNECTED_NETWORK = 0,
48 PAGE_NOT_FOUND_ON_DISCONNECTED_NETWORK = 1, 52 PAGE_NOT_FOUND_ON_DISCONNECTED_NETWORK = 1,
53 // Flaky Network means the network reported an error when trying to fetch
54 // the resource.
49 REDIRECTED_ON_FLAKY_NETWORK = 2, 55 REDIRECTED_ON_FLAKY_NETWORK = 2,
50 PAGE_NOT_FOUND_ON_FLAKY_NETWORK = 3, 56 PAGE_NOT_FOUND_ON_FLAKY_NETWORK = 3,
51 IGNORED_FLAKY_NETWORK_FORWARD_BACK = 4, 57 IGNORED_FLAKY_NETWORK_FORWARD_BACK = 4,
52 REDIRECTED_ON_CONNECTED_NETWORK = 5, 58 REDIRECTED_ON_CONNECTED_NETWORK = 5,
53 NO_TAB_ID = 6, 59 NO_TAB_ID = 6,
54 SHOW_NET_ERROR_PAGE = 7, 60 SHOW_NET_ERROR_PAGE = 7,
55 REDIRECT_LOOP_OFFLINE = 8, 61 REDIRECT_LOOP_OFFLINE = 8,
56 REDIRECT_LOOP_ONLINE = 9, 62 REDIRECT_LOOP_ONLINE = 9,
63 // Prohibitively slow means that the NetworkQualityEstimator reported a
64 // connection of 2G slow.
tbansal1 2016/07/26 20:12:48 Do not put "2G slow" in the comment as NQE could h
RyanSturm 2016/07/26 21:48:12 Done.
65 REDIRECTED_ON_PROHIBITVELY_SLOW_NETWORK = 10,
tbansal1 2016/07/26 20:12:48 s/TV/TIV/
RyanSturm 2016/07/26 21:48:12 Done.
66 PAGE_NOT_FOUND_ON_PROHIBITVELY_SLOW_NETWORK = 11,
67 PAGE_NOT_FRESH_ON_PROHIBITVELY_SLOW_NETWORK = 12,
57 REDIRECT_RESULT_MAX, 68 REDIRECT_RESULT_MAX,
58 }; 69 };
59 70
60 ~OfflinePageTabHelper() override; 71 ~OfflinePageTabHelper() override;
61 72
62 const OfflinePageItem* offline_page() { return offline_page_.get(); } 73 const OfflinePageItem* offline_page() { return offline_page_.get(); }
63 74
75 // Allow tests to change the freshness of offline pages by using a custom
76 // clock.
77 void SetClockForTesting(std::unique_ptr<base::Clock> clock);
Dmitry Titov 2016/07/26 21:10:36 Drive-by: Note how we use DefaultDelegate to injec
RyanSturm 2016/07/26 21:48:13 Done.
78
64 private: 79 private:
65 friend class content::WebContentsUserData<OfflinePageTabHelper>; 80 friend class content::WebContentsUserData<OfflinePageTabHelper>;
66 friend class OfflinePageTabHelperTest; 81 friend class OfflinePageTabHelperTest;
67 FRIEND_TEST_ALL_PREFIXES(OfflinePageTabHelperTest, 82 FRIEND_TEST_ALL_PREFIXES(OfflinePageTabHelperTest,
68 NewNavigationCancelsPendingRedirects); 83 NewNavigationCancelsPendingRedirects);
69 84
70 explicit OfflinePageTabHelper(content::WebContents* web_contents); 85 explicit OfflinePageTabHelper(content::WebContents* web_contents);
71 86
72 void SetDelegateForTesting(std::unique_ptr<Delegate> delegate); 87 void SetDelegateForTesting(std::unique_ptr<Delegate> delegate);
73 88
(...skipping 26 matching lines...) Expand all
100 // Returns true if a given URL is in redirect chain already. 115 // Returns true if a given URL is in redirect chain already.
101 bool IsInRedirectLoop(const GURL& to_url) const; 116 bool IsInRedirectLoop(const GURL& to_url) const;
102 117
103 void ReportRedirectResultUMA(RedirectResult result); 118 void ReportRedirectResultUMA(RedirectResult result);
104 119
105 // Iff the tab we are associated with is redirected to an offline page, 120 // Iff the tab we are associated with is redirected to an offline page,
106 // |offline_page_| will be non-null. This can be used to synchronously ask 121 // |offline_page_| will be non-null. This can be used to synchronously ask
107 // about the offline state of the current web contents. 122 // about the offline state of the current web contents.
108 std::unique_ptr<OfflinePageItem> offline_page_; 123 std::unique_ptr<OfflinePageItem> offline_page_;
109 std::unique_ptr<Delegate> delegate_; 124 std::unique_ptr<Delegate> delegate_;
125
126 // Typically the default Clock implementation, but can be overriden in tests.
127 std::unique_ptr<base::Clock> clock_;
128
110 base::WeakPtrFactory<OfflinePageTabHelper> weak_ptr_factory_; 129 base::WeakPtrFactory<OfflinePageTabHelper> weak_ptr_factory_;
111 130
112 DISALLOW_COPY_AND_ASSIGN(OfflinePageTabHelper); 131 DISALLOW_COPY_AND_ASSIGN(OfflinePageTabHelper);
113 }; 132 };
114 133
115 } // namespace offline_pages 134 } // namespace offline_pages
116 135
117 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_ 136 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698