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

Side by Side Diff: chromeos/dbus/shill_manager_client_stub.cc

Issue 12676017: Adding policy support to the new network configuration stack. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed remaining comments of Steven. Created 7 years, 8 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 | Annotate | Revision Log
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 "chromeos/dbus/shill_manager_client_stub.h" 5 #include "chromeos/dbus/shill_manager_client_stub.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/chromeos/chromeos_version.h" 8 #include "base/chromeos/chromeos_version.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chromeos/chromeos_switches.h" 12 #include "chromeos/chromeos_switches.h"
13 #include "chromeos/dbus/dbus_thread_manager.h" 13 #include "chromeos/dbus/dbus_thread_manager.h"
14 #include "chromeos/dbus/shill_profile_client.h"
14 #include "chromeos/dbus/shill_property_changed_observer.h" 15 #include "chromeos/dbus/shill_property_changed_observer.h"
15 #include "chromeos/dbus/shill_service_client.h" 16 #include "chromeos/dbus/shill_service_client.h"
16 #include "dbus/bus.h" 17 #include "dbus/bus.h"
17 #include "dbus/message.h" 18 #include "dbus/message.h"
18 #include "dbus/object_path.h" 19 #include "dbus/object_path.h"
19 #include "dbus/object_proxy.h" 20 #include "dbus/object_proxy.h"
20 #include "dbus/values_util.h" 21 #include "dbus/values_util.h"
21 #include "third_party/cros_system_api/dbus/service_constants.h" 22 #include "third_party/cros_system_api/dbus/service_constants.h"
22 23
23 namespace chromeos { 24 namespace chromeos {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 CallNotifyObserversPropertyChanged(flimflam::kServiceWatchListProperty, 0); 153 CallNotifyObserversPropertyChanged(flimflam::kServiceWatchListProperty, 0);
153 } 154 }
154 155
155 void ShillManagerClientStub::ConfigureService( 156 void ShillManagerClientStub::ConfigureService(
156 const base::DictionaryValue& properties, 157 const base::DictionaryValue& properties,
157 const ObjectPathCallback& callback, 158 const ObjectPathCallback& callback,
158 const ErrorCallback& error_callback) { 159 const ErrorCallback& error_callback) {
159 if (callback.is_null()) 160 if (callback.is_null())
160 return; 161 return;
161 162
162 // For the purposes of this stub, we're going to assume that the GUID property
163 // is set to the service path because we don't want to re-implement Shill's
164 // property matching magic here.
165 ShillServiceClient::TestInterface* service_client = 163 ShillServiceClient::TestInterface* service_client =
166 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); 164 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
167 165
168 std::string guid; 166 std::string guid;
169 std::string type; 167 std::string type;
170 if (!properties.GetString(flimflam::kGuidProperty, &guid) || 168 if (!properties.GetString(flimflam::kGuidProperty, &guid) ||
171 !properties.GetString(flimflam::kTypeProperty, &type)) { 169 !properties.GetString(flimflam::kTypeProperty, &type)) {
172 // If the properties aren't filled out completely, then just return an empty 170 // If the properties aren't filled out completely, then just return an empty
173 // object path. 171 // object path.
174 MessageLoop::current()->PostTask( 172 MessageLoop::current()->PostTask(
175 FROM_HERE, base::Bind(callback, dbus::ObjectPath())); 173 FROM_HERE, base::Bind(callback, dbus::ObjectPath()));
176 return; 174 return;
177 } 175 }
178 176
177 // For the purposes of this stub, we're going to assume that the GUID property
178 // is set to the service path because we don't want to re-implement Shill's
179 // property matching magic here.
180 std::string service_path = guid;
181
179 std::string ipconfig_path; 182 std::string ipconfig_path;
180 properties.GetString(shill::kIPConfigProperty, &ipconfig_path); 183 properties.GetString(shill::kIPConfigProperty, &ipconfig_path);
181 184
182 // Add the service to the service client stub if not already there.
183 service_client->AddServiceWithIPConfig(guid, guid, type, flimflam::kStateIdle,
184 ipconfig_path, true);
185 185
186 // Merge the new properties with existing properties, if any. 186 // Merge the new properties with existing properties, if any.
187 scoped_ptr<base::DictionaryValue> merged_properties;
188 const base::DictionaryValue* existing_properties = 187 const base::DictionaryValue* existing_properties =
189 service_client->GetServiceProperties(guid); 188 service_client->GetServiceProperties(service_path);
190 if (existing_properties) { 189 if (!existing_properties) {
191 merged_properties.reset(existing_properties->DeepCopy()); 190 // Add a new service to the service client stub because none exists, yet.
192 } else { 191 service_client->AddServiceWithIPConfig(service_path, guid, type,
193 merged_properties.reset(new base::DictionaryValue); 192 flimflam::kStateIdle, ipconfig_path,
193 true); // Add service to watch list.
194 existing_properties = service_client->GetServiceProperties(service_path);
194 } 195 }
196
197 scoped_ptr<base::DictionaryValue> merged_properties(
198 existing_properties->DeepCopy());
195 merged_properties->MergeDictionary(&properties); 199 merged_properties->MergeDictionary(&properties);
196 200
197 // Now set all the properties. 201 // Now set all the properties.
198 for (base::DictionaryValue::Iterator iter(*merged_properties); 202 for (base::DictionaryValue::Iterator iter(*merged_properties);
199 !iter.IsAtEnd(); iter.Advance()) { 203 !iter.IsAtEnd(); iter.Advance()) {
200 service_client->SetServiceProperty(guid, iter.key(), iter.value()); 204 service_client->SetServiceProperty(service_path, iter.key(), iter.value());
201 } 205 }
202 206
207 ShillProfileClient::TestInterface* profile_test =
208 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface();
209 profile_test->AddService(service_path);
210
203 MessageLoop::current()->PostTask( 211 MessageLoop::current()->PostTask(
204 FROM_HERE, base::Bind(callback, dbus::ObjectPath(guid))); 212 FROM_HERE, base::Bind(callback, dbus::ObjectPath(service_path)));
205 } 213 }
206 214
215 void ShillManagerClientStub::ConfigureServiceForProfile(
216 const dbus::ObjectPath& profile_path,
217 const base::DictionaryValue& properties,
218 const ObjectPathCallback& callback,
219 const ErrorCallback& error_callback) {
220 std::string profile_property;
221 properties.GetStringWithoutPathExpansion(flimflam::kProfileProperty,
222 &profile_property);
223 CHECK(profile_property == profile_path.value());
224 ConfigureService(properties, callback, error_callback);
225 }
226
227
207 void ShillManagerClientStub::GetService( 228 void ShillManagerClientStub::GetService(
208 const base::DictionaryValue& properties, 229 const base::DictionaryValue& properties,
209 const ObjectPathCallback& callback, 230 const ObjectPathCallback& callback,
210 const ErrorCallback& error_callback) { 231 const ErrorCallback& error_callback) {
211 if (callback.is_null()) 232 if (callback.is_null())
212 return; 233 return;
213 MessageLoop::current()->PostTask( 234 MessageLoop::current()->PostTask(
214 FROM_HERE, base::Bind(callback, dbus::ObjectPath())); 235 FROM_HERE, base::Bind(callback, dbus::ObjectPath()));
215 } 236 }
216 237
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 std::string type; 522 std::string type;
502 properties->GetString(flimflam::kTypeProperty, &type); 523 properties->GetString(flimflam::kTypeProperty, &type);
503 if (TechnologyEnabled(type)) 524 if (TechnologyEnabled(type))
504 new_service_list->Append((*iter)->DeepCopy()); 525 new_service_list->Append((*iter)->DeepCopy());
505 } 526 }
506 } 527 }
507 return new_service_list; 528 return new_service_list;
508 } 529 }
509 530
510 } // namespace chromeos 531 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698