Xiaohui Chen | a8bced8 | 2015-02-27 10:35:26 -0800 | [diff] [blame] | 1 | // Copyright 2015 The Chromium OS 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 "debugd/src/session_manager_proxy.h" |
| 6 | |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 7 | #include <base/bind.h> |
Xiaohui Chen | a8bced8 | 2015-02-27 10:35:26 -0800 | [diff] [blame] | 8 | #include <base/logging.h> |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 9 | #include <chromeos/dbus/service_constants.h> |
| 10 | #include <dbus/message.h> |
| 11 | #include <dbus/object_proxy.h> |
| 12 | |
| 13 | namespace { |
| 14 | |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 15 | void OnSignalConnected(const std::string& interface, |
| 16 | const std::string& signal, |
| 17 | bool success) { |
| 18 | if (!success) { |
| 19 | LOG(ERROR) << "Could not connect to signal " << signal |
| 20 | << " on interface " << interface; |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | } // namespace |
Xiaohui Chen | a8bced8 | 2015-02-27 10:35:26 -0800 | [diff] [blame] | 25 | |
| 26 | namespace debugd { |
| 27 | |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 28 | SessionManagerProxy::SessionManagerProxy(scoped_refptr<dbus::Bus> bus) |
| 29 | : bus_(bus), |
| 30 | proxy_(bus->GetObjectProxy( |
| 31 | login_manager::kSessionManagerServiceName, |
| 32 | dbus::ObjectPath(login_manager::kSessionManagerServicePath))), |
| 33 | weak_ptr_factory_(this) { |
| 34 | proxy_->ConnectToSignal( |
| 35 | login_manager::kSessionManagerInterface, |
| 36 | login_manager::kLoginPromptVisibleSignal, |
| 37 | base::Bind(&SessionManagerProxy::OnLoginPromptVisible, |
| 38 | weak_ptr_factory_.GetWeakPtr()), |
| 39 | base::Bind(&OnSignalConnected)); |
| 40 | } |
| 41 | |
| 42 | |
| 43 | void SessionManagerProxy::OnLoginPromptVisible(dbus::Signal*) { |
Jorge Lucangeli Obes | 9d5a1c5 | 2015-03-20 15:43:21 +0000 | [diff] [blame] | 44 | // Try to enable Chrome remote debugging again on Login prompt. |
Xiaohui Chen | a8bced8 | 2015-02-27 10:35:26 -0800 | [diff] [blame] | 45 | // Theoretically it should already be enabled during debugd Init(). But |
| 46 | // There might be a timing issue if debugd started too fast. We try again |
| 47 | // here if the first attempt in Init() failed. |
Jorge Lucangeli Obes | 9d5a1c5 | 2015-03-20 15:43:21 +0000 | [diff] [blame] | 48 | EnableChromeRemoteDebuggingInternal(); |
Xiaohui Chen | a8bced8 | 2015-02-27 10:35:26 -0800 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | void SessionManagerProxy::EnableChromeRemoteDebugging() { |
| 52 | VLOG(1) << "Enable Chrome remote debugging: " |
| 53 | << should_enable_chrome_remote_debugging_ |
| 54 | << " " |
| 55 | << is_chrome_remote_debugging_enabled_; |
| 56 | should_enable_chrome_remote_debugging_ = true; |
| 57 | EnableChromeRemoteDebuggingInternal(); |
| 58 | } |
| 59 | |
| 60 | void SessionManagerProxy::EnableChromeRemoteDebuggingInternal() { |
Jorge Lucangeli Obes | 9d5a1c5 | 2015-03-20 15:43:21 +0000 | [diff] [blame] | 61 | VLOG(1) << "Enable Chrome remote debugging internal: " |
| 62 | << should_enable_chrome_remote_debugging_ |
| 63 | << " " |
| 64 | << is_chrome_remote_debugging_enabled_; |
Xiaohui Chen | a8bced8 | 2015-02-27 10:35:26 -0800 | [diff] [blame] | 65 | if (!should_enable_chrome_remote_debugging_ || |
| 66 | is_chrome_remote_debugging_enabled_) { |
| 67 | return; |
| 68 | } |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 69 | |
Daniel Erat | 8ae9ce6 | 2017-12-16 01:02:41 -0800 | [diff] [blame^] | 70 | dbus::MethodCall method_call( |
| 71 | login_manager::kSessionManagerInterface, |
| 72 | login_manager::kSessionManagerEnableChromeTesting); |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 73 | dbus::MessageWriter writer(&method_call); |
Daniel Erat | 8ae9ce6 | 2017-12-16 01:02:41 -0800 | [diff] [blame^] | 74 | writer.AppendBool(true); // force_restart |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 75 | writer.AppendArrayOfStrings({"--remote-debugging-port=9222"}); |
Daniel Erat | 8ae9ce6 | 2017-12-16 01:02:41 -0800 | [diff] [blame^] | 76 | writer.AppendArrayOfStrings({}); // extra_environment_variables |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 77 | if (proxy_->CallMethodAndBlock(&method_call, |
| 78 | dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)) { |
Xiaohui Chen | a8bced8 | 2015-02-27 10:35:26 -0800 | [diff] [blame] | 79 | is_chrome_remote_debugging_enabled_ = true; |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 80 | } else { |
| 81 | LOG(ERROR) << "Failed to enable Chrome remote debugging"; |
Xiaohui Chen | a8bced8 | 2015-02-27 10:35:26 -0800 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | |
Xiaohui Chen | a8bced8 | 2015-02-27 10:35:26 -0800 | [diff] [blame] | 85 | } // namespace debugd |