Home | History | Annotate | Download | only in http
      1 // Copyright (c) 2009 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 #ifndef NET_HTTP_HTTP_BYTE_RANGE_H_
      6 #define NET_HTTP_HTTP_BYTE_RANGE_H_
      7 #pragma once
      8 
      9 #include "base/basictypes.h"
     10 
     11 namespace net {
     12 
     13 // A container class that represents a "range" specified for range request
     14 // specified by RFC 2616 Section 14.35.1.
     15 // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.1
     16 class HttpByteRange {
     17  public:
     18   HttpByteRange();
     19 
     20   // Since this class is POD, we use constructor, assignment operator
     21   // and destructor provided by compiler.
     22   int64 first_byte_position() const { return first_byte_position_; }
     23   void set_first_byte_position(int64 value) { first_byte_position_ =  value; }
     24 
     25   int64 last_byte_position() const { return last_byte_position_; }
     26   void set_last_byte_position(int64 value) { last_byte_position_ = value; }
     27 
     28   int64 suffix_length() const { return suffix_length_; }
     29   void set_suffix_length(int64 value) { suffix_length_ = value; }
     30 
     31   // Returns true if this is a suffix byte range.
     32   bool IsSuffixByteRange() const;
     33   // Returns true if the first byte position is specified in this request.
     34   bool HasFirstBytePosition() const;
     35   // Returns true if the last byte position is specified in this request.
     36   bool HasLastBytePosition() const;
     37 
     38   // Returns true if this range is valid.
     39   bool IsValid() const;
     40 
     41   // A method that when given the size in bytes of a file, adjust the internal
     42   // |first_byte_position_| and |last_byte_position_| values according to the
     43   // range specified by this object. If the range specified is invalid with
     44   // regard to the size or |size| is negative, returns false and there will be
     45   // no side effect.
     46   // Returns false if this method is called more than once and there will be
     47   // no side effect.
     48   bool ComputeBounds(int64 size);
     49 
     50  private:
     51   int64 first_byte_position_;
     52   int64 last_byte_position_;
     53   int64 suffix_length_;
     54   bool has_computed_bounds_;
     55 };
     56 
     57 }  // namespace net
     58 
     59 #endif  // NET_HTTP_HTTP_BYTE_RANGE_H_
     60