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..f6bb66934614b00aa28f96ce38bc7da3ea4d13ba |
--- /dev/null |
+++ b/chrome/browser/extensions/api/diagnostics_private/diagnostics_private_api.cc |
@@ -0,0 +1,53 @@ |
+// 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 extensions { |
+ |
+DiagnosticsPrivateSendPacketFunction::DiagnosticsPrivateSendPacketFunction() {} |
+ |
+DiagnosticsPrivateSendPacketFunction::~DiagnosticsPrivateSendPacketFunction() {} |
+ |
+bool DiagnosticsPrivateSendPacketFunction::Prepare() { |
+ parameters_ = SendPacket::Params::Create(*args_); |
+ EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
+ return true; |
+} |
+ |
+void DiagnosticsPrivateSendPacketFunction::AsyncWorkStart() { |
+ SendPingPacket( |
stevenjb
2013/06/18 19:19:28
qualify this with extensions:: to make it clear th
Bei Zhang
2013/06/18 22:04:46
Done.
|
+ 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( |
+ const std::string& error, |
+ const std::string& ip, |
+ double latency) { |
+ if (error.empty()) { |
+ extensions::api::diagnostics_private::SendPacketResult result; |
+ result.ip = ip; |
+ result.latency = latency; |
+ SetResult(result.ToValue().release()); |
+ } else { |
+ SetError(error); |
+ } |
+ AsyncWorkCompleted(); |
+} |
+ |
+} // namespace extensions |