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

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

Issue 2541073003: Instrument SdchManager using MemoryDumpProvider (Closed)
Patch Set: Address Randy's comments Created 3 years, 12 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
« no previous file with comments | « net/base/sdch_manager.h ('k') | net/base/sdch_manager_unittest.cc » ('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) 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/base/sdch_manager.h" 5 #include "net/base/sdch_manager.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/base64url.h" 11 #include "base/base64url.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/stringprintf.h"
16 #include "base/time/default_clock.h" 17 #include "base/time/default_clock.h"
18 #include "base/trace_event/memory_allocator_dump.h"
19 #include "base/trace_event/process_memory_dump.h"
17 #include "base/values.h" 20 #include "base/values.h"
18 #include "crypto/sha2.h" 21 #include "crypto/sha2.h"
19 #include "net/base/parse_number.h" 22 #include "net/base/parse_number.h"
20 #include "net/base/sdch_net_log_params.h" 23 #include "net/base/sdch_net_log_params.h"
21 #include "net/base/sdch_observer.h" 24 #include "net/base/sdch_observer.h"
22 #include "net/url_request/url_request_http_job.h" 25 #include "net/url_request/url_request_http_job.h"
23 26
24 namespace { 27 namespace {
25 28
26 void StripTrailingDot(GURL* gurl) { 29 void StripTrailingDot(GURL* gurl) {
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 } 320 }
318 321
319 void SdchManager::AddObserver(SdchObserver* observer) { 322 void SdchManager::AddObserver(SdchObserver* observer) {
320 observers_.AddObserver(observer); 323 observers_.AddObserver(observer);
321 } 324 }
322 325
323 void SdchManager::RemoveObserver(SdchObserver* observer) { 326 void SdchManager::RemoveObserver(SdchObserver* observer) {
324 observers_.RemoveObserver(observer); 327 observers_.RemoveObserver(observer);
325 } 328 }
326 329
330 void SdchManager::DumpMemoryStats(
331 base::trace_event::ProcessMemoryDump* pmd,
332 const std::string& parent_dump_absolute_name) const {
333 // If there are no dictionaries stored, return early without creating a new
334 // MemoryAllocatorDump.
335 size_t total_count = dictionaries_.size();
336 if (total_count == 0)
337 return;
338 std::string name = base::StringPrintf("net/sdch_manager_%p", this);
339 base::trace_event::MemoryAllocatorDump* dump = pmd->GetAllocatorDump(name);
340 if (dump == nullptr) {
341 dump = pmd->CreateAllocatorDump(name);
342 size_t total_size = 0;
343 for (const auto& dictionary : dictionaries_) {
344 total_size += dictionary.second->data.text().size();
345 }
346 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
347 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
348 total_size);
349 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameObjectCount,
350 base::trace_event::MemoryAllocatorDump::kUnitsObjects,
351 total_count);
352 }
353 // Create an empty row under parent's dump so size can be attributed correctly
354 // if |this| is shared between URLRequestContexts.
355 base::trace_event::MemoryAllocatorDump* empty_row_dump =
356 pmd->CreateAllocatorDump(parent_dump_absolute_name + "/sdch_manager");
357 pmd->AddOwnershipEdge(empty_row_dump->guid(), dump->guid());
358 }
359
327 SdchProblemCode SdchManager::AddSdchDictionary( 360 SdchProblemCode SdchManager::AddSdchDictionary(
328 const std::string& dictionary_text, 361 const std::string& dictionary_text,
329 const GURL& dictionary_url, 362 const GURL& dictionary_url,
330 std::string* server_hash_p) { 363 std::string* server_hash_p) {
331 DCHECK(thread_checker_.CalledOnValidThread()); 364 DCHECK(thread_checker_.CalledOnValidThread());
332 std::string client_hash; 365 std::string client_hash;
333 std::string server_hash; 366 std::string server_hash;
334 GenerateHash(dictionary_text, &client_hash, &server_hash); 367 GenerateHash(dictionary_text, &client_hash, &server_hash);
335 if (dictionaries_.find(server_hash) != dictionaries_.end()) 368 if (dictionaries_.find(server_hash) != dictionaries_.end())
336 return SDCH_DICTIONARY_ALREADY_LOADED; // Already loaded. 369 return SDCH_DICTIONARY_ALREADY_LOADED; // Already loaded.
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 entry_dict->SetInteger("tries", it->second.count); 527 entry_dict->SetInteger("tries", it->second.count);
495 entry_dict->SetInteger("reason", it->second.reason); 528 entry_dict->SetInteger("reason", it->second.reason);
496 entry_list->Append(std::move(entry_dict)); 529 entry_list->Append(std::move(entry_dict));
497 } 530 }
498 value->Set("blacklisted", std::move(entry_list)); 531 value->Set("blacklisted", std::move(entry_list));
499 532
500 return std::move(value); 533 return std::move(value);
501 } 534 }
502 535
503 } // namespace net 536 } // namespace net
OLDNEW
« no previous file with comments | « net/base/sdch_manager.h ('k') | net/base/sdch_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698