• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "chrome/browser/extensions/api/diagnostics/diagnostics_api.h"
6 
7 namespace SendPacket = extensions::api::diagnostics::SendPacket;
8 
9 namespace {
10 
11 const char kErrorPingNotImplemented[] = "Not implemented";
12 const char kErrorPingFailed[] = "Failed to send ping packet";
13 
14 }
15 
16 namespace extensions {
17 
DiagnosticsSendPacketFunction()18 DiagnosticsSendPacketFunction::DiagnosticsSendPacketFunction() {}
19 
~DiagnosticsSendPacketFunction()20 DiagnosticsSendPacketFunction::~DiagnosticsSendPacketFunction() {}
21 
Prepare()22 bool DiagnosticsSendPacketFunction::Prepare() {
23   parameters_ = SendPacket::Params::Create(*args_);
24   EXTENSION_FUNCTION_VALIDATE(parameters_.get());
25   return true;
26 }
27 
Respond()28 bool DiagnosticsSendPacketFunction::Respond() {
29   return error_.empty();
30 }
31 
OnCompleted(SendPacketResultCode result_code,const std::string & ip,double latency)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;
43     }
44     case SEND_PACKET_NOT_IMPLEMENTED:
45       SetError(kErrorPingNotImplemented);
46       break;
47     case SEND_PACKET_FAILED:
48       SetError(kErrorPingFailed);
49       break;
50   }
51   AsyncWorkCompleted();
52 }
53 
54 }  // namespace extensions
55