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

Unified 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, 5 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 22ff4a148d1db2f201c57e451d954748580ddd62..72319fb936d63b6d853d3de754ec58909122c73b 100644
--- a/chrome/browser/android/offline_pages/offline_page_tab_helper.h
+++ b/chrome/browser/android/offline_pages/offline_page_tab_helper.h
@@ -5,20 +5,24 @@
#ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_
#define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "components/offline_pages/offline_page_types.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
#include "url/gurl.h"
+namespace base {
+class Clock;
+}
+
namespace content {
class WebContents;
}
namespace offline_pages {
struct OfflinePageItem;
// Per-tab class to manage switch between online version and offline version.
class OfflinePageTabHelper :
@@ -39,35 +43,46 @@ class OfflinePageTabHelper :
// The fringe errors (like no OfflinePageModel, etc.) are not reported due
// to their low probability.
// NOTE: because this is used for UMA reporting, these values should not be
// changed or reused; new values should be ended immediately before the MAX
// value. Make sure to update the histogram enum
// (OfflinePagesRedirectResult in histograms.xml) accordingly.
// Public for testing.
enum class RedirectResult {
REDIRECTED_ON_DISCONNECTED_NETWORK = 0,
PAGE_NOT_FOUND_ON_DISCONNECTED_NETWORK = 1,
+ // Flaky Network means the network reported an error when trying to fetch
+ // the resource.
REDIRECTED_ON_FLAKY_NETWORK = 2,
PAGE_NOT_FOUND_ON_FLAKY_NETWORK = 3,
IGNORED_FLAKY_NETWORK_FORWARD_BACK = 4,
REDIRECTED_ON_CONNECTED_NETWORK = 5,
NO_TAB_ID = 6,
SHOW_NET_ERROR_PAGE = 7,
REDIRECT_LOOP_OFFLINE = 8,
REDIRECT_LOOP_ONLINE = 9,
+ // Prohibitively slow means that the NetworkQualityEstimator reported a
+ // 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.
+ REDIRECTED_ON_PROHIBITVELY_SLOW_NETWORK = 10,
tbansal1 2016/07/26 20:12:48 s/TV/TIV/
RyanSturm 2016/07/26 21:48:12 Done.
+ PAGE_NOT_FOUND_ON_PROHIBITVELY_SLOW_NETWORK = 11,
+ PAGE_NOT_FRESH_ON_PROHIBITVELY_SLOW_NETWORK = 12,
REDIRECT_RESULT_MAX,
};
~OfflinePageTabHelper() override;
const OfflinePageItem* offline_page() { return offline_page_.get(); }
+ // Allow tests to change the freshness of offline pages by using a custom
+ // clock.
+ 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.
+
private:
friend class content::WebContentsUserData<OfflinePageTabHelper>;
friend class OfflinePageTabHelperTest;
FRIEND_TEST_ALL_PREFIXES(OfflinePageTabHelperTest,
NewNavigationCancelsPendingRedirects);
explicit OfflinePageTabHelper(content::WebContents* web_contents);
void SetDelegateForTesting(std::unique_ptr<Delegate> delegate);
@@ -100,18 +115,22 @@ class OfflinePageTabHelper :
// Returns true if a given URL is in redirect chain already.
bool IsInRedirectLoop(const GURL& to_url) const;
void ReportRedirectResultUMA(RedirectResult result);
// Iff the tab we are associated with is redirected to an offline page,
// |offline_page_| will be non-null. This can be used to synchronously ask
// about the offline state of the current web contents.
std::unique_ptr<OfflinePageItem> offline_page_;
std::unique_ptr<Delegate> delegate_;
+
+ // Typically the default Clock implementation, but can be overriden in tests.
+ std::unique_ptr<base::Clock> clock_;
+
base::WeakPtrFactory<OfflinePageTabHelper> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(OfflinePageTabHelper);
};
} // namespace offline_pages
#endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_

Powered by Google App Engine
This is Rietveld 408576698