Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: media/blink/url_index.cc

Issue 2910553002: fully cache small audio/video (Closed)
Patch Set: comment added Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/blink/url_index.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <set> 5 #include <set>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 return true; 142 return true;
143 } 143 }
144 144
145 void UrlData::OnEmpty() { 145 void UrlData::OnEmpty() {
146 DCHECK(thread_checker_.CalledOnValidThread()); 146 DCHECK(thread_checker_.CalledOnValidThread());
147 base::ThreadTaskRunnerHandle::Get()->PostTask( 147 base::ThreadTaskRunnerHandle::Get()->PostTask(
148 FROM_HERE, base::Bind(&UrlIndex::RemoveUrlDataIfEmpty, url_index_, 148 FROM_HERE, base::Bind(&UrlIndex::RemoveUrlDataIfEmpty, url_index_,
149 scoped_refptr<UrlData>(this))); 149 scoped_refptr<UrlData>(this)));
150 } 150 }
151 151
152 bool UrlData::Valid() const { 152 bool UrlData::FullyCached() {
153 DCHECK(thread_checker_.CalledOnValidThread());
154 if (length_ == kPositionNotSpecified)
155 return false;
156 // Check that the first unavailable block in the cache is after the
157 // end of the file.
158 return (multibuffer()->FindNextUnavailable(0) << kBlockSizeShift) >= length_;
159 }
160
161 bool UrlData::Valid() {
153 DCHECK(thread_checker_.CalledOnValidThread()); 162 DCHECK(thread_checker_.CalledOnValidThread());
154 base::Time now = base::Time::Now(); 163 base::Time now = base::Time::Now();
155 if (!range_supported_) 164 if (!range_supported_ && !FullyCached())
156 return false; 165 return false;
157 // When ranges are not supported, we cannot re-use cached data. 166 // When ranges are not supported, we cannot re-use cached data.
158 if (valid_until_ > now) 167 if (valid_until_ > now)
159 return true; 168 return true;
160 if (now - last_used_ < 169 if (now - last_used_ <
161 base::TimeDelta::FromSeconds(kUrlMappingTimeoutSeconds)) 170 base::TimeDelta::FromSeconds(kUrlMappingTimeoutSeconds))
162 return true; 171 return true;
163 return false; 172 return false;
164 } 173 }
165 174
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 url_data->CachedSize() > (*by_url_slot)->CachedSize())) { 278 url_data->CachedSize() > (*by_url_slot)->CachedSize())) {
270 *by_url_slot = url_data; 279 *by_url_slot = url_data;
271 } else { 280 } else {
272 (*by_url_slot)->MergeFrom(url_data); 281 (*by_url_slot)->MergeFrom(url_data);
273 } 282 }
274 } 283 }
275 return *by_url_slot; 284 return *by_url_slot;
276 } 285 }
277 286
278 } // namespace media 287 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/url_index.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698