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

Side by Side Diff: net/tools/quic/quic_http_response_cache.cc

Issue 2718633002: debug on ios simulator
Patch Set: add to BUILD.gn test_support_bundle_data Created 3 years, 9 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
OLDNEW
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_http_response_cache.h" 5 #include "net/tools/quic/quic_http_response_cache.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/base_paths.h"
10 #include "base/path_service.h"
9 #include "base/files/file_enumerator.h" 11 #include "base/files/file_enumerator.h"
10 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
11 #include "net/http/http_util.h" 13 #include "net/http/http_util.h"
12 #include "net/quic/platform/api/quic_bug_tracker.h" 14 #include "net/quic/platform/api/quic_bug_tracker.h"
13 #include "net/quic/platform/api/quic_logging.h" 15 #include "net/quic/platform/api/quic_logging.h"
14 #include "net/quic/platform/api/quic_map_util.h" 16 #include "net/quic/platform/api/quic_map_util.h"
15 #include "net/quic/platform/api/quic_ptr_util.h" 17 #include "net/quic/platform/api/quic_ptr_util.h"
16 #include "net/quic/platform/api/quic_text_utils.h" 18 #include "net/quic/platform/api/quic_text_utils.h"
19 #include "base/threading/thread_restrictions.h"
17 #include "net/spdy/spdy_http_utils.h" 20 #include "net/spdy/spdy_http_utils.h"
18 21
19 using base::FilePath; 22 using base::FilePath;
20 using base::IntToString; 23 using base::IntToString;
21 using base::StringPiece; 24 using base::StringPiece;
22 using std::string; 25 using std::string;
23 26
24 namespace net { 27 namespace net {
25 28
26 QuicHttpResponseCache::ServerPushInfo::ServerPushInfo(QuicUrl request_url, 29 QuicHttpResponseCache::ServerPushInfo::ServerPushInfo(QuicUrl request_url,
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 StringPiece host, 226 StringPiece host,
224 StringPiece path, 227 StringPiece path,
225 SpecialResponseType response_type) { 228 SpecialResponseType response_type) {
226 AddResponseImpl(host, path, response_type, SpdyHeaderBlock(), "", 229 AddResponseImpl(host, path, response_type, SpdyHeaderBlock(), "",
227 SpdyHeaderBlock()); 230 SpdyHeaderBlock());
228 } 231 }
229 232
230 QuicHttpResponseCache::QuicHttpResponseCache() {} 233 QuicHttpResponseCache::QuicHttpResponseCache() {}
231 234
232 void QuicHttpResponseCache::InitializeFromDirectory( 235 void QuicHttpResponseCache::InitializeFromDirectory(
236 const string& cache_directory, const FilePath& directory) {
237 if (cache_directory.empty()) {
238 QUIC_BUG << "cache_directory must not be empty.";
239 return;
240 }
241 LOG(ERROR)
242 << "Attempting to initialize QuicHttpResponseCache from directory: "
243 << cache_directory;
244 // FilePath directory(FilePath::FromUTF8Unsafe(cache_directory));
245
246 base::FileEnumerator iter(directory, true, base::FileEnumerator::FILES);
247 int count = 0;
248 for (base::FilePath file = iter.Next(); !file.value().empty(); file = iter.Nex t()) {
249 count ++;
250 }
251 LOG(ERROR) << "@@@@ Inside QUIC of the file size: " << count;
252
253 base::FileEnumerator file_list(directory, true, base::FileEnumerator::FILES);
254 std::list<std::unique_ptr<ResourceFile>> resource_files;
255 int i = 0;
256
257 for (FilePath file_iter = file_list.Next(); !file_iter.empty();
258 file_iter = file_list.Next()) {
259 LOG(ERROR) << i++;
260 // Need to skip files in .svn directories
261 if (file_iter.value().find(FILE_PATH_LITERAL("/.svn/")) != string::npos) {
262 LOG(ERROR) << "skipped /.svn/";
263 continue;
264 }
265 LOG(ERROR) << "entered here";
266 std::unique_ptr<ResourceFile> resource_file(new ResourceFile(file_iter));
267
268 // Tease apart filename into host and path.
269 StringPiece base(resource_file->file_name());
270 base.remove_prefix(cache_directory.length());
271 if (base[0] == '/') {
272 base.remove_prefix(1);
273 }
274
275 resource_file->SetHostPathFromBase(base);
276 resource_file->Read();
277
278 AddResponse(resource_file->host(), resource_file->path(),
279 resource_file->spdy_headers().Clone(), resource_file->body());
280
281 resource_files.push_back(std::move(resource_file));
282 }
283
284 LOG(ERROR) << "size of resource files " << resource_files.size();
285 for (const auto& resource_file : resource_files) {
286 std::list<ServerPushInfo> push_resources;
287 for (const auto& push_url : resource_file->push_urls()) {
288 QuicUrl url(push_url);
289 const Response* response = GetResponse(url.host(), url.path());
290 if (!response) {
291 QUIC_BUG << "Push URL '" << push_url << "' not found.";
292 return;
293 }
294 push_resources.push_back(ServerPushInfo(url, response->headers().Clone(),
295 kV3LowestPriority,
296 response->body().as_string()));
297 }
298 MaybeAddServerPushResources(resource_file->host(), resource_file->path(),
299 push_resources);
300 }
301 }
302
303 void QuicHttpResponseCache::InitializeFromDirectory(
233 const string& cache_directory) { 304 const string& cache_directory) {
234 if (cache_directory.empty()) { 305 if (cache_directory.empty()) {
235 QUIC_BUG << "cache_directory must not be empty."; 306 QUIC_BUG << "cache_directory must not be empty.";
236 return; 307 return;
237 } 308 }
238 QUIC_LOG(INFO) 309 LOG(ERROR)
239 << "Attempting to initialize QuicHttpResponseCache from directory: " 310 << "Attempting to initialize QuicHttpResponseCache from directory: "
240 << cache_directory; 311 << cache_directory;
241 FilePath directory(FilePath::FromUTF8Unsafe(cache_directory)); 312 FilePath directory(FilePath::FromUTF8Unsafe(cache_directory));
242 base::FileEnumerator file_list(directory, true, base::FileEnumerator::FILES); 313
314 base::FileEnumerator file_list(directory, true, base::FileEnumerator::FILES);
243 std::list<std::unique_ptr<ResourceFile>> resource_files; 315 std::list<std::unique_ptr<ResourceFile>> resource_files;
244 for (FilePath file_iter = file_list.Next(); !file_iter.empty(); 316 for (FilePath file_iter = file_list.Next(); !file_iter.empty();
245 file_iter = file_list.Next()) { 317 file_iter = file_list.Next()) {
246 // Need to skip files in .svn directories 318 // Need to skip files in .svn directories
247 if (file_iter.value().find(FILE_PATH_LITERAL("/.svn/")) != string::npos) { 319 if (file_iter.value().find(FILE_PATH_LITERAL("/.svn/")) != string::npos) {
248 continue; 320 continue;
249 } 321 }
250 322
251 std::unique_ptr<ResourceFile> resource_file(new ResourceFile(file_iter)); 323 std::unique_ptr<ResourceFile> resource_file(new ResourceFile(file_iter));
252 324
(...skipping 24 matching lines...) Expand all
277 } 349 }
278 push_resources.push_back(ServerPushInfo(url, response->headers().Clone(), 350 push_resources.push_back(ServerPushInfo(url, response->headers().Clone(),
279 kV3LowestPriority, 351 kV3LowestPriority,
280 response->body().as_string())); 352 response->body().as_string()));
281 } 353 }
282 MaybeAddServerPushResources(resource_file->host(), resource_file->path(), 354 MaybeAddServerPushResources(resource_file->host(), resource_file->path(),
283 push_resources); 355 push_resources);
284 } 356 }
285 } 357 }
286 358
359
360
287 std::list<ServerPushInfo> QuicHttpResponseCache::GetServerPushResources( 361 std::list<ServerPushInfo> QuicHttpResponseCache::GetServerPushResources(
288 string request_url) { 362 string request_url) {
289 QuicWriterMutexLock lock(&response_mutex_); 363 QuicWriterMutexLock lock(&response_mutex_);
290 364
291 std::list<ServerPushInfo> resources; 365 std::list<ServerPushInfo> resources;
292 auto resource_range = server_push_resources_.equal_range(request_url); 366 auto resource_range = server_push_resources_.equal_range(request_url);
293 for (auto it = resource_range.first; it != resource_range.second; ++it) { 367 for (auto it = resource_range.first; it != resource_range.second; ++it) {
294 resources.push_back(it->second); 368 resources.push_back(it->second);
295 } 369 }
296 QUIC_DVLOG(1) << "Found " << resources.size() << " push resources for " 370 QUIC_DVLOG(1) << "Found " << resources.size() << " push resources for "
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 string QuicHttpResponseCache::GetKey(StringPiece host, StringPiece path) const { 405 string QuicHttpResponseCache::GetKey(StringPiece host, StringPiece path) const {
332 return host.as_string() + path.as_string(); 406 return host.as_string() + path.as_string();
333 } 407 }
334 408
335 void QuicHttpResponseCache::MaybeAddServerPushResources( 409 void QuicHttpResponseCache::MaybeAddServerPushResources(
336 StringPiece request_host, 410 StringPiece request_host,
337 StringPiece request_path, 411 StringPiece request_path,
338 std::list<ServerPushInfo> push_resources) { 412 std::list<ServerPushInfo> push_resources) {
339 string request_url = GetKey(request_host, request_path); 413 string request_url = GetKey(request_host, request_path);
340 414
415 LOG(ERROR) << "====== zhongyi: maybe add server push resource " << request_url ;
341 for (const auto& push_resource : push_resources) { 416 for (const auto& push_resource : push_resources) {
342 if (PushResourceExistsInCache(request_url, push_resource)) { 417 if (PushResourceExistsInCache(request_url, push_resource)) {
418 LOG(ERROR) << "push resource exists in cache";
343 continue; 419 continue;
344 } 420 }
345 421
346 QUIC_DVLOG(1) << "Add request-resource association: request url " 422 LOG(ERROR) << "Add request-resource association: request url "
347 << request_url << " push url " 423 << request_url << " push url "
348 << push_resource.request_url.ToString() 424 << push_resource.request_url.ToString()
349 << " response headers " 425 << " response headers "
350 << push_resource.headers.DebugString(); 426 << push_resource.headers.DebugString();
351 { 427 {
352 QuicWriterMutexLock lock(&response_mutex_); 428 QuicWriterMutexLock lock(&response_mutex_);
353 server_push_resources_.insert(std::make_pair(request_url, push_resource)); 429 server_push_resources_.insert(std::make_pair(request_url, push_resource));
354 } 430 }
355 string host = push_resource.request_url.host(); 431 string host = push_resource.request_url.host();
356 if (host.empty()) { 432 if (host.empty()) {
357 host = request_host.as_string(); 433 host = request_host.as_string();
358 } 434 }
359 string path = push_resource.request_url.path(); 435 string path = push_resource.request_url.path();
360 bool found_existing_response = false; 436 bool found_existing_response = false;
361 { 437 {
362 QuicWriterMutexLock lock(&response_mutex_); 438 QuicWriterMutexLock lock(&response_mutex_);
363 found_existing_response = QuicContainsKey(responses_, GetKey(host, path)); 439 found_existing_response = QuicContainsKey(responses_, GetKey(host, path));
364 } 440 }
365 if (!found_existing_response) { 441 if (!found_existing_response) {
366 // Add a server push response to responses map, if it is not in the map. 442 // Add a server push response to responses map, if it is not in the map.
367 StringPiece body = push_resource.body; 443 StringPiece body = push_resource.body;
368 QUIC_DVLOG(1) << "Add response for push resource: host " << host 444 LOG(ERROR) << "Add response for push resource: host " << host
369 << " path " << path; 445 << " path " << path;
370 AddResponse(host, path, push_resource.headers.Clone(), body); 446 AddResponse(host, path, push_resource.headers.Clone(), body);
371 } 447 }
372 } 448 }
373 } 449 }
374 450
375 bool QuicHttpResponseCache::PushResourceExistsInCache( 451 bool QuicHttpResponseCache::PushResourceExistsInCache(
376 string original_request_url, 452 string original_request_url,
377 ServerPushInfo resource) { 453 ServerPushInfo resource) {
378 QuicWriterMutexLock lock(&response_mutex_); 454 QuicWriterMutexLock lock(&response_mutex_);
379 auto resource_range = 455 auto resource_range =
380 server_push_resources_.equal_range(original_request_url); 456 server_push_resources_.equal_range(original_request_url);
381 for (auto it = resource_range.first; it != resource_range.second; ++it) { 457 for (auto it = resource_range.first; it != resource_range.second; ++it) {
382 ServerPushInfo push_resource = it->second; 458 ServerPushInfo push_resource = it->second;
459 LOG(ERROR) << "#1: " << push_resource.request_url.ToString();
383 if (push_resource.request_url.ToString() == 460 if (push_resource.request_url.ToString() ==
384 resource.request_url.ToString()) { 461 resource.request_url.ToString()) {
385 return true; 462 return true;
386 } 463 }
387 } 464 }
388 return false; 465 return false;
389 } 466 }
390 467
391 } // namespace net 468 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_http_response_cache.h ('k') | net/tools/quic/quic_http_response_cache_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698