OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/trace_event/memory_allocator_dump_guid.h" | 5 #include "base/trace_event/memory_allocator_dump_guid.h" |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/sha1.h" | 8 #include "base/sha1.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 | 10 |
11 namespace base { | 11 namespace base { |
12 namespace trace_event { | 12 namespace trace_event { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | |
16 bool g_use_shared_memory_guid_for_testing = false; | |
17 | |
15 uint64_t HashString(const std::string& str) { | 18 uint64_t HashString(const std::string& str) { |
16 uint64_t hash[(kSHA1Length + sizeof(uint64_t) - 1) / sizeof(uint64_t)] = {0}; | 19 uint64_t hash[(kSHA1Length + sizeof(uint64_t) - 1) / sizeof(uint64_t)] = {0}; |
17 SHA1HashBytes(reinterpret_cast<const unsigned char*>(str.data()), str.size(), | 20 SHA1HashBytes(reinterpret_cast<const unsigned char*>(str.data()), str.size(), |
18 reinterpret_cast<unsigned char*>(hash)); | 21 reinterpret_cast<unsigned char*>(hash)); |
19 return hash[0]; | 22 return hash[0]; |
20 } | 23 } |
24 | |
21 } // namespace | 25 } // namespace |
22 | 26 |
27 // static | |
28 bool MemoryAllocatorDumpGuid::UseSharedMemoryBasedGUIDs() { | |
29 // TODO(hajimehoshi): This should just become the default behavior once the | |
30 // Mojo GUID (crbug.com/604726) is fixed. | |
31 if (g_use_shared_memory_guid_for_testing) | |
Primiano Tucci (use gerrit)
2017/06/08 15:09:33
I think the global var should just be g_use_shred_
ssid
2017/06/08 18:44:23
Ah yes, presubmit didn't complain for some reason!
| |
32 return true; | |
33 return false; | |
34 } | |
35 | |
36 // static | |
37 void MemoryAllocatorDumpGuid::SetUseSharedMemoryBasedGUIDsForTesting() { | |
38 g_use_shared_memory_guid_for_testing = true; | |
39 } | |
40 | |
23 MemoryAllocatorDumpGuid::MemoryAllocatorDumpGuid(uint64_t guid) : guid_(guid) {} | 41 MemoryAllocatorDumpGuid::MemoryAllocatorDumpGuid(uint64_t guid) : guid_(guid) {} |
24 | 42 |
25 MemoryAllocatorDumpGuid::MemoryAllocatorDumpGuid() | 43 MemoryAllocatorDumpGuid::MemoryAllocatorDumpGuid() |
26 : MemoryAllocatorDumpGuid(0u) { | 44 : MemoryAllocatorDumpGuid(0u) { |
27 } | 45 } |
28 | 46 |
29 MemoryAllocatorDumpGuid::MemoryAllocatorDumpGuid(const std::string& guid_str) | 47 MemoryAllocatorDumpGuid::MemoryAllocatorDumpGuid(const std::string& guid_str) |
30 : MemoryAllocatorDumpGuid(HashString(guid_str)) { | 48 : MemoryAllocatorDumpGuid(HashString(guid_str)) { |
31 } | 49 } |
32 | 50 |
33 std::string MemoryAllocatorDumpGuid::ToString() const { | 51 std::string MemoryAllocatorDumpGuid::ToString() const { |
34 return StringPrintf("%" PRIx64, guid_); | 52 return StringPrintf("%" PRIx64, guid_); |
35 } | 53 } |
36 | 54 |
37 } // namespace trace_event | 55 } // namespace trace_event |
38 } // namespace base | 56 } // namespace base |
OLD | NEW |