blob: 161d4f08017d3f558f682645caef82b4fbb82a5a [file] [log] [blame]
Xiaohui Chena8bced82015-02-27 10:35:26 -08001// 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 Carusocc7106c2017-04-27 14:22:42 -07007#include <base/bind.h>
Xiaohui Chena8bced82015-02-27 10:35:26 -08008#include <base/logging.h>
Eric Carusocc7106c2017-04-27 14:22:42 -07009#include <chromeos/dbus/service_constants.h>
10#include <dbus/message.h>
11#include <dbus/object_proxy.h>
12
13namespace {
14
Eric Carusocc7106c2017-04-27 14:22:42 -070015void 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 Chena8bced82015-02-27 10:35:26 -080025
26namespace debugd {
27
Eric Carusocc7106c2017-04-27 14:22:42 -070028SessionManagerProxy::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
43void SessionManagerProxy::OnLoginPromptVisible(dbus::Signal*) {
Jorge Lucangeli Obes9d5a1c52015-03-20 15:43:21 +000044 // Try to enable Chrome remote debugging again on Login prompt.
Xiaohui Chena8bced82015-02-27 10:35:26 -080045 // 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 Obes9d5a1c52015-03-20 15:43:21 +000048 EnableChromeRemoteDebuggingInternal();
Xiaohui Chena8bced82015-02-27 10:35:26 -080049}
50
51void 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
60void SessionManagerProxy::EnableChromeRemoteDebuggingInternal() {
Jorge Lucangeli Obes9d5a1c52015-03-20 15:43:21 +000061 VLOG(1) << "Enable Chrome remote debugging internal: "
62 << should_enable_chrome_remote_debugging_
63 << " "
64 << is_chrome_remote_debugging_enabled_;
Xiaohui Chena8bced82015-02-27 10:35:26 -080065 if (!should_enable_chrome_remote_debugging_ ||
66 is_chrome_remote_debugging_enabled_) {
67 return;
68 }
Eric Carusocc7106c2017-04-27 14:22:42 -070069
Daniel Erat8ae9ce62017-12-16 01:02:41 -080070 dbus::MethodCall method_call(
71 login_manager::kSessionManagerInterface,
72 login_manager::kSessionManagerEnableChromeTesting);
Eric Carusocc7106c2017-04-27 14:22:42 -070073 dbus::MessageWriter writer(&method_call);
Daniel Erat8ae9ce62017-12-16 01:02:41 -080074 writer.AppendBool(true); // force_restart
Eric Carusocc7106c2017-04-27 14:22:42 -070075 writer.AppendArrayOfStrings({"--remote-debugging-port=9222"});
Daniel Erat8ae9ce62017-12-16 01:02:41 -080076 writer.AppendArrayOfStrings({}); // extra_environment_variables
Eric Carusocc7106c2017-04-27 14:22:42 -070077 if (proxy_->CallMethodAndBlock(&method_call,
78 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)) {
Xiaohui Chena8bced82015-02-27 10:35:26 -080079 is_chrome_remote_debugging_enabled_ = true;
Eric Carusocc7106c2017-04-27 14:22:42 -070080 } else {
81 LOG(ERROR) << "Failed to enable Chrome remote debugging";
Xiaohui Chena8bced82015-02-27 10:35:26 -080082 }
83}
84
Xiaohui Chena8bced82015-02-27 10:35:26 -080085} // namespace debugd