| 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/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 } | 35 } |
| 36 | 36 |
| 37 void ResourceMultiBuffer::OnEmpty() { | 37 void ResourceMultiBuffer::OnEmpty() { |
| 38 url_data_->OnEmpty(); | 38 url_data_->OnEmpty(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 UrlData::UrlData(const GURL& url, | 41 UrlData::UrlData(const GURL& url, |
| 42 CORSMode cors_mode, | 42 CORSMode cors_mode, |
| 43 const base::WeakPtr<UrlIndex>& url_index) | 43 const base::WeakPtr<UrlIndex>& url_index) |
| 44 : url_(url), | 44 : url_(url), |
| 45 have_data_origin_(false), |
| 45 cors_mode_(cors_mode), | 46 cors_mode_(cors_mode), |
| 46 url_index_(url_index), | 47 url_index_(url_index), |
| 47 length_(kPositionNotSpecified), | 48 length_(kPositionNotSpecified), |
| 48 range_supported_(false), | 49 range_supported_(false), |
| 49 cacheable_(false), | 50 cacheable_(false), |
| 50 last_used_(), | 51 last_used_(), |
| 51 multibuffer_(this, url_index_->block_shift_), | 52 multibuffer_(this, url_index_->block_shift_), |
| 52 frame_(url_index->frame()) {} | 53 frame_(url_index->frame()) {} |
| 53 | 54 |
| 54 UrlData::~UrlData() {} | 55 UrlData::~UrlData() {} |
| 55 | 56 |
| 56 std::pair<GURL, UrlData::CORSMode> UrlData::key() const { | 57 std::pair<GURL, UrlData::CORSMode> UrlData::key() const { |
| 57 DCHECK(thread_checker_.CalledOnValidThread()); | 58 DCHECK(thread_checker_.CalledOnValidThread()); |
| 58 return std::make_pair(url(), cors_mode()); | 59 return std::make_pair(url(), cors_mode()); |
| 59 } | 60 } |
| 60 | 61 |
| 61 void UrlData::set_valid_until(base::Time valid_until) { | 62 void UrlData::set_valid_until(base::Time valid_until) { |
| 62 DCHECK(thread_checker_.CalledOnValidThread()); | 63 DCHECK(thread_checker_.CalledOnValidThread()); |
| 63 valid_until_ = valid_until; | 64 valid_until_ = valid_until; |
| 64 } | 65 } |
| 65 | 66 |
| 66 void UrlData::MergeFrom(const scoped_refptr<UrlData>& other) { | 67 void UrlData::MergeFrom(const scoped_refptr<UrlData>& other) { |
| 67 // We're merging from another UrlData that refers to the *same* | 68 // We're merging from another UrlData that refers to the *same* |
| 68 // resource, so when we merge the metadata, we can use the most | 69 // resource, so when we merge the metadata, we can use the most |
| 69 // optimistic values. | 70 // optimistic values. |
| 70 DCHECK(thread_checker_.CalledOnValidThread()); | 71 if (ValidateDataOrigin(other->data_origin_)) { |
| 71 valid_until_ = std::max(valid_until_, other->valid_until_); | 72 DCHECK(thread_checker_.CalledOnValidThread()); |
| 72 // set_length() will not override the length if already known. | 73 valid_until_ = std::max(valid_until_, other->valid_until_); |
| 73 set_length(other->length_); | 74 // set_length() will not override the length if already known. |
| 74 cacheable_ |= other->cacheable_; | 75 set_length(other->length_); |
| 75 range_supported_ |= other->range_supported_; | 76 cacheable_ |= other->cacheable_; |
| 76 if (last_modified_.is_null()) { | 77 range_supported_ |= other->range_supported_; |
| 77 last_modified_ = other->last_modified_; | 78 if (last_modified_.is_null()) { |
| 79 last_modified_ = other->last_modified_; |
| 80 } |
| 81 multibuffer()->MergeFrom(other->multibuffer()); |
| 78 } | 82 } |
| 79 multibuffer()->MergeFrom(other->multibuffer()); | |
| 80 } | 83 } |
| 81 | 84 |
| 82 void UrlData::set_cacheable(bool cacheable) { | 85 void UrlData::set_cacheable(bool cacheable) { |
| 83 DCHECK(thread_checker_.CalledOnValidThread()); | 86 DCHECK(thread_checker_.CalledOnValidThread()); |
| 84 cacheable_ = cacheable; | 87 cacheable_ = cacheable; |
| 85 } | 88 } |
| 86 | 89 |
| 87 void UrlData::set_length(int64_t length) { | 90 void UrlData::set_length(int64_t length) { |
| 88 DCHECK(thread_checker_.CalledOnValidThread()); | 91 DCHECK(thread_checker_.CalledOnValidThread()); |
| 89 if (length != kPositionNotSpecified) { | 92 if (length != kPositionNotSpecified) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 116 void UrlData::OnRedirect(const RedirectCB& cb) { | 119 void UrlData::OnRedirect(const RedirectCB& cb) { |
| 117 DCHECK(thread_checker_.CalledOnValidThread()); | 120 DCHECK(thread_checker_.CalledOnValidThread()); |
| 118 redirect_callbacks_.push_back(cb); | 121 redirect_callbacks_.push_back(cb); |
| 119 } | 122 } |
| 120 | 123 |
| 121 void UrlData::Use() { | 124 void UrlData::Use() { |
| 122 DCHECK(thread_checker_.CalledOnValidThread()); | 125 DCHECK(thread_checker_.CalledOnValidThread()); |
| 123 last_used_ = base::Time::Now(); | 126 last_used_ = base::Time::Now(); |
| 124 } | 127 } |
| 125 | 128 |
| 129 bool UrlData::ValidateDataOrigin(const GURL& origin) { |
| 130 if (!have_data_origin_) { |
| 131 data_origin_ = origin; |
| 132 have_data_origin_ = true; |
| 133 return true; |
| 134 } |
| 135 if (cors_mode_ == UrlData::CORS_UNSPECIFIED) { |
| 136 return data_origin_ == origin; |
| 137 } |
| 138 // The actual cors checks is done in the net layer. |
| 139 return true; |
| 140 } |
| 141 |
| 126 void UrlData::OnEmpty() { | 142 void UrlData::OnEmpty() { |
| 127 DCHECK(thread_checker_.CalledOnValidThread()); | 143 DCHECK(thread_checker_.CalledOnValidThread()); |
| 128 base::MessageLoop::current()->PostTask( | 144 base::MessageLoop::current()->PostTask( |
| 129 FROM_HERE, base::Bind(&UrlIndex::RemoveUrlDataIfEmpty, url_index_, | 145 FROM_HERE, base::Bind(&UrlIndex::RemoveUrlDataIfEmpty, url_index_, |
| 130 scoped_refptr<UrlData>(this))); | 146 scoped_refptr<UrlData>(this))); |
| 131 } | 147 } |
| 132 | 148 |
| 133 bool UrlData::Valid() const { | 149 bool UrlData::Valid() const { |
| 134 DCHECK(thread_checker_.CalledOnValidThread()); | 150 DCHECK(thread_checker_.CalledOnValidThread()); |
| 135 base::Time now = base::Time::Now(); | 151 base::Time now = base::Time::Now(); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 url_data->CachedSize() > (*by_url_slot)->CachedSize())) { | 245 url_data->CachedSize() > (*by_url_slot)->CachedSize())) { |
| 230 *by_url_slot = url_data; | 246 *by_url_slot = url_data; |
| 231 } else { | 247 } else { |
| 232 (*by_url_slot)->MergeFrom(url_data); | 248 (*by_url_slot)->MergeFrom(url_data); |
| 233 } | 249 } |
| 234 } | 250 } |
| 235 return *by_url_slot; | 251 return *by_url_slot; |
| 236 } | 252 } |
| 237 | 253 |
| 238 } // namespace media | 254 } // namespace media |
| OLD | NEW |