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

Side by Side Diff: content/browser/renderer_host/duplicate_content_resource_handler.cc

Issue 10824236: Only track http and https in duplicate resource handler metrics (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 4 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 | « no previous file | 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 "content/browser/renderer_host/duplicate_content_resource_handler.h" 5 #include "content/browser/renderer_host/duplicate_content_resource_handler.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/string_util.h"
12 #include "content/browser/renderer_host/resource_request_info_impl.h" 13 #include "content/browser/renderer_host/resource_request_info_impl.h"
13 #include "net/base/io_buffer.h" 14 #include "net/base/io_buffer.h"
14 #include "net/url_request/url_request.h" 15 #include "net/url_request/url_request.h"
15 16
16 namespace content { 17 namespace content {
17 namespace { 18 namespace {
18 19
19 class GlobalDuplicateRecords { 20 class GlobalDuplicateRecords {
20 public: 21 public:
21 static GlobalDuplicateRecords* GetInstance() { 22 static GlobalDuplicateRecords* GetInstance() {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 const net::URLRequestStatus& status, 83 const net::URLRequestStatus& status,
83 const std::string& security_info) { 84 const std::string& security_info) {
84 85
85 if (status.is_success()) 86 if (status.is_success())
86 RecordContentMetrics(); 87 RecordContentMetrics();
87 88
88 return next_handler_->OnResponseCompleted(request_id, status, security_info); 89 return next_handler_->OnResponseCompleted(request_id, status, security_info);
89 } 90 }
90 91
91 void DuplicateContentResourceHandler::RecordContentMetrics() { 92 void DuplicateContentResourceHandler::RecordContentMetrics() {
93 // Ignore data and blob URLs.
94 const std::string& url_spec = request_->url().spec();
95 if (StartsWithASCII(url_spec, "data:", false) ||
gavinp 2012/08/09 17:28:05 So since data URLs will usually have the same URL
96 StartsWithASCII(url_spec, "blob:", false)) {
97 bytes_read_ = 0;
98 read_buffer_ = NULL;
99 return;
100 }
92 MH_UINT32 contents_hash = PMurHash32_Result(pmurhash_ph1_, 101 MH_UINT32 contents_hash = PMurHash32_Result(pmurhash_ph1_,
93 pmurhash_pcarry_, bytes_read_); 102 pmurhash_pcarry_, bytes_read_);
94
95 // Combine the contents_hash with the url, so we can test if future content 103 // Combine the contents_hash with the url, so we can test if future content
96 // identical resources have the same original url or not. 104 // identical resources have the same original url or not.
97 MH_UINT32 hashed_with_url;
98 const std::string& url_spec = request_->url().spec();
99 PMurHash32_Process(&pmurhash_ph1_, &pmurhash_pcarry_, 105 PMurHash32_Process(&pmurhash_ph1_, &pmurhash_pcarry_,
100 url_spec.data(), url_spec.length()); 106 url_spec.data(), url_spec.length());
101 hashed_with_url = PMurHash32_Result(pmurhash_ph1_, pmurhash_pcarry_, 107 MH_UINT32 hashed_with_url = PMurHash32_Result(pmurhash_ph1_, pmurhash_pcarry_,
102 url_spec.length() + bytes_read_); 108 url_spec.length() + bytes_read_);
frankwang 2012/08/09 17:21:12 nit: indentation
103 109
104 DVLOG(4) << "url: " << url_spec; 110 DVLOG(4) << "url: " << url_spec;
105 DVLOG(4) << "contents hash: " << contents_hash; 111 DVLOG(4) << "contents hash: " << contents_hash;
106 DVLOG(4) << "hash with url: " << hashed_with_url; 112 DVLOG(4) << "hash with url: " << hashed_with_url;
107 113
108 std::set<MH_UINT32>* content_matches = 114 std::set<MH_UINT32>* content_matches =
109 GlobalDuplicateRecords::GetInstance()->content_matches(); 115 GlobalDuplicateRecords::GetInstance()->content_matches();
110 std::set<MH_UINT32>* content_and_url_matches = 116 std::set<MH_UINT32>* content_and_url_matches =
111 GlobalDuplicateRecords::GetInstance()->content_and_url_matches(); 117 GlobalDuplicateRecords::GetInstance()->content_and_url_matches();
112 118
(...skipping 12 matching lines...) Expand all
125 resource_type_, ResourceType::LAST_TYPE); 131 resource_type_, ResourceType::LAST_TYPE);
126 } 132 }
127 content_matches->insert(contents_hash); 133 content_matches->insert(contents_hash);
128 content_and_url_matches->insert(hashed_with_url); 134 content_and_url_matches->insert(hashed_with_url);
129 135
130 bytes_read_ = 0; 136 bytes_read_ = 0;
131 read_buffer_ = NULL; 137 read_buffer_ = NULL;
132 } 138 }
133 139
134 } // namespace content 140 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698