blob: f04241b19c47cea49965f97ea7cb2cf83dd0ec0a [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
15const char kEnableChromeTesting[] = "EnableChromeTesting";
16
17void 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 Chena8bced82015-02-27 10:35:26 -080027
28namespace debugd {
29
Eric Carusocc7106c2017-04-27 14:22:42 -070030SessionManagerProxy::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
45void SessionManagerProxy::OnLoginPromptVisible(dbus::Signal*) {
Jorge Lucangeli Obes9d5a1c52015-03-20 15:43:21 +000046 // Try to enable Chrome remote debugging again on Login prompt.
Xiaohui Chena8bced82015-02-27 10:35:26 -080047 // 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 Obes9d5a1c52015-03-20 15:43:21 +000050 EnableChromeRemoteDebuggingInternal();
Xiaohui Chena8bced82015-02-27 10:35:26 -080051}
52
53void 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
62void SessionManagerProxy::EnableChromeRemoteDebuggingInternal() {
Jorge Lucangeli Obes9d5a1c52015-03-20 15:43:21 +000063 VLOG(1) << "Enable Chrome remote debugging internal: "
64 << should_enable_chrome_remote_debugging_
65 << " "
66 << is_chrome_remote_debugging_enabled_;
Xiaohui Chena8bced82015-02-27 10:35:26 -080067 if (!should_enable_chrome_remote_debugging_ ||
68 is_chrome_remote_debugging_enabled_) {
69 return;
70 }
Eric Carusocc7106c2017-04-27 14:22:42 -070071
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 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