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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 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 #include "icmp_packet_sender.h"
6
7 #include "base/bind.h"
8 #include "base/chromeos/chromeos_version.h"
9 #include "base/json/json_reader.h"
10 #include "base/memory/singleton.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "base/values.h"
13
14 #include "chromeos/dbus/dbus_thread_manager.h"
15 #include "chromeos/dbus/debug_daemon_client.h"
16 #include "chromeos/dbus/permission_broker_client.h"
17
18 using base::Value;
19
20 namespace chromeos {
21
22 ICMPPacketSender::ICMPPacketSender() {}
23
24 ICMPPacketSender::~ICMPPacketSender() {}
25
26 ICMPPacketSender* ICMPPacketSender::GetInstance() {
27 return Singleton<ICMPPacketSender>::get();
28 }
29
30 void ICMPPacketSender::Send(const std::string& ip,
31 int* ttl, int* timeout, int* size,
32 const SendCallback& callback) {
33 chromeos::DebugDaemonClient* debugd_client =
34 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
35 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.
36 if (ttl)
37 config["ttl"] = base::IntToString(*ttl);
38 if (timeout)
39 config["timeout"] = base::IntToString(*timeout);
40 if (size)
41 config["size"] = base::IntToString(*size);
42 debugd_client->TestICMPWithOptions(ip, config,
43 base::Bind(&ICMPPacketSender::OnSend,
44 base::Unretained(this),
45 callback));
46 }
47
48 void ICMPPacketSender::OnSend(const SendCallback& callback,
49 bool succeeded, const std::string& status) {
50 if (succeeded) {
51 // Parses the result and returns IP and latency.
52 scoped_ptr<Value> parsed_value(base::JSONReader::Read(status));
53 base::DictionaryValue* result;
54 if (parsed_value.get() && parsed_value->GetAsDictionary(&result)) {
55 base::DictionaryValue::Iterator iterator(*result);
56 // Returns the first item.
57 if (!iterator.IsAtEnd()) {
58 std::string ip = iterator.key();
59 const base::DictionaryValue* info;
60 if (iterator.value().GetAsDictionary(&info)) {
61 int latency;
62 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.
63 callback.Run(true, ip, latency);
64 return;
65 }
66 }
67 }
68 }
69 }
70
71 callback.Run(false, "", 0);
72 }
73
74 } // namespace chromeos
OLDNEW
« 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