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
3 // found in the LICENSE file.
5 #ifndef NET_URL_REQUEST_URL_REQUEST_STATUS_H_
6 #define NET_URL_REQUEST_URL_REQUEST_STATUS_H_
8 #include "net/base/net_export.h"
12 // Represents the result of a URL request. It encodes errors and various
14 class NET_EXPORT URLRequestStatus
{
17 // Request succeeded, |error_| will be 0.
20 // An IO request is pending, and the caller will be informed when it is
24 // Request was cancelled programatically.
27 // The request failed for some reason. |error_| may have more information.
31 // Creates a successful URLRequestStatus.
32 URLRequestStatus() : status_(SUCCESS
), error_(0) {}
34 // Creates a URLRequestStatus with specified status and error parameters. New
35 // consumers should use URLRequestStatus::FromError instead.
36 URLRequestStatus(Status status
, int error
);
38 // 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 // and all others map to FAILED. Other combinations of status and error are
41 // deprecated. See https://crbug.com/490311.
42 static URLRequestStatus
FromError(int error
);
44 Status
status() const { return status_
; }
45 int error() const { return error_
; }
47 // Returns true if the status is success, which makes some calling code more
48 // convenient because this is the most common test.
49 bool is_success() const {
50 return status_
== SUCCESS
|| status_
== IO_PENDING
;
53 // Returns true if the request is waiting for IO.
54 bool is_io_pending() const {
55 return status_
== IO_PENDING
;
59 // Application level status.
62 // Error code from the network layer if an error was encountered.
68 #endif // NET_URL_REQUEST_URL_REQUEST_STATUS_H_