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

Side by Side Diff: content/browser/dom_storage/dom_storage_area.cc

Issue 1906243002: [tracing] Add a memory dump provider for DOM storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix loop. Created 4 years, 8 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/dom_storage/dom_storage_area.h" 5 #include "content/browser/dom_storage/dom_storage_area.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cctype> // for std::isalnum
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/location.h" 11 #include "base/location.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
13 #include "base/process/process_info.h" 14 #include "base/process/process_info.h"
15 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
15 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "base/trace_event/memory_dump_manager.h"
19 #include "base/trace_event/process_memory_dump.h"
16 #include "content/browser/dom_storage/dom_storage_namespace.h" 20 #include "content/browser/dom_storage/dom_storage_namespace.h"
17 #include "content/browser/dom_storage/dom_storage_task_runner.h" 21 #include "content/browser/dom_storage/dom_storage_task_runner.h"
18 #include "content/browser/dom_storage/local_storage_database_adapter.h" 22 #include "content/browser/dom_storage/local_storage_database_adapter.h"
19 #include "content/browser/dom_storage/session_storage_database.h" 23 #include "content/browser/dom_storage/session_storage_database.h"
20 #include "content/browser/dom_storage/session_storage_database_adapter.h" 24 #include "content/browser/dom_storage/session_storage_database_adapter.h"
21 #include "content/common/dom_storage/dom_storage_map.h" 25 #include "content/common/dom_storage/dom_storage_map.h"
22 #include "content/common/dom_storage/dom_storage_types.h" 26 #include "content/common/dom_storage/dom_storage_types.h"
23 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
24 #include "storage/browser/database/database_util.h" 28 #include "storage/browser/database/database_util.h"
25 #include "storage/common/database/database_identifier.h" 29 #include "storage/common/database/database_identifier.h"
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 if (!backing_) 327 if (!backing_)
324 return; 328 return;
325 329
326 bool success = task_runner_->PostShutdownBlockingTask( 330 bool success = task_runner_->PostShutdownBlockingTask(
327 FROM_HERE, 331 FROM_HERE,
328 DOMStorageTaskRunner::COMMIT_SEQUENCE, 332 DOMStorageTaskRunner::COMMIT_SEQUENCE,
329 base::Bind(&DOMStorageArea::ShutdownInCommitSequence, this)); 333 base::Bind(&DOMStorageArea::ShutdownInCommitSequence, this));
330 DCHECK(success); 334 DCHECK(success);
331 } 335 }
332 336
337 void DOMStorageArea::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd) {
338 if (!map_->bytes_used())
339 return;
340 // Limit the url length to 50 and strip special characters.
341 std::string url = origin_.spec().substr(0, 50);
342 for (size_t index = 0; index < url.size(); ++index) {
343 if (!std::isalnum(url[index]))
344 url[index] = '_';
michaeln 2016/04/22 23:39:41 From a privacy perspective, is it ok to capture UR
ssid 2016/04/23 00:19:15 Actually traces contain lot of sensitive informati
345 }
346 std::string name = StringPrintf("dom_storage/%s/%p", url.c_str(), this);
347 auto mad = pmd->CreateAllocatorDump(name + "/storage_map");
348 mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
349 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
350 map_->bytes_used());
351
352 const char* system_allocator_name =
353 base::trace_event::MemoryDumpManager::GetInstance()
354 ->system_allocator_pool_name();
355 if (system_allocator_name)
356 pmd->AddSuballocation(mad->guid(), system_allocator_name);
357 // TODO(ssid): Add memory usage of backing storage crbug.com/605785.
358 }
359
333 void DOMStorageArea::InitialImportIfNeeded() { 360 void DOMStorageArea::InitialImportIfNeeded() {
334 if (is_initial_import_done_) 361 if (is_initial_import_done_)
335 return; 362 return;
336 363
337 DCHECK(backing_.get()); 364 DCHECK(backing_.get());
338 365
339 base::TimeTicks before = base::TimeTicks::Now(); 366 base::TimeTicks before = base::TimeTicks::Now();
340 DOMStorageValuesMap initial_values; 367 DOMStorageValuesMap initial_values;
341 backing_->ReadAllValues(&initial_values); 368 backing_->ReadAllValues(&initial_values);
342 map_->SwapValues(&initial_values); 369 map_->SwapValues(&initial_values);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 commit_batch_->clear_all_first, 502 commit_batch_->clear_all_first,
476 commit_batch_->changed_values); 503 commit_batch_->changed_values);
477 DCHECK(success); 504 DCHECK(success);
478 } 505 }
479 commit_batch_.reset(); 506 commit_batch_.reset();
480 backing_.reset(); 507 backing_.reset();
481 session_storage_backing_ = NULL; 508 session_storage_backing_ = NULL;
482 } 509 }
483 510
484 } // namespace content 511 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/dom_storage/dom_storage_area.h ('k') | content/browser/dom_storage/dom_storage_namespace.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698