Chromium Code Reviews| 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_NAME("networkingPrivate.getProperties"); | |
| 26 | |
| 27 protected: | |
| 28 virtual ~NetworkingGetPropertiesFunction(); | |
| 29 | |
| 30 // AsyncExtensionFunction overrides. | |
| 31 virtual bool RunImpl() OVERRIDE; | |
| 32 | |
| 33 private: | |
| 34 void ResultCallback(DBusMethodCallStatus call_status, | |
| 35 const base::DictionaryValue& result); | |
| 36 DISALLOW_COPY_AND_ASSIGN(NetworkingGetPropertiesFunction); | |
| 37 }; | |
| 38 | |
| 39 // Implements the chrome.networkingPrivate.getVisibleNetworks method. | |
| 40 class NetworkingGetVisibleNetworksFunction : public AsyncExtensionFunction { | |
| 41 public: | |
| 42 NetworkingGetVisibleNetworksFunction() {} | |
| 43 DECLARE_EXTENSION_FUNCTION_NAME("networkingPrivate.getVisibleNetworks"); | |
| 44 | |
| 45 protected: | |
| 46 virtual ~NetworkingGetVisibleNetworksFunction(); | |
| 47 | |
| 48 // AsyncExtensionFunction overrides. | |
| 49 virtual bool RunImpl() OVERRIDE; | |
| 50 | |
| 51 private: | |
| 52 class ResultList : public base::RefCounted<ResultList> { | |
| 53 public: | |
| 54 ResultList() : list(new base::ListValue), count(0) {} | |
| 55 scoped_ptr<base::ListValue> list; | |
| 56 int count; | |
|
stevenjb
2013/01/17 00:04:30
Since this is a class, we should use member_ and a
Greg Spencer (Chromium)
2013/01/18 01:20:30
Yeah, OK. It really is just a struct with a const
| |
| 57 }; | |
| 58 | |
| 59 class ScopedDecrementer { | |
| 60 public: | |
| 61 ScopedDecrementer(NetworkingGetVisibleNetworksFunction* parent, | |
| 62 scoped_refptr<ResultList> result_list); | |
| 63 ~ScopedDecrementer(); | |
| 64 | |
| 65 private: | |
| 66 NetworkingGetVisibleNetworksFunction* parent_; | |
| 67 scoped_refptr<ResultList> result_list_; | |
| 68 }; | |
| 69 | |
| 70 void ManagerPropertiesCallback(const std::string& network_type, | |
| 71 DBusMethodCallStatus call_status, | |
| 72 const base::DictionaryValue& result); | |
| 73 void ServicePropertiesCallback(const std::string& service_path, | |
| 74 const std::string& network_type, | |
| 75 scoped_refptr<ResultList> result_list, | |
| 76 DBusMethodCallStatus call_status, | |
| 77 const base::DictionaryValue& result); | |
|
stevenjb
2013/01/17 00:04:30
nit: WS
Greg Spencer (Chromium)
2013/01/18 01:20:30
Done.
| |
| 78 DISALLOW_COPY_AND_ASSIGN(NetworkingGetVisibleNetworksFunction); | |
| 79 }; | |
| 80 | |
| 81 // Implements the chrome.networkingPrivate.requestConnect method. | |
| 82 class NetworkingRequestConnectFunction : public AsyncExtensionFunction { | |
| 83 public: | |
| 84 NetworkingRequestConnectFunction() {} | |
| 85 DECLARE_EXTENSION_FUNCTION_NAME("networkingPrivate.requestConnect"); | |
| 86 | |
| 87 protected: | |
| 88 virtual ~NetworkingRequestConnectFunction(); | |
| 89 | |
| 90 // AsyncExtensionFunction overrides. | |
| 91 virtual bool RunImpl() OVERRIDE; | |
| 92 | |
| 93 private: | |
| 94 void ConnectSuccess(); | |
| 95 void ConnectFailed(const std::string& errorName, | |
| 96 const std::string& errorMessage); | |
|
stevenjb
2013/01/17 00:04:30
nit: WS
Greg Spencer (Chromium)
2013/01/18 01:20:30
Done.
| |
| 97 DISALLOW_COPY_AND_ASSIGN(NetworkingRequestConnectFunction); | |
| 98 }; | |
| 99 | |
| 100 // Implements the chrome.networkingPrivate.requestDisconnect method. | |
| 101 class NetworkingRequestDisconnectFunction : public AsyncExtensionFunction { | |
| 102 public: | |
| 103 NetworkingRequestDisconnectFunction() {} | |
| 104 DECLARE_EXTENSION_FUNCTION_NAME("networkingPrivate.requestDisconnect"); | |
| 105 | |
| 106 protected: | |
| 107 virtual ~NetworkingRequestDisconnectFunction(); | |
| 108 | |
| 109 // AsyncExtensionFunction overrides. | |
| 110 virtual bool RunImpl() OVERRIDE; | |
| 111 | |
| 112 private: | |
| 113 void ConnectSuccess(); | |
| 114 void ConnectFailed(const std::string& errorName, | |
| 115 const std::string& errorMessage); | |
|
stevenjb
2013/01/17 00:04:30
nit: WS
Greg Spencer (Chromium)
2013/01/18 01:20:30
Done.
| |
| 116 DISALLOW_COPY_AND_ASSIGN(NetworkingRequestDisconnectFunction); | |
| 117 }; | |
| 118 | |
| 119 // Manages and registers the networkingPrivate API with the extension system. | |
| 120 class NetworkingPrivateAPI : public ProfileKeyedService { | |
| 121 public: | |
| 122 explicit NetworkingPrivateAPI(Profile* profile); | |
| 123 virtual ~NetworkingPrivateAPI(); | |
| 124 | |
| 125 // ProfileKeyedService overrides. | |
| 126 virtual void Shutdown() OVERRIDE; | |
| 127 | |
| 128 // Convenience function to return the NetworkingPrivateAPI for a Profile. | |
| 129 static NetworkingPrivateAPI* Get(Profile* profile); | |
|
stevenjb
2013/01/17 00:04:30
nit: WS
Greg Spencer (Chromium)
2013/01/18 01:20:30
Done.
| |
| 130 private: | |
| 131 DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateAPI); | |
| 132 }; | |
| 133 | |
| 134 } // namespace chromeos | |
| 135 | |
| 136 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_NETWORKING_PRIVATE_API_H_ | |
| OLD | NEW |