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