OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/quic/quic_in_memory_cache.h" | 5 #include "net/quic/quic_in_memory_cache.h" |
6 | 6 |
7 #include "base/files/file_enumerator.h" | 7 #include "base/files/file_enumerator.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "net/http/http_util.h" | 11 #include "net/http/http_util.h" |
12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
13 | 13 |
14 using base::FilePath; | 14 using base::FilePath; |
15 using base::StringPiece; | 15 using base::StringPiece; |
16 using std::string; | 16 using std::string; |
17 | 17 |
18 // Specifies the directory used during QuicInMemoryCache | 18 // Specifies the directory used during QuicInMemoryCache |
19 // construction to seed the cache. Cache directory can be | 19 // construction to seed the cache. Cache directory can be |
20 // generated using `wget -p --save-headers <url> | 20 // generated using `wget -p --save-headers <url> |
21 | 21 |
22 namespace net { | 22 namespace net { |
23 | 23 |
24 FilePath::StringType g_quic_in_memory_cache_dir = FILE_PATH_LITERAL(""); | 24 FilePath::StringType* g_quic_in_memory_cache_dir = NULL; |
25 | 25 |
26 QuicInMemoryCache::Response::Response() : response_type_(REGULAR_RESPONSE) { | 26 QuicInMemoryCache::Response::Response() : response_type_(REGULAR_RESPONSE) { |
27 } | 27 } |
28 | 28 |
29 QuicInMemoryCache::Response::~Response() { | 29 QuicInMemoryCache::Response::~Response() { |
30 } | 30 } |
31 | 31 |
32 // static | 32 // static |
33 QuicInMemoryCache* QuicInMemoryCache::GetInstance() { | 33 QuicInMemoryCache* QuicInMemoryCache::GetInstance() { |
34 return Singleton<QuicInMemoryCache>::get(); | 34 return Singleton<QuicInMemoryCache>::get(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 Initialize(); | 91 Initialize(); |
92 } | 92 } |
93 | 93 |
94 void QuicInMemoryCache::ResetForTests() { | 94 void QuicInMemoryCache::ResetForTests() { |
95 STLDeleteValues(&responses_); | 95 STLDeleteValues(&responses_); |
96 Initialize(); | 96 Initialize(); |
97 } | 97 } |
98 | 98 |
99 void QuicInMemoryCache::Initialize() { | 99 void QuicInMemoryCache::Initialize() { |
100 // If there's no defined cache dir, we have no initialization to do. | 100 // If there's no defined cache dir, we have no initialization to do. |
101 if (g_quic_in_memory_cache_dir.size() == 0) { | 101 if (g_quic_in_memory_cache_dir == NULL) { |
102 VLOG(1) << "No cache directory found. Skipping initialization."; | 102 VLOG(1) << "No cache directory found. Skipping initialization."; |
103 return; | 103 return; |
104 } | 104 } |
105 VLOG(1) << "Attempting to initialize QuicInMemoryCache from directory: " | 105 VLOG(1) << "Attempting to initialize QuicInMemoryCache from directory: " |
106 << g_quic_in_memory_cache_dir; | 106 << *g_quic_in_memory_cache_dir; |
107 | 107 |
108 FilePath directory(g_quic_in_memory_cache_dir); | 108 FilePath directory(*g_quic_in_memory_cache_dir); |
109 base::FileEnumerator file_list(directory, | 109 base::FileEnumerator file_list(directory, |
110 true, | 110 true, |
111 base::FileEnumerator::FILES); | 111 base::FileEnumerator::FILES); |
112 | 112 |
113 FilePath file = file_list.Next(); | 113 FilePath file = file_list.Next(); |
114 for (; !file.empty(); file = file_list.Next()) { | 114 for (; !file.empty(); file = file_list.Next()) { |
115 // Need to skip files in .svn directories | 115 // Need to skip files in .svn directories |
116 if (file.value().find(FILE_PATH_LITERAL("/.svn/")) != string::npos) { | 116 if (file.value().find(FILE_PATH_LITERAL("/.svn/")) != string::npos) { |
117 continue; | 117 continue; |
118 } | 118 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 QuicInMemoryCache::~QuicInMemoryCache() { | 174 QuicInMemoryCache::~QuicInMemoryCache() { |
175 STLDeleteValues(&responses_); | 175 STLDeleteValues(&responses_); |
176 } | 176 } |
177 | 177 |
178 string QuicInMemoryCache::GetKey(const GURL& url) const { | 178 string QuicInMemoryCache::GetKey(const GURL& url) const { |
179 // Take everything but the scheme portion of the URL. | 179 // Take everything but the scheme portion of the URL. |
180 return url.host() + url.PathForRequest(); | 180 return url.host() + url.PathForRequest(); |
181 } | 181 } |
182 | 182 |
183 } // namespace net | 183 } // namespace net |
OLD | NEW |