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 "diagnostics_private_api.h" | |
6 | |
7 #include "chrome/browser/extensions/api/diagnostics_private/send_ping_packet.h" | |
8 | |
9 namespace SendPacket = extensions::api::diagnostics_private::SendPacket; | |
10 | |
11 using base::Callback; | |
12 | |
13 namespace { | |
14 | |
15 const char kErrorPingNotImplemented[] = "Not implemented."; | |
16 const char kErrorPingFailed[] = "Failed to send ping packet."; | |
17 | |
18 } | |
19 | |
20 namespace extensions { | |
21 | |
22 DiagnosticsPrivateSendPacketFunction::DiagnosticsPrivateSendPacketFunction() {} | |
23 | |
24 DiagnosticsPrivateSendPacketFunction::~DiagnosticsPrivateSendPacketFunction() {} | |
25 | |
26 bool DiagnosticsPrivateSendPacketFunction::Prepare() { | |
27 parameters_ = SendPacket::Params::Create(*args_); | |
28 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | |
29 return true; | |
30 } | |
31 | |
32 void DiagnosticsPrivateSendPacketFunction::AsyncWorkStart() { | |
33 extensions::SendPingPacket( | |
34 parameters_->options.ip, | |
35 parameters_->options.ttl.get(), | |
36 parameters_->options.timeout.get(), | |
37 parameters_->options.size.get(), | |
38 base::Bind(&DiagnosticsPrivateSendPacketFunction::OnComplete, this)); | |
39 } | |
40 | |
41 bool DiagnosticsPrivateSendPacketFunction::Respond() { | |
42 return error_.empty(); | |
43 } | |
44 | |
45 void DiagnosticsPrivateSendPacketFunction::OnComplete( | |
46 SendPingPacketErrorCode error_code, | |
47 const std::string& ip, | |
48 double latency) { | |
49 if (error_code == extensions::SEND_PING_PACKET_OK) { | |
50 extensions::api::diagnostics_private::SendPacketResult result; | |
51 result.ip = ip; | |
52 result.latency = latency; | |
53 SetResult(result.ToValue().release()); | |
54 } else { | |
55 switch (error_code) { | |
56 case extensions::SEND_PING_PACKET_NOT_IMPLEMENTED: | |
stevenjb
2013/06/18 22:14:51
indent case 2 spaces past switch, following lines
Bei Zhang
2013/06/18 23:48:40
Done.
| |
57 SetError(kErrorPingNotImplemented); | |
58 break; | |
59 case extensions::SEND_PING_PACKET_FAILED: | |
60 SetError(kErrorPingFailed); | |
61 break; | |
62 case extensions::SEND_PING_PACKET_OK: | |
63 NOTREACHED(); | |
64 break; | |
65 } | |
66 } | |
67 AsyncWorkCompleted(); | |
68 } | |
69 | |
70 } // namespace extensions | |
OLD | NEW |