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.
4
5#ifndef CHROMEOS_DBUS_DEBUG_DAEMON_CLIENT_H_
6#define CHROMEOS_DBUS_DEBUG_DAEMON_CLIENT_H_
7
8#include "base/callback.h"
9#include "base/files/file.h"
10#include "base/memory/ref_counted_memory.h"
11#include "base/task_runner.h"
12#include "chromeos/chromeos_export.h"
13#include "chromeos/dbus/dbus_client.h"
14
15#include <map>
16
17namespace metrics {
18class PerfDataProto;
19}
20
21namespace chromeos {
22
23// DebugDaemonClient is used to communicate with the debug daemon.
24class CHROMEOS_EXPORT DebugDaemonClient : public DBusClient {
25 public:
26  virtual ~DebugDaemonClient();
27
28  // Called once GetDebugLogs() is complete. Takes one parameter:
29  // - succeeded: was the logs stored successfully.
30  typedef base::Callback<void(bool succeeded)> GetDebugLogsCallback;
31
32  // Requests to store debug logs into |file| and calls |callback|
33  // when completed. Debug logs will be stored in the .tgz if
34  // |is_compressed| is true, otherwise in logs will be stored in .tar format.
35  virtual void DumpDebugLogs(bool is_compressed,
36                             base::File file,
37                             scoped_refptr<base::TaskRunner> task_runner,
38                             const GetDebugLogsCallback& callback) = 0;
39
40  // Called once SetDebugMode() is complete. Takes one parameter:
41  // - succeeded: debug mode was changed successfully.
42  typedef base::Callback<void(bool succeeded)> SetDebugModeCallback;
43
44  // Requests to change debug mode to given |subsystem| and calls
45  // |callback| when completed. |subsystem| should be one of the
46  // following: "wifi", "ethernet", "cellular" or "none".
47  virtual void SetDebugMode(const std::string& subsystem,
48                            const SetDebugModeCallback& callback) = 0;
49
50  // Called once GetRoutes() is complete.
51  typedef base::Callback<void(bool succeeded,
52                              const std::vector<std::string>& routes)>
53      GetRoutesCallback;
54  virtual void GetRoutes(bool numeric, bool ipv6,
55                         const GetRoutesCallback& callback) = 0;
56
57  // Called once GetNetworkStatus() is complete.
58  typedef base::Callback<void(bool succeeded, const std::string& status)>
59      GetNetworkStatusCallback;
60
61  // Gets information about network status as json.
62  virtual void GetNetworkStatus(const GetNetworkStatusCallback& callback) = 0;
63
64  // Called once GetModemStatus() is complete.
65  typedef base::Callback<void(bool succeeded, const std::string& status)>
66      GetModemStatusCallback;
67
68  // Gets information about modem status as json.
69  virtual void GetModemStatus(const GetModemStatusCallback& callback) = 0;
70
71  // Called once GetWiMaxStatus() is complete.
72  typedef base::Callback<void(bool succeeded, const std::string& status)>
73      GetWiMaxStatusCallback;
74
75  // Gets information about WiMAX status as json.
76  virtual void GetWiMaxStatus(const GetWiMaxStatusCallback& callback) = 0;
77
78  // Called once GetNetworkInterfaces() is complete. Takes two parameters:
79  // - succeeded: information was obtained successfully.
80  // - status: network interfaces information in json. For details, please refer
81  //   to http://gerrit.chromium.org/gerrit/#/c/28045/5/src/helpers/netif.cc
82  typedef base::Callback<void(bool succeeded, const std::string& status)>
83      GetNetworkInterfacesCallback;
84
85  // Gets information about network interfaces as json.
86  virtual void GetNetworkInterfaces(
87      const GetNetworkInterfacesCallback& callback) = 0;
88
89  // Called once GetPerfData() is complete only if the the data is successfully
90  // obtained from debugd.
91  typedef base::Callback<void(const std::vector<uint8>& data)>
92      GetPerfDataCallback;
93
94  // Runs perf for |duration| seconds and returns data collected.
95  virtual void GetPerfData(uint32_t duration,
96                           const GetPerfDataCallback& callback) = 0;
97
98  // Callback type for GetScrubbedLogs(), GetAllLogs() or GetUserLogFiles().
99  typedef base::Callback<void(bool succeeded,
100                              const std::map<std::string, std::string>& logs)>
101      GetLogsCallback;
102
103  // Gets scrubbed logs from debugd.
104  virtual void GetScrubbedLogs(const GetLogsCallback& callback) = 0;
105
106  // Gets all logs collected by debugd.
107  virtual void GetAllLogs(const GetLogsCallback& callback) = 0;
108
109  // Gets list of user log files that must be read by Chrome.
110  virtual void GetUserLogFiles(const GetLogsCallback& callback) = 0;
111
112  // Requests to start system/kernel tracing.
113  virtual void StartSystemTracing() = 0;
114
115  // Called once RequestStopSystemTracing() is complete. Takes one parameter:
116  // - result: the data collected while tracing was active
117  typedef base::Callback<void(const scoped_refptr<base::RefCountedString>&
118      result)> StopSystemTracingCallback;
119
120  // Requests to stop system tracing and calls |callback| when completed.
121  virtual bool RequestStopSystemTracing(
122      scoped_refptr<base::TaskRunner> task_runner,
123      const StopSystemTracingCallback& callback) = 0;
124
125  // Returns an empty SystemTracingCallback that does nothing.
126  static StopSystemTracingCallback EmptyStopSystemTracingCallback();
127
128  // Called once TestICMP() is complete. Takes two parameters:
129  // - succeeded: information was obtained successfully.
130  // - status: information about ICMP connectivity to a specified host as json.
131  //   For details please refer to
132  //   https://gerrit.chromium.org/gerrit/#/c/30310/2/src/helpers/icmp.cc
133  typedef base::Callback<void(bool succeeded, const std::string& status)>
134      TestICMPCallback;
135
136  // Tests ICMP connectivity to a specified host. The |ip_address| contains the
137  // IPv4 or IPv6 address of the host, for example "8.8.8.8".
138  virtual void TestICMP(const std::string& ip_address,
139                        const TestICMPCallback& callback) = 0;
140
141  // Tests ICMP connectivity to a specified host. The |ip_address| contains the
142  // IPv4 or IPv6 address of the host, for example "8.8.8.8".
143  virtual void TestICMPWithOptions(
144      const std::string& ip_address,
145      const std::map<std::string, std::string>& options,
146      const TestICMPCallback& callback) = 0;
147
148  // Trigger uploading of crashes.
149  virtual void UploadCrashes() = 0;
150
151  // Factory function, creates a new instance and returns ownership.
152  // For normal usage, access the singleton via DBusThreadManager::Get().
153  static DebugDaemonClient* Create();
154
155 protected:
156  // Create() should be used instead.
157  DebugDaemonClient();
158
159 private:
160  DISALLOW_COPY_AND_ASSIGN(DebugDaemonClient);
161};
162
163}  // namespace chromeos
164
165#endif  // CHROMEOS_DBUS_DEBUG_DAEMON_CLIENT_H_
166