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

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

Issue 2326913003: Privatize StrongBinding lifetime management (Closed)
Patch Set: rebase Created 4 years, 3 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 #include "chrome/browser/metrics/leak_detector/leak_detector_remote_controller.h " 5 #include "chrome/browser/metrics/leak_detector/leak_detector_remote_controller.h "
6 6
7 #include "base/bind.h"
8 #include "base/callback.h"
7 #include "components/metrics/leak_detector/protobuf_to_mojo_converter.h" 9 #include "components/metrics/leak_detector/protobuf_to_mojo_converter.h"
8 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
11 #include "mojo/public/cpp/bindings/strong_binding.h"
9 12
10 namespace metrics { 13 namespace metrics {
11 14
12 namespace { 15 namespace {
13 16
14 // All instances of LeakDetectorRemoteController will need to reference a single 17 // All instances of LeakDetectorRemoteController will need to reference a single
15 // LocalController instance, referenced by this pointer. All remote LeakDetector 18 // LocalController instance, referenced by this pointer. All remote LeakDetector
16 // clients will get their params from and send leak reports to this instance. 19 // clients will get their params from and send leak reports to this instance.
17 LeakDetectorRemoteController::LocalController* g_local_controller = nullptr; 20 LeakDetectorRemoteController::LocalController* g_local_controller = nullptr;
18 21
19 } // namespace 22 } // namespace
20 23
21 LeakDetectorRemoteController::~LeakDetectorRemoteController() {} 24 LeakDetectorRemoteController::~LeakDetectorRemoteController() {}
22 25
23 // static 26 // static
24 void LeakDetectorRemoteController::Create(mojom::LeakDetectorRequest request) { 27 void LeakDetectorRemoteController::Create(mojom::LeakDetectorRequest request) {
25 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 28 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
26 new LeakDetectorRemoteController(std::move(request)); 29 std::unique_ptr<LeakDetectorRemoteController> controller =
30 base::WrapUnique(new LeakDetectorRemoteController);
31 base::Closure error_handler =
32 base::Bind(&LeakDetectorRemoteController::OnRemoteProcessShutdown,
33 base::Unretained(controller.get()));
34 auto binding =
35 mojo::MakeStrongBinding(std::move(controller), std::move(request));
36 binding->set_connection_error_handler(error_handler);
27 } 37 }
28 38
29 void LeakDetectorRemoteController::GetParams( 39 void LeakDetectorRemoteController::GetParams(
30 const mojom::LeakDetector::GetParamsCallback& callback) { 40 const mojom::LeakDetector::GetParamsCallback& callback) {
31 // If no controller exists, send an empty param protobuf. The remote caller 41 // If no controller exists, send an empty param protobuf. The remote caller
32 // should not initialize anything if the params are empty. 42 // should not initialize anything if the params are empty.
33 MemoryLeakReportProto_Params params; 43 MemoryLeakReportProto_Params params;
34 if (g_local_controller) { 44 if (g_local_controller) {
35 params = g_local_controller->GetParamsAndRecordRequest(); 45 params = g_local_controller->GetParamsAndRecordRequest();
36 // A non-zero sampling rate tells the remote process to enable the leak 46 // A non-zero sampling rate tells the remote process to enable the leak
(...skipping 24 matching lines...) Expand all
61 g_local_controller->SendLeakReports(report_protos); 71 g_local_controller->SendLeakReports(report_protos);
62 } 72 }
63 } 73 }
64 74
65 void LeakDetectorRemoteController::OnRemoteProcessShutdown() { 75 void LeakDetectorRemoteController::OnRemoteProcessShutdown() {
66 if (leak_detector_enabled_on_remote_process_ && g_local_controller) { 76 if (leak_detector_enabled_on_remote_process_ && g_local_controller) {
67 g_local_controller->OnRemoteProcessShutdown(); 77 g_local_controller->OnRemoteProcessShutdown();
68 } 78 }
69 } 79 }
70 80
71 LeakDetectorRemoteController::LeakDetectorRemoteController( 81 LeakDetectorRemoteController::LeakDetectorRemoteController()
72 mojom::LeakDetectorRequest request) 82 : leak_detector_enabled_on_remote_process_(false) {}
73 : binding_(this, std::move(request)),
74 leak_detector_enabled_on_remote_process_(false) {
75 binding_.set_connection_error_handler(
76 base::Bind(&LeakDetectorRemoteController::OnRemoteProcessShutdown,
77 base::Unretained(this)));
78 }
79 83
80 // static 84 // static
81 void LeakDetectorRemoteController::SetLocalControllerInstance( 85 void LeakDetectorRemoteController::SetLocalControllerInstance(
82 LocalController* controller) { 86 LocalController* controller) {
83 // This must be on the same thread as the Mojo-based functions of this class, 87 // This must be on the same thread as the Mojo-based functions of this class,
84 // to avoid race conditions on |g_local_controller|. 88 // to avoid race conditions on |g_local_controller|.
85 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 89 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
86 g_local_controller = controller; 90 g_local_controller = controller;
87 } 91 }
88 92
89 } // namespace metrics 93 } // namespace metrics
OLDNEW
« no previous file with comments | « chrome/browser/metrics/leak_detector/leak_detector_remote_controller.h ('k') | chrome/gpu/chrome_content_gpu_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698