Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/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 std::string ip = parameters_->options.ip; | |
|
xiaowenx
2013/06/17 06:19:38
const std::string& ip = parameters_->options.ip;
Bei Zhang
2013/06/17 07:30:54
Done.
| |
| 29 std::string type = "icmp"; | |
|
xiaowenx
2013/06/17 05:26:41
We should return error if the user gives any proto
Bei Zhang
2013/06/17 07:30:54
Actually we should remove this option for now. We
| |
| 30 long ttl = 1; | |
|
xiaowenx
2013/06/17 06:19:38
The generated code for SendPacketOptions.ttl is of
Bei Zhang
2013/06/17 07:30:54
Nice catch! It definitely should.
| |
| 31 long timeout = 5000; | |
|
xiaowenx
2013/06/17 07:19:31
timeout is specified in seconds, so you probably w
Bei Zhang
2013/06/17 07:30:54
If sub-second timeout could not be specified, then
| |
| 32 long size = 4; | |
| 33 | |
| 34 | |
|
xiaowenx
2013/06/17 06:19:38
is the extra empty line needed?
Bei Zhang
2013/06/17 07:30:54
Done.
| |
| 35 if (parameters_->options.ttl.get()) | |
|
xiaowenx
2013/06/17 06:19:38
.get() isn't needed: https://code.google.com/p/chr
Bei Zhang
2013/06/17 07:30:54
Hmm, I didn't know this. Yet I've never seen any c
| |
| 36 ttl = *parameters_->options.ttl; | |
|
xiaowenx
2013/06/17 06:19:38
Maybe this kind of syntax would be easier: int ttl
Bei Zhang
2013/06/17 07:30:54
Done.
| |
| 37 if (parameters_->options.timeout.get()) | |
| 38 timeout = *parameters_->options.timeout; | |
| 39 if (parameters_->options.size.get()) | |
| 40 size = *parameters_->options.size; | |
| 41 | |
| 42 #if defined(OS_CHROMEOS) | |
| 43 chromeos::PacketSender::GetInstance()->Send(ip, type, ttl, timeout, size, | |
| 44 base::Bind(&PingPrivateSendPacketFunction::OnComplete, this)); | |
| 45 #else | |
| 46 SetError("Not implemented"); | |
| 47 AsyncWorkCompleted(); | |
| 48 #endif | |
| 49 } | |
| 50 | |
| 51 bool PingPrivateSendPacketFunction::Respond() { | |
| 52 return error_.empty(); | |
| 53 } | |
| 54 | |
| 55 void PingPrivateSendPacketFunction::OnComplete(bool suceeded, | |
| 56 std::string ip, int latency) { | |
| 57 extensions::api::ping_private::SendPacketResult result; | |
| 58 result.ip = ip; | |
| 59 result.latency = latency; | |
| 60 SetResult(result.ToValue().release()); | |
| 61 AsyncWorkCompleted(); | |
| 62 } | |
| 63 | |
| 64 } // namespace extensions | |
| 65 | |
|
xiaowenx
2013/06/17 06:19:38
is the extra empty line needed?
Bei Zhang
2013/06/17 07:30:54
Done.
| |
| OLD | NEW |