| 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 "chrome/renderer/leak_detector/leak_detector_monitor_client.h" |
| 6 |
| 7 #include "content/public/common/service_registry.h" |
| 8 #include "content/public/renderer/render_thread.h" |
| 9 |
| 10 namespace metrics { |
| 11 |
| 12 static LeakDetectorMonitorClient* g_leak_detector_service = NULL; |
| 13 |
| 14 // static |
| 15 void LeakDetectorMonitorClient::Initialize() { |
| 16 CHECK(!g_leak_detector_service); |
| 17 g_leak_detector_service = new LeakDetectorMonitorClient(); |
| 18 } |
| 19 |
| 20 // static |
| 21 void LeakDetectorMonitorClient::Shutdown() { |
| 22 CHECK(g_leak_detector_service); |
| 23 delete g_leak_detector_service; |
| 24 g_leak_detector_service = NULL; |
| 25 } |
| 26 |
| 27 // static |
| 28 LeakDetectorMonitorClient* LeakDetectorMonitorClient::GetInstance() { |
| 29 CHECK(g_leak_detector_service) |
| 30 << "LoginState::Get() called before Initialize()"; |
| 31 return g_leak_detector_service; |
| 32 } |
| 33 |
| 34 // static |
| 35 bool LeakDetectorMonitorClient::IsInitialized() { |
| 36 return g_leak_detector_service; |
| 37 } |
| 38 |
| 39 LeakDetectorMonitorClient::LeakDetectorMonitorClient() { |
| 40 content::ServiceRegistry* registry = |
| 41 content::RenderThread::Get()->GetServiceRegistry(); |
| 42 if (registry) { |
| 43 // Registry can be null during testing. |
| 44 LOG(ERROR) << "Connecting to remote service"; |
| 45 registry->ConnectToRemoteService(mojo::GetProxy(&leak_detector_monitor_)); |
| 46 LOG(ERROR) << " result: " << leak_detector_monitor_; |
| 47 |
| 48 OnLeakFound(); |
| 49 } |
| 50 } |
| 51 |
| 52 LeakDetectorMonitorClient::~LeakDetectorMonitorClient() { |
| 53 } |
| 54 |
| 55 void LeakDetectorMonitorClient::OnLeakFound() { |
| 56 LOG(ERROR) << "LeakDetectorMonitorClient::OnLeakFound"; |
| 57 leak_detector_monitor_->StoreLeakReport(); |
| 58 LOG(ERROR) << "Done"; |
| 59 } |
| 60 |
| 61 } // namespace metrics |
| OLD | NEW |