| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/browser/api/diagnostics/diagnostics_api.h" | 5 #include "extensions/browser/api/diagnostics/diagnostics_api.h" |
| 6 | 6 |
| 7 namespace { | 7 namespace { |
| 8 | 8 |
| 9 const char kErrorPingNotImplemented[] = "Not implemented"; | 9 const char kErrorPingNotImplemented[] = "Not implemented"; |
| 10 const char kErrorPingFailed[] = "Failed to send ping packet"; | 10 const char kErrorPingFailed[] = "Failed to send ping packet"; |
| 11 } | 11 } |
| 12 | 12 |
| 13 namespace extensions { | 13 namespace extensions { |
| 14 | 14 |
| 15 namespace SendPacket = core_api::diagnostics::SendPacket; | 15 namespace SendPacket = api::diagnostics::SendPacket; |
| 16 | 16 |
| 17 DiagnosticsSendPacketFunction::DiagnosticsSendPacketFunction() { | 17 DiagnosticsSendPacketFunction::DiagnosticsSendPacketFunction() { |
| 18 } | 18 } |
| 19 | 19 |
| 20 DiagnosticsSendPacketFunction::~DiagnosticsSendPacketFunction() { | 20 DiagnosticsSendPacketFunction::~DiagnosticsSendPacketFunction() { |
| 21 } | 21 } |
| 22 | 22 |
| 23 bool DiagnosticsSendPacketFunction::Prepare() { | 23 bool DiagnosticsSendPacketFunction::Prepare() { |
| 24 parameters_ = SendPacket::Params::Create(*args_); | 24 parameters_ = SendPacket::Params::Create(*args_); |
| 25 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); | 25 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
| 26 return true; | 26 return true; |
| 27 } | 27 } |
| 28 | 28 |
| 29 bool DiagnosticsSendPacketFunction::Respond() { | 29 bool DiagnosticsSendPacketFunction::Respond() { |
| 30 return error_.empty(); | 30 return error_.empty(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void DiagnosticsSendPacketFunction::OnCompleted( | 33 void DiagnosticsSendPacketFunction::OnCompleted( |
| 34 SendPacketResultCode result_code, | 34 SendPacketResultCode result_code, |
| 35 const std::string& ip, | 35 const std::string& ip, |
| 36 double latency) { | 36 double latency) { |
| 37 switch (result_code) { | 37 switch (result_code) { |
| 38 case SEND_PACKET_OK: { | 38 case SEND_PACKET_OK: { |
| 39 core_api::diagnostics::SendPacketResult result; | 39 api::diagnostics::SendPacketResult result; |
| 40 result.ip = ip; | 40 result.ip = ip; |
| 41 result.latency = latency; | 41 result.latency = latency; |
| 42 results_ = SendPacket::Results::Create(result); | 42 results_ = SendPacket::Results::Create(result); |
| 43 break; | 43 break; |
| 44 } | 44 } |
| 45 case SEND_PACKET_NOT_IMPLEMENTED: | 45 case SEND_PACKET_NOT_IMPLEMENTED: |
| 46 SetError(kErrorPingNotImplemented); | 46 SetError(kErrorPingNotImplemented); |
| 47 break; | 47 break; |
| 48 case SEND_PACKET_FAILED: | 48 case SEND_PACKET_FAILED: |
| 49 SetError(kErrorPingFailed); | 49 SetError(kErrorPingFailed); |
| 50 break; | 50 break; |
| 51 } | 51 } |
| 52 AsyncWorkCompleted(); | 52 AsyncWorkCompleted(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 } // namespace extensions | 55 } // namespace extensions |
| OLD | NEW |