Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / net / url_request / url_request_status.cc
blob2a6a2fae861c202a51fc677558a7f3584c286373
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
3 // found in the LICENSE file.
5 #include "net/url_request/url_request_status.h"
7 #include "base/logging.h"
8 #include "net/base/net_errors.h"
10 namespace net {
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.
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;
37 URLRequestStatus URLRequestStatus::FromError(int error) {
38 if (error == OK) {
39 return URLRequestStatus(SUCCESS, OK);
40 } else if (error == ERR_IO_PENDING) {
41 return URLRequestStatus(IO_PENDING, ERR_IO_PENDING);
42 } else if (error == ERR_ABORTED) {
43 return URLRequestStatus(CANCELED, ERR_ABORTED);
44 } else {
45 return URLRequestStatus(FAILED, error);
49 } // namespace net