| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/metrics/leak_detector/leak_detector.h" | 5 #include "components/metrics/leak_detector/leak_detector.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 #endif // defined(OS_CHROMEOS) | 187 #endif // defined(OS_CHROMEOS) |
| 188 | 188 |
| 189 task_runner_ = task_runner; | 189 task_runner_ = task_runner; |
| 190 | 190 |
| 191 // CustomAllocator can use the default allocator, as long as the hook | 191 // CustomAllocator can use the default allocator, as long as the hook |
| 192 // functions can handle recursive calls. | 192 // functions can handle recursive calls. |
| 193 leak_detector::CustomAllocator::Initialize(); | 193 leak_detector::CustomAllocator::Initialize(); |
| 194 | 194 |
| 195 // The initialization should be done only once. Check for this by examining | 195 // The initialization should be done only once. Check for this by examining |
| 196 // whether |impl_| has already been initialized. | 196 // whether |impl_| has already been initialized. |
| 197 CHECK(!impl_.get()) << "Cannot initialize LeakDetector more than once!"; | 197 // Cannot initialize LeakDetector more than once! |
| 198 CHECK(!impl_.get()); |
| 198 impl_.reset(new leak_detector::LeakDetectorImpl( | 199 impl_.reset(new leak_detector::LeakDetectorImpl( |
| 199 mapping.addr, mapping.size, params.size_suspicion_threshold(), | 200 mapping.addr, mapping.size, params.size_suspicion_threshold(), |
| 200 params.call_stack_suspicion_threshold())); | 201 params.call_stack_suspicion_threshold())); |
| 201 | 202 |
| 202 // Register allocator hook functions. This must be done last since the | 203 // Register allocator hook functions. This must be done last since the |
| 203 // preceding code will need to call the allocator. | 204 // preceding code will need to call the allocator. |
| 204 base::allocator::SetHooks(&AllocHook, &FreeHook); | 205 base::allocator::SetHooks(&AllocHook, &FreeHook); |
| 205 } | 206 } |
| 206 | 207 |
| 207 void LeakDetector::AddObserver(Observer* observer) { | 208 void LeakDetector::AddObserver(Observer* observer) { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 } | 347 } |
| 347 | 348 |
| 348 { | 349 { |
| 349 base::AutoLock lock(observers_lock_); | 350 base::AutoLock lock(observers_lock_); |
| 350 for (Observer& observer : observers_) | 351 for (Observer& observer : observers_) |
| 351 observer.OnLeaksFound(reports); | 352 observer.OnLeaksFound(reports); |
| 352 } | 353 } |
| 353 } | 354 } |
| 354 | 355 |
| 355 } // namespace metrics | 356 } // namespace metrics |
| OLD | NEW |