1 // Copyright (c) 2012 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.
5 #ifndef CHROMEOS_DBUS_DEBUG_DAEMON_CLIENT_H_
6 #define CHROMEOS_DBUS_DEBUG_DAEMON_CLIENT_H_
10 #include "base/callback.h"
11 #include "base/files/file.h"
12 #include "base/memory/ref_counted_memory.h"
13 #include "base/task_runner.h"
14 #include "chromeos/chromeos_export.h"
15 #include "chromeos/dbus/dbus_client.h"
16 #include "third_party/cros_system_api/dbus/service_constants.h"
20 // DebugDaemonClient is used to communicate with the debug daemon.
21 class CHROMEOS_EXPORT DebugDaemonClient
: public DBusClient
{
23 ~DebugDaemonClient() override
;
25 // Called once GetDebugLogs() is complete. Takes one parameter:
26 // - succeeded: was the logs stored successfully.
27 typedef base::Callback
<void(bool succeeded
)> GetDebugLogsCallback
;
29 // Requests to store debug logs into |file| and calls |callback|
30 // when completed. Debug logs will be stored in the .tgz if
31 // |is_compressed| is true, otherwise in logs will be stored in .tar format.
32 virtual void DumpDebugLogs(bool is_compressed
,
34 scoped_refptr
<base::TaskRunner
> task_runner
,
35 const GetDebugLogsCallback
& callback
) = 0;
37 // Called once SetDebugMode() is complete. Takes one parameter:
38 // - succeeded: debug mode was changed successfully.
39 typedef base::Callback
<void(bool succeeded
)> SetDebugModeCallback
;
41 // Requests to change debug mode to given |subsystem| and calls
42 // |callback| when completed. |subsystem| should be one of the
43 // following: "wifi", "ethernet", "cellular" or "none".
44 virtual void SetDebugMode(const std::string
& subsystem
,
45 const SetDebugModeCallback
& callback
) = 0;
47 // Called once GetRoutes() is complete.
48 typedef base::Callback
<void(bool succeeded
,
49 const std::vector
<std::string
>& routes
)>
51 virtual void GetRoutes(bool numeric
, bool ipv6
,
52 const GetRoutesCallback
& callback
) = 0;
54 // Called once GetNetworkStatus() is complete.
55 typedef base::Callback
<void(bool succeeded
, const std::string
& status
)>
56 GetNetworkStatusCallback
;
58 // Gets information about network status as json.
59 virtual void GetNetworkStatus(const GetNetworkStatusCallback
& callback
) = 0;
61 // Called once GetModemStatus() is complete.
62 typedef base::Callback
<void(bool succeeded
, const std::string
& status
)>
63 GetModemStatusCallback
;
65 // Gets information about modem status as json.
66 virtual void GetModemStatus(const GetModemStatusCallback
& callback
) = 0;
68 // Called once GetWiMaxStatus() is complete.
69 typedef base::Callback
<void(bool succeeded
, const std::string
& status
)>
70 GetWiMaxStatusCallback
;
72 // Gets information about WiMAX status as json.
73 virtual void GetWiMaxStatus(const GetWiMaxStatusCallback
& callback
) = 0;
75 // Called once GetNetworkInterfaces() is complete. Takes two parameters:
76 // - succeeded: information was obtained successfully.
77 // - status: network interfaces information in json. For details, please refer
78 // to http://gerrit.chromium.org/gerrit/#/c/28045/5/src/helpers/netif.cc
79 typedef base::Callback
<void(bool succeeded
, const std::string
& status
)>
80 GetNetworkInterfacesCallback
;
82 // Gets information about network interfaces as json.
83 virtual void GetNetworkInterfaces(
84 const GetNetworkInterfacesCallback
& callback
) = 0;
86 // Called once GetPerfData() is complete only if the the data is successfully
87 // obtained from debugd.
88 typedef base::Callback
<void(const std::vector
<uint8
>& data
)>
91 // Runs perf for |duration| seconds and returns data collected.
92 // TODO(sque): This is being replaced by GetPerfOutput(). Remove this function
93 // and the above callback typedef when the new function is running.
94 virtual void GetPerfData(uint32_t duration
,
95 const GetPerfDataCallback
& callback
) = 0;
97 // Called once GetPerfOutput() is complete only if the the data is
98 // successfully obtained from debugd.
100 // - The status from running perf.
101 // - Output from "perf record", in PerfDataProto format.
102 // - Output from "perf stat", in PerfStatProto format.
103 using GetPerfOutputCallback
=
104 base::Callback
<void(int status
,
105 const std::vector
<uint8
>& perf_data
,
106 const std::vector
<uint8
>& perf_stat
)>;
108 // Runs perf for |duration| seconds and returns data collected.
109 virtual void GetPerfOutput(uint32_t duration
,
110 const GetPerfOutputCallback
& callback
) = 0;
112 // Callback type for GetScrubbedLogs(), GetAllLogs() or GetUserLogFiles().
113 typedef base::Callback
<void(bool succeeded
,
114 const std::map
<std::string
, std::string
>& logs
)>
117 // Gets scrubbed logs from debugd.
118 virtual void GetScrubbedLogs(const GetLogsCallback
& callback
) = 0;
120 // Gets all logs collected by debugd.
121 virtual void GetAllLogs(const GetLogsCallback
& callback
) = 0;
123 // Gets list of user log files that must be read by Chrome.
124 virtual void GetUserLogFiles(const GetLogsCallback
& callback
) = 0;
126 // Requests to start system/kernel tracing.
127 virtual void StartSystemTracing() = 0;
129 // Called once RequestStopSystemTracing() is complete. Takes one parameter:
130 // - result: the data collected while tracing was active
131 typedef base::Callback
<void(const scoped_refptr
<base::RefCountedString
>&
132 result
)> StopSystemTracingCallback
;
134 // Requests to stop system tracing and calls |callback| when completed.
135 virtual bool RequestStopSystemTracing(
136 scoped_refptr
<base::TaskRunner
> task_runner
,
137 const StopSystemTracingCallback
& callback
) = 0;
139 // Returns an empty SystemTracingCallback that does nothing.
140 static StopSystemTracingCallback
EmptyStopSystemTracingCallback();
142 // Called once TestICMP() is complete. Takes two parameters:
143 // - succeeded: information was obtained successfully.
144 // - status: information about ICMP connectivity to a specified host as json.
145 // For details please refer to
146 // https://gerrit.chromium.org/gerrit/#/c/30310/2/src/helpers/icmp.cc
147 typedef base::Callback
<void(bool succeeded
, const std::string
& status
)>
150 // Tests ICMP connectivity to a specified host. The |ip_address| contains the
151 // IPv4 or IPv6 address of the host, for example "8.8.8.8".
152 virtual void TestICMP(const std::string
& ip_address
,
153 const TestICMPCallback
& callback
) = 0;
155 // Tests ICMP connectivity to a specified host. The |ip_address| contains the
156 // IPv4 or IPv6 address of the host, for example "8.8.8.8".
157 virtual void TestICMPWithOptions(
158 const std::string
& ip_address
,
159 const std::map
<std::string
, std::string
>& options
,
160 const TestICMPCallback
& callback
) = 0;
162 // Called once EnableDebuggingFeatures() is complete. |succeeded| will be true
163 // if debugging features have been successfully enabled.
164 typedef base::Callback
<void(bool succeeded
)> EnableDebuggingCallback
;
166 // Enables debugging features (sshd, boot from USB). |password| is a new
167 // password for root user. Can be only called in dev mode.
168 virtual void EnableDebuggingFeatures(
169 const std::string
& password
,
170 const EnableDebuggingCallback
& callback
) = 0;
172 static const int DEV_FEATURE_NONE
= 0;
173 static const int DEV_FEATURE_ALL_ENABLED
=
174 debugd::DevFeatureFlag::DEV_FEATURE_ROOTFS_VERIFICATION_REMOVED
|
175 debugd::DevFeatureFlag::DEV_FEATURE_BOOT_FROM_USB_ENABLED
|
176 debugd::DevFeatureFlag::DEV_FEATURE_SSH_SERVER_CONFIGURED
|
177 debugd::DevFeatureFlag::DEV_FEATURE_DEV_MODE_ROOT_PASSWORD_SET
;
179 // Called once QueryDebuggingFeatures() is complete. |succeeded| will be true
180 // if debugging features have been successfully enabled. |feature_mask| is a
181 // bitmask made out of DebuggingFeature enum values.
182 typedef base::Callback
<void(bool succeeded
,
183 int feature_mask
)> QueryDevFeaturesCallback
;
184 // Checks which debugging features have been already enabled.
185 virtual void QueryDebuggingFeatures(
186 const QueryDevFeaturesCallback
& callback
) = 0;
188 // Removes rootfs verification from the file system. Can be only called in
190 virtual void RemoveRootfsVerification(
191 const EnableDebuggingCallback
& callback
) = 0;
193 // Trigger uploading of crashes.
194 virtual void UploadCrashes() = 0;
196 // A callback for WaitForServiceToBeAvailable().
197 typedef base::Callback
<void(bool service_is_ready
)>
198 WaitForServiceToBeAvailableCallback
;
200 // Runs the callback as soon as the service becomes available.
201 virtual void WaitForServiceToBeAvailable(
202 const WaitForServiceToBeAvailableCallback
& callback
) = 0;
204 // Factory function, creates a new instance and returns ownership.
205 // For normal usage, access the singleton via DBusThreadManager::Get().
206 static DebugDaemonClient
* Create();
209 // Create() should be used instead.
213 DISALLOW_COPY_AND_ASSIGN(DebugDaemonClient
);
216 } // namespace chromeos
218 #endif // CHROMEOS_DBUS_DEBUG_DAEMON_CLIENT_H_