BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / media / blink / buffered_data_source_host_impl.cc
blob542b8567dbc14189081db929ead9e1d63996c438
1 // Copyright 2014 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 "media/blink/buffered_data_source_host_impl.h"
7 #include "media/base/timestamp_constants.h"
9 namespace media {
11 BufferedDataSourceHostImpl::BufferedDataSourceHostImpl()
12 : total_bytes_(0),
13 did_loading_progress_(false) { }
15 BufferedDataSourceHostImpl::~BufferedDataSourceHostImpl() { }
17 void BufferedDataSourceHostImpl::SetTotalBytes(int64 total_bytes) {
18 total_bytes_ = total_bytes;
21 void BufferedDataSourceHostImpl::AddBufferedByteRange(int64 start, int64 end) {
22 buffered_byte_ranges_.Add(start, end);
23 did_loading_progress_ = true;
26 static base::TimeDelta TimeForByteOffset(
27 int64 byte_offset, int64 total_bytes, base::TimeDelta duration) {
28 double position = static_cast<double>(byte_offset) / total_bytes;
29 // Snap to the beginning/end where the approximation can look especially bad.
30 if (position < 0.01)
31 return base::TimeDelta();
32 if (position > 0.99)
33 return duration;
34 return base::TimeDelta::FromMilliseconds(
35 static_cast<int64>(position * duration.InMilliseconds()));
38 void BufferedDataSourceHostImpl::AddBufferedTimeRanges(
39 Ranges<base::TimeDelta>* buffered_time_ranges,
40 base::TimeDelta media_duration) const {
41 DCHECK(media_duration != kNoTimestamp());
42 DCHECK(media_duration != kInfiniteDuration());
43 if (total_bytes_ && buffered_byte_ranges_.size()) {
44 for (size_t i = 0; i < buffered_byte_ranges_.size(); ++i) {
45 int64 start = buffered_byte_ranges_.start(i);
46 int64 end = buffered_byte_ranges_.end(i);
47 buffered_time_ranges->Add(
48 TimeForByteOffset(start, total_bytes_, media_duration),
49 TimeForByteOffset(end, total_bytes_, media_duration));
54 bool BufferedDataSourceHostImpl::DidLoadingProgress() {
55 bool ret = did_loading_progress_;
56 did_loading_progress_ = false;
57 return ret;
60 } // namespace media