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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 base::TimeDelta::FromSeconds(kUrlMappingTimeoutSeconds)) | 160 base::TimeDelta::FromSeconds(kUrlMappingTimeoutSeconds)) |
161 return true; | 161 return true; |
162 return false; | 162 return false; |
163 } | 163 } |
164 | 164 |
165 void UrlData::set_last_modified(base::Time last_modified) { | 165 void UrlData::set_last_modified(base::Time last_modified) { |
166 DCHECK(thread_checker_.CalledOnValidThread()); | 166 DCHECK(thread_checker_.CalledOnValidThread()); |
167 last_modified_ = last_modified; | 167 last_modified_ = last_modified; |
168 } | 168 } |
169 | 169 |
170 void UrlData::set_etag(const std::string& etag) { | |
171 DCHECK(thread_checker_.CalledOnValidThread()); | |
172 etag_ = etag; | |
173 } | |
174 | |
170 void UrlData::set_range_supported() { | 175 void UrlData::set_range_supported() { |
171 DCHECK(thread_checker_.CalledOnValidThread()); | 176 DCHECK(thread_checker_.CalledOnValidThread()); |
172 range_supported_ = true; | 177 range_supported_ = true; |
173 } | 178 } |
174 | 179 |
175 ResourceMultiBuffer* UrlData::multibuffer() { | 180 ResourceMultiBuffer* UrlData::multibuffer() { |
176 DCHECK(thread_checker_.CalledOnValidThread()); | 181 DCHECK(thread_checker_.CalledOnValidThread()); |
177 return &multibuffer_; | 182 return &multibuffer_; |
178 } | 183 } |
179 | 184 |
(...skipping 28 matching lines...) Expand all Loading... | |
208 return i->second; | 213 return i->second; |
209 } | 214 } |
210 return NewUrlData(gurl, cors_mode); | 215 return NewUrlData(gurl, cors_mode); |
211 } | 216 } |
212 | 217 |
213 scoped_refptr<UrlData> UrlIndex::NewUrlData(const GURL& url, | 218 scoped_refptr<UrlData> UrlIndex::NewUrlData(const GURL& url, |
214 UrlData::CORSMode cors_mode) { | 219 UrlData::CORSMode cors_mode) { |
215 return new UrlData(url, cors_mode, weak_factory_.GetWeakPtr()); | 220 return new UrlData(url, cors_mode, weak_factory_.GetWeakPtr()); |
216 } | 221 } |
217 | 222 |
223 namespace { | |
224 bool HasStrongEtag(const scoped_refptr<UrlData>& entry) { | |
DaleCurtis
2016/09/13 23:31:52
Don't pass scoped_refptr by const& anymore. I'd ju
hubbe
2016/09/14 00:23:06
Done.
| |
225 if (entry->etag().size() < 2) | |
226 return false; | |
227 if (entry->etag()[0] == 'W' && entry->etag()[1] == '/') | |
228 return false; | |
229 return true; | |
230 } | |
231 | |
232 bool IsNewDataForSameResource(const scoped_refptr<UrlData>& new_entry, | |
233 const scoped_refptr<UrlData>& old_entry) { | |
234 if (HasStrongEtag(new_entry) && HasStrongEtag(old_entry)) { | |
235 if (new_entry->etag() != old_entry->etag()) | |
236 return true; | |
237 } | |
238 if (!new_entry->last_modified().is_null()) { | |
239 if (new_entry->last_modified() != old_entry->last_modified()) | |
240 return true; | |
241 } | |
242 return false; | |
243 } | |
244 }; | |
245 | |
218 scoped_refptr<UrlData> UrlIndex::TryInsert( | 246 scoped_refptr<UrlData> UrlIndex::TryInsert( |
219 const scoped_refptr<UrlData>& url_data) { | 247 const scoped_refptr<UrlData>& url_data) { |
220 scoped_refptr<UrlData>* by_url_slot; | 248 scoped_refptr<UrlData>* by_url_slot; |
221 bool urldata_valid = url_data->Valid(); | 249 bool urldata_valid = url_data->Valid(); |
222 if (urldata_valid) { | 250 if (urldata_valid) { |
223 by_url_slot = &by_url_.insert(std::make_pair(url_data->key(), url_data)) | 251 by_url_slot = &by_url_.insert(std::make_pair(url_data->key(), url_data)) |
224 .first->second; | 252 .first->second; |
225 } else { | 253 } else { |
226 std::map<UrlData::KeyType, scoped_refptr<UrlData>>::iterator iter; | 254 std::map<UrlData::KeyType, scoped_refptr<UrlData>>::iterator iter; |
227 iter = by_url_.find(url_data->key()); | 255 iter = by_url_.find(url_data->key()); |
228 if (iter == by_url_.end()) | 256 if (iter == by_url_.end()) |
229 return url_data; | 257 return url_data; |
230 by_url_slot = &iter->second; | 258 by_url_slot = &iter->second; |
231 } | 259 } |
232 if (*by_url_slot == url_data) | 260 if (*by_url_slot == url_data) |
233 return url_data; | 261 return url_data; |
234 | 262 |
235 // TODO(hubbe): Support etag validation. | 263 if (IsNewDataForSameResource(url_data, *by_url_slot)) { |
236 if (!url_data->last_modified().is_null()) { | 264 if (urldata_valid) |
237 if ((*by_url_slot)->last_modified() != url_data->last_modified()) { | 265 *by_url_slot = url_data; |
238 if (urldata_valid) | 266 return url_data; |
239 *by_url_slot = url_data; | |
240 return url_data; | |
241 } | |
242 } | 267 } |
268 | |
243 // Check if we should replace the in-cache url data with our url data. | 269 // Check if we should replace the in-cache url data with our url data. |
244 if (urldata_valid) { | 270 if (urldata_valid) { |
245 if ((!(*by_url_slot)->Valid() || | 271 if ((!(*by_url_slot)->Valid() || |
246 url_data->CachedSize() > (*by_url_slot)->CachedSize())) { | 272 url_data->CachedSize() > (*by_url_slot)->CachedSize())) { |
247 *by_url_slot = url_data; | 273 *by_url_slot = url_data; |
248 } else { | 274 } else { |
249 (*by_url_slot)->MergeFrom(url_data); | 275 (*by_url_slot)->MergeFrom(url_data); |
250 } | 276 } |
251 } | 277 } |
252 return *by_url_slot; | 278 return *by_url_slot; |
253 } | 279 } |
254 | 280 |
255 } // namespace media | 281 } // namespace media |
OLD | NEW |