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

Unified Diff: chromeos/dbus/packet_sender.cc

Issue 17210002: Connectivity Diagnostics API: chrome.diagnostics.sendPacket (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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/packet_sender.h ('K') | « chromeos/dbus/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/packet_sender.cc
diff --git a/chromeos/dbus/packet_sender.cc b/chromeos/dbus/packet_sender.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9ee43a8dc8815ad89d7f38cab37a598c7edf1345
--- /dev/null
+++ b/chromeos/dbus/packet_sender.cc
@@ -0,0 +1,62 @@
+// 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 "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 "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 {
+
+PacketSender::PacketSender() {}
+
+PacketSender::~PacketSender() {}
+
+PacketSender* PacketSender::GetInstance() {
+ return Singleton<PacketSender>::get();
+}
+
+void PacketSender::Send(std::string ip, std::string type, int ttl, int timeout,
xiaowenx 2013/06/17 05:26:41 Use const std::string&?
Bei Zhang 2013/06/17 07:30:54 Done.
+ int size, const SendCallback& callback) {
+ chromeos::DebugDaemonClient* debugd_client =
+ chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
+ std::map<std::string, std::string> config;
+ config["ttl"] = base::IntToString(ttl);
+ config["timeout"] = base::IntToString(timeout);
+ config["size"] = base::IntToString(size);
+ debugd_client->TestICMPWithOptions(ip, config,
+ base::Bind(&PacketSender::OnSend,
+ base::Unretained(this),
+ callback));
+}
+
+void PacketSender::OnSend(const SendCallback& callback,
+ bool succeeded, const std::string& status) {
+ if (succeeded) {
+ // Parse the result an gives ip and latency
xiaowenx 2013/06/17 05:26:41 "an gives ip and latency" => "and return IP and la
Bei Zhang 2013/06/17 07:30:54 Done.
+ scoped_ptr<Value> parsed_value(base::JSONReader::Read(status));
+ base::DictionaryValue* result;
+ std::string ip;
+ int latency;
+
+ if (parsed_value->GetAsDictionary(&result) &&
xiaowenx 2013/06/17 05:26:41 Need to check whether parsed_value is NULL
Bei Zhang 2013/06/17 07:30:54 Done.
+ result->GetString("ip", &ip) && result->GetInteger("ttl", &latency)) {
xiaowenx 2013/06/17 05:26:41 It returns something like: { "<ip>" : { ... "time
Bei Zhang 2013/06/17 07:30:54 Done.
+ callback.Run(true, ip, latency);
+ return;
+ }
+ }
+
+ callback.Run(false, "", 0);
+}
+
+} // namespace chromeos
« chromeos/dbus/packet_sender.h ('K') | « chromeos/dbus/packet_sender.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698