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

Unified Diff: base/trace_event/memory_allocator_attributes_type_info.cc

Issue 1124763003: Update from https://crrev.com/327068 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: update nacl, buildtools, fix display_change_notifier_unittest Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: base/trace_event/memory_allocator_attributes_type_info.cc
diff --git a/base/trace_event/memory_allocator_attributes_type_info.cc b/base/trace_event/memory_allocator_attributes_type_info.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7d1e61cada7f3423a2d48e7b188fbf13b8195f2c
--- /dev/null
+++ b/base/trace_event/memory_allocator_attributes_type_info.cc
@@ -0,0 +1,61 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/trace_event/memory_allocator_attributes_type_info.h"
+
+#include "base/lazy_instance.h"
+#include "base/logging.h"
+
+namespace base {
+namespace trace_event {
+
+namespace {
+base::LazyInstance<const std::string> kNotFound = LAZY_INSTANCE_INITIALIZER;
+
+std::string GetKey(const std::string& allocator_name,
+ const std::string& attribute_name) {
+ return allocator_name + "/" + attribute_name;
+}
+} // namespace
+
+MemoryAllocatorAttributesTypeInfo::MemoryAllocatorAttributesTypeInfo() {
+}
+
+MemoryAllocatorAttributesTypeInfo::~MemoryAllocatorAttributesTypeInfo() {
+}
+
+const std::string& MemoryAllocatorAttributesTypeInfo::Get(
+ const std::string& allocator_name,
+ const std::string& attribute_name) const {
+ auto it = type_info_map_.find(GetKey(allocator_name, attribute_name));
+ if (it == type_info_map_.end())
+ return kNotFound.Get();
+ return it->second;
+}
+
+void MemoryAllocatorAttributesTypeInfo::Set(const std::string& allocator_name,
+ const std::string& attribute_name,
+ const std::string& attribute_type) {
+ std::string key = GetKey(allocator_name, attribute_name);
+ DCHECK_EQ(0u, type_info_map_.count(key));
+ type_info_map_[key] = attribute_type;
+}
+
+bool MemoryAllocatorAttributesTypeInfo::Exists(
+ const std::string& allocator_name,
+ const std::string& attribute_name) const {
+ return type_info_map_.count(GetKey(allocator_name, attribute_name)) == 1;
+}
+
+void MemoryAllocatorAttributesTypeInfo::Update(
+ const MemoryAllocatorAttributesTypeInfo& other) {
+ for (auto it = other.type_info_map_.begin();
+ it != other.type_info_map_.end(); ++it) {
+ bool no_duplicates = type_info_map_.insert(*it).second;
+ DCHECK(no_duplicates) << "Duplicated allocator attribute " << it->first;
+ }
+}
+
+} // namespace trace_event
+} // namespace base

Powered by Google App Engine
This is Rietveld 408576698