Index: chrome/browser/chromeos/extensions/networking_private_api.h |
diff --git a/chrome/browser/chromeos/extensions/networking_private_api.h b/chrome/browser/chromeos/extensions/networking_private_api.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..dde2c268f481bb2789063cdf00329b94f6ddc9bd |
--- /dev/null |
+++ b/chrome/browser/chromeos/extensions/networking_private_api.h |
@@ -0,0 +1,161 @@ |
+// 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. |
+ |
+// These classes implement the chrome.networkingPrivate JavaScript extension |
+// API. |
+ |
+#ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_NETWORKING_PRIVATE_API_H_ |
+#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_NETWORKING_PRIVATE_API_H_ |
+ |
+#include <string> |
+ |
+#include "base/memory/ref_counted.h" |
+#include "base/values.h" |
+#include "chrome/browser/extensions/extension_function.h" |
+#include "chrome/browser/profiles/profile_keyed_service.h" |
+#include "chromeos/dbus/dbus_method_call_status.h" |
+ |
+namespace chromeos { |
+ |
+// Implements the chrome.networkingPrivate.getProperties method. |
+class NetworkingGetPropertiesFunction : public AsyncExtensionFunction { |
+ public: |
+ NetworkingGetPropertiesFunction() {} |
+ DECLARE_EXTENSION_FUNCTION_NAME("networkingPrivate.getProperties"); |
+ |
+ protected: |
+ virtual ~NetworkingGetPropertiesFunction(); |
+ |
+ // AsyncExtensionFunction overrides. |
+ virtual bool RunImpl() OVERRIDE; |
+ |
+ private: |
+ void ResultCallback(DBusMethodCallStatus call_status, |
+ const base::DictionaryValue& result); |
+ DISALLOW_COPY_AND_ASSIGN(NetworkingGetPropertiesFunction); |
+}; |
+ |
+// Implements the chrome.networkingPrivate.getVisibleNetworks method. |
+class NetworkingGetVisibleNetworksFunction : public AsyncExtensionFunction { |
+ public: |
+ NetworkingGetVisibleNetworksFunction() {} |
+ DECLARE_EXTENSION_FUNCTION_NAME("networkingPrivate.getVisibleNetworks"); |
+ |
+ protected: |
+ virtual ~NetworkingGetVisibleNetworksFunction(); |
+ |
+ // AsyncExtensionFunction overrides. |
+ virtual bool RunImpl() OVERRIDE; |
+ |
+ private: |
+ class ScopedDecrementer; |
+ |
+ class ResultList : public base::RefCounted<ResultList> { |
+ public: |
+ explicit ResultList(int count); |
+ |
+ int count() const { return count_; } |
+ base::ListValue* release() { return list_.release(); } |
+ void Append(base::Value* value); |
+ |
+ private: |
+ friend class base::RefCounted<ResultList>; |
+ friend class ScopedDecrementer; |
+ ~ResultList(); |
+ |
+ scoped_ptr<base::ListValue> list_; |
+ int count_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ResultList); |
+ }; |
+ |
+ class ScopedDecrementer { |
pneubeck (no reviews)
2013/01/18 13:22:36
The forward declaration is enough, this can move t
Greg Spencer (Chromium)
2013/01/18 19:53:56
Done, and for ResultList too.
|
+ public: |
+ ScopedDecrementer(NetworkingGetVisibleNetworksFunction* parent, |
+ scoped_refptr<ResultList> result_list); |
+ ~ScopedDecrementer(); |
+ |
+ private: |
+ NetworkingGetVisibleNetworksFunction* parent_; |
+ scoped_refptr<ResultList> result_list_; |
+ }; |
+ |
+ void ManagerPropertiesCallback(const std::string& network_type, |
+ DBusMethodCallStatus call_status, |
+ const base::DictionaryValue& result); |
+ |
+ void ServicePropertiesCallback(const std::string& service_path, |
+ const std::string& network_type, |
+ scoped_refptr<ResultList> result_list, |
+ DBusMethodCallStatus call_status, |
+ const base::DictionaryValue& result); |
+ |
+ DISALLOW_COPY_AND_ASSIGN(NetworkingGetVisibleNetworksFunction); |
+}; |
+ |
+// Implements the chrome.networkingPrivate.requestConnect method. |
+class NetworkingRequestConnectFunction : public AsyncExtensionFunction { |
+ public: |
+ NetworkingRequestConnectFunction() {} |
+ DECLARE_EXTENSION_FUNCTION_NAME("networkingPrivate.requestConnect"); |
+ |
+ protected: |
+ virtual ~NetworkingRequestConnectFunction(); |
+ |
+ // AsyncExtensionFunction overrides. |
+ virtual bool RunImpl() OVERRIDE; |
+ |
+ private: |
+ // Called when the request to connect succeeds. Doesn't mean that the connect |
+ // itself succeeded, just that the request did. |
+ void ConnectRequestSuccess(); |
+ |
+ void ConnectRequestFailed(const std::string& errorName, |
+ const std::string& errorMessage); |
+ |
+ DISALLOW_COPY_AND_ASSIGN(NetworkingRequestConnectFunction); |
+}; |
+ |
+// Implements the chrome.networkingPrivate.requestDisconnect method. |
+class NetworkingRequestDisconnectFunction : public AsyncExtensionFunction { |
+ public: |
+ NetworkingRequestDisconnectFunction() {} |
+ DECLARE_EXTENSION_FUNCTION_NAME("networkingPrivate.requestDisconnect"); |
+ |
+ protected: |
+ virtual ~NetworkingRequestDisconnectFunction(); |
+ |
+ // AsyncExtensionFunction overrides. |
+ virtual bool RunImpl() OVERRIDE; |
+ |
+ private: |
+ // Called when the request to disconnect succeeds. Doesn't mean that the |
+ // disconnect itself succeeded, just that the request did. |
+ void DisconnectRequestSuccess(); |
+ |
+ void DisconnectRequestFailed(const std::string& errorName, |
+ const std::string& errorMessage); |
+ |
+ DISALLOW_COPY_AND_ASSIGN(NetworkingRequestDisconnectFunction); |
+}; |
+ |
+// Manages and registers the networkingPrivate API with the extension system. |
+class NetworkingPrivateAPI : public ProfileKeyedService { |
+ public: |
+ explicit NetworkingPrivateAPI(Profile* profile); |
+ virtual ~NetworkingPrivateAPI(); |
+ |
+ // ProfileKeyedService overrides. |
+ virtual void Shutdown() OVERRIDE; |
+ |
+ // Convenience function to return the NetworkingPrivateAPI for a Profile. |
+ static NetworkingPrivateAPI* Get(Profile* profile); |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateAPI); |
+}; |
+ |
+} // namespace chromeos |
+ |
+#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_NETWORKING_PRIVATE_API_H_ |