Finish refactoring of DomCodeToUsLayoutKeyboardCode().
[chromium-blink-merge.git] / extensions / browser / api / diagnostics / diagnostics_api.cc
blob684577ce6fdfb4223ab058e5e634ef3a9ee13a69
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"
7 namespace {
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());
26 return true;
29 bool DiagnosticsSendPacketFunction::Respond() {
30 return error_.empty();
33 void DiagnosticsSendPacketFunction::OnCompleted(
34 SendPacketResultCode result_code,
35 const std::string& ip,
36 double latency) {
37 switch (result_code) {
38 case SEND_PACKET_OK: {
39 core_api::diagnostics::SendPacketResult result;
40 result.ip = ip;
41 result.latency = latency;
42 results_ = SendPacket::Results::Create(result);
43 break;
45 case SEND_PACKET_NOT_IMPLEMENTED:
46 SetError(kErrorPingNotImplemented);
47 break;
48 case SEND_PACKET_FAILED:
49 SetError(kErrorPingFailed);
50 break;
52 AsyncWorkCompleted();
55 } // namespace extensions