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

Unified Diff: media/blink/url_index.cc

Issue 2338963002: Store, use and send etags. (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/blink/url_index.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/blink/url_index.cc
diff --git a/media/blink/url_index.cc b/media/blink/url_index.cc
index 97325f07e4ad049539f6e63ea3f4bb2b2882e115..2c52e65bc118cb1cfab01b37b36cad30b0d646a6 100644
--- a/media/blink/url_index.cc
+++ b/media/blink/url_index.cc
@@ -167,6 +167,11 @@ void UrlData::set_last_modified(base::Time last_modified) {
last_modified_ = last_modified;
}
+void UrlData::set_etag(const std::string& etag) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ etag_ = etag;
+}
+
void UrlData::set_range_supported() {
DCHECK(thread_checker_.CalledOnValidThread());
range_supported_ = true;
@@ -215,6 +220,29 @@ scoped_refptr<UrlData> UrlIndex::NewUrlData(const GURL& url,
return new UrlData(url, cors_mode, weak_factory_.GetWeakPtr());
}
+namespace {
+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.
+ if (entry->etag().size() < 2)
+ return false;
+ if (entry->etag()[0] == 'W' && entry->etag()[1] == '/')
+ return false;
+ return true;
+}
+
+bool IsNewDataForSameResource(const scoped_refptr<UrlData>& new_entry,
+ const scoped_refptr<UrlData>& old_entry) {
+ if (HasStrongEtag(new_entry) && HasStrongEtag(old_entry)) {
+ if (new_entry->etag() != old_entry->etag())
+ return true;
+ }
+ if (!new_entry->last_modified().is_null()) {
+ if (new_entry->last_modified() != old_entry->last_modified())
+ return true;
+ }
+ return false;
+}
+};
+
scoped_refptr<UrlData> UrlIndex::TryInsert(
const scoped_refptr<UrlData>& url_data) {
scoped_refptr<UrlData>* by_url_slot;
@@ -232,14 +260,12 @@ scoped_refptr<UrlData> UrlIndex::TryInsert(
if (*by_url_slot == url_data)
return url_data;
- // TODO(hubbe): Support etag validation.
- if (!url_data->last_modified().is_null()) {
- if ((*by_url_slot)->last_modified() != url_data->last_modified()) {
- if (urldata_valid)
- *by_url_slot = url_data;
- return url_data;
- }
+ if (IsNewDataForSameResource(url_data, *by_url_slot)) {
+ if (urldata_valid)
+ *by_url_slot = url_data;
+ return url_data;
}
+
// Check if we should replace the in-cache url data with our url data.
if (urldata_valid) {
if ((!(*by_url_slot)->Valid() ||
« 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