| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/tools/quic/quic_in_memory_cache.h" | 5 #include "net/tools/quic/quic_in_memory_cache.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/files/file_enumerator.h" | 9 #include "base/files/file_enumerator.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 return url; | 148 return url; |
| 149 } | 149 } |
| 150 | 150 |
| 151 void QuicInMemoryCache::ResourceFile::HandleXOriginalUrl() { | 151 void QuicInMemoryCache::ResourceFile::HandleXOriginalUrl() { |
| 152 StringPiece url(x_original_url_); | 152 StringPiece url(x_original_url_); |
| 153 // Remove the protocol so we can add it below. | 153 // Remove the protocol so we can add it below. |
| 154 url = RemoveScheme(url); | 154 url = RemoveScheme(url); |
| 155 SetHostPathFromBase(url); | 155 SetHostPathFromBase(url); |
| 156 } | 156 } |
| 157 | 157 |
| 158 // static | |
| 159 QuicInMemoryCache* QuicInMemoryCache::GetInstance() { | |
| 160 return base::Singleton<QuicInMemoryCache>::get(); | |
| 161 } | |
| 162 | |
| 163 const QuicInMemoryCache::Response* QuicInMemoryCache::GetResponse( | 158 const QuicInMemoryCache::Response* QuicInMemoryCache::GetResponse( |
| 164 StringPiece host, | 159 StringPiece host, |
| 165 StringPiece path) const { | 160 StringPiece path) const { |
| 166 base::AutoLock lock(response_mutex_); | 161 base::AutoLock lock(response_mutex_); |
| 167 | 162 |
| 168 auto it = responses_.find(GetKey(host, path)); | 163 auto it = responses_.find(GetKey(host, path)); |
| 169 if (it == responses_.end()) { | 164 if (it == responses_.end()) { |
| 170 DVLOG(1) << "Get response for resource failed: host " << host << " path " | 165 DVLOG(1) << "Get response for resource failed: host " << host << " path " |
| 171 << path; | 166 << path; |
| 172 if (default_response_.get()) { | 167 if (default_response_.get()) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 219 |
| 225 void QuicInMemoryCache::AddSpecialResponse(StringPiece host, | 220 void QuicInMemoryCache::AddSpecialResponse(StringPiece host, |
| 226 StringPiece path, | 221 StringPiece path, |
| 227 SpecialResponseType response_type) { | 222 SpecialResponseType response_type) { |
| 228 AddResponseImpl(host, path, response_type, SpdyHeaderBlock(), "", | 223 AddResponseImpl(host, path, response_type, SpdyHeaderBlock(), "", |
| 229 SpdyHeaderBlock()); | 224 SpdyHeaderBlock()); |
| 230 } | 225 } |
| 231 | 226 |
| 232 QuicInMemoryCache::QuicInMemoryCache() {} | 227 QuicInMemoryCache::QuicInMemoryCache() {} |
| 233 | 228 |
| 234 void QuicInMemoryCache::ResetForTests() { | |
| 235 base::AutoLock lock(response_mutex_); | |
| 236 responses_.clear(); | |
| 237 server_push_resources_.clear(); | |
| 238 } | |
| 239 | |
| 240 void QuicInMemoryCache::InitializeFromDirectory(const string& cache_directory) { | 229 void QuicInMemoryCache::InitializeFromDirectory(const string& cache_directory) { |
| 241 if (cache_directory.empty()) { | 230 if (cache_directory.empty()) { |
| 242 QUIC_BUG << "cache_directory must not be empty."; | 231 QUIC_BUG << "cache_directory must not be empty."; |
| 243 return; | 232 return; |
| 244 } | 233 } |
| 245 VLOG(1) << "Attempting to initialize QuicInMemoryCache from directory: " | 234 VLOG(1) << "Attempting to initialize QuicInMemoryCache from directory: " |
| 246 << cache_directory; | 235 << cache_directory; |
| 247 FilePath directory(FilePath::FromUTF8Unsafe(cache_directory)); | 236 FilePath directory(FilePath::FromUTF8Unsafe(cache_directory)); |
| 248 base::FileEnumerator file_list(directory, true, base::FileEnumerator::FILES); | 237 base::FileEnumerator file_list(directory, true, base::FileEnumerator::FILES); |
| 249 std::list<std::unique_ptr<ResourceFile>> resource_files; | 238 std::list<std::unique_ptr<ResourceFile>> resource_files; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 for (auto it = resource_range.first; it != resource_range.second; ++it) { | 374 for (auto it = resource_range.first; it != resource_range.second; ++it) { |
| 386 ServerPushInfo push_resource = it->second; | 375 ServerPushInfo push_resource = it->second; |
| 387 if (push_resource.request_url.spec() == resource.request_url.spec()) { | 376 if (push_resource.request_url.spec() == resource.request_url.spec()) { |
| 388 return true; | 377 return true; |
| 389 } | 378 } |
| 390 } | 379 } |
| 391 return false; | 380 return false; |
| 392 } | 381 } |
| 393 | 382 |
| 394 } // namespace net | 383 } // namespace net |
| OLD | NEW |