Index: base/allocator/allocator_interception_mac.mm |
diff --git a/base/allocator/allocator_interception_mac.mm b/base/allocator/allocator_interception_mac.mm |
index 70c40c45c2055ce7212d89872d49575120145364..6a72e232bf07fbdf6ee35c85a42cd2efed111b36 100644 |
--- a/base/allocator/allocator_interception_mac.mm |
+++ b/base/allocator/allocator_interception_mac.mm |
@@ -29,11 +29,15 @@ |
#include "base/allocator/features.h" |
#include "base/allocator/malloc_zone_functions_mac.h" |
+#include "base/base_switches.h" |
+#include "base/bind.h" |
+#include "base/command_line.h" |
Primiano Tucci (use gerrit)
2017/04/03 08:03:24
nit: you don't need command-line and base_switches
|
#include "base/logging.h" |
#include "base/mac/mac_util.h" |
#include "base/mac/mach_logging.h" |
#include "base/process/memory.h" |
#include "base/scoped_clear_errno.h" |
+#include "base/threading/sequenced_task_runner_handle.h" |
#include "build/build_config.h" |
#include "third_party/apple_apsl/CFBase.h" |
@@ -524,5 +528,36 @@ void UninterceptMallocZonesForTesting() { |
ClearAllMallocZonesForTesting(); |
} |
+namespace { |
+ |
+void ShimNewMallocZones(base::Time end_time, base::TimeDelta delay) { |
+ StoreFunctionsForAllZones(); |
+ |
+ // Use the functions for the default zone as a template to replace those |
+ // new zones. |
+ ChromeMallocZone* default_zone = |
+ reinterpret_cast<ChromeMallocZone*>(malloc_default_zone()); |
+ DCHECK(IsMallocZoneAlreadyStored(default_zone)); |
+ |
+ MallocZoneFunctions new_functions; |
+ StoreZoneFunctions(default_zone, &new_functions); |
+ ReplaceFunctionsForStoredZones(&new_functions); |
+ |
+ if (base::Time::Now() > end_time) |
+ return; |
+ |
+ base::TimeDelta next_delay = delay * 2; |
+ SequencedTaskRunnerHandle::Get()->PostDelayedTask( |
+ FROM_HERE, base::Bind(&ShimNewMallocZones, end_time, next_delay), delay); |
+} |
+ |
+} // namespace |
+ |
+void PeriodicallyShimNewMallocZones() { |
+ base::Time end_time = base::Time::Now() + base::TimeDelta::FromMinutes(1); |
+ base::TimeDelta initial_delay = base::TimeDelta::FromSeconds(1); |
+ ShimNewMallocZones(end_time, initial_delay); |
+} |
+ |
} // namespace allocator |
} // namespace base |