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

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

Issue 2105173002: Add enum-based UMA reporting to automatic redirect logic of Offline Pages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed last Mark's comments. 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/android/offline_pages/offline_page_tab_helper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 16 matching lines...) Expand all
27 public: 27 public:
28 // Delegate that is used to better handle external dependencies. 28 // Delegate that is used to better handle external dependencies.
29 // Default implementation is in .cc file, while tests provide an override. 29 // Default implementation is in .cc file, while tests provide an override.
30 class Delegate { 30 class Delegate {
31 public: 31 public:
32 virtual ~Delegate() {} 32 virtual ~Delegate() {}
33 virtual bool GetTabId(content::WebContents* web_contents, 33 virtual bool GetTabId(content::WebContents* web_contents,
34 std::string* tab_id) const = 0; 34 std::string* tab_id) const = 0;
35 }; 35 };
36 36
37 // This enum is used for UMA reporting. It contains all possible outcomes of
38 // redirect intent and result. Generally one of these outcomes will happen.
39 // The fringe errors (like no OfflinePageModel, etc.) are not reported due
40 // to their low probability.
41 // 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
43 // value. Make sure to update the histogram enum
44 // (OfflinePagesRedirectResult in histograms.xml) accordingly.
45 // Public for testing.
46 enum class RedirectResult {
47 REDIRECTED_ON_DISCONNECTED_NETWORK = 0,
48 PAGE_NOT_FOUND_ON_DISCONNECTED_NETWORK = 1,
49 REDIRECTED_ON_FLAKY_NETWORK = 2,
50 PAGE_NOT_FOUND_ON_FLAKY_NETWORK = 3,
51 IGNORED_FLAKY_NETWORK_FORWARD_BACK = 4,
52 REDIRECTED_ON_CONNECTED_NETWORK = 5,
53 NO_TAB_ID = 6,
54 SHOW_NET_ERROR_PAGE = 7,
55 REDIRECT_LOOP_OFFLINE = 8,
56 REDIRECT_LOOP_ONLINE = 9,
57 REDIRECT_RESULT_MAX,
58 };
59
37 ~OfflinePageTabHelper() override; 60 ~OfflinePageTabHelper() override;
38 61
39 const OfflinePageItem* offline_page() { return offline_page_.get(); } 62 const OfflinePageItem* offline_page() { return offline_page_.get(); }
40 63
41 private: 64 private:
42 enum class RedirectReason {
43 DISCONNECTED_NETWORK,
44 FLAKY_NETWORK,
45 FLAKY_NETWORK_FORWARD_BACK
46 };
47
48 friend class content::WebContentsUserData<OfflinePageTabHelper>; 65 friend class content::WebContentsUserData<OfflinePageTabHelper>;
49 friend class OfflinePageTabHelperTest; 66 friend class OfflinePageTabHelperTest;
50 FRIEND_TEST_ALL_PREFIXES(OfflinePageTabHelperTest, 67 FRIEND_TEST_ALL_PREFIXES(OfflinePageTabHelperTest,
51 NewNavigationCancelsPendingRedirects); 68 NewNavigationCancelsPendingRedirects);
52 69
53 explicit OfflinePageTabHelper(content::WebContents* web_contents); 70 explicit OfflinePageTabHelper(content::WebContents* web_contents);
54 71
55 void SetDelegateForTesting(std::unique_ptr<Delegate> delegate); 72 void SetDelegateForTesting(std::unique_ptr<Delegate> delegate);
56 73
57 // Overridden from content::WebContentsObserver: 74 // Overridden from content::WebContentsObserver:
58 void DidStartNavigation( 75 void DidStartNavigation(
59 content::NavigationHandle* navigation_handle) override; 76 content::NavigationHandle* navigation_handle) override;
60 void DidFinishNavigation( 77 void DidFinishNavigation(
61 content::NavigationHandle* navigation_handle) override; 78 content::NavigationHandle* navigation_handle) override;
62 79
63 void RedirectToOnline(const GURL& from_url, 80 void RedirectToOnline(const GURL& from_url,
64 const OfflinePageItem* offline_page); 81 const OfflinePageItem* offline_page);
65 82
66 // 3 step redirection to the offline page. First getting all the pages, then 83 // 3 step redirection to the offline page. First getting all the pages, then
67 // selecting appropriate page to redirect to and finally attempting to 84 // selecting appropriate page to redirect to and finally attempting to
68 // redirect to that offline page, and caching metadata of that page locally. 85 // redirect to that offline page, and caching metadata of that page locally.
69 void GetPagesForRedirectToOffline(const GURL& online_url, 86 // RedirectResult is accumulated along the codepath to reflect the overall
70 RedirectReason reason); 87 // result of redirection - and be reported to UMA at the end.
88 void GetPagesForRedirectToOffline(RedirectResult result,
89 const GURL& online_url);
71 void SelectBestPageForRedirectToOffline( 90 void SelectBestPageForRedirectToOffline(
91 RedirectResult result,
72 const GURL& online_url, 92 const GURL& online_url,
73 RedirectReason reason,
74 const MultipleOfflinePageItemResult& pages); 93 const MultipleOfflinePageItemResult& pages);
75 void TryRedirectToOffline(RedirectReason redirect_reason, 94 void TryRedirectToOffline(RedirectResult result,
76 const GURL& from_url, 95 const GURL& from_url,
77 const OfflinePageItem& offline_page); 96 const OfflinePageItem& offline_page);
78 97
79 void Redirect(const GURL& from_url, const GURL& to_url); 98 void Redirect(const GURL& from_url, const GURL& to_url);
80 99
100 // Returns true if a given URL is in redirect chain already.
101 bool IsInRedirectLoop(const GURL& to_url) const;
102
103 void ReportRedirectResultUMA(RedirectResult result);
104
81 // Iff the tab we are associated with is redirected to an offline page, 105 // Iff the tab we are associated with is redirected to an offline page,
82 // |offline_page_| will be non-null. This can be used to synchronously ask 106 // |offline_page_| will be non-null. This can be used to synchronously ask
83 // about the offline state of the current web contents. 107 // about the offline state of the current web contents.
84 std::unique_ptr<OfflinePageItem> offline_page_; 108 std::unique_ptr<OfflinePageItem> offline_page_;
85 std::unique_ptr<Delegate> delegate_; 109 std::unique_ptr<Delegate> delegate_;
86 base::WeakPtrFactory<OfflinePageTabHelper> weak_ptr_factory_; 110 base::WeakPtrFactory<OfflinePageTabHelper> weak_ptr_factory_;
87 111
88 DISALLOW_COPY_AND_ASSIGN(OfflinePageTabHelper); 112 DISALLOW_COPY_AND_ASSIGN(OfflinePageTabHelper);
89 }; 113 };
90 114
91 } // namespace offline_pages 115 } // namespace offline_pages
92 116
93 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_ 117 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/offline_pages/offline_page_tab_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698