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 // | 4 // |
5 // This file's dependencies should be kept to a minimum so that it can be | 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. | 6 // included in WebKit code that doesn't rely on much of common. |
7 | 7 |
8 #ifndef NET_URL_REQUEST_URL_REQUEST_STATUS_H_ | 8 #ifndef NET_URL_REQUEST_URL_REQUEST_STATUS_H_ |
9 #define NET_URL_REQUEST_URL_REQUEST_STATUS_H_ | 9 #define NET_URL_REQUEST_URL_REQUEST_STATUS_H_ |
10 | 10 |
11 namespace net { | 11 namespace net { |
12 | 12 |
13 // Represents the result of a URL request. It encodes errors and various | 13 // Represents the result of a URL request. It encodes errors and various |
14 // types of success. | 14 // types of success. |
15 class URLRequestStatus { | 15 class URLRequestStatus { |
16 public: | 16 public: |
17 enum Status { | 17 enum Status { |
18 // Request succeeded, |error_| will be 0. | 18 // Request succeeded, |error_| will be 0. |
19 SUCCESS = 0, | 19 SUCCESS = 0, |
20 | 20 |
21 // An IO request is pending, and the caller will be informed when it is | 21 // An IO request is pending, and the caller will be informed when it is |
22 // completed. | 22 // completed. |
23 IO_PENDING, | 23 IO_PENDING, |
24 | 24 |
25 // Request was successful but was handled by an external program, so there | |
26 // is no response data. This usually means the current page should not be | |
27 // navigated, but no error should be displayed. |error_| will be 0. | |
28 HANDLED_EXTERNALLY, | |
29 | |
30 // Request was cancelled programatically. | 25 // Request was cancelled programatically. |
31 CANCELED, | 26 CANCELED, |
32 | 27 |
33 // The request failed for some reason. |error_| may have more information. | 28 // The request failed for some reason. |error_| may have more information. |
34 FAILED, | 29 FAILED, |
35 }; | 30 }; |
36 | 31 |
37 URLRequestStatus() : status_(SUCCESS), error_(0) {} | 32 URLRequestStatus() : status_(SUCCESS), error_(0) {} |
38 URLRequestStatus(Status s, int e) : status_(s), error_(e) {} | 33 URLRequestStatus(Status s, int e) : status_(s), error_(e) {} |
39 | 34 |
40 Status status() const { return status_; } | 35 Status status() const { return status_; } |
41 void set_status(Status s) { status_ = s; } | 36 void set_status(Status s) { status_ = s; } |
42 | 37 |
43 int error() const { return error_; } | 38 int error() const { return error_; } |
44 void set_error(int e) { error_ = e; } | 39 void set_error(int e) { error_ = e; } |
45 | 40 |
46 // Returns true if the status is success, which makes some calling code more | 41 // Returns true if the status is success, which makes some calling code more |
47 // convenient because this is the most common test. Note that we do NOT treat | 42 // convenient because this is the most common test. |
48 // HANDLED_EXTERNALLY as success. For everything except user notifications, | |
49 // this value should be handled like an error (processing should stop). | |
50 bool is_success() const { | 43 bool is_success() const { |
51 return status_ == SUCCESS || status_ == IO_PENDING; | 44 return status_ == SUCCESS || status_ == IO_PENDING; |
52 } | 45 } |
53 | 46 |
54 // Returns true if the request is waiting for IO. | 47 // Returns true if the request is waiting for IO. |
55 bool is_io_pending() const { | 48 bool is_io_pending() const { |
56 return status_ == IO_PENDING; | 49 return status_ == IO_PENDING; |
57 } | 50 } |
58 | 51 |
59 private: | 52 private: |
60 // Application level status. | 53 // Application level status. |
61 Status status_; | 54 Status status_; |
62 | 55 |
63 // Error code from the network layer if an error was encountered. | 56 // Error code from the network layer if an error was encountered. |
64 int error_; | 57 int error_; |
65 }; | 58 }; |
66 | 59 |
67 } // namespace net | 60 } // namespace net |
68 | 61 |
69 #endif // NET_URL_REQUEST_URL_REQUEST_STATUS_H_ | 62 #endif // NET_URL_REQUEST_URL_REQUEST_STATUS_H_ |
OLD | NEW |