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 ScopedDecrementer; | |
| 53 | |
| 54 class ResultList : public base::RefCounted<ResultList> { | |
| 55 public: | |
| 56 explicit ResultList(int count); | |
| 57 | |
| 58 int count() const { return count_; } | |
| 59 base::ListValue* release() { return list_.release(); } | |
| 60 void Append(base::Value* value); | |
| 61 | |
| 62 private: | |
| 63 friend class base::RefCounted<ResultList>; | |
| 64 friend class ScopedDecrementer; | |
| 65 ~ResultList(); | |
| 66 | |
| 67 scoped_ptr<base::ListValue> list_; | |
| 68 int count_; | |
| 69 | |
| 70 DISALLOW_COPY_AND_ASSIGN(ResultList); | |
| 71 }; | |
| 72 | |
| 73 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.
| |
| 74 public: | |
| 75 ScopedDecrementer(NetworkingGetVisibleNetworksFunction* parent, | |
| 76 scoped_refptr<ResultList> result_list); | |
| 77 ~ScopedDecrementer(); | |
| 78 | |
| 79 private: | |
| 80 NetworkingGetVisibleNetworksFunction* parent_; | |
| 81 scoped_refptr<ResultList> result_list_; | |
| 82 }; | |
| 83 | |
| 84 void ManagerPropertiesCallback(const std::string& network_type, | |
| 85 DBusMethodCallStatus call_status, | |
| 86 const base::DictionaryValue& result); | |
| 87 | |
| 88 void ServicePropertiesCallback(const std::string& service_path, | |
| 89 const std::string& network_type, | |
| 90 scoped_refptr<ResultList> result_list, | |
| 91 DBusMethodCallStatus call_status, | |
| 92 const base::DictionaryValue& result); | |
| 93 | |
| 94 DISALLOW_COPY_AND_ASSIGN(NetworkingGetVisibleNetworksFunction); | |
| 95 }; | |
| 96 | |
| 97 // Implements the chrome.networkingPrivate.requestConnect method. | |
| 98 class NetworkingRequestConnectFunction : public AsyncExtensionFunction { | |
| 99 public: | |
| 100 NetworkingRequestConnectFunction() {} | |
| 101 DECLARE_EXTENSION_FUNCTION_NAME("networkingPrivate.requestConnect"); | |
| 102 | |
| 103 protected: | |
| 104 virtual ~NetworkingRequestConnectFunction(); | |
| 105 | |
| 106 // AsyncExtensionFunction overrides. | |
| 107 virtual bool RunImpl() OVERRIDE; | |
| 108 | |
| 109 private: | |
| 110 // Called when the request to connect succeeds. Doesn't mean that the connect | |
| 111 // itself succeeded, just that the request did. | |
| 112 void ConnectRequestSuccess(); | |
| 113 | |
| 114 void ConnectRequestFailed(const std::string& errorName, | |
| 115 const std::string& errorMessage); | |
| 116 | |
| 117 DISALLOW_COPY_AND_ASSIGN(NetworkingRequestConnectFunction); | |
| 118 }; | |
| 119 | |
| 120 // Implements the chrome.networkingPrivate.requestDisconnect method. | |
| 121 class NetworkingRequestDisconnectFunction : public AsyncExtensionFunction { | |
| 122 public: | |
| 123 NetworkingRequestDisconnectFunction() {} | |
| 124 DECLARE_EXTENSION_FUNCTION_NAME("networkingPrivate.requestDisconnect"); | |
| 125 | |
| 126 protected: | |
| 127 virtual ~NetworkingRequestDisconnectFunction(); | |
| 128 | |
| 129 // AsyncExtensionFunction overrides. | |
| 130 virtual bool RunImpl() OVERRIDE; | |
| 131 | |
| 132 private: | |
| 133 // Called when the request to disconnect succeeds. Doesn't mean that the | |
| 134 // disconnect itself succeeded, just that the request did. | |
| 135 void DisconnectRequestSuccess(); | |
| 136 | |
| 137 void DisconnectRequestFailed(const std::string& errorName, | |
| 138 const std::string& errorMessage); | |
| 139 | |
| 140 DISALLOW_COPY_AND_ASSIGN(NetworkingRequestDisconnectFunction); | |
| 141 }; | |
| 142 | |
| 143 // Manages and registers the networkingPrivate API with the extension system. | |
| 144 class NetworkingPrivateAPI : public ProfileKeyedService { | |
| 145 public: | |
| 146 explicit NetworkingPrivateAPI(Profile* profile); | |
| 147 virtual ~NetworkingPrivateAPI(); | |
| 148 | |
| 149 // ProfileKeyedService overrides. | |
| 150 virtual void Shutdown() OVERRIDE; | |
| 151 | |
| 152 // Convenience function to return the NetworkingPrivateAPI for a Profile. | |
| 153 static NetworkingPrivateAPI* Get(Profile* profile); | |
| 154 | |
| 155 private: | |
| 156 DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateAPI); | |
| 157 }; | |
| 158 | |
| 159 } // namespace chromeos | |
| 160 | |
| 161 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_NETWORKING_PRIVATE_API_H_ | |
| OLD | NEW |