Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: net/url_request/url_request_status.h

Issue 1164823002: Remove URLRequestStatus mutators and introduce FromError. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: typo Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/url_request/url_request.cc ('k') | net/url_request/url_request_status.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
8 #include "net/base/net_export.h"
9
11 namespace net { 10 namespace net {
12 11
13 // Represents the result of a URL request. It encodes errors and various 12 // Represents the result of a URL request. It encodes errors and various
14 // types of success. 13 // types of success.
15 class URLRequestStatus { 14 class NET_EXPORT URLRequestStatus {
16 public: 15 public:
17 enum Status { 16 enum Status {
18 // Request succeeded, |error_| will be 0. 17 // Request succeeded, |error_| will be 0.
19 SUCCESS = 0, 18 SUCCESS = 0,
20 19
21 // An IO request is pending, and the caller will be informed when it is 20 // An IO request is pending, and the caller will be informed when it is
22 // completed. 21 // completed.
23 IO_PENDING, 22 IO_PENDING,
24 23
25 // Request was cancelled programatically. 24 // Request was cancelled programatically.
26 CANCELED, 25 CANCELED,
27 26
28 // The request failed for some reason. |error_| may have more information. 27 // The request failed for some reason. |error_| may have more information.
29 FAILED, 28 FAILED,
30 }; 29 };
31 30
31 // Creates a successful URLRequestStatus.
32 URLRequestStatus() : status_(SUCCESS), error_(0) {} 32 URLRequestStatus() : status_(SUCCESS), error_(0) {}
33 URLRequestStatus(Status s, int e) : status_(s), error_(e) {} 33
34 // Creates a URLRequestStatus with specified status and error parameters. New
35 // consumers should use URLRequestStatus::FromError instead.
36 URLRequestStatus(Status status, int error) : status_(status), error_(error) {}
37
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);
34 43
35 Status status() const { return status_; } 44 Status status() const { return status_; }
36 void set_status(Status s) { status_ = s; }
37
38 int error() const { return error_; } 45 int error() const { return error_; }
39 void set_error(int e) { error_ = e; }
40 46
41 // Returns true if the status is success, which makes some calling code more 47 // Returns true if the status is success, which makes some calling code more
42 // convenient because this is the most common test. 48 // convenient because this is the most common test.
43 bool is_success() const { 49 bool is_success() const {
44 return status_ == SUCCESS || status_ == IO_PENDING; 50 return status_ == SUCCESS || status_ == IO_PENDING;
45 } 51 }
46 52
47 // Returns true if the request is waiting for IO. 53 // Returns true if the request is waiting for IO.
48 bool is_io_pending() const { 54 bool is_io_pending() const {
49 return status_ == IO_PENDING; 55 return status_ == IO_PENDING;
50 } 56 }
51 57
52 private: 58 private:
53 // Application level status. 59 // Application level status.
54 Status status_; 60 Status status_;
55 61
56 // Error code from the network layer if an error was encountered. 62 // Error code from the network layer if an error was encountered.
57 int error_; 63 int error_;
58 }; 64 };
59 65
60 } // namespace net 66 } // namespace net
61 67
62 #endif // NET_URL_REQUEST_URL_REQUEST_STATUS_H_ 68 #endif // NET_URL_REQUEST_URL_REQUEST_STATUS_H_
OLDNEW
« no previous file with comments | « net/url_request/url_request.cc ('k') | net/url_request/url_request_status.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698