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 "chrome/browser/extensions/api/diagnostics/diagnostics_api.h" | |
6 | |
7 #include "chrome/browser/extensions/api/diagnostics/send_ping_packet.h" | |
8 | |
9 namespace SendPacket = extensions::api::diagnostics::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."; | |
asargent_no_longer_on_chrome
2013/06/20 22:51:29
nit: I think we usually don't end the developer-re
Bei Zhang
2013/06/21 08:31:07
Done.
| |
17 | |
18 } | |
19 | |
20 namespace extensions { | |
21 | |
22 DiagnosticsSendPacketFunction::DiagnosticsSendPacketFunction() {} | |
23 | |
24 DiagnosticsSendPacketFunction::~DiagnosticsSendPacketFunction() {} | |
25 | |
26 bool DiagnosticsSendPacketFunction::Prepare() { | |
27 parameters_ = SendPacket::Params::Create(*args_); | |
28 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | |
29 return true; | |
30 } | |
31 | |
32 void DiagnosticsSendPacketFunction::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(&DiagnosticsSendPacketFunction::OnComplete, this)); | |
39 } | |
40 | |
41 bool DiagnosticsSendPacketFunction::Respond() { | |
42 return error_.empty(); | |
43 } | |
44 | |
45 void DiagnosticsSendPacketFunction::OnComplete( | |
46 SendPingPacketResultCode result_code, | |
47 const std::string& ip, | |
48 double latency) { | |
49 | |
50 switch (result_code) { | |
51 case extensions::SEND_PING_PACKET_OK: { | |
52 extensions::api::diagnostics::SendPacketResult result; | |
53 result.ip = ip; | |
54 result.latency = latency; | |
55 SetResult(result.ToValue().release()); | |
56 break; | |
57 } | |
58 case extensions::SEND_PING_PACKET_NOT_IMPLEMENTED: | |
59 SetError(kErrorPingNotImplemented); | |
60 break; | |
61 case extensions::SEND_PING_PACKET_FAILED: | |
62 SetError(kErrorPingFailed); | |
63 break; | |
64 } | |
xiaowenx
2013/06/20 19:42:44
Do you want to have a default case that also does
Bei Zhang
2013/06/21 08:31:07
default case for enums are not recommended as it m
| |
65 AsyncWorkCompleted(); | |
66 } | |
67 | |
68 } // namespace extensions | |
OLD | NEW |