Commit 57bd00e1 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Move LeakTracker out of base/.

It is only used in ios/components/io_thread/, so move it there.

Change-Id: Icc86011f711f2325a7bd33931fd8b12d6e2164ad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2373366Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Reviewed-by: default avatarMike Dougherty <michaeldo@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#820838}
parent 86539c31
...@@ -215,7 +215,6 @@ component("base") { ...@@ -215,7 +215,6 @@ component("base") {
"debug/dump_without_crashing.cc", "debug/dump_without_crashing.cc",
"debug/dump_without_crashing.h", "debug/dump_without_crashing.h",
"debug/leak_annotations.h", "debug/leak_annotations.h",
"debug/leak_tracker.h",
"debug/profiler.cc", "debug/profiler.cc",
"debug/profiler.h", "debug/profiler.h",
"debug/stack_trace.cc", "debug/stack_trace.cc",
...@@ -2722,7 +2721,6 @@ test("base_unittests") { ...@@ -2722,7 +2721,6 @@ test("base_unittests") {
"debug/alias_unittest.cc", "debug/alias_unittest.cc",
"debug/crash_logging_unittest.cc", "debug/crash_logging_unittest.cc",
"debug/debugger_unittest.cc", "debug/debugger_unittest.cc",
"debug/leak_tracker_unittest.cc",
"debug/stack_trace_unittest.cc", "debug/stack_trace_unittest.cc",
"debug/task_trace_unittest.cc", "debug/task_trace_unittest.cc",
"deferred_sequenced_task_runner_unittest.cc", "deferred_sequenced_task_runner_unittest.cc",
......
...@@ -23,13 +23,17 @@ component("io_thread") { ...@@ -23,13 +23,17 @@ component("io_thread") {
sources = [ sources = [
"ios_io_thread.h", "ios_io_thread.h",
"ios_io_thread.mm", "ios_io_thread.mm",
"leak_tracker.h",
] ]
} }
source_set("unit_tests") { source_set("unit_tests") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
testonly = true testonly = true
sources = [ "ios_io_thread_unittest.mm" ] sources = [
"ios_io_thread_unittest.mm",
"leak_tracker_unittest.cc",
]
deps = [ deps = [
":io_thread", ":io_thread",
"//base", "//base",
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "base/check_op.h" #include "base/check_op.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/debug/leak_tracker.h"
#include "base/environment.h" #include "base/environment.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/metrics/field_trial.h" #include "base/metrics/field_trial.h"
...@@ -33,6 +32,7 @@ ...@@ -33,6 +32,7 @@
#include "components/proxy_config/pref_proxy_config_tracker.h" #include "components/proxy_config/pref_proxy_config_tracker.h"
#include "components/variations/variations_associated_data.h" #include "components/variations/variations_associated_data.h"
#include "components/version_info/version_info.h" #include "components/version_info/version_info.h"
#include "ios/components/io_thread/leak_tracker.h"
#include "ios/web/common/user_agent.h" #include "ios/web/common/user_agent.h"
#include "ios/web/public/thread/web_task_traits.h" #include "ios/web/public/thread/web_task_traits.h"
#include "ios/web/public/thread/web_thread.h" #include "ios/web/public/thread/web_thread.h"
...@@ -123,7 +123,7 @@ class SystemURLRequestContextGetter : public net::URLRequestContextGetter { ...@@ -123,7 +123,7 @@ class SystemURLRequestContextGetter : public net::URLRequestContextGetter {
IOSIOThread* io_thread_; // Weak pointer, owned by ApplicationContext. IOSIOThread* io_thread_; // Weak pointer, owned by ApplicationContext.
scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_; LeakTracker<SystemURLRequestContextGetter> leak_tracker_;
}; };
SystemURLRequestContextGetter::SystemURLRequestContextGetter( SystemURLRequestContextGetter::SystemURLRequestContextGetter(
...@@ -307,7 +307,7 @@ void IOSIOThread::CleanUp() { ...@@ -307,7 +307,7 @@ void IOSIOThread::CleanUp() {
delete globals_; delete globals_;
globals_ = nullptr; globals_ = nullptr;
base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks();
} }
void IOSIOThread::CreateDefaultAuthHandlerFactory() { void IOSIOThread::CreateDefaultAuthHandlerFactory() {
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef BASE_DEBUG_LEAK_TRACKER_H_ #ifndef IOS_COMPONENTS_IO_THREAD_LEAK_TRACKER_H_
#define BASE_DEBUG_LEAK_TRACKER_H_ #define IOS_COMPONENTS_IO_THREAD_LEAK_TRACKER_H_
#include <stddef.h> #include <stddef.h>
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
// class URLRequest { // class URLRequest {
// ... // ...
// private: // private:
// base::LeakTracker<URLRequest> leak_tracker_; // LeakTracker<URLRequest> leak_tracker_;
// }; // };
// //
// //
...@@ -48,13 +48,10 @@ ...@@ -48,13 +48,10 @@
// //
// If ENABLE_LEAK_TRACKER is not defined, then the check has no effect. // If ENABLE_LEAK_TRACKER is not defined, then the check has no effect.
namespace base {
namespace debug {
#ifndef ENABLE_LEAK_TRACKER #ifndef ENABLE_LEAK_TRACKER
// If leak tracking is disabled, do nothing. // If leak tracking is disabled, do nothing.
template<typename T> template <typename T>
class LeakTracker { class LeakTracker {
public: public:
// This destructor suppresses warnings about instances of this class not being // This destructor suppresses warnings about instances of this class not being
...@@ -68,16 +65,12 @@ class LeakTracker { ...@@ -68,16 +65,12 @@ class LeakTracker {
// If leak tracking is enabled we track where the object was allocated from. // If leak tracking is enabled we track where the object was allocated from.
template<typename T> template <typename T>
class LeakTracker : public LinkNode<LeakTracker<T> > { class LeakTracker : public base::LinkNode<LeakTracker<T>> {
public: public:
LeakTracker() { LeakTracker() { instances()->Append(this); }
instances()->Append(this);
}
~LeakTracker() { ~LeakTracker() { this->RemoveFromList(); }
this->RemoveFromList();
}
static void CheckForLeaks() { static void CheckForLeaks() {
// Walk the allocation list and print each entry it contains. // Walk the allocation list and print each entry it contains.
...@@ -87,12 +80,12 @@ class LeakTracker : public LinkNode<LeakTracker<T> > { ...@@ -87,12 +80,12 @@ class LeakTracker : public LinkNode<LeakTracker<T> > {
// This way if we hit the CHECK() in a release build, the leak // This way if we hit the CHECK() in a release build, the leak
// information will be available in mini-dump. // information will be available in mini-dump.
const size_t kMaxStackTracesToCopyOntoStack = 3; const size_t kMaxStackTracesToCopyOntoStack = 3;
StackTrace stacktraces[kMaxStackTracesToCopyOntoStack]; base::debug::StackTrace stacktraces[kMaxStackTracesToCopyOntoStack];
for (LinkNode<LeakTracker<T> >* node = instances()->head(); for (base::LinkNode<LeakTracker<T>>* node = instances()->head();
node != instances()->end(); node != instances()->end(); node = node->next()) {
node = node->next()) { base::debug::StackTrace& allocation_stack =
StackTrace& allocation_stack = node->value()->allocation_stack_; node->value()->allocation_stack_;
if (count < kMaxStackTracesToCopyOntoStack) if (count < kMaxStackTracesToCopyOntoStack)
stacktraces[count] = allocation_stack; stacktraces[count] = allocation_stack;
...@@ -117,9 +110,8 @@ class LeakTracker : public LinkNode<LeakTracker<T> > { ...@@ -117,9 +110,8 @@ class LeakTracker : public LinkNode<LeakTracker<T> > {
static int NumLiveInstances() { static int NumLiveInstances() {
// Walk the allocation list and count how many entries it has. // Walk the allocation list and count how many entries it has.
int count = 0; int count = 0;
for (LinkNode<LeakTracker<T> >* node = instances()->head(); for (base::LinkNode<LeakTracker<T>>* node = instances()->head();
node != instances()->end(); node != instances()->end(); node = node->next()) {
node = node->next()) {
++count; ++count;
} }
return count; return count;
...@@ -127,17 +119,14 @@ class LeakTracker : public LinkNode<LeakTracker<T> > { ...@@ -127,17 +119,14 @@ class LeakTracker : public LinkNode<LeakTracker<T> > {
private: private:
// Each specialization of LeakTracker gets its own static storage. // Each specialization of LeakTracker gets its own static storage.
static LinkedList<LeakTracker<T> >* instances() { static base::LinkedList<LeakTracker<T>>* instances() {
static LinkedList<LeakTracker<T> > list; static base::LinkedList<LeakTracker<T>> list;
return &list; return &list;
} }
StackTrace allocation_stack_; base::debug::StackTrace allocation_stack_;
}; };
#endif // ENABLE_LEAK_TRACKER #endif // ENABLE_LEAK_TRACKER
} // namespace debug #endif // IOS_COMPONENTS_IO_THREAD_LEAK_TRACKER_H_
} // namespace base
#endif // BASE_DEBUG_LEAK_TRACKER_H_
...@@ -2,15 +2,12 @@ ...@@ -2,15 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/debug/leak_tracker.h" #include "ios/components/io_thread/leak_tracker.h"
#include <memory> #include <memory>
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace base {
namespace debug {
namespace { namespace {
class ClassA { class ClassA {
...@@ -110,6 +107,3 @@ TEST(LeakTrackerTest, NoOpCheckForLeaks) { ...@@ -110,6 +107,3 @@ TEST(LeakTrackerTest, NoOpCheckForLeaks) {
#endif // ENABLE_LEAK_TRACKER #endif // ENABLE_LEAK_TRACKER
} // namespace } // namespace
} // namespace debug
} // namespace base
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment