Chromium Code Reviews| 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 // | |
| 5 // This file's dependencies should be kept to a minimum so that it can be | |
| 6 // included in WebKit code that doesn't rely on much of common. | |
| 7 | 4 |
| 8 #ifndef NET_URL_REQUEST_URL_REQUEST_STATUS_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_STATUS_H_ |
| 9 #define NET_URL_REQUEST_URL_REQUEST_STATUS_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_STATUS_H_ |
| 10 | 7 |
| 11 namespace net { | 8 namespace net { |
| 12 | 9 |
| 13 // Represents the result of a URL request. It encodes errors and various | 10 // Represents the result of a URL request. It encodes errors and various |
| 14 // types of success. | 11 // types of success. |
| 15 class URLRequestStatus { | 12 class URLRequestStatus { |
| 16 public: | 13 public: |
| 17 enum Status { | 14 enum Status { |
| 18 // Request succeeded, |error_| will be 0. | 15 // Request succeeded, |error_| will be 0. |
| 19 SUCCESS = 0, | 16 SUCCESS = 0, |
| 20 | 17 |
| 21 // An IO request is pending, and the caller will be informed when it is | 18 // An IO request is pending, and the caller will be informed when it is |
| 22 // completed. | 19 // completed. |
| 23 IO_PENDING, | 20 IO_PENDING, |
| 24 | 21 |
| 25 // Request was cancelled programatically. | 22 // Request was cancelled programatically. |
| 26 CANCELED, | 23 CANCELED, |
| 27 | 24 |
| 28 // The request failed for some reason. |error_| may have more information. | 25 // The request failed for some reason. |error_| may have more information. |
| 29 FAILED, | 26 FAILED, |
| 30 }; | 27 }; |
| 31 | 28 |
| 29 // Creates a successful URLRequestStatus. | |
| 32 URLRequestStatus() : status_(SUCCESS), error_(0) {} | 30 URLRequestStatus() : status_(SUCCESS), error_(0) {} |
| 33 URLRequestStatus(Status s, int e) : status_(s), error_(e) {} | 31 |
| 32 // Creates a URLRequestStatus with specified status and error parameters. Use | |
| 33 // URLRequestStatus::FromError instead. | |
|
mmenke
2015/06/02 18:41:33
Maybe "Use URLRequestStatus::FromError instead" ->
davidben
2015/06/02 19:19:42
Done.
| |
| 34 URLRequestStatus(Status status, int error) : status_(status), error_(error) {} | |
| 35 | |
| 36 // Creates a URLRequestStatus, initializing the status from |error|. OK maps | |
| 37 // to SUCCESS, ERR_IO_PENDING maps to IO_PENDING, ERR_ABORTED maps to CANCELED | |
| 38 // and all others map to FAILED. Other combinations of status and error are | |
| 39 // deprecated. See https://crbug.com/490311. | |
| 40 static URLRequestStatus FromError(int error); | |
| 34 | 41 |
| 35 Status status() const { return status_; } | 42 Status status() const { return status_; } |
| 36 void set_status(Status s) { status_ = s; } | |
| 37 | |
| 38 int error() const { return error_; } | 43 int error() const { return error_; } |
| 39 void set_error(int e) { error_ = e; } | |
| 40 | 44 |
| 41 // Returns true if the status is success, which makes some calling code more | 45 // Returns true if the status is success, which makes some calling code more |
| 42 // convenient because this is the most common test. | 46 // convenient because this is the most common test. |
| 43 bool is_success() const { | 47 bool is_success() const { |
| 44 return status_ == SUCCESS || status_ == IO_PENDING; | 48 return status_ == SUCCESS || status_ == IO_PENDING; |
| 45 } | 49 } |
| 46 | 50 |
| 47 // Returns true if the request is waiting for IO. | 51 // Returns true if the request is waiting for IO. |
| 48 bool is_io_pending() const { | 52 bool is_io_pending() const { |
| 49 return status_ == IO_PENDING; | 53 return status_ == IO_PENDING; |
| 50 } | 54 } |
| 51 | 55 |
| 52 private: | 56 private: |
| 53 // Application level status. | 57 // Application level status. |
| 54 Status status_; | 58 Status status_; |
| 55 | 59 |
| 56 // Error code from the network layer if an error was encountered. | 60 // Error code from the network layer if an error was encountered. |
| 57 int error_; | 61 int error_; |
| 58 }; | 62 }; |
| 59 | 63 |
| 60 } // namespace net | 64 } // namespace net |
| 61 | 65 |
| 62 #endif // NET_URL_REQUEST_URL_REQUEST_STATUS_H_ | 66 #endif // NET_URL_REQUEST_URL_REQUEST_STATUS_H_ |
| OLD | NEW |