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

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

Issue 14566009: Add NetworkConnectionHandler class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Modify Shill stubs Created 7 years, 7 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"
(...skipping 21 matching lines...) Expand all
32 explicit ValueEquals(const Value* first) : first_(first) {} 32 explicit ValueEquals(const Value* first) : first_(first) {}
33 bool operator()(const Value* second) const { 33 bool operator()(const Value* second) const {
34 return first_->Equals(second); 34 return first_->Equals(second);
35 } 35 }
36 const Value* first_; 36 const Value* first_;
37 }; 37 };
38 38
39 } // namespace 39 } // namespace
40 40
41 ShillManagerClientStub::ShillManagerClientStub() 41 ShillManagerClientStub::ShillManagerClientStub()
42 : weak_ptr_factory_(this) { 42 : weak_ptr_factory_(this) {
43 SetDefaultProperties(); 43 SetDefaultProperties();
44 } 44 }
45 45
46 ShillManagerClientStub::~ShillManagerClientStub() {} 46 ShillManagerClientStub::~ShillManagerClientStub() {}
47 47
48 // ShillManagerClient overrides. 48 // ShillManagerClient overrides.
49 49
50 void ShillManagerClientStub::AddPropertyChangedObserver( 50 void ShillManagerClientStub::AddPropertyChangedObserver(
51 ShillPropertyChangedObserver* observer) { 51 ShillPropertyChangedObserver* observer) {
52 observer_list_.AddObserver(observer); 52 observer_list_.AddObserver(observer);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 base::TimeDelta::FromSeconds(kDisableTechnologyDelaySeconds)); 173 base::TimeDelta::FromSeconds(kDisableTechnologyDelaySeconds));
174 } else { 174 } else {
175 SetTechnologyEnabled(type, callback, false); 175 SetTechnologyEnabled(type, callback, false);
176 } 176 }
177 } 177 }
178 178
179 void ShillManagerClientStub::ConfigureService( 179 void ShillManagerClientStub::ConfigureService(
180 const base::DictionaryValue& properties, 180 const base::DictionaryValue& properties,
181 const ObjectPathCallback& callback, 181 const ObjectPathCallback& callback,
182 const ErrorCallback& error_callback) { 182 const ErrorCallback& error_callback) {
183 if (callback.is_null())
184 return;
185
186 ShillServiceClient::TestInterface* service_client = 183 ShillServiceClient::TestInterface* service_client =
187 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); 184 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
188 185
189 std::string guid; 186 std::string guid;
190 std::string type; 187 std::string type;
191 if (!properties.GetString(flimflam::kGuidProperty, &guid) || 188 if (!properties.GetString(flimflam::kGuidProperty, &guid) ||
192 !properties.GetString(flimflam::kTypeProperty, &type)) { 189 !properties.GetString(flimflam::kTypeProperty, &type)) {
190 LOG(ERROR) << "ConfugureService requies GUID and Type to be defined";
pneubeck (no reviews) 2013/05/07 08:46:39 ConfugureService -> ConfigureService
stevenjb 2013/05/08 01:57:22 Done.
193 // If the properties aren't filled out completely, then just return an empty 191 // If the properties aren't filled out completely, then just return an empty
194 // object path. 192 // object path.
195 MessageLoop::current()->PostTask( 193 if (!callback.is_null()) {
196 FROM_HERE, base::Bind(callback, dbus::ObjectPath())); 194 MessageLoop::current()->PostTask(
195 FROM_HERE, base::Bind(callback, dbus::ObjectPath()));
196 }
197 return; 197 return;
198 } 198 }
199 199
200 // For the purposes of this stub, we're going to assume that the GUID property 200 // For the purposes of this stub, we're going to assume that the GUID property
201 // is set to the service path because we don't want to re-implement Shill's 201 // is set to the service path because we don't want to re-implement Shill's
202 // property matching magic here. 202 // property matching magic here.
203 std::string service_path = guid; 203 std::string service_path = guid;
204 204
205 std::string ipconfig_path; 205 std::string ipconfig_path;
206 properties.GetString(shill::kIPConfigProperty, &ipconfig_path); 206 properties.GetString(shill::kIPConfigProperty, &ipconfig_path);
(...skipping 17 matching lines...) Expand all
224 // Now set all the properties. 224 // Now set all the properties.
225 for (base::DictionaryValue::Iterator iter(*merged_properties); 225 for (base::DictionaryValue::Iterator iter(*merged_properties);
226 !iter.IsAtEnd(); iter.Advance()) { 226 !iter.IsAtEnd(); iter.Advance()) {
227 service_client->SetServiceProperty(service_path, iter.key(), iter.value()); 227 service_client->SetServiceProperty(service_path, iter.key(), iter.value());
228 } 228 }
229 229
230 ShillProfileClient::TestInterface* profile_test = 230 ShillProfileClient::TestInterface* profile_test =
231 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); 231 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface();
232 profile_test->AddService(service_path); 232 profile_test->AddService(service_path);
233 233
234 MessageLoop::current()->PostTask( 234 if (!callback.is_null()) {
235 FROM_HERE, base::Bind(callback, dbus::ObjectPath(service_path))); 235 MessageLoop::current()->PostTask(
236 FROM_HERE, base::Bind(callback, dbus::ObjectPath(service_path)));
237 }
236 } 238 }
237 239
238 void ShillManagerClientStub::ConfigureServiceForProfile( 240 void ShillManagerClientStub::ConfigureServiceForProfile(
239 const dbus::ObjectPath& profile_path, 241 const dbus::ObjectPath& profile_path,
240 const base::DictionaryValue& properties, 242 const base::DictionaryValue& properties,
241 const ObjectPathCallback& callback, 243 const ObjectPathCallback& callback,
242 const ErrorCallback& error_callback) { 244 const ErrorCallback& error_callback) {
243 std::string profile_property; 245 std::string profile_property;
244 properties.GetStringWithoutPathExpansion(flimflam::kProfileProperty, 246 properties.GetStringWithoutPathExpansion(flimflam::kProfileProperty,
245 &profile_property); 247 &profile_property);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 if (GetListProperty(flimflam::kDevicesProperty)->Remove( 327 if (GetListProperty(flimflam::kDevicesProperty)->Remove(
326 device_path_value, NULL)) { 328 device_path_value, NULL)) {
327 CallNotifyObserversPropertyChanged(flimflam::kDevicesProperty, 0); 329 CallNotifyObserversPropertyChanged(flimflam::kDevicesProperty, 0);
328 } 330 }
329 } 331 }
330 332
331 void ShillManagerClientStub::ClearDevices() { 333 void ShillManagerClientStub::ClearDevices() {
332 stub_properties_.Remove(flimflam::kDevicesProperty, NULL); 334 stub_properties_.Remove(flimflam::kDevicesProperty, NULL);
333 } 335 }
334 336
335 void ShillManagerClientStub::ClearServices() { 337 void ShillManagerClientStub::ClearManagerServices() {
336 stub_properties_.Remove(flimflam::kServicesProperty, NULL); 338 stub_properties_.Remove(flimflam::kServicesProperty, NULL);
337 stub_properties_.Remove(flimflam::kServiceWatchListProperty, NULL); 339 stub_properties_.Remove(flimflam::kServiceWatchListProperty, NULL);
338 } 340 }
339 341
340 void ShillManagerClientStub::AddService(const std::string& service_path, 342 void ShillManagerClientStub::AddManagerService(const std::string& service_path,
341 bool add_to_watch_list) { 343 bool add_to_watch_list) {
342 if (GetListProperty(flimflam::kServicesProperty)->AppendIfNotPresent( 344 if (GetListProperty(flimflam::kServicesProperty)->AppendIfNotPresent(
343 base::Value::CreateStringValue(service_path))) { 345 base::Value::CreateStringValue(service_path))) {
344 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); 346 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0);
345 } 347 }
346 if (add_to_watch_list) 348 if (add_to_watch_list)
347 AddServiceToWatchList(service_path); 349 AddServiceToWatchList(service_path);
348 } 350 }
349 351
350 void ShillManagerClientStub::AddServiceAtIndex(const std::string& service_path, 352 void ShillManagerClientStub::MoveServiceToIndex(
351 size_t index, 353 const std::string& service_path,
352 bool add_to_watch_list) { 354 size_t index,
355 bool add_to_watch_list) {
353 base::StringValue path_value(service_path); 356 base::StringValue path_value(service_path);
354 base::ListValue* service_list = 357 base::ListValue* service_list = GetListProperty(flimflam::kServicesProperty);
355 GetListProperty(flimflam::kServicesProperty);
356 base::ListValue::iterator iter = 358 base::ListValue::iterator iter =
357 std::find_if(service_list->begin(), service_list->end(), 359 std::find_if(service_list->begin(), service_list->end(),
358 ValueEquals(&path_value)); 360 ValueEquals(&path_value));
359 if (iter != service_list->end()) 361 if (iter == service_list->end()) {
360 service_list->Erase(iter, NULL); 362 LOG(ERROR) << "Service not found to move: " << service_path;
363 return;
364 }
365 service_list->Erase(iter, NULL);
361 service_list->Insert(index, path_value.DeepCopy()); 366 service_list->Insert(index, path_value.DeepCopy());
362 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); 367 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0);
363 if (add_to_watch_list) 368 if (add_to_watch_list)
364 AddServiceToWatchList(service_path); 369 AddServiceToWatchList(service_path);
365 } 370 }
366 371
367 void ShillManagerClientStub::RemoveService(const std::string& service_path) { 372 void ShillManagerClientStub::RemoveManagerService(
373 const std::string& service_path) {
368 base::StringValue service_path_value(service_path); 374 base::StringValue service_path_value(service_path);
369 if (GetListProperty(flimflam::kServicesProperty)->Remove( 375 if (GetListProperty(flimflam::kServicesProperty)->Remove(
370 service_path_value, NULL)) { 376 service_path_value, NULL)) {
371 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); 377 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0);
372 } 378 }
373 if (GetListProperty(flimflam::kServiceWatchListProperty)->Remove( 379 if (GetListProperty(flimflam::kServiceWatchListProperty)->Remove(
374 service_path_value, NULL)) { 380 service_path_value, NULL)) {
375 CallNotifyObserversPropertyChanged( 381 CallNotifyObserversPropertyChanged(
376 flimflam::kServiceWatchListProperty, 0); 382 flimflam::kServiceWatchListProperty, 0);
377 } 383 }
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 base::FundamentalValue(false)); 613 base::FundamentalValue(false));
608 } 614 }
609 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); 615 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0);
610 CallNotifyObserversPropertyChanged(flimflam::kServiceWatchListProperty, 616 CallNotifyObserversPropertyChanged(flimflam::kServiceWatchListProperty,
611 0); 617 0);
612 if (!callback.is_null()) 618 if (!callback.is_null())
613 MessageLoop::current()->PostTask(FROM_HERE, callback); 619 MessageLoop::current()->PostTask(FROM_HERE, callback);
614 } 620 }
615 621
616 } // namespace chromeos 622 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698