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

Side by Side Diff: components/error_page/renderer/net_error_helper_core.cc

Issue 1921973002: Convert //components/[a-e]* from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 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 #include "components/error_page/renderer/net_error_helper_core.h" 5 #include "components/error_page/renderer/net_error_helper_core.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 return false; 187 return false;
188 } 188 }
189 189
190 // Creates a request body for use with the fixurl service. Sets parameters 190 // Creates a request body for use with the fixurl service. Sets parameters
191 // shared by all types of requests to the service. |correction_params| must 191 // shared by all types of requests to the service. |correction_params| must
192 // contain the parameters specific to the actual request type. 192 // contain the parameters specific to the actual request type.
193 std::string CreateRequestBody( 193 std::string CreateRequestBody(
194 const std::string& method, 194 const std::string& method,
195 const std::string& error_param, 195 const std::string& error_param,
196 const NetErrorHelperCore::NavigationCorrectionParams& correction_params, 196 const NetErrorHelperCore::NavigationCorrectionParams& correction_params,
197 scoped_ptr<base::DictionaryValue> params_dict) { 197 std::unique_ptr<base::DictionaryValue> params_dict) {
198 // Set params common to all request types. 198 // Set params common to all request types.
199 params_dict->SetString("key", correction_params.api_key); 199 params_dict->SetString("key", correction_params.api_key);
200 params_dict->SetString("clientName", "chrome"); 200 params_dict->SetString("clientName", "chrome");
201 params_dict->SetString("error", error_param); 201 params_dict->SetString("error", error_param);
202 202
203 if (!correction_params.language.empty()) 203 if (!correction_params.language.empty())
204 params_dict->SetString("language", correction_params.language); 204 params_dict->SetString("language", correction_params.language);
205 205
206 if (!correction_params.country_code.empty()) 206 if (!correction_params.country_code.empty())
207 params_dict->SetString("originCountry", correction_params.country_code); 207 params_dict->SetString("originCountry", correction_params.country_code);
(...skipping 14 matching lines...) Expand all
222 // |correction_request_body| to be the body for the correction request. 222 // |correction_request_body| to be the body for the correction request.
223 std::string CreateFixUrlRequestBody( 223 std::string CreateFixUrlRequestBody(
224 const blink::WebURLError& error, 224 const blink::WebURLError& error,
225 const NetErrorHelperCore::NavigationCorrectionParams& correction_params) { 225 const NetErrorHelperCore::NavigationCorrectionParams& correction_params) {
226 std::string error_param; 226 std::string error_param;
227 bool result = ShouldUseFixUrlServiceForError(error, &error_param); 227 bool result = ShouldUseFixUrlServiceForError(error, &error_param);
228 DCHECK(result); 228 DCHECK(result);
229 229
230 // TODO(mmenke): Investigate open sourcing the relevant protocol buffers and 230 // TODO(mmenke): Investigate open sourcing the relevant protocol buffers and
231 // using those directly instead. 231 // using those directly instead.
232 scoped_ptr<base::DictionaryValue> params(new base::DictionaryValue()); 232 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue());
233 params->SetString("urlQuery", PrepareUrlForUpload(error.unreachableURL)); 233 params->SetString("urlQuery", PrepareUrlForUpload(error.unreachableURL));
234 return CreateRequestBody("linkdoctor.fixurl.fixurl", error_param, 234 return CreateRequestBody("linkdoctor.fixurl.fixurl", error_param,
235 correction_params, std::move(params)); 235 correction_params, std::move(params));
236 } 236 }
237 237
238 std::string CreateClickTrackingUrlRequestBody( 238 std::string CreateClickTrackingUrlRequestBody(
239 const blink::WebURLError& error, 239 const blink::WebURLError& error,
240 const NetErrorHelperCore::NavigationCorrectionParams& correction_params, 240 const NetErrorHelperCore::NavigationCorrectionParams& correction_params,
241 const NavigationCorrectionResponse& response, 241 const NavigationCorrectionResponse& response,
242 const NavigationCorrection& correction) { 242 const NavigationCorrection& correction) {
243 std::string error_param; 243 std::string error_param;
244 bool result = ShouldUseFixUrlServiceForError(error, &error_param); 244 bool result = ShouldUseFixUrlServiceForError(error, &error_param);
245 DCHECK(result); 245 DCHECK(result);
246 246
247 scoped_ptr<base::DictionaryValue> params(new base::DictionaryValue()); 247 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue());
248 248
249 params->SetString("originalUrlQuery", 249 params->SetString("originalUrlQuery",
250 PrepareUrlForUpload(error.unreachableURL)); 250 PrepareUrlForUpload(error.unreachableURL));
251 251
252 params->SetString("clickedUrlCorrection", correction.url_correction); 252 params->SetString("clickedUrlCorrection", correction.url_correction);
253 params->SetString("clickType", correction.click_type); 253 params->SetString("clickType", correction.click_type);
254 params->SetString("clickData", correction.click_data); 254 params->SetString("clickData", correction.click_data);
255 255
256 params->SetString("eventId", response.event_id); 256 params->SetString("eventId", response.event_id);
257 params->SetString("fingerprint", response.fingerprint); 257 params->SetString("fingerprint", response.fingerprint);
258 258
259 return CreateRequestBody("linkdoctor.fixurl.clicktracking", error_param, 259 return CreateRequestBody("linkdoctor.fixurl.clicktracking", error_param,
260 correction_params, std::move(params)); 260 correction_params, std::move(params));
261 } 261 }
262 262
263 base::string16 FormatURLForDisplay(const GURL& url, bool is_rtl) { 263 base::string16 FormatURLForDisplay(const GURL& url, bool is_rtl) {
264 // Translate punycode into UTF8, unescape UTF8 URLs. 264 // Translate punycode into UTF8, unescape UTF8 URLs.
265 base::string16 url_for_display(url_formatter::FormatUrl( 265 base::string16 url_for_display(url_formatter::FormatUrl(
266 url, url_formatter::kFormatUrlOmitNothing, 266 url, url_formatter::kFormatUrlOmitNothing,
267 net::UnescapeRule::NORMAL, nullptr, nullptr, nullptr)); 267 net::UnescapeRule::NORMAL, nullptr, nullptr, nullptr));
268 // URLs are always LTR. 268 // URLs are always LTR.
269 if (is_rtl) 269 if (is_rtl)
270 base::i18n::WrapStringWithLTRFormatting(&url_for_display); 270 base::i18n::WrapStringWithLTRFormatting(&url_for_display);
271 return url_for_display; 271 return url_for_display;
272 } 272 }
273 273
274 scoped_ptr<NavigationCorrectionResponse> ParseNavigationCorrectionResponse( 274 std::unique_ptr<NavigationCorrectionResponse> ParseNavigationCorrectionResponse(
275 const std::string raw_response) { 275 const std::string raw_response) {
276 // TODO(mmenke): Open source related protocol buffers and use them directly. 276 // TODO(mmenke): Open source related protocol buffers and use them directly.
277 scoped_ptr<base::Value> parsed = base::JSONReader::Read(raw_response); 277 std::unique_ptr<base::Value> parsed = base::JSONReader::Read(raw_response);
278 scoped_ptr<NavigationCorrectionResponse> response( 278 std::unique_ptr<NavigationCorrectionResponse> response(
279 new NavigationCorrectionResponse()); 279 new NavigationCorrectionResponse());
280 base::JSONValueConverter<NavigationCorrectionResponse> converter; 280 base::JSONValueConverter<NavigationCorrectionResponse> converter;
281 if (!parsed || !converter.Convert(*parsed, response.get())) 281 if (!parsed || !converter.Convert(*parsed, response.get()))
282 response.reset(); 282 response.reset();
283 return response; 283 return response;
284 } 284 }
285 285
286 void LogCorrectionTypeShown(int type_id) { 286 void LogCorrectionTypeShown(int type_id) {
287 UMA_HISTOGRAM_ENUMERATION( 287 UMA_HISTOGRAM_ENUMERATION(
288 "Net.ErrorPageCounts.NavigationCorrectionLinksShown", type_id, 288 "Net.ErrorPageCounts.NavigationCorrectionLinksShown", type_id,
289 kWebSearchQueryUMAId + 1); 289 kWebSearchQueryUMAId + 1);
290 } 290 }
291 291
292 scoped_ptr<ErrorPageParams> CreateErrorPageParams( 292 std::unique_ptr<ErrorPageParams> CreateErrorPageParams(
293 const NavigationCorrectionResponse& response, 293 const NavigationCorrectionResponse& response,
294 const blink::WebURLError& error, 294 const blink::WebURLError& error,
295 const NetErrorHelperCore::NavigationCorrectionParams& correction_params, 295 const NetErrorHelperCore::NavigationCorrectionParams& correction_params,
296 bool is_rtl) { 296 bool is_rtl) {
297 // Version of URL for display in suggestions. It has to be sanitized first 297 // Version of URL for display in suggestions. It has to be sanitized first
298 // because any received suggestions will be relative to the sanitized URL. 298 // because any received suggestions will be relative to the sanitized URL.
299 base::string16 original_url_for_display = 299 base::string16 original_url_for_display =
300 FormatURLForDisplay(SanitizeURL(GURL(error.unreachableURL)), is_rtl); 300 FormatURLForDisplay(SanitizeURL(GURL(error.unreachableURL)), is_rtl);
301 301
302 scoped_ptr<ErrorPageParams> params(new ErrorPageParams()); 302 std::unique_ptr<ErrorPageParams> params(new ErrorPageParams());
303 params->override_suggestions.reset(new base::ListValue()); 303 params->override_suggestions.reset(new base::ListValue());
304 scoped_ptr<base::ListValue> parsed_corrections(new base::ListValue()); 304 std::unique_ptr<base::ListValue> parsed_corrections(new base::ListValue());
305 for (ScopedVector<NavigationCorrection>::const_iterator it = 305 for (ScopedVector<NavigationCorrection>::const_iterator it =
306 response.corrections.begin(); 306 response.corrections.begin();
307 it != response.corrections.end(); ++it) { 307 it != response.corrections.end(); ++it) {
308 // Doesn't seem like a good idea to show these. 308 // Doesn't seem like a good idea to show these.
309 if ((*it)->is_porn || (*it)->is_soft_porn) 309 if ((*it)->is_porn || (*it)->is_soft_porn)
310 continue; 310 continue;
311 311
312 int tracking_id = it - response.corrections.begin(); 312 int tracking_id = it - response.corrections.begin();
313 313
314 if ((*it)->correction_type == "reloadPage") { 314 if ((*it)->correction_type == "reloadPage") {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 // probe status. 441 // probe status.
442 bool needs_dns_updates; 442 bool needs_dns_updates;
443 443
444 // True if a blank page was loaded, and navigation corrections need to be 444 // True if a blank page was loaded, and navigation corrections need to be
445 // loaded to generate the real error page. 445 // loaded to generate the real error page.
446 bool needs_load_navigation_corrections; 446 bool needs_load_navigation_corrections;
447 447
448 // Navigation correction service paramers, which will be used in response to 448 // Navigation correction service paramers, which will be used in response to
449 // certain types of network errors. They are all stored here in case they 449 // certain types of network errors. They are all stored here in case they
450 // change over the course of displaying the error page. 450 // change over the course of displaying the error page.
451 scoped_ptr<NetErrorHelperCore::NavigationCorrectionParams> 451 std::unique_ptr<NetErrorHelperCore::NavigationCorrectionParams>
452 navigation_correction_params; 452 navigation_correction_params;
453 453
454 scoped_ptr<NavigationCorrectionResponse> navigation_correction_response; 454 std::unique_ptr<NavigationCorrectionResponse> navigation_correction_response;
455 455
456 // All the navigation corrections that have been clicked, for tracking 456 // All the navigation corrections that have been clicked, for tracking
457 // purposes. 457 // purposes.
458 std::set<int> clicked_corrections; 458 std::set<int> clicked_corrections;
459 459
460 // Track if specific buttons are included in an error page, for statistics. 460 // Track if specific buttons are included in an error page, for statistics.
461 bool reload_button_in_page; 461 bool reload_button_in_page;
462 bool show_saved_copy_button_in_page; 462 bool show_saved_copy_button_in_page;
463 bool show_cached_copy_button_in_page; 463 bool show_cached_copy_button_in_page;
464 bool show_offline_pages_button_in_page; 464 bool show_offline_pages_button_in_page;
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 } else { 702 } else {
703 // These values do not matter, as error pages in iframes hide the buttons. 703 // These values do not matter, as error pages in iframes hide the buttons.
704 bool reload_button_in_page; 704 bool reload_button_in_page;
705 bool show_saved_copy_button_in_page; 705 bool show_saved_copy_button_in_page;
706 bool show_cached_copy_button_in_page; 706 bool show_cached_copy_button_in_page;
707 bool show_offline_pages_button_in_page; 707 bool show_offline_pages_button_in_page;
708 708
709 delegate_->GenerateLocalizedErrorPage( 709 delegate_->GenerateLocalizedErrorPage(
710 error, is_failed_post, 710 error, is_failed_post,
711 false /* No diagnostics dialogs allowed for subframes. */, 711 false /* No diagnostics dialogs allowed for subframes. */,
712 false /* No offline button provided in subframes */, 712 false /* No offline button provided in subframes */, nullptr,
713 scoped_ptr<ErrorPageParams>(), &reload_button_in_page, 713 &reload_button_in_page, &show_saved_copy_button_in_page,
714 &show_saved_copy_button_in_page, &show_cached_copy_button_in_page, 714 &show_cached_copy_button_in_page, &show_offline_pages_button_in_page,
715 &show_offline_pages_button_in_page, error_html); 715 error_html);
716 } 716 }
717 } 717 }
718 718
719 void NetErrorHelperCore::OnNetErrorInfo(DnsProbeStatus status) { 719 void NetErrorHelperCore::OnNetErrorInfo(DnsProbeStatus status) {
720 DCHECK_NE(DNS_PROBE_POSSIBLE, status); 720 DCHECK_NE(DNS_PROBE_POSSIBLE, status);
721 721
722 last_probe_status_ = status; 722 last_probe_status_ = status;
723 723
724 if (!committed_error_page_info_ || 724 if (!committed_error_page_info_ ||
725 !committed_error_page_info_->needs_dns_updates || 725 !committed_error_page_info_->needs_dns_updates ||
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 // loading, a DNS probe status scheduled to be sent to it may be thrown 773 // loading, a DNS probe status scheduled to be sent to it may be thrown
774 // out, but since the new error page should trigger a new DNS probe, it 774 // out, but since the new error page should trigger a new DNS probe, it
775 // will just get the results for the next page load. 775 // will just get the results for the next page load.
776 last_probe_status_ = DNS_PROBE_POSSIBLE; 776 last_probe_status_ = DNS_PROBE_POSSIBLE;
777 pending_error_page_info->needs_dns_updates = true; 777 pending_error_page_info->needs_dns_updates = true;
778 error = GetUpdatedError(error); 778 error = GetUpdatedError(error);
779 } 779 }
780 780
781 delegate_->GenerateLocalizedErrorPage( 781 delegate_->GenerateLocalizedErrorPage(
782 error, pending_error_page_info->was_failed_post, 782 error, pending_error_page_info->was_failed_post,
783 can_show_network_diagnostics_dialog_, 783 can_show_network_diagnostics_dialog_, HasOfflinePages(), nullptr,
784 HasOfflinePages(),
785 scoped_ptr<ErrorPageParams>(),
786 &pending_error_page_info->reload_button_in_page, 784 &pending_error_page_info->reload_button_in_page,
787 &pending_error_page_info->show_saved_copy_button_in_page, 785 &pending_error_page_info->show_saved_copy_button_in_page,
788 &pending_error_page_info->show_cached_copy_button_in_page, 786 &pending_error_page_info->show_cached_copy_button_in_page,
789 &pending_error_page_info->show_offline_pages_button_in_page, 787 &pending_error_page_info->show_offline_pages_button_in_page, error_html);
790 error_html);
791 } 788 }
792 789
793 void NetErrorHelperCore::UpdateErrorPage() { 790 void NetErrorHelperCore::UpdateErrorPage() {
794 DCHECK(committed_error_page_info_->needs_dns_updates); 791 DCHECK(committed_error_page_info_->needs_dns_updates);
795 DCHECK(committed_error_page_info_->is_finished_loading); 792 DCHECK(committed_error_page_info_->is_finished_loading);
796 DCHECK_NE(DNS_PROBE_POSSIBLE, last_probe_status_); 793 DCHECK_NE(DNS_PROBE_POSSIBLE, last_probe_status_);
797 794
798 UMA_HISTOGRAM_ENUMERATION("DnsProbe.ErrorPageUpdateStatus", 795 UMA_HISTOGRAM_ENUMERATION("DnsProbe.ErrorPageUpdateStatus",
799 last_probe_status_, 796 last_probe_status_,
800 DNS_PROBE_MAX); 797 DNS_PROBE_MAX);
(...skipping 24 matching lines...) Expand all
825 DCHECK(committed_error_page_info_->navigation_correction_params); 822 DCHECK(committed_error_page_info_->navigation_correction_params);
826 823
827 pending_error_page_info_.reset(new ErrorPageInfo( 824 pending_error_page_info_.reset(new ErrorPageInfo(
828 committed_error_page_info_->error, 825 committed_error_page_info_->error,
829 committed_error_page_info_->was_failed_post, 826 committed_error_page_info_->was_failed_post,
830 committed_error_page_info_->was_ignoring_cache)); 827 committed_error_page_info_->was_ignoring_cache));
831 pending_error_page_info_->navigation_correction_response = 828 pending_error_page_info_->navigation_correction_response =
832 ParseNavigationCorrectionResponse(corrections); 829 ParseNavigationCorrectionResponse(corrections);
833 830
834 std::string error_html; 831 std::string error_html;
835 scoped_ptr<ErrorPageParams> params; 832 std::unique_ptr<ErrorPageParams> params;
836 if (pending_error_page_info_->navigation_correction_response) { 833 if (pending_error_page_info_->navigation_correction_response) {
837 // Copy navigation correction parameters used for the request, so tracking 834 // Copy navigation correction parameters used for the request, so tracking
838 // requests can still be sent if the configuration changes. 835 // requests can still be sent if the configuration changes.
839 pending_error_page_info_->navigation_correction_params.reset( 836 pending_error_page_info_->navigation_correction_params.reset(
840 new NavigationCorrectionParams( 837 new NavigationCorrectionParams(
841 *committed_error_page_info_->navigation_correction_params)); 838 *committed_error_page_info_->navigation_correction_params));
842 params = CreateErrorPageParams( 839 params = CreateErrorPageParams(
843 *pending_error_page_info_->navigation_correction_response, 840 *pending_error_page_info_->navigation_correction_response,
844 pending_error_page_info_->error, 841 pending_error_page_info_->error,
845 *pending_error_page_info_->navigation_correction_params, is_rtl); 842 *pending_error_page_info_->navigation_correction_params, is_rtl);
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 1062
1066 bool NetErrorHelperCore::HasOfflinePages() const { 1063 bool NetErrorHelperCore::HasOfflinePages() const {
1067 #if defined(OS_ANDROID) 1064 #if defined(OS_ANDROID)
1068 return has_offline_pages_; 1065 return has_offline_pages_;
1069 #else 1066 #else
1070 return false; 1067 return false;
1071 #endif // defined(OS_ANDROID) 1068 #endif // defined(OS_ANDROID)
1072 } 1069 }
1073 1070
1074 } // namespace error_page 1071 } // namespace error_page
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698