OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "net/url_request/url_request_status.h" | 5 #include "net/url_request/url_request_status.h" |
6 | 6 |
| 7 #include "base/logging.h" |
7 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
8 | 9 |
9 namespace net { | 10 namespace net { |
10 | 11 |
| 12 URLRequestStatus::URLRequestStatus(Status status, int error) |
| 13 : status_(status), error_(error) { |
| 14 // URLRequestStatus should get folded into error. However, it is possible to |
| 15 // create URLRequestStatuses with inconsistent |status_| and |error_| |
| 16 // fields. As callers are cleaned up, these assertions avoid regressing any |
| 17 // invariants that have been established. |
| 18 // |
| 19 // https://crbug.com/490311 |
| 20 DCHECK_GE(0, error_); |
| 21 switch (status_) { |
| 22 case SUCCESS: |
| 23 DCHECK_EQ(OK, error_); |
| 24 break; |
| 25 case IO_PENDING: |
| 26 // TODO(davidben): Switch all IO_PENDING status to ERR_IO_PENDING. |
| 27 DCHECK(error_ == 0 || error_ == ERR_IO_PENDING); |
| 28 break; |
| 29 case CANCELED: |
| 30 case FAILED: |
| 31 DCHECK_NE(OK, error_); |
| 32 DCHECK_NE(ERR_IO_PENDING, error_); |
| 33 break; |
| 34 } |
| 35 } |
| 36 |
11 URLRequestStatus URLRequestStatus::FromError(int error) { | 37 URLRequestStatus URLRequestStatus::FromError(int error) { |
12 if (error == OK) { | 38 if (error == OK) { |
13 return URLRequestStatus(SUCCESS, OK); | 39 return URLRequestStatus(SUCCESS, OK); |
14 } else if (error == ERR_IO_PENDING) { | 40 } else if (error == ERR_IO_PENDING) { |
15 return URLRequestStatus(IO_PENDING, ERR_IO_PENDING); | 41 return URLRequestStatus(IO_PENDING, ERR_IO_PENDING); |
16 } else if (error == ERR_ABORTED) { | 42 } else if (error == ERR_ABORTED) { |
17 return URLRequestStatus(CANCELED, ERR_ABORTED); | 43 return URLRequestStatus(CANCELED, ERR_ABORTED); |
18 } else { | 44 } else { |
19 return URLRequestStatus(FAILED, error); | 45 return URLRequestStatus(FAILED, error); |
20 } | 46 } |
21 } | 47 } |
22 | 48 |
23 } // namespace net | 49 } // namespace net |
OLD | NEW |