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

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

Issue 2225213002: Make GetBestPageForOnlineURL async (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make GetBestPageForOnlineURL async Created 4 years, 4 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 "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 14 matching lines...) Expand all
25 class OfflinePageTabHelper : 25 class OfflinePageTabHelper :
26 public content::WebContentsObserver, 26 public content::WebContentsObserver,
27 public content::WebContentsUserData<OfflinePageTabHelper> { 27 public content::WebContentsUserData<OfflinePageTabHelper> {
28 public: 28 public:
29 // Delegate that is used to better handle external dependencies. 29 // Delegate that is used to better handle external dependencies.
30 // Default implementation is in .cc file, while tests provide an override. 30 // Default implementation is in .cc file, while tests provide an override.
31 class Delegate { 31 class Delegate {
32 public: 32 public:
33 virtual ~Delegate() {} 33 virtual ~Delegate() {}
34 virtual bool GetTabId(content::WebContents* web_contents, 34 virtual bool GetTabId(content::WebContents* web_contents,
35 std::string* tab_id) const = 0; 35 int* tab_id) const = 0;
36 virtual base::Time Now() const = 0; 36 virtual base::Time Now() const = 0;
37 }; 37 };
38 38
39 // This enum is used for UMA reporting. It contains all possible outcomes of 39 // This enum is used for UMA reporting. It contains all possible outcomes of
40 // redirect intent and result. Generally one of these outcomes will happen. 40 // redirect intent and result. Generally one of these outcomes will happen.
41 // The fringe errors (like no OfflinePageModel, etc.) are not reported due 41 // The fringe errors (like no OfflinePageModel, etc.) are not reported due
42 // to their low probability. 42 // to their low probability.
43 // NOTE: because this is used for UMA reporting, these values should not be 43 // NOTE: because this is used for UMA reporting, these values should not be
44 // changed or reused; new values should be ended immediately before the MAX 44 // changed or reused; new values should be ended immediately before the MAX
45 // value. Make sure to update the histogram enum 45 // value. Make sure to update the histogram enum
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 content::NavigationHandle* navigation_handle) override; 87 content::NavigationHandle* navigation_handle) override;
88 88
89 void RedirectToOnline(const GURL& from_url, 89 void RedirectToOnline(const GURL& from_url,
90 const OfflinePageItem* offline_page); 90 const OfflinePageItem* offline_page);
91 91
92 // 3 step redirection to the offline page. First getting all the pages, then 92 // 3 step redirection to the offline page. First getting all the pages, then
93 // selecting appropriate page to redirect to and finally attempting to 93 // selecting appropriate page to redirect to and finally attempting to
94 // redirect to that offline page, and caching metadata of that page locally. 94 // redirect to that offline page, and caching metadata of that page locally.
95 // RedirectResult is accumulated along the codepath to reflect the overall 95 // RedirectResult is accumulated along the codepath to reflect the overall
96 // result of redirection - and be reported to UMA at the end. 96 // result of redirection - and be reported to UMA at the end.
97 void GetPagesForRedirectToOffline(RedirectResult result, 97 void GetBestPageForRedirectToOffline(RedirectResult result,
98 const GURL& online_url); 98 const GURL& online_url);
99 void SelectBestPageForRedirectToOffline( 99 void GetBestPageForOnlineURLDone(
Dmitry Titov 2016/08/10 02:56:37 the name doesn't match what this method does now.
jianli 2016/08/11 00:33:27 Per discussion, changed to SelectPageForOnlineURLD
100 RedirectResult result, 100 RedirectResult result,
101 const GURL& online_url, 101 const GURL& online_url,
102 const MultipleOfflinePageItemResult& pages); 102 const OfflinePageItem* offline_page);
103 void TryRedirectToOffline(RedirectResult result, 103 void TryRedirectToOffline(RedirectResult result,
104 const GURL& from_url, 104 const GURL& from_url,
105 const OfflinePageItem& offline_page); 105 const OfflinePageItem& offline_page);
106 106
107 void Redirect(const GURL& from_url, const GURL& to_url); 107 void Redirect(const GURL& from_url, const GURL& to_url);
108 108
109 // Returns true if a given URL is in redirect chain already. 109 // Returns true if a given URL is in redirect chain already.
110 bool IsInRedirectLoop(const GURL& to_url) const; 110 bool IsInRedirectLoop(const GURL& to_url) const;
111 111
112 void ReportRedirectResultUMA(RedirectResult result); 112 void ReportRedirectResultUMA(RedirectResult result);
113 113
114 // Iff the tab we are associated with is redirected to an offline page, 114 // Iff the tab we are associated with is redirected to an offline page,
115 // |offline_page_| will be non-null. This can be used to synchronously ask 115 // |offline_page_| will be non-null. This can be used to synchronously ask
116 // about the offline state of the current web contents. 116 // about the offline state of the current web contents.
117 std::unique_ptr<OfflinePageItem> offline_page_; 117 std::unique_ptr<OfflinePageItem> offline_page_;
118 std::unique_ptr<Delegate> delegate_; 118 std::unique_ptr<Delegate> delegate_;
119 119
120 base::WeakPtrFactory<OfflinePageTabHelper> weak_ptr_factory_; 120 base::WeakPtrFactory<OfflinePageTabHelper> weak_ptr_factory_;
121 121
122 DISALLOW_COPY_AND_ASSIGN(OfflinePageTabHelper); 122 DISALLOW_COPY_AND_ASSIGN(OfflinePageTabHelper);
123 }; 123 };
124 124
125 } // namespace offline_pages 125 } // namespace offline_pages
126 126
127 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_ 127 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_TAB_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698