Chromium Code Reviews| Index: components/metrics/leak_detector/leak_detector.cc |
| diff --git a/components/metrics/leak_detector/leak_detector.cc b/components/metrics/leak_detector/leak_detector.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b3e5ed0786946aad6524390e17be1a07c23199d3 |
| --- /dev/null |
| +++ b/components/metrics/leak_detector/leak_detector.cc |
| @@ -0,0 +1,58 @@ |
| +// Copyright 2016 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 "components/metrics/leak_detector/leak_detector.h" |
| + |
| +#include <algorithm> |
| + |
| +#include "content/public/browser/browser_thread.h" |
| + |
| +using content::BrowserThread; |
|
Alexei Svitkine (slow)
2016/02/23 01:23:35
Nit: Just use the content:: prefix in the code dir
Simon Que
2016/02/23 02:38:29
Done.
|
| + |
| +namespace metrics { |
| + |
| +const base::Feature kEnableRuntimeMemoryLeakDetector = { |
|
Alexei Svitkine (slow)
2016/02/23 01:23:35
Nit: No =
Simon Que
2016/02/23 02:38:29
Done.
|
| + "enable-runtime-memory-leak-detector", base::FEATURE_DISABLED_BY_DEFAULT}; |
|
Alexei Svitkine (slow)
2016/02/23 01:23:35
Nit: "RuntimeMemoryLeakDetector"
Given you're not
Simon Que
2016/02/23 02:38:29
Done.
|
| + |
| +LeakDetector::LeakReport::LeakReport() {} |
| + |
| +LeakDetector::LeakReport::~LeakReport() {} |
| + |
| +LeakDetector::LeakDetector(float sampling_rate, |
| + int max_stack_depth, |
| + uint64_t analysis_interval_bytes, |
| + int size_suspicion_threshold, |
| + int call_stack_suspicion_threshold) |
| + : weak_factory_(this) {} |
| + |
| +LeakDetector::LeakDetector() : LeakDetector(1.0f, 4, 32 * 1024 * 1024, 4, 4) {} |
| + |
| +LeakDetector::~LeakDetector() {} |
| + |
| +void LeakDetector::AddObserver(Observer* observer) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + observers_.AddObserver(observer); |
| +} |
| + |
| +void LeakDetector::RemoveObserver(Observer* observer) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + observers_.RemoveObserver(observer); |
| +} |
| + |
| +void LeakDetector::NotifyObservers(const std::vector<LeakReport>& reports) { |
| + if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| + BrowserThread::PostTask(BrowserThread::UI, |
| + FROM_HERE, |
| + base::Bind(&LeakDetector::NotifyObservers, |
| + weak_factory_.GetWeakPtr(), |
| + reports)); |
| + return; |
| + } |
| + |
| + for (const LeakReport& report : reports) { |
| + FOR_EACH_OBSERVER(Observer, observers_, OnLeakFound(report)); |
| + } |
| +} |
| + |
| +} // namespace metrics |