1 // Copyright 2017 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef COMPONENTS_ERROR_PAGE_COMMON_ERROR_H_ 6 #define COMPONENTS_ERROR_PAGE_COMMON_ERROR_H_ 7 8 #include <string> 9 10 #include "net/dns/public/resolve_error_info.h" 11 #include "url/gurl.h" 12 13 namespace error_page { 14 15 // Represents an error info necessary to show an error page. 16 // This class is a copiable value class. 17 class Error { 18 public: 19 // For network errors 20 static const char kNetErrorDomain[]; 21 // For http errors. 22 static const char kHttpErrorDomain[]; 23 // For DNS probe errors. 24 static const char kDnsProbeErrorDomain[]; 25 26 // Returns a kNetErrorDomain error. 27 static Error NetError(const GURL& url, 28 int reason, 29 net::ResolveErrorInfo resolve_error_info, 30 bool stale_copy_in_cache); 31 // Returns a kHttpErrorDomain error. 32 static Error HttpError(const GURL& url, int status); 33 // Returns a kDnsProbeErrorDomain error. 34 static Error DnsProbeError(const GURL& url, 35 int status, 36 bool stale_copy_in_cache); 37 38 // Returns the url that failed to load. url()39 const GURL& url() const { return url_; } 40 // Returns the domain of this error. domain()41 const std::string& domain() const { return domain_; } 42 // Returns a numeric error code. The meaning of this code depends on the 43 // domain string. reason()44 int reason() const { return reason_; } 45 // Returns error details of the host resolution. resolve_error_info()46 const net::ResolveErrorInfo& resolve_error_info() const { 47 return resolve_error_info_; 48 } 49 // Returns true if chrome has a stale cache entry for the url. stale_copy_in_cache()50 bool stale_copy_in_cache() const { return stale_copy_in_cache_; } 51 52 private: 53 Error(const GURL& url, 54 const std::string& domain, 55 int reason, 56 net::ResolveErrorInfo resolve_error_info, 57 bool stale_copy_in_cache); 58 59 GURL url_; 60 std::string domain_; 61 int reason_; 62 net::ResolveErrorInfo resolve_error_info_; 63 bool stale_copy_in_cache_; 64 }; 65 66 } // namespace error_page 67 68 #endif // COMPONENTS_ERROR_PAGE_COMMON_ERROR_H_ 69