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

Side by Side Diff: net/http/infinite_cache.cc

Issue 10959026: Http cache: Make sure we separate the infinite cache simulation from the real cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/http/infinite_cache.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/http/infinite_cache.h" 5 #include "net/http/infinite_cache.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 reinterpret_cast<const Bytef*>(data), data_len); 307 reinterpret_cast<const Bytef*>(data), data_len);
308 } 308 }
309 309
310 void InfiniteCacheTransaction::OnTruncatedResponse() { 310 void InfiniteCacheTransaction::OnTruncatedResponse() {
311 if (!cache_) 311 if (!cache_)
312 return; 312 return;
313 313
314 resource_data_->details.flags |= TRUNCATED; 314 resource_data_->details.flags |= TRUNCATED;
315 } 315 }
316 316
317 void InfiniteCacheTransaction::OnServedFromCache() { 317 void InfiniteCacheTransaction::OnServedFromCache(
318 const HttpResponseInfo* response) {
318 if (!cache_) 319 if (!cache_)
319 return; 320 return;
320 321
321 resource_data_->details.flags |= CACHED; 322 resource_data_->details.flags |= CACHED;
323 if (!resource_data_->details.last_access)
324 OnResponseReceived(response);
322 } 325 }
323 326
324 void InfiniteCacheTransaction::Finish() { 327 void InfiniteCacheTransaction::Finish() {
325 if (!cache_ || !resource_data_.get()) 328 if (!cache_ || !resource_data_.get())
326 return; 329 return;
327 330
328 if (!resource_data_->details.headers_size) 331 if (!resource_data_->details.headers_size)
329 return; 332 return;
330 333
331 cache_->ProcessResource(resource_data_.Pass()); 334 cache_->ProcessResource(resource_data_.Pass());
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 header_->num_requests++; 499 header_->num_requests++;
497 KeyMap::iterator i = map_.find(data->key); 500 KeyMap::iterator i = map_.find(data->key);
498 if (i != map_.end()) { 501 if (i != map_.end()) {
499 if (data->details.flags & DOOM_METHOD) { 502 if (data->details.flags & DOOM_METHOD) {
500 Remove(i->second); 503 Remove(i->second);
501 map_.erase(i); 504 map_.erase(i);
502 return; 505 return;
503 } 506 }
504 data->details.use_count = i->second.use_count; 507 data->details.use_count = i->second.use_count;
505 data->details.update_count = i->second.update_count; 508 data->details.update_count = i->second.update_count;
506 if (data->details.flags & CACHED) { 509 bool reused = CanReuse(i->second, data->details);
510 bool data_changed = DataChanged(i->second, data->details);
511 bool headers_changed = HeadersChanged(i->second, data->details);
512
513 if (reused && data_changed)
514 header_->num_bad_hits++;
515
516 if (reused)
507 RecordHit(i->second, &data->details); 517 RecordHit(i->second, &data->details);
508 } else {
509 bool reused = CanReuse(i->second, data->details);
510 bool data_changed = DataChanged(i->second, data->details);
511 bool headers_changed = HeadersChanged(i->second, data->details);
512 518
513 if (reused && data_changed) 519 if (headers_changed)
514 header_->num_bad_hits++; 520 UMA_HISTOGRAM_BOOLEAN("InfiniteCache.HeadersChange", true);
515 521
516 if (reused) 522 if (data_changed)
517 RecordHit(i->second, &data->details); 523 RecordUpdate(i->second, &data->details);
518
519 if (headers_changed)
520 UMA_HISTOGRAM_BOOLEAN("InfiniteCache.HeadersChange", true);
521
522 if (data_changed)
523 RecordUpdate(i->second, &data->details);
524 }
525 524
526 if (data->details.flags & NO_STORE) { 525 if (data->details.flags & NO_STORE) {
527 Remove(i->second); 526 Remove(i->second);
528 map_.erase(i); 527 map_.erase(i);
529 return; 528 return;
530 } 529 }
531 530
532 map_[data->key] = data->details; 531 map_[data->key] = data->details;
533 return; 532 return;
534 } 533 }
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 bool have_to_drop = (old.flags & TRUNCATED) && !(old.flags & RESUMABLE); 888 bool have_to_drop = (old.flags & TRUNCATED) && !(old.flags & RESUMABLE);
890 if (reason && (old.flags & REVALIDATEABLE) && !have_to_drop) 889 if (reason && (old.flags & REVALIDATEABLE) && !have_to_drop)
891 reason += REUSE_REVALIDATEABLE; 890 reason += REUSE_REVALIDATEABLE;
892 891
893 UMA_HISTOGRAM_ENUMERATION("InfiniteCache.ReuseFailure", reason, 15); 892 UMA_HISTOGRAM_ENUMERATION("InfiniteCache.ReuseFailure", reason, 15);
894 return !reason; 893 return !reason;
895 } 894 }
896 895
897 bool InfiniteCache::Worker::DataChanged(const Details& old, 896 bool InfiniteCache::Worker::DataChanged(const Details& old,
898 const Details& current) { 897 const Details& current) {
898 if (current.flags & CACHED)
899 return false;
900
899 bool changed = false; 901 bool changed = false;
900 if (old.response_size != current.response_size) { 902 if (old.response_size != current.response_size) {
901 changed = true; 903 changed = true;
902 UpdateSize(old.response_size, current.response_size); 904 UpdateSize(old.response_size, current.response_size);
903 } 905 }
904 906
905 if (old.response_hash != current.response_hash) 907 if (old.response_hash != current.response_hash)
906 changed = true; 908 changed = true;
907 909
908 return changed; 910 return changed;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 int InfiniteCache::FlushDataForTest(const CompletionCallback& callback) { 1014 int InfiniteCache::FlushDataForTest(const CompletionCallback& callback) {
1013 DCHECK(worker_); 1015 DCHECK(worker_);
1014 int* result = new int; 1016 int* result = new int;
1015 task_runner_->PostTaskAndReply( 1017 task_runner_->PostTaskAndReply(
1016 FROM_HERE, base::Bind(&InfiniteCache::Worker::Flush, worker_, result), 1018 FROM_HERE, base::Bind(&InfiniteCache::Worker::Flush, worker_, result),
1017 base::Bind(&OnComplete, callback, base::Owned(result))); 1019 base::Bind(&OnComplete, callback, base::Owned(result)));
1018 return net::ERR_IO_PENDING; 1020 return net::ERR_IO_PENDING;
1019 } 1021 }
1020 1022
1021 } // namespace net 1023 } // namespace net
OLDNEW
« no previous file with comments | « net/http/infinite_cache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698