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

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: Addressed Gaurav's and Steven's comments. Created 7 years, 9 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.SetStringWithoutPathExpansion(
159 onc::network_config::kGUID, service_path); 162 onc::network_config::kGUID, service_path);
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 if (ManagedNetworkConfigurationHandler::IsInitialized()) {
180 // TODO(gspencer): Currently we're using the service path as the 183 ManagedNetworkConfigurationHandler::Get()->GetProperties(
181 // |network_guid|. Eventually this should be using the real GUID. 184 params->network_guid,
182 DBusThreadManager::Get()->GetShillServiceClient()->GetProperties( 185 base::Bind(
183 dbus::ObjectPath(params->network_guid), 186 &NetworkingPrivateGetPropertiesFunction::GetPropertiesSuccess,
184 base::Bind(&NetworkingPrivateGetPropertiesFunction::ResultCallback, 187 this),
185 this)); 188 base::Bind(&NetworkingPrivateGetPropertiesFunction::GetPropertiesFailed,
189 this));
190 } else {
191 // TODO(gspencer): Currently we're using the service path as the
192 // |network_guid|. Eventually this should be using the real GUID.
193 DBusThreadManager::Get()->GetShillServiceClient()->GetProperties(
194 dbus::ObjectPath(params->network_guid),
195 base::Bind(&NetworkingPrivateGetPropertiesFunction::ResultCallback,
196 this,
197 params->network_guid));
198 }
186 return true; 199 return true;
187 } 200 }
188 201
189 void NetworkingPrivateGetPropertiesFunction::ResultCallback( 202 void NetworkingPrivateGetPropertiesFunction::ResultCallback(
203 const std::string& service_path,
190 DBusMethodCallStatus call_status, 204 DBusMethodCallStatus call_status,
191 const base::DictionaryValue& result) { 205 const base::DictionaryValue& result) {
206 scoped_ptr<base::DictionaryValue> onc_properties(
207 onc::TranslateShillServiceToONCPart(
208 result,
209 &onc::kNetworkConfigurationSignature));
210 GetPropertiesSuccess(service_path,
211 *onc_properties);
212 }
213
214 void NetworkingPrivateGetPropertiesFunction::GetPropertiesSuccess(
215 const std::string& service_path,
216 const base::DictionaryValue& dictionary) {
192 scoped_ptr<api::NetworkProperties> filtered_result( 217 scoped_ptr<api::NetworkProperties> filtered_result(
193 CreateFilteredResult(result)); 218 CreateFilteredResult(dictionary));
219 filtered_result->additional_properties.SetStringWithoutPathExpansion(
220 onc::network_config::kGUID, service_path);
194 results_ = api::GetProperties::Results::Create(*filtered_result); 221 results_ = api::GetProperties::Results::Create(*filtered_result);
195 SendResponse(true); 222 SendResponse(true);
196 } 223 }
197 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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 const std::string& result) { 447 const std::string& result) {
414 results_ = api::VerifyAndSignData::Results::Create(result); 448 results_ = api::VerifyAndSignData::Results::Create(result);
415 SendResponse(true); 449 SendResponse(true);
416 } 450 }
417 451
418 void NetworkingPrivateVerifyAndSignDataFunction::ErrorCallback( 452 void NetworkingPrivateVerifyAndSignDataFunction::ErrorCallback(
419 const std::string& error_name, const std::string& error) { 453 const std::string& error_name, const std::string& error) {
420 error_ = error_name; 454 error_ = error_name;
421 SendResponse(false); 455 SendResponse(false);
422 } 456 }
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/extensions/networking_private_api.h ('k') | chrome/browser/chromeos/net/OWNERS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698