Chromium Code Reviews| Index: chrome/browser/extensions/api/diagnostics_private/diagnostics_private_api.cc |
| diff --git a/chrome/browser/extensions/api/diagnostics_private/diagnostics_private_api.cc b/chrome/browser/extensions/api/diagnostics_private/diagnostics_private_api.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0e793b6aeaf941edc39eb4a2b0459fdf4ce470a6 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/diagnostics_private/diagnostics_private_api.cc |
| @@ -0,0 +1,70 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "diagnostics_private_api.h" |
| + |
| +#include "chrome/browser/extensions/api/diagnostics_private/send_ping_packet.h" |
| + |
| +namespace SendPacket = extensions::api::diagnostics_private::SendPacket; |
| + |
| +using base::Callback; |
| + |
| +namespace { |
| + |
| +const char kErrorPingNotImplemented[] = "Not implemented."; |
| +const char kErrorPingFailed[] = "Failed to send ping packet."; |
| + |
| +} |
| + |
| +namespace extensions { |
| + |
| +DiagnosticsPrivateSendPacketFunction::DiagnosticsPrivateSendPacketFunction() {} |
| + |
| +DiagnosticsPrivateSendPacketFunction::~DiagnosticsPrivateSendPacketFunction() {} |
| + |
| +bool DiagnosticsPrivateSendPacketFunction::Prepare() { |
| + parameters_ = SendPacket::Params::Create(*args_); |
| + EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
| + return true; |
| +} |
| + |
| +void DiagnosticsPrivateSendPacketFunction::AsyncWorkStart() { |
| + extensions::SendPingPacket( |
| + parameters_->options.ip, |
| + parameters_->options.ttl.get(), |
| + parameters_->options.timeout.get(), |
| + parameters_->options.size.get(), |
| + base::Bind(&DiagnosticsPrivateSendPacketFunction::OnComplete, this)); |
| +} |
| + |
| +bool DiagnosticsPrivateSendPacketFunction::Respond() { |
| + return error_.empty(); |
| +} |
| + |
| +void DiagnosticsPrivateSendPacketFunction::OnComplete( |
| + SendPingPacketErrorCode error_code, |
| + const std::string& ip, |
| + double latency) { |
| + if (error_code == extensions::SEND_PING_PACKET_OK) { |
| + extensions::api::diagnostics_private::SendPacketResult result; |
| + result.ip = ip; |
| + result.latency = latency; |
| + SetResult(result.ToValue().release()); |
| + } else { |
| + switch (error_code) { |
| + case extensions::SEND_PING_PACKET_NOT_IMPLEMENTED: |
|
stevenjb
2013/06/18 22:14:51
indent case 2 spaces past switch, following lines
Bei Zhang
2013/06/18 23:48:40
Done.
|
| + SetError(kErrorPingNotImplemented); |
| + break; |
| + case extensions::SEND_PING_PACKET_FAILED: |
| + SetError(kErrorPingFailed); |
| + break; |
| + case extensions::SEND_PING_PACKET_OK: |
| + NOTREACHED(); |
| + break; |
| + } |
| + } |
| + AsyncWorkCompleted(); |
| +} |
| + |
| +} // namespace extensions |