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 #ifndef CHROME_BROWSER_METRICS_LEAK_DETECTOR_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_METRICS_LEAK_DETECTOR_CONTROLLER_H_ |
6 #define CHROME_BROWSER_METRICS_LEAK_DETECTOR_CONTROLLER_H_ | 6 #define CHROME_BROWSER_METRICS_LEAK_DETECTOR_CONTROLLER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/threading/thread_checker.h" | 11 #include "base/threading/thread_checker.h" |
12 #include "components/metrics/leak_detector/leak_detector.h" | |
13 #include "components/metrics/proto/memory_leak_report.pb.h" | 12 #include "components/metrics/proto/memory_leak_report.pb.h" |
14 | 13 |
15 namespace metrics { | 14 namespace metrics { |
16 | 15 |
17 // This class initializes the LeakDetector on the browser process and registers | 16 // This class initializes the LeakDetector on the browser process and registers |
18 // itself to be notified of leak reports. | 17 // itself to be notified of leak reports. |
19 class LeakDetectorController : public LeakDetector::Observer { | 18 class LeakDetectorController : public LeakDetector::Observer { |
20 public: | 19 public: |
21 LeakDetectorController(); | 20 LeakDetectorController(); |
22 ~LeakDetectorController() override; | 21 ~LeakDetectorController() override; |
23 | 22 |
24 // Retrieves all reports in |stored_reports_|, moving them to |*reports|. | 23 // Retrieves all reports in |stored_reports_|, moving them to |*reports|. |
25 // |stored_reports_| is empty afterwards. | 24 // |stored_reports_| is empty afterwards. |
26 void GetLeakReports(std::vector<MemoryLeakReportProto>* reports); | 25 void GetLeakReports(std::vector<MemoryLeakReportProto>* reports); |
27 | 26 |
28 protected: | 27 protected: |
29 // LeakDetector::Observer: | 28 // LeakDetector::Observer: |
30 void OnLeakFound(const LeakDetector::LeakReport& report) override; | 29 void OnLeakFound(const LeakDetector::LeakReport& report) override; |
31 | 30 |
32 private: | 31 private: |
33 // Leak detector interface object. | |
34 LeakDetector detector_; | |
35 | |
36 // All leak reports received through OnLeakFound() are stored in protobuf | 32 // All leak reports received through OnLeakFound() are stored in protobuf |
37 // format. | 33 // format. |
38 std::vector<MemoryLeakReportProto> stored_reports_; | 34 std::vector<MemoryLeakReportProto> stored_reports_; |
39 | 35 |
40 // For thread safety. | 36 // For thread safety. |
41 base::ThreadChecker thread_checker_; | 37 base::ThreadChecker thread_checker_; |
42 | 38 |
43 DISALLOW_COPY_AND_ASSIGN(LeakDetectorController); | 39 DISALLOW_COPY_AND_ASSIGN(LeakDetectorController); |
44 }; | 40 }; |
45 | 41 |
46 } // namespace metrics | 42 } // namespace metrics |
47 | 43 |
48 #endif // CHROME_BROWSER_METRICS_LEAK_DETECTOR_CONTROLLER_H_ | 44 #endif // CHROME_BROWSER_METRICS_LEAK_DETECTOR_CONTROLLER_H_ |
OLD | NEW |