| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 NET_URL_REQUEST_URL_REQUEST_STATUS_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_STATUS_H_ |
| 6 #define NET_URL_REQUEST_URL_REQUEST_STATUS_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_STATUS_H_ |
| 7 | 7 |
| 8 #include "net/base/net_errors.h" |
| 8 #include "net/base/net_export.h" | 9 #include "net/base/net_export.h" |
| 9 | 10 |
| 10 namespace net { | 11 namespace net { |
| 11 | 12 |
| 12 // Represents the result of a URL request. It encodes errors and various | 13 // Represents the result of a URL request. It encodes errors and various |
| 13 // types of success. | 14 // types of success. |
| 14 class NET_EXPORT URLRequestStatus { | 15 class NET_EXPORT URLRequestStatus { |
| 15 public: | 16 public: |
| 16 enum Status { | 17 enum Status { |
| 17 // Request succeeded, |error_| will be 0. | 18 // Request succeeded, |error_| will be 0. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 34 // Creates a URLRequestStatus with specified status and error parameters. New | 35 // Creates a URLRequestStatus with specified status and error parameters. New |
| 35 // consumers should use URLRequestStatus::FromError instead. | 36 // consumers should use URLRequestStatus::FromError instead. |
| 36 URLRequestStatus(Status status, int error); | 37 URLRequestStatus(Status status, int error); |
| 37 | 38 |
| 38 // Creates a URLRequestStatus, initializing the status from |error|. OK maps | 39 // Creates a URLRequestStatus, initializing the status from |error|. OK maps |
| 39 // to SUCCESS, ERR_IO_PENDING maps to IO_PENDING, ERR_ABORTED maps to CANCELED | 40 // to SUCCESS, ERR_IO_PENDING maps to IO_PENDING, ERR_ABORTED maps to CANCELED |
| 40 // and all others map to FAILED. Other combinations of status and error are | 41 // and all others map to FAILED. Other combinations of status and error are |
| 41 // deprecated. See https://crbug.com/490311. | 42 // deprecated. See https://crbug.com/490311. |
| 42 static URLRequestStatus FromError(int error); | 43 static URLRequestStatus FromError(int error); |
| 43 | 44 |
| 45 // Returns a net::Error corresponding to |status_|. |
| 46 // net::OK for OK |
| 47 // net::ERR_IO_PENDING for IO_PENDING |
| 48 // net::ERR_ABORTED for CANCELLED |
| 49 // net::Error for FAILED |
| 50 net::Error ToNetError() const; |
| 51 |
| 44 Status status() const { return status_; } | 52 Status status() const { return status_; } |
| 45 int error() const { return error_; } | 53 int error() const { return error_; } |
| 46 | 54 |
| 47 // Returns true if the status is success, which makes some calling code more | 55 // Returns true if the status is success, which makes some calling code more |
| 48 // convenient because this is the most common test. | 56 // convenient because this is the most common test. |
| 49 bool is_success() const { | 57 bool is_success() const { |
| 50 return status_ == SUCCESS || status_ == IO_PENDING; | 58 return status_ == SUCCESS || status_ == IO_PENDING; |
| 51 } | 59 } |
| 52 | 60 |
| 53 // Returns true if the request is waiting for IO. | 61 // Returns true if the request is waiting for IO. |
| 54 bool is_io_pending() const { | 62 bool is_io_pending() const { |
| 55 return status_ == IO_PENDING; | 63 return status_ == IO_PENDING; |
| 56 } | 64 } |
| 57 | 65 |
| 58 private: | 66 private: |
| 59 // Application level status. | 67 // Application level status. |
| 60 Status status_; | 68 Status status_; |
| 61 | 69 |
| 62 // Error code from the network layer if an error was encountered. | 70 // Error code from the network layer if an error was encountered. |
| 63 int error_; | 71 int error_; |
| 64 }; | 72 }; |
| 65 | 73 |
| 66 } // namespace net | 74 } // namespace net |
| 67 | 75 |
| 68 #endif // NET_URL_REQUEST_URL_REQUEST_STATUS_H_ | 76 #endif // NET_URL_REQUEST_URL_REQUEST_STATUS_H_ |
| OLD | NEW |