Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Unified Diff: chromeos/dbus/icmp_packet_sender.cc

Issue 17210002: Connectivity Diagnostics API: chrome.diagnostics.sendPacket (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use avg instead of time Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« chromeos/dbus/icmp_packet_sender.h ('K') | « chromeos/dbus/icmp_packet_sender.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/dbus/icmp_packet_sender.cc
diff --git a/chromeos/dbus/icmp_packet_sender.cc b/chromeos/dbus/icmp_packet_sender.cc
new file mode 100644
index 0000000000000000000000000000000000000000..18ffac0f8f9ba00383865b34aa5ab559a602ef91
--- /dev/null
+++ b/chromeos/dbus/icmp_packet_sender.cc
@@ -0,0 +1,74 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "icmp_packet_sender.h"
+
+#include "base/bind.h"
+#include "base/chromeos/chromeos_version.h"
+#include "base/json/json_reader.h"
+#include "base/memory/singleton.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/values.h"
+
+#include "chromeos/dbus/dbus_thread_manager.h"
+#include "chromeos/dbus/debug_daemon_client.h"
+#include "chromeos/dbus/permission_broker_client.h"
+
+using base::Value;
+
+namespace chromeos {
+
+ICMPPacketSender::ICMPPacketSender() {}
+
+ICMPPacketSender::~ICMPPacketSender() {}
+
+ICMPPacketSender* ICMPPacketSender::GetInstance() {
+ return Singleton<ICMPPacketSender>::get();
+}
+
+void ICMPPacketSender::Send(const std::string& ip,
+ int* ttl, int* timeout, int* size,
+ const SendCallback& callback) {
+ chromeos::DebugDaemonClient* debugd_client =
+ chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
+ std::map<std::string, std::string> config;
xiaowenx 2013/06/17 08:29:34 Need to add count=1 as parameter to TestICMPWithOp
Bei Zhang 2013/06/17 09:13:11 Done.
+ if (ttl)
+ config["ttl"] = base::IntToString(*ttl);
+ if (timeout)
+ config["timeout"] = base::IntToString(*timeout);
+ if (size)
+ config["size"] = base::IntToString(*size);
+ debugd_client->TestICMPWithOptions(ip, config,
+ base::Bind(&ICMPPacketSender::OnSend,
+ base::Unretained(this),
+ callback));
+}
+
+void ICMPPacketSender::OnSend(const SendCallback& callback,
+ bool succeeded, const std::string& status) {
+ if (succeeded) {
+ // Parses the result and returns IP and latency.
+ scoped_ptr<Value> parsed_value(base::JSONReader::Read(status));
+ base::DictionaryValue* result;
+ if (parsed_value.get() && parsed_value->GetAsDictionary(&result)) {
+ base::DictionaryValue::Iterator iterator(*result);
+ // Returns the first item.
+ if (!iterator.IsAtEnd()) {
+ std::string ip = iterator.key();
+ const base::DictionaryValue* info;
+ if (iterator.value().GetAsDictionary(&info)) {
+ int latency;
+ if (info->GetInteger("avg", &latency)) {
xiaowenx 2013/06/17 08:41:32 double latency; info->GetDouble(...)
Bei Zhang 2013/06/17 09:13:11 Done.
+ callback.Run(true, ip, latency);
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ callback.Run(false, "", 0);
+}
+
+} // namespace chromeos
« chromeos/dbus/icmp_packet_sender.h ('K') | « chromeos/dbus/icmp_packet_sender.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698