1 // Copyright 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.
5 #include "chrome/browser/extensions/api/diagnostics/diagnostics_api.h"
7 namespace SendPacket
= extensions::api::diagnostics::SendPacket
;
11 const char kErrorPingNotImplemented
[] = "Not implemented";
12 const char kErrorPingFailed
[] = "Failed to send ping packet";
16 namespace extensions
{
18 DiagnosticsSendPacketFunction::DiagnosticsSendPacketFunction() {}
20 DiagnosticsSendPacketFunction::~DiagnosticsSendPacketFunction() {}
22 bool DiagnosticsSendPacketFunction::Prepare() {
23 parameters_
= SendPacket::Params::Create(*args_
);
24 EXTENSION_FUNCTION_VALIDATE(parameters_
.get());
28 bool DiagnosticsSendPacketFunction::Respond() {
29 return error_
.empty();
32 void DiagnosticsSendPacketFunction::OnCompleted(
33 SendPacketResultCode result_code
,
34 const std::string
& ip
,
36 switch (result_code
) {
37 case SEND_PACKET_OK
: {
38 extensions::api::diagnostics::SendPacketResult result
;
40 result
.latency
= latency
;
41 results_
= SendPacket::Results::Create(result
);
44 case SEND_PACKET_NOT_IMPLEMENTED
:
45 SetError(kErrorPingNotImplemented
);
47 case SEND_PACKET_FAILED
:
48 SetError(kErrorPingFailed
);
54 } // namespace extensions