[EasyUnlock] Add a private API for establishing an insecure Bluetooth connection.
[chromium-blink-merge.git] / chrome / browser / extensions / api / diagnostics / diagnostics_api.cc
blob0f6e8d286d2a56464dab7146096bc81f0d56fd3f
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;
9 namespace {
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());
25 return true;
28 bool DiagnosticsSendPacketFunction::Respond() {
29 return error_.empty();
32 void DiagnosticsSendPacketFunction::OnCompleted(
33 SendPacketResultCode result_code,
34 const std::string& ip,
35 double latency) {
36 switch (result_code) {
37 case SEND_PACKET_OK: {
38 extensions::api::diagnostics::SendPacketResult result;
39 result.ip = ip;
40 result.latency = latency;
41 results_ = SendPacket::Results::Create(result);
42 break;
44 case SEND_PACKET_NOT_IMPLEMENTED:
45 SetError(kErrorPingNotImplemented);
46 break;
47 case SEND_PACKET_FAILED:
48 SetError(kErrorPingFailed);
49 break;
51 AsyncWorkCompleted();
54 } // namespace extensions