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