Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: chrome/browser/metrics/leak_detector/leak_detector_remote_controller.h

Issue 2062743002: Randomly enable leak detector based on probability parameter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use RenderThreadObserver interface to shutdown remote client on same thread Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_LEAK_DETECTOR_REMOTE_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_METRICS_LEAK_DETECTOR_LEAK_DETECTOR_REMOTE_CONTROLLER_H_
6 #define CHROME_BROWSER_METRICS_LEAK_DETECTOR_LEAK_DETECTOR_REMOTE_CONTROLLER_H_ 6 #define CHROME_BROWSER_METRICS_LEAK_DETECTOR_LEAK_DETECTOR_REMOTE_CONTROLLER_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "components/metrics/leak_detector/leak_detector.mojom.h" 12 #include "components/metrics/leak_detector/leak_detector.mojom.h"
13 #include "components/metrics/proto/memory_leak_report.pb.h" 13 #include "components/metrics/proto/memory_leak_report.pb.h"
14 #include "mojo/public/cpp/bindings/interface_request.h" 14 #include "mojo/public/cpp/bindings/interface_request.h"
15 #include "mojo/public/cpp/bindings/strong_binding.h" 15 #include "mojo/public/cpp/bindings/strong_binding.h"
16 16
17 namespace metrics { 17 namespace metrics {
18 18
19 // This class acts as an interface to LeakDetector clients running on processes 19 // This class acts as an interface to LeakDetector clients running on processes
20 // other than its own (the browser process). 20 // other than its own (the browser process).
21 class LeakDetectorRemoteController : public mojom::LeakDetector { 21 class LeakDetectorRemoteController : public mojom::LeakDetector {
22 public: 22 public:
23 // Interface class to be implemented by a local controller class that provides 23 // Interface class to be implemented by a local controller class that provides
24 // leak detector parameters and can pass leak reports to UMA. 24 // leak detector parameters and can pass leak reports to UMA.
25 class LocalController { 25 class LocalController {
26 public: 26 public:
27 virtual ~LocalController() {} 27 virtual ~LocalController() {}
28 28
29 // Returns a set of leak detection params to be used when initializing the 29 // Returns a set of leak detection params to be used when initializing the
30 // leak detector on a remote process. 30 // leak detector on a remote process. The controller may vary the parameters
31 virtual MemoryLeakReportProto::Params GetParams() const = 0; 31 // between each call to this function, and to change its internal state.
32 // Hence this is function is not const.
33 virtual MemoryLeakReportProto::Params GetParamsAndRecordRequest() = 0;
32 34
33 // Pass a vector of memory leak reports provided by a remote process to the 35 // Pass a vector of memory leak reports provided by a remote process to the
34 // local controller class. 36 // local controller class.
35 virtual void SendLeakReports( 37 virtual void SendLeakReports(
36 const std::vector<MemoryLeakReportProto>& reports) = 0; 38 const std::vector<MemoryLeakReportProto>& reports) = 0;
37 39
38 // Signal that a remote process that had been running the leak detector 40 // Signal that a remote process that had been running the leak detector
39 // (i.e. been given params with sampling_rate = 0). 41 // (i.e. been given params with sampling_rate = 0).
40 virtual void OnRemoteProcessShutdown() = 0; 42 virtual void OnRemoteProcessShutdown() = 0;
41 }; 43 };
42 44
43 ~LeakDetectorRemoteController() override; 45 ~LeakDetectorRemoteController() override;
44 46
45 static void Create(mojom::LeakDetectorRequest request); 47 static void Create(mojom::LeakDetectorRequest request);
46 48
47 // mojom::LeakDetector: 49 // mojom::LeakDetector:
48 void GetParams( 50 void GetParams(
49 const mojom::LeakDetector::GetParamsCallback& callback) override; 51 const mojom::LeakDetector::GetParamsCallback& callback) override;
50 void SendLeakReports(std::vector<mojom::MemoryLeakReportPtr>) override; 52 void SendLeakReports(std::vector<mojom::MemoryLeakReportPtr>) override;
51 53
52 // Sets a global pointer to a LocalController implementation. The global 54 // Sets a global pointer to a LocalController implementation. The global
53 // pointer is defined in the .cc file. 55 // pointer is defined in the .cc file.
54 static void SetLocalControllerInstance(LocalController* controller); 56 static void SetLocalControllerInstance(LocalController* controller);
55 57
56 private: 58 private:
57 explicit LeakDetectorRemoteController(mojom::LeakDetectorRequest request); 59 explicit LeakDetectorRemoteController(mojom::LeakDetectorRequest request);
58 60
61 // Gets called when the remote process terminates and the Mojo connection gets
62 // closed as a result.
63 void OnRemoteProcessShutdown();
64
59 mojo::StrongBinding<mojom::LeakDetector> binding_; 65 mojo::StrongBinding<mojom::LeakDetector> binding_;
60 66
67 // Indicates whether remote process received MemoryLeakReportProto::Params
68 // with a non-zero sampling rate, i.e. enabled leak detector.
69 bool leak_detector_enabled_on_remote_process_;
70
61 DISALLOW_COPY_AND_ASSIGN(LeakDetectorRemoteController); 71 DISALLOW_COPY_AND_ASSIGN(LeakDetectorRemoteController);
62 }; 72 };
63 73
64 } // namespace metrics 74 } // namespace metrics
65 75
66 #endif // CHROME_BROWSER_METRICS_LEAK_DETECTOR_LEAK_DETECTOR_REMOTE_CONTROLLER_ H_ 76 #endif // CHROME_BROWSER_METRICS_LEAK_DETECTOR_LEAK_DETECTOR_REMOTE_CONTROLLER_ H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698