Update include paths in miscellaneous content/ directories for base/process changes.
[chromium-blink-merge.git] / net / http / http_byte_range.cc
blob60683c5584f5578dd0c4e76ce41f4c12341cdacc
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.
5 #include <algorithm>
7 #include "net/http/http_byte_range.h"
9 namespace {
11 const int64 kPositionNotSpecified = -1;
13 } // namespace
15 namespace net {
17 HttpByteRange::HttpByteRange()
18 : first_byte_position_(kPositionNotSpecified),
19 last_byte_position_(kPositionNotSpecified),
20 suffix_length_(kPositionNotSpecified),
21 has_computed_bounds_(false) {
24 bool HttpByteRange::IsSuffixByteRange() const {
25 return suffix_length_ != kPositionNotSpecified;
28 bool HttpByteRange::HasFirstBytePosition() const {
29 return first_byte_position_ != kPositionNotSpecified;
32 bool HttpByteRange::HasLastBytePosition() const {
33 return last_byte_position_ != kPositionNotSpecified;
36 bool HttpByteRange::IsValid() const {
37 if (suffix_length_ > 0)
38 return true;
39 return (first_byte_position_ >= 0 &&
40 (last_byte_position_ == kPositionNotSpecified ||
41 last_byte_position_ >= first_byte_position_));
44 bool HttpByteRange::ComputeBounds(int64 size) {
45 if (size < 0)
46 return false;
47 if (has_computed_bounds_)
48 return false;
49 has_computed_bounds_ = true;
51 // Empty values.
52 if (!HasFirstBytePosition() &&
53 !HasLastBytePosition() &&
54 !IsSuffixByteRange()) {
55 first_byte_position_ = 0;
56 last_byte_position_ = size - 1;
57 return true;
59 if (!IsValid())
60 return false;
61 if (IsSuffixByteRange()) {
62 first_byte_position_ = size - std::min(size, suffix_length_);
63 last_byte_position_ = size - 1;
64 return true;
66 if (first_byte_position_ < size) {
67 if (HasLastBytePosition())
68 last_byte_position_ = std::min(size - 1, last_byte_position_);
69 else
70 last_byte_position_ = size - 1;
71 return true;
73 return false;
76 } // namespace net