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

Side by Side Diff: net/base/sdch_manager.cc

Issue 8018: Clean up filter and content encoding handling ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month 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/base/sdch_manager.h ('k') | net/build/net_unittests.vcproj » ('j') | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "base/field_trial.h"
5 #include "base/histogram.h" 6 #include "base/histogram.h"
6 #include "base/logging.h" 7 #include "base/logging.h"
7 #include "base/sha2.h" 8 #include "base/sha2.h"
8 #include "base/string_util.h" 9 #include "base/string_util.h"
9 #include "net/base/base64.h" 10 #include "net/base/base64.h"
10 #include "net/base/registry_controlled_domain.h" 11 #include "net/base/registry_controlled_domain.h"
11 #include "net/base/sdch_manager.h" 12 #include "net/base/sdch_manager.h"
12 #include "net/url_request/url_request_http_job.h" 13 #include "net/url_request/url_request_http_job.h"
13 14
14 15
15 //------------------------------------------------------------------------------ 16 //------------------------------------------------------------------------------
16 // static 17 // static
17 SdchManager* SdchManager::global_; 18 SdchManager* SdchManager::global_;
18 19
19 // static 20 // static
20 SdchManager* SdchManager::Global() { 21 SdchManager* SdchManager::Global() {
21 return global_; 22 return global_;
22 } 23 }
23 24
24 // static 25 // static
25 void SdchManager::SdchErrorRecovery(ProblemCodes problem) { 26 void SdchManager::SdchErrorRecovery(ProblemCodes problem) {
26 static LinearHistogram histogram(L"Sdch.ProblemCodes", MIN_PROBLEM_CODE, 27 static LinearHistogram histogram(L"Sdch.ProblemCodes", MIN_PROBLEM_CODE,
27 MAX_PROBLEM_CODE - 1, MAX_PROBLEM_CODE); 28 MAX_PROBLEM_CODE - 1, MAX_PROBLEM_CODE);
28 // TODO(jar): Set UMA flag for uploading. 29 histogram.SetFlags(kUmaTargetedHistogramFlag);
29 histogram.Add(problem); 30 histogram.Add(problem);
30 } 31 }
31 32
32 // static 33 // static
33 void SdchManager::ClearBlacklistings() { 34 void SdchManager::ClearBlacklistings() {
34 Global()->blacklisted_domains_.clear(); 35 Global()->blacklisted_domains_.clear();
35 } 36 }
36 37
37 38
38 //------------------------------------------------------------------------------ 39 //------------------------------------------------------------------------------
39 SdchManager::SdchManager() : sdch_enabled_(false) { 40 SdchManager::SdchManager() : sdch_enabled_(false) {
40 DCHECK(!global_); 41 DCHECK(!global_);
41 global_ = this; 42 global_ = this;
42 } 43 }
43 44
44 SdchManager::~SdchManager() { 45 SdchManager::~SdchManager() {
45 DCHECK(global_ == this); 46 DCHECK(global_ == this);
46 while (!dictionaries_.empty()) { 47 while (!dictionaries_.empty()) {
47 DictionaryMap::iterator it = dictionaries_.begin(); 48 DictionaryMap::iterator it = dictionaries_.begin();
48 it->second->Release(); 49 it->second->Release();
49 dictionaries_.erase(it->first); 50 dictionaries_.erase(it->first);
50 } 51 }
51 global_ = NULL; 52 global_ = NULL;
52 } 53 }
53 54
54 // static 55 // static
55 bool SdchManager::BlacklistDomain(const GURL& url) { 56 bool SdchManager::BlacklistDomain(const GURL& url) {
56 if (!global_ ) 57 if (!global_ )
57 return false; 58 return false;
58 std::string domain(url.host()); 59 std::string domain(url.host());
60 UMA_HISTOGRAM_TIMES(L"Sdch.UptimeBeforeBlacklisting",
61 Time::Now() - FieldTrialList::application_start_time());
59 global_->blacklisted_domains_.insert(url.host()); 62 global_->blacklisted_domains_.insert(url.host());
60 return true; 63 return true;
61 } 64 }
62 65
63 void SdchManager::EnableSdchSupport(const std::string& domain) { 66 void SdchManager::EnableSdchSupport(const std::string& domain) {
64 // We presume that there is a SDCH manager instance. 67 // We presume that there is a SDCH manager instance.
65 global_->supported_domain_ = domain; 68 global_->supported_domain_ = domain;
66 global_->sdch_enabled_ = true; 69 global_->sdch_enabled_ = true;
67 } 70 }
68 71
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 167 }
165 168
166 if (line_end >= header_end) 169 if (line_end >= header_end)
167 break; 170 break;
168 line_start = line_end + 1; 171 line_start = line_end + 1;
169 } 172 }
170 173
171 if (!Dictionary::CanSet(domain, path, ports, dictionary_url)) 174 if (!Dictionary::CanSet(domain, path, ports, dictionary_url))
172 return false; 175 return false;
173 176
174 HISTOGRAM_COUNTS(L"Sdch.Dictionary size loaded", dictionary_text.size()); 177 UMA_HISTOGRAM_COUNTS(L"Sdch.Dictionary size loaded", dictionary_text.size());
175 DLOG(INFO) << "Loaded dictionary with client hash " << client_hash << 178 DLOG(INFO) << "Loaded dictionary with client hash " << client_hash <<
176 " and server hash " << server_hash; 179 " and server hash " << server_hash;
177 Dictionary* dictionary = 180 Dictionary* dictionary =
178 new Dictionary(dictionary_text, header_end + 2, client_hash, 181 new Dictionary(dictionary_text, header_end + 2, client_hash,
179 dictionary_url, domain, path, expiration, ports); 182 dictionary_url, domain, path, expiration, ports);
180 dictionary->AddRef(); 183 dictionary->AddRef();
181 dictionaries_[server_hash] = dictionary; 184 dictionaries_[server_hash] = dictionary;
182 return true; 185 return true;
183 } 186 }
184 187
185 void SdchManager::GetVcdiffDictionary(const std::string& server_hash, 188 void SdchManager::GetVcdiffDictionary(const std::string& server_hash,
186 const GURL& referring_url, Dictionary** dictionary) { 189 const GURL& referring_url, Dictionary** dictionary) {
187 *dictionary = NULL; 190 *dictionary = NULL;
188 DictionaryMap::iterator it = dictionaries_.find(server_hash); 191 DictionaryMap::iterator it = dictionaries_.find(server_hash);
189 if (it == dictionaries_.end()) { 192 if (it == dictionaries_.end()) {
190 SdchErrorRecovery(DICTIONARY_NOT_FOUND_FOR_HASH);
191 return; 193 return;
192 } 194 }
193 Dictionary* matching_dictionary = it->second; 195 Dictionary* matching_dictionary = it->second;
194 if (!matching_dictionary->CanUse(referring_url)) 196 if (!matching_dictionary->CanUse(referring_url))
195 return; 197 return;
196 *dictionary = matching_dictionary; 198 *dictionary = matching_dictionary;
197 } 199 }
198 200
199 // TODO(jar): If we have evictions from the dictionaries_, then we need to 201 // TODO(jar): If we have evictions from the dictionaries_, then we need to
200 // change this interface to return a list of reference counted Dictionary 202 // change this interface to return a list of reference counted Dictionary
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 return false; 382 return false;
381 return restriction[prefix_length - 1] == '/' || path[prefix_length] == '/'; 383 return restriction[prefix_length - 1] == '/' || path[prefix_length] == '/';
382 } 384 }
383 385
384 // static 386 // static
385 bool SdchManager::Dictionary::DomainMatch(const GURL& gurl, 387 bool SdchManager::Dictionary::DomainMatch(const GURL& gurl,
386 const std::string& restriction) { 388 const std::string& restriction) {
387 // TODO(jar): This is not precisely a domain match definition. 389 // TODO(jar): This is not precisely a domain match definition.
388 return gurl.DomainIs(restriction.data(), restriction.size()); 390 return gurl.DomainIs(restriction.data(), restriction.size());
389 } 391 }
OLDNEW
« no previous file with comments | « net/base/sdch_manager.h ('k') | net/build/net_unittests.vcproj » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698