error.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #ifndef COMPONENTS_ERROR_PAGE_COMMON_ERROR_H_
  5. #define COMPONENTS_ERROR_PAGE_COMMON_ERROR_H_
  6. #include <string>
  7. #include "net/dns/public/resolve_error_info.h"
  8. #include "url/gurl.h"
  9. namespace error_page {
  10. // Represents an error info necessary to show an error page.
  11. // This class is a copiable value class.
  12. class Error {
  13. public:
  14. // For network errors
  15. static const char kNetErrorDomain[];
  16. // For http errors.
  17. static const char kHttpErrorDomain[];
  18. // For DNS probe errors.
  19. static const char kDnsProbeErrorDomain[];
  20. // Returns a kNetErrorDomain error.
  21. static Error NetError(const GURL& url,
  22. int reason,
  23. int extended_reason,
  24. net::ResolveErrorInfo resolve_error_info,
  25. bool stale_copy_in_cache);
  26. // Returns a kHttpErrorDomain error.
  27. static Error HttpError(const GURL& url, int status);
  28. // Returns a kDnsProbeErrorDomain error.
  29. static Error DnsProbeError(const GURL& url,
  30. int status,
  31. bool stale_copy_in_cache);
  32. ~Error();
  33. Error(const Error&);
  34. Error& operator=(const Error&);
  35. // Returns the url that failed to load.
  36. const GURL& url() const { return url_; }
  37. // Returns the domain of this error.
  38. const std::string& domain() const { return domain_; }
  39. // Returns a numeric error code. The meaning of this code depends on the
  40. // domain string.
  41. int reason() const { return reason_; }
  42. // Returns a numeric error code containing additional information about the
  43. // error. Note that the extended reason is only relevant when `reason()` is
  44. // `kNetErrorDomain`.
  45. int extended_reason() const { return extended_reason_; }
  46. // Returns error details of the host resolution.
  47. const net::ResolveErrorInfo& resolve_error_info() const {
  48. return resolve_error_info_;
  49. }
  50. // Returns true if chrome has a stale cache entry for the url.
  51. bool stale_copy_in_cache() const { return stale_copy_in_cache_; }
  52. private:
  53. Error(const GURL& url,
  54. const std::string& domain,
  55. int reason,
  56. int extended_reason,
  57. net::ResolveErrorInfo resolve_error_info,
  58. bool stale_copy_in_cache);
  59. GURL url_;
  60. std::string domain_;
  61. int reason_;
  62. int extended_reason_;
  63. net::ResolveErrorInfo resolve_error_info_;
  64. bool stale_copy_in_cache_;
  65. };
  66. } // namespace error_page
  67. #endif // COMPONENTS_ERROR_PAGE_COMMON_ERROR_H_