Commit 0e889137 authored by hshi@chromium.org's avatar hshi@chromium.org

debugd: Add TestICMP functionality.

BUG=139442
TEST=CQ

Review URL: https://chromiumcodereview.appspot.com/10829396

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152168 0039d316-1c4b-4281-b951-d872f2087c98
parent 15d206e1
...@@ -306,6 +306,20 @@ class DebugDaemonClientImpl : public DebugDaemonClient { ...@@ -306,6 +306,20 @@ class DebugDaemonClientImpl : public DebugDaemonClient {
return true; return true;
} }
virtual void TestICMP(const std::string& ip_address,
const TestICMPCallback& callback) OVERRIDE {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kTestICMP);
dbus::MessageWriter writer(&method_call);
writer.AppendString(ip_address);
debugdaemon_proxy_->CallMethod(
&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::Bind(&DebugDaemonClientImpl::OnTestICMP,
weak_ptr_factory_.GetWeakPtr(),
callback));
}
private: private:
// Called to check descriptor validity on a thread where i/o is permitted. // Called to check descriptor validity on a thread where i/o is permitted.
static void CheckValidity(dbus::FileDescriptor* file_descriptor) { static void CheckValidity(dbus::FileDescriptor* file_descriptor) {
...@@ -458,6 +472,14 @@ class DebugDaemonClientImpl : public DebugDaemonClient { ...@@ -458,6 +472,14 @@ class DebugDaemonClientImpl : public DebugDaemonClient {
// NB: requester is signaled when i/o completes // NB: requester is signaled when i/o completes
} }
void OnTestICMP(const TestICMPCallback& callback, dbus::Response* response) {
std::string status;
if (response && dbus::MessageReader(response).PopString(&status))
callback.Run(true, status);
else
callback.Run(false, "");
}
// Called when pipe i/o completes; pass data on and delete the instance. // Called when pipe i/o completes; pass data on and delete the instance.
void OnIOComplete() { void OnIOComplete() {
callback_.Run(base::RefCountedString::TakeString(pipe_reader_->data())); callback_.Run(base::RefCountedString::TakeString(pipe_reader_->data()));
...@@ -512,6 +534,11 @@ class DebugDaemonClientStubImpl : public DebugDaemonClient { ...@@ -512,6 +534,11 @@ class DebugDaemonClientStubImpl : public DebugDaemonClient {
std::map<std::string, std::string> empty; std::map<std::string, std::string> empty;
callback.Run(false, empty); callback.Run(false, empty);
} }
virtual void TestICMP(const std::string& ip_address,
const TestICMPCallback& callback) OVERRIDE {
callback.Run(false, "");
}
}; };
DebugDaemonClient::DebugDaemonClient() { DebugDaemonClient::DebugDaemonClient() {
......
...@@ -96,6 +96,19 @@ class CHROMEOS_EXPORT DebugDaemonClient { ...@@ -96,6 +96,19 @@ class CHROMEOS_EXPORT DebugDaemonClient {
// Returns an empty SystemTracingCallback that does nothing. // Returns an empty SystemTracingCallback that does nothing.
static StopSystemTracingCallback EmptyStopSystemTracingCallback(); static StopSystemTracingCallback EmptyStopSystemTracingCallback();
// Called once TestICMP() is complete. Takes two parameters:
// - succeeded: information was obtained successfully.
// - status: information about ICMP connectivity to a specified host as json.
// For details please refer to
// https://gerrit.chromium.org/gerrit/#/c/30310/2/src/helpers/icmp.cc
typedef base::Callback<void(bool succeeded, const std::string& status)>
TestICMPCallback;
// Tests ICMP connectivity to a specified host. The |ip_address| contains the
// IPv4 or IPv6 address of the host, for example "8.8.8.8".
virtual void TestICMP(const std::string& ip_address,
const TestICMPCallback& callback) = 0;
// Factory function, creates a new instance and returns ownership. // Factory function, creates a new instance and returns ownership.
// For normal usage, access the singleton via DBusThreadManager::Get(). // For normal usage, access the singleton via DBusThreadManager::Get().
static DebugDaemonClient* Create(DBusClientImplementationType type, static DebugDaemonClient* Create(DBusClientImplementationType type,
......
...@@ -27,6 +27,7 @@ class MockDebugDaemonClient : public DebugDaemonClient { ...@@ -27,6 +27,7 @@ class MockDebugDaemonClient : public DebugDaemonClient {
MOCK_METHOD1(RequestStopSystemTracing, MOCK_METHOD1(RequestStopSystemTracing,
bool(const StopSystemTracingCallback&)); bool(const StopSystemTracingCallback&));
MOCK_METHOD0(StartSystemTracing, void()); MOCK_METHOD0(StartSystemTracing, void());
MOCK_METHOD2(TestICMP, void(const std::string&, const TestICMPCallback&));
}; };
} // namespace chromeos } // namespace chromeos
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment