Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 20 matching lines...) Expand all Loading... | |
| 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 ~OfflinePageTabHelper() override; | 37 ~OfflinePageTabHelper() override; |
| 38 | 38 |
| 39 const OfflinePageItem* offline_page() { return offline_page_.get(); } | 39 const OfflinePageItem* offline_page() { return offline_page_.get(); } |
| 40 | 40 |
| 41 private: | 41 // This enum is used for UMA reporting. It contains all possible outcomes of |
| 42 enum class RedirectReason { | 42 // redirect intent and result. One of these outcomes will happen. The fringe |
| 43 DISCONNECTED_NETWORK, | 43 // errors (like no OfflinePageModel etc) are not included. |
| 44 FLAKY_NETWORK, | 44 // Public for testing. |
| 45 FLAKY_NETWORK_FORWARD_BACK | 45 enum RedirectResult { |
|
dewittj
2016/06/29 00:16:32
nit: enum class
jianli
2016/06/29 00:19:30
using enum class?
Dmitry Titov
2016/06/29 01:51:31
Done.
Dmitry Titov
2016/06/29 01:51:31
Done. Adds more static_cast<int>() in the test cod
| |
| 46 DISCONNECTED_NETWORK, // Redirect to offline, success | |
|
jianli
2016/06/29 00:19:30
Since now this enum is about redirect result, it i
Dmitry Titov
2016/06/29 01:51:31
Done.
| |
| 47 DISCONNECTED_NETWORK_NOT_FOUND, // Redirect failed, no snapshot | |
|
dewittj
2016/06/29 00:16:32
the wording of the NOT_FOUND enum values is a litt
Dmitry Titov
2016/06/29 01:51:31
Done.
| |
| 48 FLAKY_NETWORK, // Redirect to offline, success | |
| 49 FLAKY_NETWORK_NOT_FOUND, // Redirect to offline failed, no snapshot | |
| 50 FLAKY_NETWORK_FORWARD_BACK, // Redirect to offline, success | |
| 51 FLAKY_NETWORK_FORWARD_BACK_NOT_FOUND, // Redirect failed, no snapshot | |
| 52 CONNECTED_NETWORK, // Redirect to online, always success | |
| 53 NO_TAB_ID, // Android Tab ID was not found | |
| 54 SHOW_NET_ERROR_PAGE, // Proceed to error page (unknown error) | |
| 55 // NOTE: always keep this entry at the end. Add new redirect results only | |
| 56 // immediately above this line. Make sure to update the histogram enum | |
| 57 // (OfflinePagesRedirectResult in histograms.xml) accordingly. | |
| 58 REDIRECT_RESULT_MAX, | |
| 46 }; | 59 }; |
| 47 | 60 |
| 61 private: | |
| 48 friend class content::WebContentsUserData<OfflinePageTabHelper>; | 62 friend class content::WebContentsUserData<OfflinePageTabHelper>; |
| 49 friend class OfflinePageTabHelperTest; | 63 friend class OfflinePageTabHelperTest; |
| 50 FRIEND_TEST_ALL_PREFIXES(OfflinePageTabHelperTest, | 64 FRIEND_TEST_ALL_PREFIXES(OfflinePageTabHelperTest, |
| 51 NewNavigationCancelsPendingRedirects); | 65 NewNavigationCancelsPendingRedirects); |
| 52 | 66 |
| 53 explicit OfflinePageTabHelper(content::WebContents* web_contents); | 67 explicit OfflinePageTabHelper(content::WebContents* web_contents); |
| 54 | 68 |
| 55 void SetDelegateForTesting(std::unique_ptr<Delegate> delegate); | 69 void SetDelegateForTesting(std::unique_ptr<Delegate> delegate); |
| 56 | 70 |
| 57 // Overridden from content::WebContentsObserver: | 71 // Overridden from content::WebContentsObserver: |
| 58 void DidStartNavigation( | 72 void DidStartNavigation( |
| 59 content::NavigationHandle* navigation_handle) override; | 73 content::NavigationHandle* navigation_handle) override; |
| 60 void DidFinishNavigation( | 74 void DidFinishNavigation( |
| 61 content::NavigationHandle* navigation_handle) override; | 75 content::NavigationHandle* navigation_handle) override; |
| 62 | 76 |
| 63 void RedirectToOnline(const GURL& from_url, | 77 void RedirectToOnline(const GURL& from_url, |
| 64 const OfflinePageItem* offline_page); | 78 const OfflinePageItem* offline_page); |
| 65 | 79 |
| 66 // 3 step redirection to the offline page. First getting all the pages, then | 80 // 3 step redirection to the offline page. First getting all the pages, then |
| 67 // selecting appropriate page to redirect to and finally attempting to | 81 // selecting appropriate page to redirect to and finally attempting to |
| 68 // redirect to that offline page, and caching metadata of that page locally. | 82 // redirect to that offline page, and caching metadata of that page locally. |
| 69 void GetPagesForRedirectToOffline(const GURL& online_url, | 83 void GetPagesForRedirectToOffline(const GURL& online_url, |
| 70 RedirectReason reason); | 84 RedirectResult result); |
| 71 void SelectBestPageForRedirectToOffline( | 85 void SelectBestPageForRedirectToOffline( |
| 72 const GURL& online_url, | 86 const GURL& online_url, |
| 73 RedirectReason reason, | 87 RedirectResult result, |
| 74 const MultipleOfflinePageItemResult& pages); | 88 const MultipleOfflinePageItemResult& pages); |
| 75 void TryRedirectToOffline(RedirectReason redirect_reason, | 89 void TryRedirectToOffline(RedirectResult result, |
| 76 const GURL& from_url, | 90 const GURL& from_url, |
| 77 const OfflinePageItem& offline_page); | 91 const OfflinePageItem& offline_page); |
| 78 | 92 |
| 79 void Redirect(const GURL& from_url, const GURL& to_url); | 93 void Redirect(const GURL& from_url, const GURL& to_url); |
| 80 | 94 |
| 95 // Returns true is a given URL is in redirect chain already. | |
|
jianli
2016/06/29 00:19:30
update comment
Dmitry Titov
2016/06/29 01:51:31
Done.
| |
| 96 bool IsInRedirectLoop(const GURL& to_url); | |
|
jianli
2016/06/29 00:19:30
nit: can we add const modifier
Dmitry Titov
2016/06/29 01:51:31
Done.
| |
| 97 void ReportUMARedirectResult(RedirectResult result, | |
|
jianli
2016/06/29 00:19:30
nit: ReportRedirectResultUMA or simply ReportRedir
Dmitry Titov
2016/06/29 01:51:31
Done.
| |
| 98 bool page_not_found = false); | |
| 99 | |
| 81 // Iff the tab we are associated with is redirected to an offline page, | 100 // 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 | 101 // |offline_page_| will be non-null. This can be used to synchronously ask |
| 83 // about the offline state of the current web contents. | 102 // about the offline state of the current web contents. |
| 84 std::unique_ptr<OfflinePageItem> offline_page_; | 103 std::unique_ptr<OfflinePageItem> offline_page_; |
| 85 std::unique_ptr<Delegate> delegate_; | 104 std::unique_ptr<Delegate> delegate_; |
| 86 base::WeakPtrFactory<OfflinePageTabHelper> weak_ptr_factory_; | 105 base::WeakPtrFactory<OfflinePageTabHelper> weak_ptr_factory_; |
| 87 | 106 |
| 88 DISALLOW_COPY_AND_ASSIGN(OfflinePageTabHelper); | 107 DISALLOW_COPY_AND_ASSIGN(OfflinePageTabHelper); |
| 89 }; | 108 }; |
| 90 | 109 |
| 91 } // namespace offline_pages | 110 } // namespace offline_pages |
| 92 | 111 |
| 93 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_ | 112 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_ |
| OLD | NEW |