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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« chromeos/dbus/packet_sender.h ('K') | « chromeos/dbus/packet_sender.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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
13 #include "chromeos/dbus/dbus_thread_manager.h"
14 #include "chromeos/dbus/debug_daemon_client.h"
15 #include "chromeos/dbus/permission_broker_client.h"
16
17 using base::Value;
18
19 namespace chromeos {
20
21 PacketSender::PacketSender() {}
22
23 PacketSender::~PacketSender() {}
24
25 PacketSender* PacketSender::GetInstance() {
26 return Singleton<PacketSender>::get();
27 }
28
29 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.
30 int size, const SendCallback& callback) {
31 chromeos::DebugDaemonClient* debugd_client =
32 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
33 std::map<std::string, std::string> config;
34 config["ttl"] = base::IntToString(ttl);
35 config["timeout"] = base::IntToString(timeout);
36 config["size"] = base::IntToString(size);
37 debugd_client->TestICMPWithOptions(ip, config,
38 base::Bind(&PacketSender::OnSend,
39 base::Unretained(this),
40 callback));
41 }
42
43 void PacketSender::OnSend(const SendCallback& callback,
44 bool succeeded, const std::string& status) {
45 if (succeeded) {
46 // 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.
47 scoped_ptr<Value> parsed_value(base::JSONReader::Read(status));
48 base::DictionaryValue* result;
49 std::string ip;
50 int latency;
51
52 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.
53 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.
54 callback.Run(true, ip, latency);
55 return;
56 }
57 }
58
59 callback.Run(false, "", 0);
60 }
61
62 } // namespace chromeos
OLDNEW
« 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