OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // These classes implement the chrome.networkingPrivate JavaScript extension |
| 6 // API. |
| 7 |
| 8 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_NETWORKING_PRIVATE_API_H_ |
| 9 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_NETWORKING_PRIVATE_API_H_ |
| 10 |
| 11 #include <string> |
| 12 |
| 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/values.h" |
| 15 #include "chrome/browser/extensions/extension_function.h" |
| 16 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 17 #include "chromeos/dbus/dbus_method_call_status.h" |
| 18 |
| 19 namespace chromeos { |
| 20 |
| 21 // Implements the chrome.networkingPrivate.getProperties method. |
| 22 class NetworkingGetPropertiesFunction : public AsyncExtensionFunction { |
| 23 public: |
| 24 NetworkingGetPropertiesFunction() {} |
| 25 DECLARE_EXTENSION_FUNCTION("networkingPrivate.getProperties", |
| 26 NETWORKINGPRIVATE_GETPROPERTIES); |
| 27 |
| 28 protected: |
| 29 virtual ~NetworkingGetPropertiesFunction(); |
| 30 |
| 31 // AsyncExtensionFunction overrides. |
| 32 virtual bool RunImpl() OVERRIDE; |
| 33 |
| 34 private: |
| 35 void ResultCallback(DBusMethodCallStatus call_status, |
| 36 const base::DictionaryValue& result); |
| 37 DISALLOW_COPY_AND_ASSIGN(NetworkingGetPropertiesFunction); |
| 38 }; |
| 39 |
| 40 // Implements the chrome.networkingPrivate.getVisibleNetworks method. |
| 41 class NetworkingGetVisibleNetworksFunction : public AsyncExtensionFunction { |
| 42 public: |
| 43 NetworkingGetVisibleNetworksFunction() {} |
| 44 DECLARE_EXTENSION_FUNCTION("networkingPrivate.getVisibleNetworks", |
| 45 NETWORKINGPRIVATE_GETVISIBLENETWORKS); |
| 46 |
| 47 protected: |
| 48 virtual ~NetworkingGetVisibleNetworksFunction(); |
| 49 |
| 50 // AsyncExtensionFunction overrides. |
| 51 virtual bool RunImpl() OVERRIDE; |
| 52 |
| 53 private: |
| 54 class ResultList; |
| 55 |
| 56 void ManagerPropertiesCallback(const std::string& network_type, |
| 57 DBusMethodCallStatus call_status, |
| 58 const base::DictionaryValue& result); |
| 59 |
| 60 void ServicePropertiesCallback(const std::string& service_path, |
| 61 const std::string& network_type, |
| 62 scoped_refptr<ResultList> result_list, |
| 63 DBusMethodCallStatus call_status, |
| 64 const base::DictionaryValue& result); |
| 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(NetworkingGetVisibleNetworksFunction); |
| 67 }; |
| 68 |
| 69 // Implements the chrome.networkingPrivate.requestConnect method. |
| 70 class NetworkingRequestConnectFunction : public AsyncExtensionFunction { |
| 71 public: |
| 72 NetworkingRequestConnectFunction() {} |
| 73 DECLARE_EXTENSION_FUNCTION("networkingPrivate.requestConnect", |
| 74 NETWORKINGPRIVATE_REQUESTCONNECT); |
| 75 |
| 76 protected: |
| 77 virtual ~NetworkingRequestConnectFunction(); |
| 78 |
| 79 // AsyncExtensionFunction overrides. |
| 80 virtual bool RunImpl() OVERRIDE; |
| 81 |
| 82 private: |
| 83 // Called when the request to connect succeeds. Doesn't mean that the connect |
| 84 // itself succeeded, just that the request did. |
| 85 void ConnectRequestSuccess(); |
| 86 |
| 87 void ConnectRequestFailed(const std::string& errorName, |
| 88 const std::string& errorMessage); |
| 89 |
| 90 DISALLOW_COPY_AND_ASSIGN(NetworkingRequestConnectFunction); |
| 91 }; |
| 92 |
| 93 // Implements the chrome.networkingPrivate.requestDisconnect method. |
| 94 class NetworkingRequestDisconnectFunction : public AsyncExtensionFunction { |
| 95 public: |
| 96 NetworkingRequestDisconnectFunction() {} |
| 97 DECLARE_EXTENSION_FUNCTION("networkingPrivate.requestDisconnect", |
| 98 NETWORKINGPRIVATE_REQUESTDISCONNECT); |
| 99 |
| 100 protected: |
| 101 virtual ~NetworkingRequestDisconnectFunction(); |
| 102 |
| 103 // AsyncExtensionFunction overrides. |
| 104 virtual bool RunImpl() OVERRIDE; |
| 105 |
| 106 private: |
| 107 // Called when the request to disconnect succeeds. Doesn't mean that the |
| 108 // disconnect itself succeeded, just that the request did. |
| 109 void DisconnectRequestSuccess(); |
| 110 |
| 111 void DisconnectRequestFailed(const std::string& errorName, |
| 112 const std::string& errorMessage); |
| 113 |
| 114 DISALLOW_COPY_AND_ASSIGN(NetworkingRequestDisconnectFunction); |
| 115 }; |
| 116 |
| 117 // Manages and registers the networkingPrivate API with the extension system. |
| 118 class NetworkingPrivateAPI : public ProfileKeyedService { |
| 119 public: |
| 120 explicit NetworkingPrivateAPI(Profile* profile); |
| 121 virtual ~NetworkingPrivateAPI(); |
| 122 |
| 123 // ProfileKeyedService overrides. |
| 124 virtual void Shutdown() OVERRIDE; |
| 125 |
| 126 // Convenience function to return the NetworkingPrivateAPI for a Profile. |
| 127 static NetworkingPrivateAPI* Get(Profile* profile); |
| 128 |
| 129 private: |
| 130 DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateAPI); |
| 131 }; |
| 132 |
| 133 } // namespace chromeos |
| 134 |
| 135 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_NETWORKING_PRIVATE_API_H_ |
OLD | NEW |