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" |
| 11 #include "content/public/browser/web_contents_observer.h" | 11 #include "content/public/browser/web_contents_observer.h" |
| 12 #include "content/public/browser/web_contents_user_data.h" | 12 #include "content/public/browser/web_contents_user_data.h" |
| 13 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 14 | 14 |
| 15 namespace base { | |
| 16 class Time; | |
| 17 } | |
| 18 | |
| 15 namespace content { | 19 namespace content { |
| 16 class WebContents; | 20 class WebContents; |
| 17 } | 21 } |
| 18 | 22 |
| 19 namespace offline_pages { | 23 namespace offline_pages { |
| 20 | 24 |
| 21 struct OfflinePageItem; | 25 struct OfflinePageItem; |
| 22 | 26 |
| 23 // Per-tab class to manage switch between online version and offline version. | 27 // Per-tab class to manage switch between online version and offline version. |
| 24 class OfflinePageTabHelper : | 28 class OfflinePageTabHelper : |
| 25 public content::WebContentsObserver, | 29 public content::WebContentsObserver, |
| 26 public content::WebContentsUserData<OfflinePageTabHelper> { | 30 public content::WebContentsUserData<OfflinePageTabHelper> { |
| 27 public: | 31 public: |
| 28 // Delegate that is used to better handle external dependencies. | 32 // Delegate that is used to better handle external dependencies. |
| 29 // Default implementation is in .cc file, while tests provide an override. | 33 // Default implementation is in .cc file, while tests provide an override. |
| 30 class Delegate { | 34 class Delegate { |
| 31 public: | 35 public: |
| 32 virtual ~Delegate() {} | 36 virtual ~Delegate() {} |
| 33 virtual bool GetTabId(content::WebContents* web_contents, | 37 virtual bool GetTabId(content::WebContents* web_contents, |
| 34 std::string* tab_id) const = 0; | 38 std::string* tab_id) const = 0; |
| 39 virtual base::Time Now() const = 0; | |
|
Lei Zhang
2016/07/28 20:41:52
a) I'm not sure you can forward declare if it's re
RyanSturm
2016/07/28 22:07:18
Done. You're absolutely right. Time is included vi
| |
| 35 }; | 40 }; |
| 36 | 41 |
| 37 // This enum is used for UMA reporting. It contains all possible outcomes of | 42 // 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. | 43 // redirect intent and result. Generally one of these outcomes will happen. |
| 39 // The fringe errors (like no OfflinePageModel, etc.) are not reported due | 44 // The fringe errors (like no OfflinePageModel, etc.) are not reported due |
| 40 // to their low probability. | 45 // to their low probability. |
| 41 // NOTE: because this is used for UMA reporting, these values should not be | 46 // 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 | 47 // changed or reused; new values should be ended immediately before the MAX |
| 43 // value. Make sure to update the histogram enum | 48 // value. Make sure to update the histogram enum |
| 44 // (OfflinePagesRedirectResult in histograms.xml) accordingly. | 49 // (OfflinePagesRedirectResult in histograms.xml) accordingly. |
| 45 // Public for testing. | 50 // Public for testing. |
| 46 enum class RedirectResult { | 51 enum class RedirectResult { |
| 47 REDIRECTED_ON_DISCONNECTED_NETWORK = 0, | 52 REDIRECTED_ON_DISCONNECTED_NETWORK = 0, |
| 48 PAGE_NOT_FOUND_ON_DISCONNECTED_NETWORK = 1, | 53 PAGE_NOT_FOUND_ON_DISCONNECTED_NETWORK = 1, |
| 54 // Flaky Network means the network reported an error when trying to fetch | |
| 55 // the resource. | |
| 49 REDIRECTED_ON_FLAKY_NETWORK = 2, | 56 REDIRECTED_ON_FLAKY_NETWORK = 2, |
| 50 PAGE_NOT_FOUND_ON_FLAKY_NETWORK = 3, | 57 PAGE_NOT_FOUND_ON_FLAKY_NETWORK = 3, |
| 51 IGNORED_FLAKY_NETWORK_FORWARD_BACK = 4, | 58 IGNORED_FLAKY_NETWORK_FORWARD_BACK = 4, |
| 52 REDIRECTED_ON_CONNECTED_NETWORK = 5, | 59 REDIRECTED_ON_CONNECTED_NETWORK = 5, |
| 53 NO_TAB_ID = 6, | 60 NO_TAB_ID = 6, |
| 54 SHOW_NET_ERROR_PAGE = 7, | 61 SHOW_NET_ERROR_PAGE = 7, |
| 55 REDIRECT_LOOP_OFFLINE = 8, | 62 REDIRECT_LOOP_OFFLINE = 8, |
| 56 REDIRECT_LOOP_ONLINE = 9, | 63 REDIRECT_LOOP_ONLINE = 9, |
| 64 // Prohibitively slow means that the NetworkQualityEstimator reported a | |
| 65 // connection slow enough to warrant showing an offline page if available. | |
| 66 REDIRECTED_ON_PROHIBITIVELY_SLOW_NETWORK = 10, | |
| 67 PAGE_NOT_FOUND_ON_PROHIBITIVELY_SLOW_NETWORK = 11, | |
| 68 PAGE_NOT_FRESH_ON_PROHIBITIVELY_SLOW_NETWORK = 12, | |
| 57 REDIRECT_RESULT_MAX, | 69 REDIRECT_RESULT_MAX, |
| 58 }; | 70 }; |
| 59 | 71 |
| 60 ~OfflinePageTabHelper() override; | 72 ~OfflinePageTabHelper() override; |
| 61 | 73 |
| 62 const OfflinePageItem* offline_page() { return offline_page_.get(); } | 74 const OfflinePageItem* offline_page() { return offline_page_.get(); } |
| 63 | 75 |
| 64 private: | 76 private: |
| 65 friend class content::WebContentsUserData<OfflinePageTabHelper>; | 77 friend class content::WebContentsUserData<OfflinePageTabHelper>; |
| 66 friend class OfflinePageTabHelperTest; | 78 friend class OfflinePageTabHelperTest; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 // Returns true if a given URL is in redirect chain already. | 112 // Returns true if a given URL is in redirect chain already. |
| 101 bool IsInRedirectLoop(const GURL& to_url) const; | 113 bool IsInRedirectLoop(const GURL& to_url) const; |
| 102 | 114 |
| 103 void ReportRedirectResultUMA(RedirectResult result); | 115 void ReportRedirectResultUMA(RedirectResult result); |
| 104 | 116 |
| 105 // Iff the tab we are associated with is redirected to an offline page, | 117 // Iff the tab we are associated with is redirected to an offline page, |
| 106 // |offline_page_| will be non-null. This can be used to synchronously ask | 118 // |offline_page_| will be non-null. This can be used to synchronously ask |
| 107 // about the offline state of the current web contents. | 119 // about the offline state of the current web contents. |
| 108 std::unique_ptr<OfflinePageItem> offline_page_; | 120 std::unique_ptr<OfflinePageItem> offline_page_; |
| 109 std::unique_ptr<Delegate> delegate_; | 121 std::unique_ptr<Delegate> delegate_; |
| 122 | |
| 110 base::WeakPtrFactory<OfflinePageTabHelper> weak_ptr_factory_; | 123 base::WeakPtrFactory<OfflinePageTabHelper> weak_ptr_factory_; |
| 111 | 124 |
| 112 DISALLOW_COPY_AND_ASSIGN(OfflinePageTabHelper); | 125 DISALLOW_COPY_AND_ASSIGN(OfflinePageTabHelper); |
| 113 }; | 126 }; |
| 114 | 127 |
| 115 } // namespace offline_pages | 128 } // namespace offline_pages |
| 116 | 129 |
| 117 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_ | 130 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_ |
| OLD | NEW |