Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(502)

Side by Side Diff: chrome/browser/chromeos/extensions/networking_private_api.cc

Issue 12211103: Adding a new ManagedNetworkConfigurationHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleaned up, ready for review. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 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 #include "chrome/browser/chromeos/extensions/networking_private_api.h" 5 #include "chrome/browser/chromeos/extensions/networking_private_api.h"
6 6
7 #include "base/bind.h"
7 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h"
10 #include "chrome/browser/chromeos/net/managed_network_configuration_handler.h"
8 #include "chrome/browser/extensions/extension_function_registry.h" 11 #include "chrome/browser/extensions/extension_function_registry.h"
9 #include "chrome/common/extensions/api/networking_private.h" 12 #include "chrome/common/extensions/api/networking_private.h"
10 #include "chromeos/dbus/dbus_thread_manager.h" 13 #include "chromeos/dbus/dbus_thread_manager.h"
11 #include "chromeos/dbus/shill_manager_client.h" 14 #include "chromeos/dbus/shill_manager_client.h"
12 #include "chromeos/dbus/shill_service_client.h" 15 #include "chromeos/dbus/shill_service_client.h"
13 #include "chromeos/network/onc/onc_constants.h" 16 #include "chromeos/network/onc/onc_constants.h"
14 #include "chromeos/network/onc/onc_signature.h" 17 #include "chromeos/network/onc/onc_signature.h"
15 #include "chromeos/network/onc/onc_translation_tables.h" 18 #include "chromeos/network/onc/onc_translation_tables.h"
16 #include "chromeos/network/onc/onc_translator.h" 19 #include "chromeos/network/onc/onc_translator.h"
17 #include "dbus/object_path.h" 20 #include "dbus/object_path.h"
18 #include "third_party/cros_system_api/dbus/service_constants.h" 21 #include "third_party/cros_system_api/dbus/service_constants.h"
19 22
20 using namespace chromeos; 23 using namespace chromeos;
21 namespace api = extensions::api::networking_private; 24 namespace api = extensions::api::networking_private;
22 25
23 namespace { 26 namespace {
24 27
25 // An error returned when no valid services were found. 28 // An error returned when no valid services were found.
26 const char kInvalidResponseError[] = "Error.invalidResponse"; 29 const char kInvalidResponseError[] = "Error.invalidResponse";
27 30
28 // This creates a new ONC dictionary that only contains the information we're 31 // Filters from the given ONC dictionary the information we're interested in
29 // interested in passing on to JavaScript. 32 // before passing it to JavaScript.
30 scoped_ptr<api::NetworkProperties> CreateFilteredResult( 33 scoped_ptr<api::NetworkProperties> CreateFilteredResult(
31 const base::DictionaryValue& properties) { 34 const base::DictionaryValue& onc_dictionary) {
32 scoped_ptr<base::DictionaryValue> onc_properties(
33 onc::TranslateShillServiceToONCPart(
34 properties,
35 &onc::kNetworkConfigurationSignature));
36
37 // Now we filter it so we only include properties that we care about for this
38 // interface.
39 static const char* const desired_fields[] = { 35 static const char* const desired_fields[] = {
40 onc::network_config::kWiFi, 36 onc::network_config::kWiFi,
41 onc::network_config::kName, 37 onc::network_config::kName,
42 onc::network_config::kGUID, 38 onc::network_config::kGUID,
43 onc::network_config::kType, 39 onc::network_config::kType,
44 onc::network_config::kConnectionState, 40 onc::network_config::kConnectionState,
45 }; 41 };
46 42
47 scoped_ptr<api::NetworkProperties> filtered_result( 43 scoped_ptr<api::NetworkProperties> filtered_result(
48 new api::NetworkProperties); 44 new api::NetworkProperties);
49 for (size_t i = 0; i < arraysize(desired_fields); ++i) { 45 for (size_t i = 0; i < arraysize(desired_fields); ++i) {
50 base::Value* value; 46 const base::Value* value;
51 if (onc_properties->Get(desired_fields[i], &value)) 47 if (onc_dictionary.GetWithoutPathExpansion(desired_fields[i], &value)) {
52 filtered_result->additional_properties.Set(desired_fields[i], 48 filtered_result->additional_properties.SetWithoutPathExpansion(
53 value->DeepCopy()); 49 desired_fields[i],
50 value->DeepCopy());
51 }
54 } 52 }
55 53
56 return filtered_result.Pass(); 54 return filtered_result.Pass();
57 } 55 }
58 56
59 class ResultList : public base::RefCounted<ResultList> { 57 class ResultList : public base::RefCounted<ResultList> {
60 public: 58 public:
61 typedef base::Callback<void(const std::string& error, 59 typedef base::Callback<void(const std::string& error,
62 scoped_ptr<base::ListValue>)> ResultCallback; 60 scoped_ptr<base::ListValue>)> ResultCallback;
63 61
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 network_type)); 132 network_type));
135 } 133 }
136 } 134 }
137 135
138 void ResultList::ServicePropertiesCallback( 136 void ResultList::ServicePropertiesCallback(
139 const std::string& service_path, 137 const std::string& service_path,
140 const std::string& network_type, 138 const std::string& network_type,
141 DBusMethodCallStatus call_status, 139 DBusMethodCallStatus call_status,
142 const base::DictionaryValue& result) { 140 const base::DictionaryValue& result) {
143 if (call_status == DBUS_METHOD_CALL_SUCCESS) { 141 if (call_status == DBUS_METHOD_CALL_SUCCESS) {
142 scoped_ptr<base::DictionaryValue> onc_properties(
143 onc::TranslateShillServiceToONCPart(
144 result,
145 &onc::kNetworkConfigurationSignature));
146
144 scoped_ptr<api::NetworkProperties> filtered_result( 147 scoped_ptr<api::NetworkProperties> filtered_result(
145 CreateFilteredResult(result)); 148 CreateFilteredResult(*onc_properties));
146 149
147 std::string onc_type; 150 std::string onc_type;
148 if (filtered_result->additional_properties.GetString( 151 if (filtered_result->additional_properties.GetString(
149 onc::network_config::kType, &onc_type) && 152 onc::network_config::kType, &onc_type) &&
150 (onc_type == network_type || 153 (onc_type == network_type ||
151 network_type == onc::network_type::kAllTypes)) { 154 network_type == onc::network_type::kAllTypes)) {
152 // TODO(gspencer): For now the "GUID" we send back is going to look 155 // TODO(gspencer): For now the "GUID" we send back is going to look
153 // remarkably like the service path. Once this code starts using the 156 // remarkably like the service path. Once this code starts using the
154 // NetworkStateHandler instead of Shill directly, we should remove 157 // NetworkStateHandler instead of Shill directly, we should remove
155 // this line so that we're sending back the actual GUID. The 158 // this line so that we're sending back the actual GUID. The
156 // JavaScript shouldn't care: this ID is opaque to it, and it 159 // JavaScript shouldn't care: this ID is opaque to it, and it
157 // shouldn't store it anywhere. 160 // shouldn't store it anywhere.
158 filtered_result->additional_properties.SetString( 161 filtered_result->additional_properties.SetString(
159 onc::network_config::kGUID, service_path); 162 onc::network_config::kGUID, service_path);
Greg Spencer (Chromium) 2013/02/19 22:58:26 So, when we switched to ManagedNetworkConfiguratio
pneubeck (no reviews) 2013/02/22 10:22:31 I thought, when we checked the different calls (cr
Greg Spencer (Chromium) 2013/02/23 00:11:29 Yes, I remember that, but I thought there was one
160 163
161 Append(filtered_result.release()); 164 Append(filtered_result.release());
162 } 165 }
163 } 166 }
164 } 167 }
165 168
166 } // namespace 169 } // namespace
167 170
168 //////////////////////////////////////////////////////////////////////////////// 171 ////////////////////////////////////////////////////////////////////////////////
169 // NetworkingPrivateGetPropertiesFunction 172 // NetworkingPrivateGetPropertiesFunction
170 173
171 NetworkingPrivateGetPropertiesFunction:: 174 NetworkingPrivateGetPropertiesFunction::
172 ~NetworkingPrivateGetPropertiesFunction() { 175 ~NetworkingPrivateGetPropertiesFunction() {
173 } 176 }
174 177
175 bool NetworkingPrivateGetPropertiesFunction::RunImpl() { 178 bool NetworkingPrivateGetPropertiesFunction::RunImpl() {
176 scoped_ptr<api::GetProperties::Params> params = 179 scoped_ptr<api::GetProperties::Params> params =
177 api::GetProperties::Params::Create(*args_); 180 api::GetProperties::Params::Create(*args_);
178 EXTENSION_FUNCTION_VALIDATE(params); 181 EXTENSION_FUNCTION_VALIDATE(params);
179 182
180 // TODO(gspencer): Currently we're using the service path as the 183 if (ManagedNetworkConfigurationHandler::IsInitialized()) {
181 // |network_guid|. Eventually this should be using the real GUID. 184 ManagedNetworkConfigurationHandler::Get()->GetProperties(
182 DBusThreadManager::Get()->GetShillServiceClient()->GetProperties( 185 params->network_guid,
183 dbus::ObjectPath(params->network_guid), 186 base::Bind(
184 base::Bind(&NetworkingPrivateGetPropertiesFunction::ResultCallback, 187 &NetworkingPrivateGetPropertiesFunction::GetPropertiesSuccess,
185 this)); 188 this),
189 base::Bind(&NetworkingPrivateGetPropertiesFunction::GetPropertiesFailed,
190 this));
191 } else {
192 // TODO(gspencer): Currently we're using the service path as the
193 // |network_guid|. Eventually this should be using the real GUID.
194 DBusThreadManager::Get()->GetShillServiceClient()->GetProperties(
195 dbus::ObjectPath(params->network_guid),
196 base::Bind(&NetworkingPrivateGetPropertiesFunction::ResultCallback,
197 this));
198 }
186 return true; 199 return true;
187 } 200 }
188 201
189 void NetworkingPrivateGetPropertiesFunction::ResultCallback( 202 void NetworkingPrivateGetPropertiesFunction::ResultCallback(
190 DBusMethodCallStatus call_status, 203 DBusMethodCallStatus call_status,
191 const base::DictionaryValue& result) { 204 const base::DictionaryValue& result) {
205 scoped_ptr<base::DictionaryValue> onc_properties(
206 onc::TranslateShillServiceToONCPart(
207 result,
208 &onc::kNetworkConfigurationSignature));
209
192 scoped_ptr<api::NetworkProperties> filtered_result( 210 scoped_ptr<api::NetworkProperties> filtered_result(
193 CreateFilteredResult(result)); 211 CreateFilteredResult(*onc_properties));
194 results_ = api::GetProperties::Results::Create(*filtered_result); 212 results_ = api::GetProperties::Results::Create(*filtered_result);
195 SendResponse(true); 213 SendResponse(true);
196 } 214 }
197 215
216 void NetworkingPrivateGetPropertiesFunction::GetPropertiesSuccess(
217 const std::string& service_path,
218 const base::DictionaryValue& dictionary) {
219 scoped_ptr<api::NetworkProperties> filtered_result(
220 CreateFilteredResult(dictionary));
221 results_ = api::GetProperties::Results::Create(*filtered_result);
222 SendResponse(true);
223 }
224
225 void NetworkingPrivateGetPropertiesFunction::GetPropertiesFailed(
226 const std::string& error_name,
227 scoped_ptr<base::DictionaryValue> error_data) {
228 error_ = error_name;
229 SendResponse(false);
230 }
231
198 //////////////////////////////////////////////////////////////////////////////// 232 ////////////////////////////////////////////////////////////////////////////////
199 // NetworkingPrivateGetVisibleNetworksFunction 233 // NetworkingPrivateGetVisibleNetworksFunction
200 234
201 NetworkingPrivateGetVisibleNetworksFunction:: 235 NetworkingPrivateGetVisibleNetworksFunction::
202 ~NetworkingPrivateGetVisibleNetworksFunction() { 236 ~NetworkingPrivateGetVisibleNetworksFunction() {
203 } 237 }
204 238
205 bool NetworkingPrivateGetVisibleNetworksFunction::RunImpl() { 239 bool NetworkingPrivateGetVisibleNetworksFunction::RunImpl() {
206 scoped_ptr<api::GetVisibleNetworks::Params> params = 240 scoped_ptr<api::GetVisibleNetworks::Params> params =
207 api::GetVisibleNetworks::Params::Create(*args_); 241 api::GetVisibleNetworks::Params::Create(*args_);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 DBusThreadManager::Get()->GetShillServiceClient()->Disconnect( 328 DBusThreadManager::Get()->GetShillServiceClient()->Disconnect(
295 dbus::ObjectPath(params->network_guid), 329 dbus::ObjectPath(params->network_guid),
296 base::Bind( 330 base::Bind(
297 &NetworkingPrivateStartDisconnectFunction::DisconnectionStartSuccess, 331 &NetworkingPrivateStartDisconnectFunction::DisconnectionStartSuccess,
298 this), 332 this),
299 base::Bind( 333 base::Bind(
300 &NetworkingPrivateStartDisconnectFunction::DisconnectionStartFailed, 334 &NetworkingPrivateStartDisconnectFunction::DisconnectionStartFailed,
301 this)); 335 this));
302 return true; 336 return true;
303 } 337 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698