| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/metrics/leak_detector/leak_detector.h" |
| 6 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "content/public/browser/browser_thread.h" |
| 10 |
| 11 namespace metrics { |
| 12 |
| 13 LeakDetector::LeakReport::LeakReport() {} |
| 14 |
| 15 LeakDetector::LeakReport::~LeakReport() {} |
| 16 |
| 17 LeakDetector::LeakDetector(float sampling_rate, |
| 18 int max_stack_depth, |
| 19 uint64_t analysis_interval_bytes, |
| 20 int size_suspicion_threshold, |
| 21 int call_stack_suspicion_threshold) |
| 22 : weak_factory_(this) {} |
| 23 |
| 24 LeakDetector::LeakDetector() : LeakDetector(1.0f, 4, 32 * 1024 * 1024, 4, 4) {} |
| 25 |
| 26 LeakDetector::~LeakDetector() {} |
| 27 |
| 28 void LeakDetector::AddObserver(Observer* observer) { |
| 29 DCHECK(thread_checker_.CalledOnValidThread()); |
| 30 observers_.AddObserver(observer); |
| 31 } |
| 32 |
| 33 void LeakDetector::RemoveObserver(Observer* observer) { |
| 34 DCHECK(thread_checker_.CalledOnValidThread()); |
| 35 observers_.RemoveObserver(observer); |
| 36 } |
| 37 |
| 38 void LeakDetector::NotifyObservers(const std::vector<LeakReport>& reports) { |
| 39 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
| 40 content::BrowserThread::PostTask(content::BrowserThread::UI, |
| 41 FROM_HERE, |
| 42 base::Bind(&LeakDetector::NotifyObservers, |
| 43 weak_factory_.GetWeakPtr(), |
| 44 reports)); |
| 45 return; |
| 46 } |
| 47 |
| 48 for (const LeakReport& report : reports) { |
| 49 FOR_EACH_OBSERVER(Observer, observers_, OnLeakFound(report)); |
| 50 } |
| 51 } |
| 52 |
| 53 } // namespace metrics |
| OLD | NEW |