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 "extensions/browser/api/diagnostics/diagnostics_api.h"
9 const char kErrorPingNotImplemented
[] = "Not implemented";
10 const char kErrorPingFailed
[] = "Failed to send ping packet";
13 namespace extensions
{
15 namespace SendPacket
= core_api::diagnostics::SendPacket
;
17 DiagnosticsSendPacketFunction::DiagnosticsSendPacketFunction() {
20 DiagnosticsSendPacketFunction::~DiagnosticsSendPacketFunction() {
23 bool DiagnosticsSendPacketFunction::Prepare() {
24 parameters_
= SendPacket::Params::Create(*args_
);
25 EXTENSION_FUNCTION_VALIDATE(parameters_
.get());
29 bool DiagnosticsSendPacketFunction::Respond() {
30 return error_
.empty();
33 void DiagnosticsSendPacketFunction::OnCompleted(
34 SendPacketResultCode result_code
,
35 const std::string
& ip
,
37 switch (result_code
) {
38 case SEND_PACKET_OK
: {
39 core_api::diagnostics::SendPacketResult result
;
41 result
.latency
= latency
;
42 results_
= SendPacket::Results::Create(result
);
45 case SEND_PACKET_NOT_IMPLEMENTED
:
46 SetError(kErrorPingNotImplemented
);
48 case SEND_PACKET_FAILED
:
49 SetError(kErrorPingFailed
);
55 } // namespace extensions