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

Side by Side Diff: chrome/renderer/net/net_error_helper_core.h

Issue 136203009: Support auto-reload on errors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Rebase? Created 6 years, 9 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_RENDERER_NET_NET_ERROR_HELPER_CORE_H_ 5 #ifndef CHROME_RENDERER_NET_NET_ERROR_HELPER_CORE_H_
6 #define CHROME_RENDERER_NET_NET_ERROR_HELPER_CORE_H_ 6 #define CHROME_RENDERER_NET_NET_ERROR_HELPER_CORE_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h"
10 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
12 #include "chrome/common/localized_error.h" 13 #include "chrome/common/localized_error.h"
13 #include "chrome/common/net/net_error_info.h" 14 #include "chrome/common/net/net_error_info.h"
15 #include "chrome/renderer/net/mockable_one_shot_timer.h"
14 #include "url/gurl.h" 16 #include "url/gurl.h"
15 17
16 namespace base { 18 namespace base {
17 class ListValue; 19 class ListValue;
18 } 20 }
19 21
20 namespace blink { 22 namespace blink {
21 struct WebURLError; 23 struct WebURLError;
22 } 24 }
23 25
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 // previous fetch must either be canceled or finished before calling. Can't 64 // previous fetch must either be canceled or finished before calling. Can't
63 // be called synchronously after a previous fetch completes. 65 // be called synchronously after a previous fetch completes.
64 virtual void FetchNavigationCorrections( 66 virtual void FetchNavigationCorrections(
65 const GURL& navigation_correction_url, 67 const GURL& navigation_correction_url,
66 const std::string& navigation_correction_request_body) = 0; 68 const std::string& navigation_correction_request_body) = 0;
67 69
68 // Cancels fetching navigation corrections. Does nothing if no fetch is 70 // Cancels fetching navigation corrections. Does nothing if no fetch is
69 // ongoing. 71 // ongoing.
70 virtual void CancelFetchNavigationCorrections() = 0; 72 virtual void CancelFetchNavigationCorrections() = 0;
71 73
74 // Starts a reload of the page in the observed frame.
75 virtual void ReloadPage() = 0;
76
72 protected: 77 protected:
73 virtual ~Delegate() {} 78 virtual ~Delegate() {}
74 }; 79 };
75 80
76 explicit NetErrorHelperCore(Delegate* delegate); 81 explicit NetErrorHelperCore(Delegate* delegate);
77 ~NetErrorHelperCore(); 82 ~NetErrorHelperCore();
78 83
79 // Examines |frame| and |error| to see if this is an error worthy of a DNS 84 // Examines |frame| and |error| to see if this is an error worthy of a DNS
80 // probe. If it is, initializes |error_strings| based on |error|, 85 // probe. If it is, initializes |error_strings| based on |error|,
81 // |is_failed_post|, and |locale| with suitable strings and returns true. 86 // |is_failed_post|, and |locale| with suitable strings and returns true.
82 // If not, returns false, in which case the caller should look up error 87 // If not, returns false, in which case the caller should look up error
83 // strings directly using LocalizedError::GetNavigationErrorStrings. 88 // strings directly using LocalizedError::GetNavigationErrorStrings.
84 // 89 //
85 // Updates the NetErrorHelper with the assumption the page will be loaded 90 // Updates the NetErrorHelper with the assumption the page will be loaded
86 // immediately. 91 // immediately.
87 void GetErrorHTML(FrameType frame_type, 92 void GetErrorHTML(FrameType frame_type,
88 const blink::WebURLError& error, 93 const blink::WebURLError& error,
89 bool is_failed_post, 94 bool is_failed_post,
90 std::string* error_html); 95 std::string* error_html);
91 96
92 // These methods handle tracking the actual state of the page. 97 // These methods handle tracking the actual state of the page.
93 void OnStartLoad(FrameType frame_type, PageType page_type); 98 void OnStartLoad(FrameType frame_type, PageType page_type);
94 void OnCommitLoad(FrameType frame_type); 99 void OnCommitLoad(FrameType frame_type);
95 void OnFinishLoad(FrameType frame_type); 100 void OnFinishLoad(FrameType frame_type);
96 void OnStop(); 101 void OnStop();
97 102
103 void CancelPendingFetches();
104
98 // Called when an error page have has been retrieved over the network. |html| 105 // Called when an error page have has been retrieved over the network. |html|
99 // must be an empty string on error. 106 // must be an empty string on error.
100 void OnNavigationCorrectionsFetched(const std::string& corrections, 107 void OnNavigationCorrectionsFetched(const std::string& corrections,
101 const std::string& accept_languages, 108 const std::string& accept_languages,
102 bool is_rtl); 109 bool is_rtl);
103 110
104 // Notifies |this| that network error information from the browser process 111 // Notifies |this| that network error information from the browser process
105 // has been received. 112 // has been received.
106 void OnNetErrorInfo(chrome_common_net::DnsProbeStatus status); 113 void OnNetErrorInfo(chrome_common_net::DnsProbeStatus status);
107 114
108 void OnSetNavigationCorrectionInfo(const GURL& navigation_correction_url, 115 void OnSetNavigationCorrectionInfo(const GURL& navigation_correction_url,
109 const std::string& language, 116 const std::string& language,
110 const std::string& country_code, 117 const std::string& country_code,
111 const std::string& api_key, 118 const std::string& api_key,
112 const GURL& search_url); 119 const GURL& search_url);
120 // Notifies |this| that the network's online status changed.
121 // Handler for NetworkStateChanged notification from the browser process. If
122 // the network state changes to online, this method is responsible for
123 // starting the auto-reload process.
124 //
125 // Warning: if there are many tabs sitting at an error page, this handler will
126 // be run at the same time for each of their top-level renderframes, which can
127 // cause many requests to be started at the same time. There's no current
128 // protection against this kind of "reload storm".
129 //
130 // TODO(rdsmith): prevent the reload storm.
131 void NetworkStateChanged(bool online);
132
133 void set_auto_reload_enabled(bool auto_reload_enabled) {
134 auto_reload_enabled_ = auto_reload_enabled;
135 }
136
137 int auto_reload_count() const { return auto_reload_count_; }
138
139 bool ShouldSuppressErrorPage(FrameType frame_type, const GURL& url);
140
141 void set_timer_for_testing(scoped_ptr<MockableOneShotTimer> timer) {
142 auto_reload_timer_.reset(timer.release());
143 }
113 144
114 private: 145 private:
115 struct ErrorPageInfo; 146 struct ErrorPageInfo;
116 147
117 // Updates the currently displayed error page with a new error based on the 148 // Updates the currently displayed error page with a new error based on the
118 // most recently received DNS probe result. The page must have finished 149 // most recently received DNS probe result. The page must have finished
119 // loading before this is called. 150 // loading before this is called.
120 void UpdateErrorPage(); 151 void UpdateErrorPage();
121 152
122 void GenerateLocalErrorPage( 153 void GenerateLocalErrorPage(
123 FrameType frame_type, 154 FrameType frame_type,
124 const blink::WebURLError& error, 155 const blink::WebURLError& error,
125 bool is_failed_post, 156 bool is_failed_post,
126 scoped_ptr<LocalizedError::ErrorPageParams> params, 157 scoped_ptr<LocalizedError::ErrorPageParams> params,
127 std::string* error_html); 158 std::string* error_html);
128 159
129 blink::WebURLError GetUpdatedError(const blink::WebURLError& error) const; 160 blink::WebURLError GetUpdatedError(const blink::WebURLError& error) const;
130 161
162 void Reload();
163 bool MaybeStartAutoReloadTimer();
164 void StartAutoReloadTimer();
165
166 static bool IsReloadableError(const ErrorPageInfo& info);
167
131 Delegate* delegate_; 168 Delegate* delegate_;
132 169
133 // The last DnsProbeStatus received from the browser. 170 // The last DnsProbeStatus received from the browser.
134 chrome_common_net::DnsProbeStatus last_probe_status_; 171 chrome_common_net::DnsProbeStatus last_probe_status_;
135 172
136 // Information for the provisional / "pre-provisional" error page. NULL when 173 // Information for the provisional / "pre-provisional" error page. NULL when
137 // there's no page pending, or the pending page is not an error page. 174 // there's no page pending, or the pending page is not an error page.
138 scoped_ptr<ErrorPageInfo> pending_error_page_info_; 175 scoped_ptr<ErrorPageInfo> pending_error_page_info_;
139 176
140 // Information for the committed error page. NULL when the committed page is 177 // Information for the committed error page. NULL when the committed page is
141 // not an error page. 178 // not an error page.
142 scoped_ptr<ErrorPageInfo> committed_error_page_info_; 179 scoped_ptr<ErrorPageInfo> committed_error_page_info_;
143 180
144 GURL navigation_correction_url_; 181 GURL navigation_correction_url_;
145 std::string language_; 182 std::string language_;
146 std::string country_code_; 183 std::string country_code_;
147 std::string api_key_; 184 std::string api_key_;
148 GURL search_url_; 185 GURL search_url_;
186
187 bool auto_reload_enabled_;
188 scoped_ptr<MockableOneShotTimer> auto_reload_timer_;
189
190 // Is the browser online?
191 bool online_;
192
193 int auto_reload_count_;
194 bool can_auto_reload_page_;
149 }; 195 };
jochen (gone - plz use gerrit) 2014/03/13 12:20:40 disallow copy/assign?
150 196
151 #endif // CHROME_RENDERER_NET_NET_ERROR_HELPER_CORE_H_ 197 #endif // CHROME_RENDERER_NET_NET_ERROR_HELPER_CORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698