OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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 #include <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "net/http/http_byte_range.h" | 10 #include "net/http/http_byte_range.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 72 |
73 if (IsSuffixByteRange()) | 73 if (IsSuffixByteRange()) |
74 return base::StringPrintf("bytes=-%" PRId64, suffix_length()); | 74 return base::StringPrintf("bytes=-%" PRId64, suffix_length()); |
75 | 75 |
76 DCHECK(HasFirstBytePosition()); | 76 DCHECK(HasFirstBytePosition()); |
77 | 77 |
78 if (!HasLastBytePosition()) | 78 if (!HasLastBytePosition()) |
79 return base::StringPrintf("bytes=%" PRId64 "-", first_byte_position()); | 79 return base::StringPrintf("bytes=%" PRId64 "-", first_byte_position()); |
80 | 80 |
81 return base::StringPrintf("bytes=%" PRId64 "-%" PRId64, | 81 return base::StringPrintf("bytes=%" PRId64 "-%" PRId64, |
82 first_byte_position(), last_byte_position()); | 82 first_byte_position(), |
| 83 last_byte_position()); |
83 } | 84 } |
84 | 85 |
85 bool HttpByteRange::ComputeBounds(int64 size) { | 86 bool HttpByteRange::ComputeBounds(int64 size) { |
86 if (size < 0) | 87 if (size < 0) |
87 return false; | 88 return false; |
88 if (has_computed_bounds_) | 89 if (has_computed_bounds_) |
89 return false; | 90 return false; |
90 has_computed_bounds_ = true; | 91 has_computed_bounds_ = true; |
91 | 92 |
92 // Empty values. | 93 // Empty values. |
93 if (!HasFirstBytePosition() && | 94 if (!HasFirstBytePosition() && !HasLastBytePosition() && |
94 !HasLastBytePosition() && | |
95 !IsSuffixByteRange()) { | 95 !IsSuffixByteRange()) { |
96 first_byte_position_ = 0; | 96 first_byte_position_ = 0; |
97 last_byte_position_ = size - 1; | 97 last_byte_position_ = size - 1; |
98 return true; | 98 return true; |
99 } | 99 } |
100 if (!IsValid()) | 100 if (!IsValid()) |
101 return false; | 101 return false; |
102 if (IsSuffixByteRange()) { | 102 if (IsSuffixByteRange()) { |
103 first_byte_position_ = size - std::min(size, suffix_length_); | 103 first_byte_position_ = size - std::min(size, suffix_length_); |
104 last_byte_position_ = size - 1; | 104 last_byte_position_ = size - 1; |
105 return true; | 105 return true; |
106 } | 106 } |
107 if (first_byte_position_ < size) { | 107 if (first_byte_position_ < size) { |
108 if (HasLastBytePosition()) | 108 if (HasLastBytePosition()) |
109 last_byte_position_ = std::min(size - 1, last_byte_position_); | 109 last_byte_position_ = std::min(size - 1, last_byte_position_); |
110 else | 110 else |
111 last_byte_position_ = size - 1; | 111 last_byte_position_ = size - 1; |
112 return true; | 112 return true; |
113 } | 113 } |
114 return false; | 114 return false; |
115 } | 115 } |
116 | 116 |
117 } // namespace net | 117 } // namespace net |
OLD | NEW |