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 #ifndef CHROME_BROWSER_EXTENSIONS_API_DIAGNOSTICS_DIAGNOSTICS_API_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_DIAGNOSTICS_DIAGNOSTICS_API_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_DIAGNOSTICS_DIAGNOSTICS_API_H_ | 6 #define EXTENSIONS_BROWSER_API_DIAGNOSTICS_DIAGNOSTICS_API_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "chrome/common/extensions/api/diagnostics.h" | |
12 #include "extensions/browser/api/async_api_function.h" | 11 #include "extensions/browser/api/async_api_function.h" |
| 12 #include "extensions/common/api/diagnostics.h" |
13 | 13 |
14 namespace extensions { | 14 namespace extensions { |
15 | 15 |
16 class DiagnosticsSendPacketFunction : public AsyncApiFunction { | 16 class DiagnosticsSendPacketFunction : public AsyncApiFunction { |
17 public: | 17 public: |
18 // Result code for sending packet. Platform specific AsyncWorkStart() will | 18 // Result code for sending packet. Platform specific AsyncWorkStart() will |
19 // finish with this ResultCode so we can maximize shared code. | 19 // finish with this ResultCode so we can maximize shared code. |
20 enum SendPacketResultCode { | 20 enum SendPacketResultCode { |
21 // Ping packed is sent and ICMP reply is received before time out. | 21 // Ping packed is sent and ICMP reply is received before time out. |
22 SEND_PACKET_OK, | 22 SEND_PACKET_OK, |
23 | 23 |
24 // Not implemented on the platform. | 24 // Not implemented on the platform. |
25 SEND_PACKET_NOT_IMPLEMENTED, | 25 SEND_PACKET_NOT_IMPLEMENTED, |
26 | 26 |
27 // The ping operation failed because of timeout or network unreachable. | 27 // The ping operation failed because of timeout or network unreachable. |
28 SEND_PACKET_FAILED, | 28 SEND_PACKET_FAILED, |
29 }; | 29 }; |
30 | 30 |
31 DECLARE_EXTENSION_FUNCTION("diagnostics.sendPacket", | 31 DECLARE_EXTENSION_FUNCTION("diagnostics.sendPacket", DIAGNOSTICS_SENDPACKET); |
32 DIAGNOSTICS_SENDPACKET); | |
33 | 32 |
34 DiagnosticsSendPacketFunction(); | 33 DiagnosticsSendPacketFunction(); |
35 | 34 |
36 protected: | 35 protected: |
37 ~DiagnosticsSendPacketFunction() override; | 36 ~DiagnosticsSendPacketFunction() override; |
38 | 37 |
39 // AsyncApiFunction: | 38 // AsyncApiFunction: |
40 bool Prepare() override; | 39 bool Prepare() override; |
41 // This methods will be implemented differently on different platforms. | 40 // This methods will be implemented differently on different platforms. |
42 void AsyncWorkStart() override; | 41 void AsyncWorkStart() override; |
43 bool Respond() override; | 42 bool Respond() override; |
44 | 43 |
45 private: | 44 private: |
46 void SendPingPacket(); | 45 void SendPingPacket(); |
47 void OnCompleted(SendPacketResultCode result_code, | 46 void OnCompleted(SendPacketResultCode result_code, |
48 const std::string& ip, | 47 const std::string& ip, |
49 double latency); | 48 double latency); |
50 | 49 |
51 scoped_ptr<extensions::api::diagnostics::SendPacket::Params> | 50 scoped_ptr<core_api::diagnostics::SendPacket::Params> parameters_; |
52 parameters_; | |
53 }; | 51 }; |
54 | 52 |
55 } // namespace extensions | 53 } // namespace extensions |
56 | 54 |
57 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAGNOSTICS_DIAGNOSTICS_API_H_ | 55 #endif // EXTENSIONS_BROWSER_API_DIAGNOSTICS_DIAGNOSTICS_API_H_ |
OLD | NEW |