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

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 feedback 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
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. One of these outcomes will happen. The fringe
39 // errors (like no OfflinePageModel etc) are not included.
Mark P 2016/06/29 19:18:27 Please add something in here that because this is
Mark P 2016/06/29 19:18:27 If "fringe errors are not included" yet "one of th
Dmitry Titov 2016/06/29 20:27:42 Done. Moved and re-phrased the comment that was ne
Dmitry Titov 2016/06/29 20:27:42 Nothing is emitted for those. These are the cases
Mark P 2016/06/30 05:09:02 Apologies, somehow I missed that comment.
40 // Public for testing.
41 enum class RedirectResult {
Mark P 2016/06/29 19:18:27 nit: why a class?
Dmitry Titov 2016/06/29 20:27:42 We seem to be getting a suggestion to use enum cla
Mark P 2016/06/30 05:09:02 Thanks for the link and explanation. class sgtm.
42 REDIRECTED_ON_DISCONNECTED_NETWORK,
43 PAGE_NOT_FOUND_ON_DISCONNECTED_NETWORK,
44 REDIRECTED_ON_FLAKY_NETWORK,
45 PAGE_NOT_FOUND_ON_FLAKY_NETWORK,
46 IGNORED_FLAKY_NETWORK_FORWARD_BACK,
47 REDIRECTED_ON_CONNECTED_NETWORK,
Mark P 2016/06/29 19:18:27 No PAGE_NOT_FOUND_ON_CONNECTED_NETWORK?
Dmitry Titov 2016/06/29 20:27:42 Right, not applicable to connected network. "Page
Mark P 2016/06/30 05:09:02 Acknowledged.
48 NO_TAB_ID,
49 SHOW_NET_ERROR_PAGE,
50 REDIRECT_LOOP_OFFLINE,
51 REDIRECT_LOOP_ONLINE,
52 // NOTE: always keep this entry at the end. Add new redirect results only
53 // immediately above this line. Make sure to update the histogram enum
54 // (OfflinePagesRedirectResult in histograms.xml) accordingly.
55 REDIRECT_RESULT_MAX,
56 };
57
37 ~OfflinePageTabHelper() override; 58 ~OfflinePageTabHelper() override;
38 59
39 const OfflinePageItem* offline_page() { return offline_page_.get(); } 60 const OfflinePageItem* offline_page() { return offline_page_.get(); }
40 61
41 private: 62 private:
42 enum class RedirectReason {
43 DISCONNECTED_NETWORK,
44 FLAKY_NETWORK,
45 FLAKY_NETWORK_FORWARD_BACK
46 };
47
48 friend class content::WebContentsUserData<OfflinePageTabHelper>; 63 friend class content::WebContentsUserData<OfflinePageTabHelper>;
49 friend class OfflinePageTabHelperTest; 64 friend class OfflinePageTabHelperTest;
50 FRIEND_TEST_ALL_PREFIXES(OfflinePageTabHelperTest, 65 FRIEND_TEST_ALL_PREFIXES(OfflinePageTabHelperTest,
51 NewNavigationCancelsPendingRedirects); 66 NewNavigationCancelsPendingRedirects);
52 67
53 explicit OfflinePageTabHelper(content::WebContents* web_contents); 68 explicit OfflinePageTabHelper(content::WebContents* web_contents);
54 69
55 void SetDelegateForTesting(std::unique_ptr<Delegate> delegate); 70 void SetDelegateForTesting(std::unique_ptr<Delegate> delegate);
56 71
57 // Overridden from content::WebContentsObserver: 72 // Overridden from content::WebContentsObserver:
58 void DidStartNavigation( 73 void DidStartNavigation(
59 content::NavigationHandle* navigation_handle) override; 74 content::NavigationHandle* navigation_handle) override;
60 void DidFinishNavigation( 75 void DidFinishNavigation(
61 content::NavigationHandle* navigation_handle) override; 76 content::NavigationHandle* navigation_handle) override;
62 77
63 void RedirectToOnline(const GURL& from_url, 78 void RedirectToOnline(const GURL& from_url,
64 const OfflinePageItem* offline_page); 79 const OfflinePageItem* offline_page);
65 80
66 // 3 step redirection to the offline page. First getting all the pages, then 81 // 3 step redirection to the offline page. First getting all the pages, then
67 // selecting appropriate page to redirect to and finally attempting to 82 // selecting appropriate page to redirect to and finally attempting to
68 // redirect to that offline page, and caching metadata of that page locally. 83 // redirect to that offline page, and caching metadata of that page locally.
69 void GetPagesForRedirectToOffline(const GURL& online_url, 84 // RedirectResult is accumulated along the codepath to reflect the overall
70 RedirectReason reason); 85 // result of redirection - and be reported to UMA at the end.
86 void GetPagesForRedirectToOffline(RedirectResult result,
87 const GURL& online_url);
71 void SelectBestPageForRedirectToOffline( 88 void SelectBestPageForRedirectToOffline(
89 RedirectResult result,
72 const GURL& online_url, 90 const GURL& online_url,
73 RedirectReason reason,
74 const MultipleOfflinePageItemResult& pages); 91 const MultipleOfflinePageItemResult& pages);
75 void TryRedirectToOffline(RedirectReason redirect_reason, 92 void TryRedirectToOffline(RedirectResult result,
76 const GURL& from_url, 93 const GURL& from_url,
77 const OfflinePageItem& offline_page); 94 const OfflinePageItem& offline_page);
78 95
79 void Redirect(const GURL& from_url, const GURL& to_url); 96 void Redirect(const GURL& from_url, const GURL& to_url);
80 97
98 // Returns true if a given URL is in redirect chain already.
99 bool IsInRedirectLoop(const GURL& to_url) const;
jianli 2016/06/29 20:20:16 nit: add empty line
Dmitry Titov 2016/06/29 20:38:03 Done.
100 void ReportRedirectResultUMA(RedirectResult result);
101
81 // Iff the tab we are associated with is redirected to an offline page, 102 // 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 103 // |offline_page_| will be non-null. This can be used to synchronously ask
83 // about the offline state of the current web contents. 104 // about the offline state of the current web contents.
84 std::unique_ptr<OfflinePageItem> offline_page_; 105 std::unique_ptr<OfflinePageItem> offline_page_;
85 std::unique_ptr<Delegate> delegate_; 106 std::unique_ptr<Delegate> delegate_;
86 base::WeakPtrFactory<OfflinePageTabHelper> weak_ptr_factory_; 107 base::WeakPtrFactory<OfflinePageTabHelper> weak_ptr_factory_;
87 108
88 DISALLOW_COPY_AND_ASSIGN(OfflinePageTabHelper); 109 DISALLOW_COPY_AND_ASSIGN(OfflinePageTabHelper);
89 }; 110 };
90 111
91 } // namespace offline_pages 112 } // namespace offline_pages
92 113
93 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_ 114 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698