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

Side by Side Diff: chrome/browser/extensions/api/ping_private/ping_private_api.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 "ping_private_api.h"
6
7 #include "base/values.h"
8
9 #if defined(OS_CHROMEOS)
10 #include "chromeos/dbus/icmp_packet_sender.h"
11 #endif // defined(OS_CHROMEOS)
12
13 namespace SendPacket = extensions::api::ping_private::SendPacket;
14
15 namespace extensions {
16
17 PingPrivateSendPacketFunction::PingPrivateSendPacketFunction() {}
18
19 PingPrivateSendPacketFunction::~PingPrivateSendPacketFunction() {}
20
21 bool PingPrivateSendPacketFunction::Prepare() {
22 parameters_ = SendPacket::Params::Create(*args_);
23 EXTENSION_FUNCTION_VALIDATE(parameters_.get());
24 return true;
25 }
26
27 void PingPrivateSendPacketFunction::AsyncWorkStart() {
28 #if defined(OS_CHROMEOS)
29 chromeos::ICMPPacketSender::GetInstance()->Send(
30 parameters_->options.ip,
31 parameters_->options.ttl.get(),
32 parameters_->options.timeout.get(),
33 parameters_->options.size.get(),
34 base::Bind(&PingPrivateSendPacketFunction::OnComplete, this));
35 #else
36 SetError("Not implemented");
37 AsyncWorkCompleted();
38 #endif
39 }
40
41 bool PingPrivateSendPacketFunction::Respond() {
42 return error_.empty();
43 }
44
45 void PingPrivateSendPacketFunction::OnComplete(bool suceeded,
46 const std::string& ip,
47 int latency) {
48 extensions::api::ping_private::SendPacketResult result;
49 result.ip = ip;
50 result.latency = latency;
51 SetResult(result.ToValue().release());
52 AsyncWorkCompleted();
53 }
54
55 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698