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 "content/public/browser/browser_thread.h" |
| 8 |
| 9 namespace metrics { |
| 10 |
| 11 LeakDetector::LeakReport::LeakReport() {} |
| 12 |
| 13 LeakDetector::LeakReport::~LeakReport() {} |
| 14 |
| 15 LeakDetector::LeakDetector(float sampling_rate, |
| 16 size_t max_call_stack_unwind_depth, |
| 17 uint64_t analysis_interval_bytes, |
| 18 uint32_t size_suspicion_threshold, |
| 19 uint32_t call_stack_suspicion_threshold) |
| 20 : weak_factory_(this) { |
| 21 // TODO(sque): Connect this class to LeakDetectorImpl and base::allocator. |
| 22 } |
| 23 |
| 24 LeakDetector::~LeakDetector() {} |
| 25 |
| 26 void LeakDetector::AddObserver(Observer* observer) { |
| 27 DCHECK(thread_checker_.CalledOnValidThread()); |
| 28 observers_.AddObserver(observer); |
| 29 } |
| 30 |
| 31 void LeakDetector::RemoveObserver(Observer* observer) { |
| 32 DCHECK(thread_checker_.CalledOnValidThread()); |
| 33 observers_.RemoveObserver(observer); |
| 34 } |
| 35 |
| 36 void LeakDetector::NotifyObservers(const std::vector<LeakReport>& reports) { |
| 37 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
| 38 content::BrowserThread::PostTask( |
| 39 content::BrowserThread::UI, FROM_HERE, |
| 40 base::Bind(&LeakDetector::NotifyObservers, weak_factory_.GetWeakPtr(), |
| 41 reports)); |
| 42 return; |
| 43 } |
| 44 |
| 45 for (const LeakReport& report : reports) { |
| 46 FOR_EACH_OBSERVER(Observer, observers_, OnLeakFound(report)); |
| 47 } |
| 48 } |
| 49 |
| 50 } // namespace metrics |
OLD | NEW |