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

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

Issue 2338963002: Store, use and send etags. (Closed)
Patch Set: comments addressed Created 4 years, 3 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 IsStrongEtag(const std::string& etag) {
225 return etag.size() > 2 && etag[0] == '"';
226 }
227
228 bool IsNewDataForSameResource(const scoped_refptr<UrlData>& new_entry,
229 const scoped_refptr<UrlData>& old_entry) {
230 if (IsStrongEtag(new_entry->etag()) && IsStrongEtag(old_entry->etag())) {
231 if (new_entry->etag() != old_entry->etag())
232 return true;
233 }
234 if (!new_entry->last_modified().is_null()) {
235 if (new_entry->last_modified() != old_entry->last_modified())
236 return true;
237 }
238 return false;
Tom Bergan 2016/09/16 19:30:21 Missed this on the first read ... What if the resp
hubbe 2016/09/16 19:33:41 That is exactly what this code does. (Unless I wro
Tom Bergan 2016/09/16 19:45:36 It is, I misread the meaning of "false" in this co
239 }
240 };
241
218 scoped_refptr<UrlData> UrlIndex::TryInsert( 242 scoped_refptr<UrlData> UrlIndex::TryInsert(
219 const scoped_refptr<UrlData>& url_data) { 243 const scoped_refptr<UrlData>& url_data) {
220 scoped_refptr<UrlData>* by_url_slot; 244 scoped_refptr<UrlData>* by_url_slot;
221 bool urldata_valid = url_data->Valid(); 245 bool urldata_valid = url_data->Valid();
222 if (urldata_valid) { 246 if (urldata_valid) {
223 by_url_slot = &by_url_.insert(std::make_pair(url_data->key(), url_data)) 247 by_url_slot = &by_url_.insert(std::make_pair(url_data->key(), url_data))
224 .first->second; 248 .first->second;
225 } else { 249 } else {
226 std::map<UrlData::KeyType, scoped_refptr<UrlData>>::iterator iter; 250 std::map<UrlData::KeyType, scoped_refptr<UrlData>>::iterator iter;
227 iter = by_url_.find(url_data->key()); 251 iter = by_url_.find(url_data->key());
228 if (iter == by_url_.end()) 252 if (iter == by_url_.end())
229 return url_data; 253 return url_data;
230 by_url_slot = &iter->second; 254 by_url_slot = &iter->second;
231 } 255 }
232 if (*by_url_slot == url_data) 256 if (*by_url_slot == url_data)
233 return url_data; 257 return url_data;
234 258
235 // TODO(hubbe): Support etag validation. 259 if (IsNewDataForSameResource(url_data, *by_url_slot)) {
236 if (!url_data->last_modified().is_null()) { 260 if (urldata_valid)
237 if ((*by_url_slot)->last_modified() != url_data->last_modified()) { 261 *by_url_slot = url_data;
238 if (urldata_valid) 262 return url_data;
239 *by_url_slot = url_data;
240 return url_data;
241 }
242 } 263 }
264
243 // Check if we should replace the in-cache url data with our url data. 265 // Check if we should replace the in-cache url data with our url data.
244 if (urldata_valid) { 266 if (urldata_valid) {
245 if ((!(*by_url_slot)->Valid() || 267 if ((!(*by_url_slot)->Valid() ||
246 url_data->CachedSize() > (*by_url_slot)->CachedSize())) { 268 url_data->CachedSize() > (*by_url_slot)->CachedSize())) {
247 *by_url_slot = url_data; 269 *by_url_slot = url_data;
248 } else { 270 } else {
249 (*by_url_slot)->MergeFrom(url_data); 271 (*by_url_slot)->MergeFrom(url_data);
250 } 272 }
251 } 273 }
252 return *by_url_slot; 274 return *by_url_slot;
253 } 275 }
254 276
255 } // namespace media 277 } // 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