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