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

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

Issue 2664753002: Remove base::StringValue (Closed)
Patch Set: Rebase Created 3 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
« no previous file with comments | « chromeos/dbus/fake_shill_profile_client.cc ('k') | chromeos/dbus/gsm_sms_client_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_service_client.h" 5 #include "chromeos/dbus/fake_shill_service_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 183
184 // Set any other services of the same Type to 'offline' first, before setting 184 // Set any other services of the same Type to 'offline' first, before setting
185 // State to Association which will trigger sorting Manager.Services and 185 // State to Association which will trigger sorting Manager.Services and
186 // sending an update. 186 // sending an update.
187 SetOtherServicesOffline(service_path.value()); 187 SetOtherServicesOffline(service_path.value());
188 188
189 // Clear Error. 189 // Clear Error.
190 service_properties->SetStringWithoutPathExpansion(shill::kErrorProperty, ""); 190 service_properties->SetStringWithoutPathExpansion(shill::kErrorProperty, "");
191 191
192 // Set Associating. 192 // Set Associating.
193 base::StringValue associating_value(shill::kStateAssociation); 193 base::Value associating_value(shill::kStateAssociation);
194 SetServiceProperty(service_path.value(), shill::kStateProperty, 194 SetServiceProperty(service_path.value(), shill::kStateProperty,
195 associating_value); 195 associating_value);
196 196
197 // Stay Associating until the state is changed again after a delay. 197 // Stay Associating until the state is changed again after a delay.
198 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 198 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
199 FROM_HERE, 199 FROM_HERE,
200 base::Bind(&FakeShillServiceClient::ContinueConnect, 200 base::Bind(&FakeShillServiceClient::ContinueConnect,
201 weak_ptr_factory_.GetWeakPtr(), service_path.value()), 201 weak_ptr_factory_.GetWeakPtr(), service_path.value()),
202 base::TimeDelta::FromSeconds(GetInteractiveDelay())); 202 base::TimeDelta::FromSeconds(GetInteractiveDelay()));
203 203
204 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); 204 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
205 } 205 }
206 206
207 void FakeShillServiceClient::Disconnect(const dbus::ObjectPath& service_path, 207 void FakeShillServiceClient::Disconnect(const dbus::ObjectPath& service_path,
208 const base::Closure& callback, 208 const base::Closure& callback,
209 const ErrorCallback& error_callback) { 209 const ErrorCallback& error_callback) {
210 base::Value* service; 210 base::Value* service;
211 if (!stub_services_.Get(service_path.value(), &service)) { 211 if (!stub_services_.Get(service_path.value(), &service)) {
212 error_callback.Run("Error.InvalidService", "Invalid Service"); 212 error_callback.Run("Error.InvalidService", "Invalid Service");
213 return; 213 return;
214 } 214 }
215 // Set Idle after a delay 215 // Set Idle after a delay
216 base::StringValue idle_value(shill::kStateIdle); 216 base::Value idle_value(shill::kStateIdle);
217 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 217 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
218 FROM_HERE, base::Bind(&FakeShillServiceClient::SetProperty, 218 FROM_HERE, base::Bind(&FakeShillServiceClient::SetProperty,
219 weak_ptr_factory_.GetWeakPtr(), service_path, 219 weak_ptr_factory_.GetWeakPtr(), service_path,
220 shill::kStateProperty, idle_value, 220 shill::kStateProperty, idle_value,
221 base::Bind(&base::DoNothing), error_callback), 221 base::Bind(&base::DoNothing), error_callback),
222 base::TimeDelta::FromSeconds(GetInteractiveDelay())); 222 base::TimeDelta::FromSeconds(GetInteractiveDelay()));
223 callback.Run(); 223 callback.Run();
224 } 224 }
225 225
226 void FakeShillServiceClient::Remove(const dbus::ObjectPath& service_path, 226 void FakeShillServiceClient::Remove(const dbus::ObjectPath& service_path,
227 const base::Closure& callback, 227 const base::Closure& callback,
228 const ErrorCallback& error_callback) { 228 const ErrorCallback& error_callback) {
229 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); 229 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
230 } 230 }
231 231
232 void FakeShillServiceClient::ActivateCellularModem( 232 void FakeShillServiceClient::ActivateCellularModem(
233 const dbus::ObjectPath& service_path, 233 const dbus::ObjectPath& service_path,
234 const std::string& carrier, 234 const std::string& carrier,
235 const base::Closure& callback, 235 const base::Closure& callback,
236 const ErrorCallback& error_callback) { 236 const ErrorCallback& error_callback) {
237 base::DictionaryValue* service_properties = 237 base::DictionaryValue* service_properties =
238 GetModifiableServiceProperties(service_path.value(), false); 238 GetModifiableServiceProperties(service_path.value(), false);
239 if (!service_properties) { 239 if (!service_properties) {
240 LOG(ERROR) << "Service not found: " << service_path.value(); 240 LOG(ERROR) << "Service not found: " << service_path.value();
241 error_callback.Run("Error.InvalidService", "Invalid Service"); 241 error_callback.Run("Error.InvalidService", "Invalid Service");
242 } 242 }
243 SetServiceProperty(service_path.value(), 243 SetServiceProperty(service_path.value(), shill::kActivationStateProperty,
244 shill::kActivationStateProperty, 244 base::Value(shill::kActivationStateActivating));
245 base::StringValue(shill::kActivationStateActivating));
246 // Set Activated after a delay 245 // Set Activated after a delay
247 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 246 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
248 FROM_HERE, 247 FROM_HERE,
249 base::Bind(&FakeShillServiceClient::SetCellularActivated, 248 base::Bind(&FakeShillServiceClient::SetCellularActivated,
250 weak_ptr_factory_.GetWeakPtr(), service_path, error_callback), 249 weak_ptr_factory_.GetWeakPtr(), service_path, error_callback),
251 base::TimeDelta::FromSeconds(GetInteractiveDelay())); 250 base::TimeDelta::FromSeconds(GetInteractiveDelay()));
252 251
253 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); 252 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
254 } 253 }
255 254
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 315
317 std::string profile_path; 316 std::string profile_path;
318 if (properties->GetStringWithoutPathExpansion(shill::kProfileProperty, 317 if (properties->GetStringWithoutPathExpansion(shill::kProfileProperty,
319 &profile_path) && 318 &profile_path) &&
320 !profile_path.empty()) { 319 !profile_path.empty()) {
321 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface()-> 320 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface()->
322 UpdateService(profile_path, service_path); 321 UpdateService(profile_path, service_path);
323 } 322 }
324 323
325 if (!ipconfig_path.empty()) { 324 if (!ipconfig_path.empty()) {
326 properties->SetWithoutPathExpansion( 325 properties->SetWithoutPathExpansion(shill::kIPConfigProperty,
327 shill::kIPConfigProperty, 326 new base::Value(ipconfig_path));
328 new base::StringValue(ipconfig_path));
329 } 327 }
330 328
331 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> 329 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()->
332 AddManagerService(service_path, true); 330 AddManagerService(service_path, true);
333 } 331 }
334 332
335 base::DictionaryValue* FakeShillServiceClient::SetServiceProperties( 333 base::DictionaryValue* FakeShillServiceClient::SetServiceProperties(
336 const std::string& service_path, 334 const std::string& service_path,
337 const std::string& guid, 335 const std::string& guid,
338 const std::string& name, 336 const std::string& name,
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 if (path == service_path) 562 if (path == service_path)
565 continue; 563 continue;
566 base::DictionaryValue* properties; 564 base::DictionaryValue* properties;
567 if (!stub_services_.GetDictionaryWithoutPathExpansion(path, &properties)) 565 if (!stub_services_.GetDictionaryWithoutPathExpansion(path, &properties))
568 NOTREACHED(); 566 NOTREACHED();
569 567
570 std::string type; 568 std::string type;
571 properties->GetString(shill::kTypeProperty, &type); 569 properties->GetString(shill::kTypeProperty, &type);
572 if (type != service_type) 570 if (type != service_type)
573 continue; 571 continue;
574 properties->SetWithoutPathExpansion( 572 properties->SetWithoutPathExpansion(shill::kStateProperty,
575 shill::kStateProperty, 573 new base::Value(shill::kStateIdle));
576 new base::StringValue(shill::kStateIdle));
577 } 574 }
578 } 575 }
579 576
580 void FakeShillServiceClient::SetCellularActivated( 577 void FakeShillServiceClient::SetCellularActivated(
581 const dbus::ObjectPath& service_path, 578 const dbus::ObjectPath& service_path,
582 const ErrorCallback& error_callback) { 579 const ErrorCallback& error_callback) {
583 SetProperty(service_path, 580 SetProperty(service_path, shill::kActivationStateProperty,
584 shill::kActivationStateProperty, 581 base::Value(shill::kActivationStateActivated),
585 base::StringValue(shill::kActivationStateActivated), 582 base::Bind(&base::DoNothing), error_callback);
586 base::Bind(&base::DoNothing),
587 error_callback);
588 SetProperty(service_path, shill::kConnectableProperty, base::Value(true), 583 SetProperty(service_path, shill::kConnectableProperty, base::Value(true),
589 base::Bind(&base::DoNothing), error_callback); 584 base::Bind(&base::DoNothing), error_callback);
590 } 585 }
591 586
592 void FakeShillServiceClient::ContinueConnect(const std::string& service_path) { 587 void FakeShillServiceClient::ContinueConnect(const std::string& service_path) {
593 VLOG(1) << "FakeShillServiceClient::ContinueConnect: " << service_path; 588 VLOG(1) << "FakeShillServiceClient::ContinueConnect: " << service_path;
594 base::DictionaryValue* service_properties = NULL; 589 base::DictionaryValue* service_properties = NULL;
595 if (!stub_services_.GetDictionary(service_path, &service_properties)) { 590 if (!stub_services_.GetDictionary(service_path, &service_properties)) {
596 LOG(ERROR) << "Service not found: " << service_path; 591 LOG(ERROR) << "Service not found: " << service_path;
597 return; 592 return;
598 } 593 }
599 594
600 if (base::ContainsKey(connect_behavior_, service_path)) { 595 if (base::ContainsKey(connect_behavior_, service_path)) {
601 const base::Closure& custom_connect_behavior = 596 const base::Closure& custom_connect_behavior =
602 connect_behavior_[service_path]; 597 connect_behavior_[service_path];
603 VLOG(1) << "Running custom connect behavior for " << service_path; 598 VLOG(1) << "Running custom connect behavior for " << service_path;
604 custom_connect_behavior.Run(); 599 custom_connect_behavior.Run();
605 return; 600 return;
606 } 601 }
607 602
608 // No custom connect behavior set, continue with the default connect behavior. 603 // No custom connect behavior set, continue with the default connect behavior.
609 std::string passphrase; 604 std::string passphrase;
610 service_properties->GetStringWithoutPathExpansion(shill::kPassphraseProperty, 605 service_properties->GetStringWithoutPathExpansion(shill::kPassphraseProperty,
611 &passphrase); 606 &passphrase);
612 if (passphrase == "failure") { 607 if (passphrase == "failure") {
613 // Simulate a password failure. 608 // Simulate a password failure.
614 SetServiceProperty(service_path, shill::kErrorProperty, 609 SetServiceProperty(service_path, shill::kErrorProperty,
615 base::StringValue(shill::kErrorBadPassphrase)); 610 base::Value(shill::kErrorBadPassphrase));
616 SetServiceProperty(service_path, shill::kStateProperty, 611 SetServiceProperty(service_path, shill::kStateProperty,
617 base::StringValue(shill::kStateFailure)); 612 base::Value(shill::kStateFailure));
618 base::ThreadTaskRunnerHandle::Get()->PostTask( 613 base::ThreadTaskRunnerHandle::Get()->PostTask(
619 FROM_HERE, 614 FROM_HERE,
620 base::Bind( 615 base::Bind(
621 base::IgnoreResult(&FakeShillServiceClient::SetServiceProperty), 616 base::IgnoreResult(&FakeShillServiceClient::SetServiceProperty),
622 weak_ptr_factory_.GetWeakPtr(), service_path, shill::kErrorProperty, 617 weak_ptr_factory_.GetWeakPtr(), service_path, shill::kErrorProperty,
623 base::StringValue(shill::kErrorBadPassphrase))); 618 base::Value(shill::kErrorBadPassphrase)));
624 } else { 619 } else {
625 // Set Online. 620 // Set Online.
626 VLOG(1) << "Setting state to Online " << service_path; 621 VLOG(1) << "Setting state to Online " << service_path;
627 SetServiceProperty(service_path, shill::kStateProperty, 622 SetServiceProperty(service_path, shill::kStateProperty,
628 base::StringValue(shill::kStateOnline)); 623 base::Value(shill::kStateOnline));
629 } 624 }
630 } 625 }
631 626
632 } // namespace chromeos 627 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/fake_shill_profile_client.cc ('k') | chromeos/dbus/gsm_sms_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698