Chromium Code Reviews| Index: chrome/browser/extensions/api/diagnostics/diagnostics_api.cc |
| diff --git a/chrome/browser/extensions/api/diagnostics/diagnostics_api.cc b/chrome/browser/extensions/api/diagnostics/diagnostics_api.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..25b3b909b7981c6e2ed49802d8b3bee6c4347e5f |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/diagnostics/diagnostics_api.cc |
| @@ -0,0 +1,68 @@ |
| +// 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 "chrome/browser/extensions/api/diagnostics/diagnostics_api.h" |
| + |
| +#include "chrome/browser/extensions/api/diagnostics/send_ping_packet.h" |
| + |
| +namespace SendPacket = extensions::api::diagnostics::SendPacket; |
| + |
| +using base::Callback; |
| + |
| +namespace { |
| + |
| +const char kErrorPingNotImplemented[] = "Not implemented."; |
| +const char kErrorPingFailed[] = "Failed to send ping packet."; |
|
asargent_no_longer_on_chrome
2013/06/20 22:51:29
nit: I think we usually don't end the developer-re
Bei Zhang
2013/06/21 08:31:07
Done.
|
| + |
| +} |
| + |
| +namespace extensions { |
| + |
| +DiagnosticsSendPacketFunction::DiagnosticsSendPacketFunction() {} |
| + |
| +DiagnosticsSendPacketFunction::~DiagnosticsSendPacketFunction() {} |
| + |
| +bool DiagnosticsSendPacketFunction::Prepare() { |
| + parameters_ = SendPacket::Params::Create(*args_); |
| + EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
| + return true; |
| +} |
| + |
| +void DiagnosticsSendPacketFunction::AsyncWorkStart() { |
| + extensions::SendPingPacket( |
| + parameters_->options.ip, |
| + parameters_->options.ttl.get(), |
| + parameters_->options.timeout.get(), |
| + parameters_->options.size.get(), |
| + base::Bind(&DiagnosticsSendPacketFunction::OnComplete, this)); |
| +} |
| + |
| +bool DiagnosticsSendPacketFunction::Respond() { |
| + return error_.empty(); |
| +} |
| + |
| +void DiagnosticsSendPacketFunction::OnComplete( |
| + SendPingPacketResultCode result_code, |
| + const std::string& ip, |
| + double latency) { |
| + |
| + switch (result_code) { |
| + case extensions::SEND_PING_PACKET_OK: { |
| + extensions::api::diagnostics::SendPacketResult result; |
| + result.ip = ip; |
| + result.latency = latency; |
| + SetResult(result.ToValue().release()); |
| + break; |
| + } |
| + case extensions::SEND_PING_PACKET_NOT_IMPLEMENTED: |
| + SetError(kErrorPingNotImplemented); |
| + break; |
| + case extensions::SEND_PING_PACKET_FAILED: |
| + SetError(kErrorPingFailed); |
| + break; |
| + } |
|
xiaowenx
2013/06/20 19:42:44
Do you want to have a default case that also does
Bei Zhang
2013/06/21 08:31:07
default case for enums are not recommended as it m
|
| + AsyncWorkCompleted(); |
| +} |
| + |
| +} // namespace extensions |