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 class RedirectResult { |
|
fgorski
2016/06/29 17:01:16
nit: Could you move this above the desctructor? It
Dmitry Titov
2016/06/29 18:25:45
Done.
| |
| 46 REDIRECTED_ON_DISCONNECTED_NETWORK, | |
| 47 PAGE_NOT_FOUND_ON_DISCONNECTED_NETWORK, | |
| 48 REDIRECTED_ON_FLAKY_NETWORK, | |
| 49 PAGE_NOT_FOUND_ON_FLAKY_NETWORK, | |
| 50 IGNORED_FLAKY_NETWORK_FORWARD_BACK, | |
| 51 REDIRECTED_ON_CONNECTED_NETWORK, | |
| 52 NO_TAB_ID, | |
| 53 SHOW_NET_ERROR_PAGE, | |
| 54 REDIRECT_LOOP_OFFLINE, | |
| 55 REDIRECT_LOOP_ONLINE, | |
| 56 // NOTE: always keep this entry at the end. Add new redirect results only | |
| 57 // immediately above this line. Make sure to update the histogram enum | |
| 58 // (OfflinePagesRedirectResult in histograms.xml) accordingly. | |
| 59 REDIRECT_RESULT_MAX, | |
| 46 }; | 60 }; |
| 47 | 61 |
| 62 private: | |
| 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 void GetPagesForRedirectToOffline(const GURL& online_url, |
| 70 RedirectReason reason); | 85 RedirectResult result); |
| 71 void SelectBestPageForRedirectToOffline( | 86 void SelectBestPageForRedirectToOffline( |
| 72 const GURL& online_url, | 87 const GURL& online_url, |
| 73 RedirectReason reason, | 88 RedirectResult result, |
| 74 const MultipleOfflinePageItemResult& pages); | 89 const MultipleOfflinePageItemResult& pages); |
| 75 void TryRedirectToOffline(RedirectReason redirect_reason, | 90 void TryRedirectToOffline(RedirectResult result, |
|
fgorski
2016/06/29 17:01:16
nit: please reorder parameters for consistency, if
Dmitry Titov
2016/06/29 18:25:44
Done.
| |
| 76 const GURL& from_url, | 91 const GURL& from_url, |
| 77 const OfflinePageItem& offline_page); | 92 const OfflinePageItem& offline_page); |
| 78 | 93 |
| 79 void Redirect(const GURL& from_url, const GURL& to_url); | 94 void Redirect(const GURL& from_url, const GURL& to_url); |
| 80 | 95 |
| 96 // Returns true if a given URL is in redirect chain already. | |
| 97 bool IsInRedirectLoop(const GURL& to_url) const; | |
| 98 void ReportRedirectResultUMA(RedirectResult result); | |
| 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 |