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

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

Issue 2336863003: Change more base::ListValue methods to use std::unique_ptr. (Closed)
Patch Set: . Created 4 years, 3 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/fake_shill_manager_client.h" 5 #include "chromeos/dbus/fake_shill_manager_client.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/memory/ptr_util.h"
12 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
13 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
14 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_split.h" 16 #include "base/strings/string_split.h"
16 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
17 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
18 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
19 #include "base/values.h" 20 #include "base/values.h"
20 #include "chromeos/chromeos_switches.h" 21 #include "chromeos/chromeos_switches.h"
21 #include "chromeos/dbus/dbus_thread_manager.h" 22 #include "chromeos/dbus/dbus_thread_manager.h"
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 } 376 }
376 377
377 ShillManagerClient::TestInterface* FakeShillManagerClient::GetTestInterface() { 378 ShillManagerClient::TestInterface* FakeShillManagerClient::GetTestInterface() {
378 return this; 379 return this;
379 } 380 }
380 381
381 // ShillManagerClient::TestInterface overrides. 382 // ShillManagerClient::TestInterface overrides.
382 383
383 void FakeShillManagerClient::AddDevice(const std::string& device_path) { 384 void FakeShillManagerClient::AddDevice(const std::string& device_path) {
384 if (GetListProperty(shill::kDevicesProperty) 385 if (GetListProperty(shill::kDevicesProperty)
385 ->AppendIfNotPresent(new base::StringValue(device_path))) { 386 ->AppendIfNotPresent(
387 base::MakeUnique<base::StringValue>(device_path))) {
386 CallNotifyObserversPropertyChanged(shill::kDevicesProperty); 388 CallNotifyObserversPropertyChanged(shill::kDevicesProperty);
387 } 389 }
388 } 390 }
389 391
390 void FakeShillManagerClient::RemoveDevice(const std::string& device_path) { 392 void FakeShillManagerClient::RemoveDevice(const std::string& device_path) {
391 base::StringValue device_path_value(device_path); 393 base::StringValue device_path_value(device_path);
392 if (GetListProperty(shill::kDevicesProperty)->Remove( 394 if (GetListProperty(shill::kDevicesProperty)->Remove(
393 device_path_value, NULL)) { 395 device_path_value, NULL)) {
394 CallNotifyObserversPropertyChanged(shill::kDevicesProperty); 396 CallNotifyObserversPropertyChanged(shill::kDevicesProperty);
395 } 397 }
396 } 398 }
397 399
398 void FakeShillManagerClient::ClearDevices() { 400 void FakeShillManagerClient::ClearDevices() {
399 GetListProperty(shill::kDevicesProperty)->Clear(); 401 GetListProperty(shill::kDevicesProperty)->Clear();
400 CallNotifyObserversPropertyChanged(shill::kDevicesProperty); 402 CallNotifyObserversPropertyChanged(shill::kDevicesProperty);
401 } 403 }
402 404
403 void FakeShillManagerClient::AddTechnology(const std::string& type, 405 void FakeShillManagerClient::AddTechnology(const std::string& type,
404 bool enabled) { 406 bool enabled) {
405 if (GetListProperty(shill::kAvailableTechnologiesProperty) 407 if (GetListProperty(shill::kAvailableTechnologiesProperty)
406 ->AppendIfNotPresent(new base::StringValue(type))) { 408 ->AppendIfNotPresent(base::MakeUnique<base::StringValue>(type))) {
407 CallNotifyObserversPropertyChanged( 409 CallNotifyObserversPropertyChanged(
408 shill::kAvailableTechnologiesProperty); 410 shill::kAvailableTechnologiesProperty);
409 } 411 }
410 if (enabled && 412 if (enabled &&
411 GetListProperty(shill::kEnabledTechnologiesProperty) 413 GetListProperty(shill::kEnabledTechnologiesProperty)
412 ->AppendIfNotPresent(new base::StringValue(type))) { 414 ->AppendIfNotPresent(base::MakeUnique<base::StringValue>(type))) {
413 CallNotifyObserversPropertyChanged( 415 CallNotifyObserversPropertyChanged(
414 shill::kEnabledTechnologiesProperty); 416 shill::kEnabledTechnologiesProperty);
415 } 417 }
416 } 418 }
417 419
418 void FakeShillManagerClient::RemoveTechnology(const std::string& type) { 420 void FakeShillManagerClient::RemoveTechnology(const std::string& type) {
419 base::StringValue type_value(type); 421 base::StringValue type_value(type);
420 if (GetListProperty(shill::kAvailableTechnologiesProperty)->Remove( 422 if (GetListProperty(shill::kAvailableTechnologiesProperty)->Remove(
421 type_value, NULL)) { 423 type_value, NULL)) {
422 CallNotifyObserversPropertyChanged( 424 CallNotifyObserversPropertyChanged(
423 shill::kAvailableTechnologiesProperty); 425 shill::kAvailableTechnologiesProperty);
424 } 426 }
425 if (GetListProperty(shill::kEnabledTechnologiesProperty)->Remove( 427 if (GetListProperty(shill::kEnabledTechnologiesProperty)->Remove(
426 type_value, NULL)) { 428 type_value, NULL)) {
427 CallNotifyObserversPropertyChanged( 429 CallNotifyObserversPropertyChanged(
428 shill::kEnabledTechnologiesProperty); 430 shill::kEnabledTechnologiesProperty);
429 } 431 }
430 } 432 }
431 433
432 void FakeShillManagerClient::SetTechnologyInitializing(const std::string& type, 434 void FakeShillManagerClient::SetTechnologyInitializing(const std::string& type,
433 bool initializing) { 435 bool initializing) {
434 if (initializing) { 436 if (initializing) {
435 if (GetListProperty(shill::kUninitializedTechnologiesProperty) 437 if (GetListProperty(shill::kUninitializedTechnologiesProperty)
436 ->AppendIfNotPresent(new base::StringValue(type))) { 438 ->AppendIfNotPresent(base::MakeUnique<base::StringValue>(type))) {
437 CallNotifyObserversPropertyChanged( 439 CallNotifyObserversPropertyChanged(
438 shill::kUninitializedTechnologiesProperty); 440 shill::kUninitializedTechnologiesProperty);
439 } 441 }
440 } else { 442 } else {
441 if (GetListProperty(shill::kUninitializedTechnologiesProperty)->Remove( 443 if (GetListProperty(shill::kUninitializedTechnologiesProperty)->Remove(
442 base::StringValue(type), NULL)) { 444 base::StringValue(type), NULL)) {
443 CallNotifyObserversPropertyChanged( 445 CallNotifyObserversPropertyChanged(
444 shill::kUninitializedTechnologiesProperty); 446 shill::kUninitializedTechnologiesProperty);
445 } 447 }
446 } 448 }
447 } 449 }
448 450
449 void FakeShillManagerClient::AddGeoNetwork( 451 void FakeShillManagerClient::AddGeoNetwork(
450 const std::string& technology, 452 const std::string& technology,
451 const base::DictionaryValue& network) { 453 const base::DictionaryValue& network) {
452 base::ListValue* list_value = NULL; 454 base::ListValue* list_value = NULL;
453 if (!stub_geo_networks_.GetListWithoutPathExpansion(technology, 455 if (!stub_geo_networks_.GetListWithoutPathExpansion(technology,
454 &list_value)) { 456 &list_value)) {
455 list_value = new base::ListValue; 457 list_value = new base::ListValue;
456 stub_geo_networks_.SetWithoutPathExpansion(technology, list_value); 458 stub_geo_networks_.SetWithoutPathExpansion(technology, list_value);
457 } 459 }
458 list_value->Append(network.DeepCopy()); 460 list_value->Append(network.DeepCopy());
459 } 461 }
460 462
461 void FakeShillManagerClient::AddProfile(const std::string& profile_path) { 463 void FakeShillManagerClient::AddProfile(const std::string& profile_path) {
462 const char* key = shill::kProfilesProperty; 464 const char* key = shill::kProfilesProperty;
463 if (GetListProperty(key) 465 if (GetListProperty(key)->AppendIfNotPresent(
464 ->AppendIfNotPresent(new base::StringValue(profile_path))) { 466 base::MakeUnique<base::StringValue>(profile_path))) {
465 CallNotifyObserversPropertyChanged(key); 467 CallNotifyObserversPropertyChanged(key);
466 } 468 }
467 } 469 }
468 470
469 void FakeShillManagerClient::ClearProperties() { 471 void FakeShillManagerClient::ClearProperties() {
470 stub_properties_.Clear(); 472 stub_properties_.Clear();
471 } 473 }
472 474
473 void FakeShillManagerClient::SetManagerProperty(const std::string& key, 475 void FakeShillManagerClient::SetManagerProperty(const std::string& key,
474 const base::Value& value) { 476 const base::Value& value) {
475 SetProperty(key, value, 477 SetProperty(key, value,
476 base::Bind(&base::DoNothing), base::Bind(&LogErrorCallback)); 478 base::Bind(&base::DoNothing), base::Bind(&LogErrorCallback));
477 } 479 }
478 480
479 void FakeShillManagerClient::AddManagerService( 481 void FakeShillManagerClient::AddManagerService(
480 const std::string& service_path, 482 const std::string& service_path,
481 bool notify_observers) { 483 bool notify_observers) {
482 VLOG(2) << "AddManagerService: " << service_path; 484 VLOG(2) << "AddManagerService: " << service_path;
483 GetListProperty(shill::kServiceCompleteListProperty) 485 GetListProperty(shill::kServiceCompleteListProperty)
484 ->AppendIfNotPresent(new base::StringValue(service_path)); 486 ->AppendIfNotPresent(base::MakeUnique<base::StringValue>(service_path));
485 SortManagerServices(false); 487 SortManagerServices(false);
486 if (notify_observers) 488 if (notify_observers)
487 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty); 489 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty);
488 } 490 }
489 491
490 void FakeShillManagerClient::RemoveManagerService( 492 void FakeShillManagerClient::RemoveManagerService(
491 const std::string& service_path) { 493 const std::string& service_path) {
492 VLOG(2) << "RemoveManagerService: " << service_path; 494 VLOG(2) << "RemoveManagerService: " << service_path;
493 base::StringValue service_path_value(service_path); 495 base::StringValue service_path_value(service_path);
494 GetListProperty(shill::kServiceCompleteListProperty)->Remove( 496 GetListProperty(shill::kServiceCompleteListProperty)->Remove(
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 return enabled; 1003 return enabled;
1002 } 1004 }
1003 1005
1004 void FakeShillManagerClient::SetTechnologyEnabled( 1006 void FakeShillManagerClient::SetTechnologyEnabled(
1005 const std::string& type, 1007 const std::string& type,
1006 const base::Closure& callback, 1008 const base::Closure& callback,
1007 bool enabled) { 1009 bool enabled) {
1008 base::ListValue* enabled_list = 1010 base::ListValue* enabled_list =
1009 GetListProperty(shill::kEnabledTechnologiesProperty); 1011 GetListProperty(shill::kEnabledTechnologiesProperty);
1010 if (enabled) 1012 if (enabled)
1011 enabled_list->AppendIfNotPresent(new base::StringValue(type)); 1013 enabled_list->AppendIfNotPresent(base::MakeUnique<base::StringValue>(type));
1012 else 1014 else
1013 enabled_list->Remove(base::StringValue(type), NULL); 1015 enabled_list->Remove(base::StringValue(type), NULL);
1014 CallNotifyObserversPropertyChanged( 1016 CallNotifyObserversPropertyChanged(
1015 shill::kEnabledTechnologiesProperty); 1017 shill::kEnabledTechnologiesProperty);
1016 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); 1018 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
1017 // May affect available services. 1019 // May affect available services.
1018 SortManagerServices(true); 1020 SortManagerServices(true);
1019 } 1021 }
1020 1022
1021 base::ListValue* FakeShillManagerClient::GetEnabledServiceList( 1023 base::ListValue* FakeShillManagerClient::GetEnabledServiceList(
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1228 LOG(WARNING) << "Invalid state: " << state << " for " << type; 1230 LOG(WARNING) << "Invalid state: " << state << " for " << type;
1229 result = shill::kStateIdle; 1231 result = shill::kStateIdle;
1230 } 1232 }
1231 } 1233 }
1232 VLOG(1) << "Initial state for: " << type << " = " << result 1234 VLOG(1) << "Initial state for: " << type << " = " << result
1233 << " Enabled: " << *enabled; 1235 << " Enabled: " << *enabled;
1234 return result; 1236 return result;
1235 } 1237 }
1236 1238
1237 } // namespace chromeos 1239 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698