Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 return (multibuffer()->FindNextUnavailable(0) << kBlockSizeShift) >= length_; | |
|
DaleCurtis
2017/05/26 16:43:57
Needs an explanation.
hubbe
2017/05/26 17:39:45
Done.
| |
| 157 } | |
| 158 | |
| 159 bool UrlData::Valid() { | |
| 153 DCHECK(thread_checker_.CalledOnValidThread()); | 160 DCHECK(thread_checker_.CalledOnValidThread()); |
| 154 base::Time now = base::Time::Now(); | 161 base::Time now = base::Time::Now(); |
| 155 if (!range_supported_) | 162 if (!range_supported_ && !FullyCached()) |
| 156 return false; | 163 return false; |
| 157 // When ranges are not supported, we cannot re-use cached data. | 164 // When ranges are not supported, we cannot re-use cached data. |
| 158 if (valid_until_ > now) | 165 if (valid_until_ > now) |
| 159 return true; | 166 return true; |
| 160 if (now - last_used_ < | 167 if (now - last_used_ < |
| 161 base::TimeDelta::FromSeconds(kUrlMappingTimeoutSeconds)) | 168 base::TimeDelta::FromSeconds(kUrlMappingTimeoutSeconds)) |
| 162 return true; | 169 return true; |
| 163 return false; | 170 return false; |
| 164 } | 171 } |
| 165 | 172 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 url_data->CachedSize() > (*by_url_slot)->CachedSize())) { | 276 url_data->CachedSize() > (*by_url_slot)->CachedSize())) { |
| 270 *by_url_slot = url_data; | 277 *by_url_slot = url_data; |
| 271 } else { | 278 } else { |
| 272 (*by_url_slot)->MergeFrom(url_data); | 279 (*by_url_slot)->MergeFrom(url_data); |
| 273 } | 280 } |
| 274 } | 281 } |
| 275 return *by_url_slot; | 282 return *by_url_slot; |
| 276 } | 283 } |
| 277 | 284 |
| 278 } // namespace media | 285 } // namespace media |
| OLD | NEW |