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