 Chromium Code Reviews
 Chromium Code Reviews Issue 10701151:
   DuplicateContentResourceHandler to monitor resources and track how many times th…  (Closed) 
  Base URL: http://src.chromium.org/svn/trunk/src/
    
  
    Issue 10701151:
   DuplicateContentResourceHandler to monitor resources and track how many times th…  (Closed) 
  Base URL: http://src.chromium.org/svn/trunk/src/| OLD | NEW | 
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <string> | |
| 6 | |
| 7 #include "content/browser/renderer_host/duplicate_resource_handler.h" | |
| 
gavinp
2012/07/11 23:39:46
Move this above #include <string>
 
frankwang
2012/07/12 01:50:36
Done.
 | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/metrics/histogram.h" | |
| 11 #include "content/browser/renderer_host/resource_request_info_impl.h" | |
| 12 #include "net/base/io_buffer.h" | |
| 13 #include "third_party/smhasher/src/MurmurHash3.h" | |
| 14 | |
| 15 | |
| 16 namespace content{ | |
| 17 | |
| 18 namespace{ | |
| 19 | |
| 20 std::set<uint32>* GetSetOfHashes(){ | |
| 
gavinp
2012/07/11 23:39:46
Nit: don't indent this.
 
frankwang
2012/07/12 01:50:36
Done.
 | |
| 21 static std::set<uint32> seen_resources; | |
| 22 return &seen_resources; | |
| 23 } | |
| 24 | |
| 25 } // namespace | |
| 26 | |
| 27 DuplicateResourceHandler::DuplicateResourceHandler( | |
| 28 scoped_ptr<ResourceHandler> next_handler, | |
| 29 net::URLRequest* request) | |
| 30 : LayeredResourceHandler(next_handler.Pass()), | |
| 31 bytes_hit_(0), | |
| 32 bytes_miss_(0), | |
| 33 read_buffer_size_(0), // keep track of bytes in read buffer | |
| 34 request_(request) { | |
| 35 } | |
| 36 | |
| 37 DuplicateResourceHandler::~DuplicateResourceHandler(){ | |
| 38 } | |
| 39 | |
| 40 bool DuplicateResourceHandler::OnWillRead(int request_id, net::IOBuffer** buf, | |
| 41 int* buf_size, int min_size){ | |
| 42 DCHECK_EQ(-1, min_size); | |
| 43 | |
| 44 read_buffer_ = *buf; | |
| 45 read_buffer_size_ = *buf_size; | |
| 
gavinp
2012/07/11 23:39:46
This is wrong. The buffer is provided by your down
 
frankwang
2012/07/12 01:50:36
Done.
 | |
| 46 | |
| 47 return true; | |
| 48 } | |
| 49 | |
| 50 bool DuplicateResourceHandler::OnReadCompleted(int request_id, int bytes_read, | |
| 51 bool* defer) { | |
| 52 | |
| 
gavinp
2012/07/11 23:39:46
if (!next_handler_->OnReadCompleted(...))
  return
 
frankwang
2012/07/12 01:50:36
Done.
 | |
| 53 // find hash of resource | |
| 54 uint32 buf_hash; | |
| 55 MurmurHash3_x86_32(read_buffer_, bytes_read, 0x0, &buf_hash); | |
| 
gavinp
2012/07/11 23:39:46
This is conceptually broken. The reads come to you
 
gavinp
2012/07/11 23:39:46
Also:
MurmurHash3_x86_32(read_buffer_->data(), by
 
frankwang
2012/07/12 01:50:36
Done.
 | |
| 56 | |
| 57 static base::Histogram* num_hits(NULL); | |
| 
gavinp
2012/07/11 23:39:46
This isn't a common pattern for creating histogram
 
frankwang
2012/07/12 01:50:36
I changed it just for one histogram. I am still di
 | |
| 58 if (!num_hits) | |
| 59 num_hits = base::BooleanHistogram::FactoryGet( | |
| 60 "hash.hit", base::Histogram::kUmaTargetedHistogramFlag); | |
| 61 | |
| 62 // if element is in hash | |
| 63 if (GetSetOfHashes()->find(buf_hash) != GetSetOfHashes()->end()){ | |
| 64 bytes_hit_ += bytes_read; | |
| 65 num_hits->AddBoolean(true); | |
| 66 | |
| 67 } else{ | |
| 68 bytes_miss_ += bytes_read; | |
| 69 num_hits->AddBoolean(false); | |
| 70 GetSetOfHashes()->insert(buf_hash); | |
| 71 } | |
| 72 | |
| 
gavinp
2012/07/11 23:41:31
I'm not sure if it's kosher to keep read_buffer_ a
 
frankwang
2012/07/12 01:50:36
Yes, I called release() on it because it was a sco
 | |
| 73 read_buffer_size_ = 0; | |
| 74 | |
| 75 return true; | |
| 76 } | |
| 77 | |
| 78 } //namespace content | |
| OLD | NEW |