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

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

Issue 24150004: Refactor the setup of Shill*Stubs' default environment. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed some includes. Created 7 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 | Annotate | Revision Log
« no previous file with comments | « chromeos/dbus/shill_service_client_stub.h ('k') | chromeos/dbus/shill_stub_helper.h » ('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 (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_service_client_stub.h" 5 #include "chromeos/dbus/shill_service_client_stub.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
8 #include "base/command_line.h" 9 #include "base/command_line.h"
9 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
10 #include "base/stl_util.h" 11 #include "base/stl_util.h"
11 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
12 #include "base/values.h" 13 #include "base/values.h"
13 #include "chromeos/chromeos_switches.h" 14 #include "chromeos/chromeos_switches.h"
14 #include "chromeos/dbus/dbus_thread_manager.h" 15 #include "chromeos/dbus/dbus_thread_manager.h"
15 #include "chromeos/dbus/shill_manager_client.h" 16 #include "chromeos/dbus/shill_manager_client.h"
16 #include "chromeos/dbus/shill_profile_client_stub.h"
17 #include "chromeos/dbus/shill_property_changed_observer.h" 17 #include "chromeos/dbus/shill_property_changed_observer.h"
18 #include "dbus/bus.h" 18 #include "dbus/bus.h"
19 #include "dbus/message.h" 19 #include "dbus/message.h"
20 #include "dbus/object_proxy.h" 20 #include "dbus/object_path.h"
21 #include "third_party/cros_system_api/dbus/service_constants.h" 21 #include "third_party/cros_system_api/dbus/service_constants.h"
22 22
23 namespace chromeos { 23 namespace chromeos {
24 24
25 namespace { 25 namespace {
26 26
27 const char kStubPortalledWifiPath[] = "portalled_wifi";
28 const char kStubPortalledWifiName[] = "Portalled Wifi";
29
30 void ErrorFunction(const std::string& error_name, 27 void ErrorFunction(const std::string& error_name,
31 const std::string& error_message) { 28 const std::string& error_message) {
32 LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message; 29 LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message;
33 } 30 }
34 31
35 void PassStubListValue(const ShillServiceClient::ListValueCallback& callback, 32 void PassStubListValue(const ShillServiceClient::ListValueCallback& callback,
36 base::ListValue* value) { 33 base::ListValue* value) {
37 callback.Run(*value); 34 callback.Run(*value);
38 } 35 }
39 36
40 void PassStubServiceProperties( 37 void PassStubServiceProperties(
41 const ShillServiceClient::DictionaryValueCallback& callback, 38 const ShillServiceClient::DictionaryValueCallback& callback,
42 DBusMethodCallStatus call_status, 39 DBusMethodCallStatus call_status,
43 const base::DictionaryValue* properties) { 40 const base::DictionaryValue* properties) {
44 callback.Run(call_status, *properties); 41 callback.Run(call_status, *properties);
45 } 42 }
46 43
47 } // namespace 44 } // namespace
48 45
49 ShillServiceClientStub::ShillServiceClientStub() : weak_ptr_factory_(this) { 46 ShillServiceClientStub::ShillServiceClientStub() : weak_ptr_factory_(this) {
50 } 47 }
51 48
52 ShillServiceClientStub::~ShillServiceClientStub() { 49 ShillServiceClientStub::~ShillServiceClientStub() {
53 STLDeleteContainerPairSecondPointers( 50 STLDeleteContainerPairSecondPointers(
54 observer_list_.begin(), observer_list_.end()); 51 observer_list_.begin(), observer_list_.end());
55 } 52 }
56 53
57 // static
58 bool ShillServiceClientStub::IsStubPortalledWifiEnabled(
59 const std::string& path) {
60 if (!CommandLine::ForCurrentProcess()->HasSwitch(
61 chromeos::switches::kEnableStubPortalledWifi)) {
62 return false;
63 }
64 return path == kStubPortalledWifiPath;
65 }
66 54
67 // ShillServiceClient overrides. 55 // ShillServiceClient overrides.
68 56
69 void ShillServiceClientStub::Init(dbus::Bus* bus) { 57 void ShillServiceClientStub::Init(dbus::Bus* bus) {
70 } 58 }
71 59
72 void ShillServiceClientStub::AddPropertyChangedObserver( 60 void ShillServiceClientStub::AddPropertyChangedObserver(
73 const dbus::ObjectPath& service_path, 61 const dbus::ObjectPath& service_path,
74 ShillPropertyChangedObserver* observer) { 62 ShillPropertyChangedObserver* observer) {
75 GetObserverList(service_path).AddObserver(observer); 63 GetObserverList(service_path).AddObserver(observer);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 base::MessageLoop::current()->PostTask( 163 base::MessageLoop::current()->PostTask(
176 FROM_HERE, 164 FROM_HERE,
177 base::Bind(&PassStubListValue, 165 base::Bind(&PassStubListValue,
178 callback, base::Owned(results.release()))); 166 callback, base::Owned(results.release())));
179 } 167 }
180 168
181 void ShillServiceClientStub::Connect(const dbus::ObjectPath& service_path, 169 void ShillServiceClientStub::Connect(const dbus::ObjectPath& service_path,
182 const base::Closure& callback, 170 const base::Closure& callback,
183 const ErrorCallback& error_callback) { 171 const ErrorCallback& error_callback) {
184 VLOG(1) << "ShillServiceClientStub::Connect: " << service_path.value(); 172 VLOG(1) << "ShillServiceClientStub::Connect: " << service_path.value();
185 base::DictionaryValue* service_properties; 173 base::DictionaryValue* service_properties = NULL;
186 if (!stub_services_.GetDictionary( 174 if (!stub_services_.GetDictionary(
187 service_path.value(), &service_properties)) { 175 service_path.value(), &service_properties)) {
188 LOG(ERROR) << "Service not found: " << service_path.value(); 176 LOG(ERROR) << "Service not found: " << service_path.value();
189 error_callback.Run("Error.InvalidService", "Invalid Service"); 177 error_callback.Run("Error.InvalidService", "Invalid Service");
190 return; 178 return;
191 } 179 }
192 180
193 // Set any other services of the same Type to 'offline' first, before setting 181 // Set any other services of the same Type to 'offline' first, before setting
194 // State to Association which will trigger sorting Manager.Services and 182 // State to Association which will trigger sorting Manager.Services and
195 // sending an update. 183 // sending an update.
196 SetOtherServicesOffline(service_path.value()); 184 SetOtherServicesOffline(service_path.value());
197 185
198 // Set Associating. 186 // Set Associating.
199 base::StringValue associating_value(flimflam::kStateAssociation); 187 base::StringValue associating_value(flimflam::kStateAssociation);
200 SetServiceProperty(service_path.value(), 188 SetServiceProperty(service_path.value(),
201 flimflam::kStateProperty, 189 flimflam::kStateProperty,
202 associating_value); 190 associating_value);
203 191
204 // Set Online after a delay. 192 // Stay Associating until the state is changed again after a delay.
205 base::TimeDelta delay; 193 base::TimeDelta delay;
206 if (CommandLine::ForCurrentProcess()->HasSwitch( 194 if (CommandLine::ForCurrentProcess()->HasSwitch(
207 chromeos::switches::kEnableStubInteractive)) { 195 chromeos::switches::kEnableStubInteractive)) {
208 const int kConnectDelaySeconds = 5; 196 const int kConnectDelaySeconds = 5;
209 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); 197 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds);
210 } 198 }
211 base::StringValue online_value(flimflam::kStateOnline);
212 if (service_path.value() == kStubPortalledWifiPath)
213 online_value = base::StringValue(flimflam::kStatePortal);
214 std::string passphrase;
215 service_properties->GetStringWithoutPathExpansion(
216 flimflam::kPassphraseProperty, &passphrase);
217 if (passphrase == "failure")
218 online_value = base::StringValue(flimflam::kStateFailure);
219 base::MessageLoop::current()->PostDelayedTask( 199 base::MessageLoop::current()->PostDelayedTask(
220 FROM_HERE, 200 FROM_HERE,
221 base::Bind(&ShillServiceClientStub::SetProperty, 201 base::Bind(&ShillServiceClientStub::ContinueConnect,
222 weak_ptr_factory_.GetWeakPtr(), 202 weak_ptr_factory_.GetWeakPtr(),
223 service_path, 203 service_path.value()),
224 flimflam::kStateProperty,
225 online_value,
226 base::Bind(&base::DoNothing),
227 error_callback),
228 delay); 204 delay);
205
229 callback.Run(); 206 callback.Run();
230 // On failure, also set the Error property.
231 if (passphrase == "failure") {
232 base::MessageLoop::current()->PostDelayedTask(
233 FROM_HERE,
234 base::Bind(&ShillServiceClientStub::SetProperty,
235 weak_ptr_factory_.GetWeakPtr(),
236 service_path,
237 flimflam::kErrorProperty,
238 base::StringValue(flimflam::kErrorBadPassphrase),
239 base::Bind(&base::DoNothing),
240 error_callback),
241 delay);
242 }
243 } 207 }
244 208
245 void ShillServiceClientStub::Disconnect(const dbus::ObjectPath& service_path, 209 void ShillServiceClientStub::Disconnect(const dbus::ObjectPath& service_path,
246 const base::Closure& callback, 210 const base::Closure& callback,
247 const ErrorCallback& error_callback) { 211 const ErrorCallback& error_callback) {
248 base::Value* service; 212 base::Value* service;
249 if (!stub_services_.Get(service_path.value(), &service)) { 213 if (!stub_services_.Get(service_path.value(), &service)) {
250 error_callback.Run("Error.InvalidService", "Invalid Service"); 214 error_callback.Run("Error.InvalidService", "Invalid Service");
251 return; 215 return;
252 } 216 }
(...skipping 23 matching lines...) Expand all
276 const ErrorCallback& error_callback) { 240 const ErrorCallback& error_callback) {
277 base::MessageLoop::current()->PostTask(FROM_HERE, callback); 241 base::MessageLoop::current()->PostTask(FROM_HERE, callback);
278 } 242 }
279 243
280 void ShillServiceClientStub::ActivateCellularModem( 244 void ShillServiceClientStub::ActivateCellularModem(
281 const dbus::ObjectPath& service_path, 245 const dbus::ObjectPath& service_path,
282 const std::string& carrier, 246 const std::string& carrier,
283 const base::Closure& callback, 247 const base::Closure& callback,
284 const ErrorCallback& error_callback) { 248 const ErrorCallback& error_callback) {
285 base::DictionaryValue* service_properties = 249 base::DictionaryValue* service_properties =
286 GetModifiableServiceProperties(service_path.value()); 250 GetModifiableServiceProperties(service_path.value(), false);
287 if (!service_properties) { 251 if (!service_properties) {
288 LOG(ERROR) << "Service not found: " << service_path.value(); 252 LOG(ERROR) << "Service not found: " << service_path.value();
289 error_callback.Run("Error.InvalidService", "Invalid Service"); 253 error_callback.Run("Error.InvalidService", "Invalid Service");
290 } 254 }
291 SetServiceProperty(service_path.value(), 255 SetServiceProperty(service_path.value(),
292 flimflam::kActivationStateProperty, 256 flimflam::kActivationStateProperty,
293 base::StringValue(flimflam::kActivationStateActivating)); 257 base::StringValue(flimflam::kActivationStateActivating));
294 base::TimeDelta delay; 258 base::TimeDelta delay;
295 if (CommandLine::ForCurrentProcess()->HasSwitch( 259 if (CommandLine::ForCurrentProcess()->HasSwitch(
296 chromeos::switches::kEnableStubInteractive)) { 260 chromeos::switches::kEnableStubInteractive)) {
(...skipping 20 matching lines...) Expand all
317 } 281 }
318 282
319 void ShillServiceClientStub::GetLoadableProfileEntries( 283 void ShillServiceClientStub::GetLoadableProfileEntries(
320 const dbus::ObjectPath& service_path, 284 const dbus::ObjectPath& service_path,
321 const DictionaryValueCallback& callback) { 285 const DictionaryValueCallback& callback) {
322 // Provide a dictionary with a single { profile_path, service_path } entry 286 // Provide a dictionary with a single { profile_path, service_path } entry
323 // if the Profile property is set, or an empty dictionary. 287 // if the Profile property is set, or an empty dictionary.
324 scoped_ptr<base::DictionaryValue> result_properties( 288 scoped_ptr<base::DictionaryValue> result_properties(
325 new base::DictionaryValue); 289 new base::DictionaryValue);
326 base::DictionaryValue* service_properties = 290 base::DictionaryValue* service_properties =
327 GetModifiableServiceProperties(service_path.value()); 291 GetModifiableServiceProperties(service_path.value(), false);
328 if (service_properties) { 292 if (service_properties) {
329 std::string profile_path; 293 std::string profile_path;
330 if (service_properties->GetStringWithoutPathExpansion( 294 if (service_properties->GetStringWithoutPathExpansion(
331 flimflam::kProfileProperty, &profile_path)) { 295 flimflam::kProfileProperty, &profile_path)) {
332 result_properties->SetStringWithoutPathExpansion( 296 result_properties->SetStringWithoutPathExpansion(
333 profile_path, service_path.value()); 297 profile_path, service_path.value());
334 } 298 }
335 } else { 299 } else {
336 LOG(WARNING) << "Service not in profile: " << service_path.value(); 300 LOG(WARNING) << "Service not in profile: " << service_path.value();
337 } 301 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 const std::string& name, 335 const std::string& name,
372 const std::string& type, 336 const std::string& type,
373 const std::string& state, 337 const std::string& state,
374 const std::string& ipconfig_path, 338 const std::string& ipconfig_path,
375 bool add_to_visible_list, 339 bool add_to_visible_list,
376 bool add_to_watch_list) { 340 bool add_to_watch_list) {
377 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> 341 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()->
378 AddManagerService(service_path, add_to_visible_list, add_to_watch_list); 342 AddManagerService(service_path, add_to_visible_list, add_to_watch_list);
379 343
380 base::DictionaryValue* properties = 344 base::DictionaryValue* properties =
381 GetModifiableServiceProperties(service_path); 345 GetModifiableServiceProperties(service_path, true);
346 connect_behavior_.erase(service_path);
382 properties->SetWithoutPathExpansion( 347 properties->SetWithoutPathExpansion(
383 flimflam::kSSIDProperty, 348 flimflam::kSSIDProperty,
384 base::Value::CreateStringValue(service_path)); 349 base::Value::CreateStringValue(service_path));
385 properties->SetWithoutPathExpansion( 350 properties->SetWithoutPathExpansion(
386 flimflam::kNameProperty, 351 flimflam::kNameProperty,
387 base::Value::CreateStringValue(name)); 352 base::Value::CreateStringValue(name));
388 properties->SetWithoutPathExpansion( 353 properties->SetWithoutPathExpansion(
389 flimflam::kTypeProperty, 354 flimflam::kTypeProperty,
390 base::Value::CreateStringValue(type)); 355 base::Value::CreateStringValue(type));
391 properties->SetWithoutPathExpansion( 356 properties->SetWithoutPathExpansion(
392 flimflam::kStateProperty, 357 flimflam::kStateProperty,
393 base::Value::CreateStringValue(state)); 358 base::Value::CreateStringValue(state));
394 if (!ipconfig_path.empty()) 359 if (!ipconfig_path.empty())
395 properties->SetWithoutPathExpansion( 360 properties->SetWithoutPathExpansion(
396 shill::kIPConfigProperty, 361 shill::kIPConfigProperty,
397 base::Value::CreateStringValue(ipconfig_path)); 362 base::Value::CreateStringValue(ipconfig_path));
398 } 363 }
399 364
400 void ShillServiceClientStub::RemoveService(const std::string& service_path) { 365 void ShillServiceClientStub::RemoveService(const std::string& service_path) {
401 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> 366 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()->
402 RemoveManagerService(service_path); 367 RemoveManagerService(service_path);
403 368
404 stub_services_.RemoveWithoutPathExpansion(service_path, NULL); 369 stub_services_.RemoveWithoutPathExpansion(service_path, NULL);
370 connect_behavior_.erase(service_path);
405 } 371 }
406 372
407 bool ShillServiceClientStub::SetServiceProperty(const std::string& service_path, 373 bool ShillServiceClientStub::SetServiceProperty(const std::string& service_path,
408 const std::string& property, 374 const std::string& property,
409 const base::Value& value) { 375 const base::Value& value) {
410 base::DictionaryValue* dict = NULL; 376 base::DictionaryValue* dict = NULL;
411 if (!stub_services_.GetDictionaryWithoutPathExpansion(service_path, &dict)) 377 if (!stub_services_.GetDictionaryWithoutPathExpansion(service_path, &dict))
412 return false; 378 return false;
413 379
414 VLOG(1) << "Service.SetProperty: " << property << " = " << value 380 VLOG(1) << "Service.SetProperty: " << property << " = " << value
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 const base::DictionaryValue* properties = NULL; 419 const base::DictionaryValue* properties = NULL;
454 stub_services_.GetDictionaryWithoutPathExpansion(service_path, &properties); 420 stub_services_.GetDictionaryWithoutPathExpansion(service_path, &properties);
455 return properties; 421 return properties;
456 } 422 }
457 423
458 void ShillServiceClientStub::ClearServices() { 424 void ShillServiceClientStub::ClearServices() {
459 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> 425 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()->
460 ClearManagerServices(); 426 ClearManagerServices();
461 427
462 stub_services_.Clear(); 428 stub_services_.Clear();
429 connect_behavior_.clear();
463 } 430 }
464 431
465 void ShillServiceClientStub::AddDefaultServices() { 432 void ShillServiceClientStub::SetConnectBehavior(const std::string& service_path,
466 const bool add_to_visible = true; 433 const base::Closure& behavior) {
467 const bool add_to_watchlist = true; 434 connect_behavior_[service_path] = behavior;
468
469 if (!CommandLine::ForCurrentProcess()->HasSwitch(
470 chromeos::switches::kDisableStubEthernet)) {
471 AddService("eth1", "eth1",
472 flimflam::kTypeEthernet,
473 flimflam::kStateOnline,
474 add_to_visible, add_to_watchlist);
475 }
476
477 // Wifi
478
479 AddService("wifi1", "wifi1",
480 flimflam::kTypeWifi,
481 flimflam::kStateOnline,
482 add_to_visible, add_to_watchlist);
483 SetServiceProperty("wifi1",
484 flimflam::kSecurityProperty,
485 base::StringValue(flimflam::kSecurityWep));
486
487 AddService("wifi2", "wifi2_PSK",
488 flimflam::kTypeWifi,
489 flimflam::kStateIdle,
490 add_to_visible, add_to_watchlist);
491 SetServiceProperty("wifi2",
492 flimflam::kSecurityProperty,
493 base::StringValue(flimflam::kSecurityPsk));
494 base::FundamentalValue strength_value(80);
495 SetServiceProperty("wifi2",
496 flimflam::kSignalStrengthProperty,
497 strength_value);
498
499 if (CommandLine::ForCurrentProcess()->HasSwitch(
500 chromeos::switches::kEnableStubPortalledWifi)) {
501 AddService(kStubPortalledWifiPath, kStubPortalledWifiName,
502 flimflam::kTypeWifi,
503 flimflam::kStatePortal,
504 add_to_visible, add_to_watchlist);
505 SetServiceProperty(kStubPortalledWifiPath,
506 flimflam::kSecurityProperty,
507 base::StringValue(flimflam::kSecurityNone));
508 }
509
510 // Wimax
511
512 AddService("wimax1", "wimax1",
513 flimflam::kTypeWimax,
514 flimflam::kStateIdle,
515 add_to_visible, add_to_watchlist);
516 SetServiceProperty("wimax1",
517 flimflam::kConnectableProperty,
518 base::FundamentalValue(true));
519
520 // Cellular
521
522 AddService("cellular1", "cellular1",
523 flimflam::kTypeCellular,
524 flimflam::kStateIdle,
525 add_to_visible, add_to_watchlist);
526 base::StringValue technology_value(flimflam::kNetworkTechnologyGsm);
527 SetServiceProperty("cellular1",
528 flimflam::kNetworkTechnologyProperty,
529 technology_value);
530 SetServiceProperty("cellular1",
531 flimflam::kActivationStateProperty,
532 base::StringValue(flimflam::kActivationStateNotActivated));
533 SetServiceProperty("cellular1",
534 flimflam::kRoamingStateProperty,
535 base::StringValue(flimflam::kRoamingStateHome));
536
537 // VPN
538
539 // Set the "Provider" dictionary properties. Note: when setting these in
540 // Shill, "Provider.Type", etc keys are used, but when reading the values
541 // "Provider" . "Type", etc keys are used. Here we are setting the values
542 // that will be read (by the UI, tests, etc).
543 base::DictionaryValue provider_properties;
544 provider_properties.SetString(flimflam::kTypeProperty,
545 flimflam::kProviderOpenVpn);
546 provider_properties.SetString(flimflam::kHostProperty, "vpn_host");
547
548 AddService("vpn1", "vpn1",
549 flimflam::kTypeVPN,
550 flimflam::kStateOnline,
551 add_to_visible, add_to_watchlist);
552 SetServiceProperty("vpn1",
553 flimflam::kProviderProperty,
554 provider_properties);
555
556 AddService("vpn2", "vpn2",
557 flimflam::kTypeVPN,
558 flimflam::kStateOffline,
559 add_to_visible, add_to_watchlist);
560 SetServiceProperty("vpn2",
561 flimflam::kProviderProperty,
562 provider_properties);
563
564 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface()->
565 AddService(ShillProfileClientStub::kSharedProfilePath, "wifi2");
566
567 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()->
568 SortManagerServices();
569 } 435 }
570 436
571 void ShillServiceClientStub::NotifyObserversPropertyChanged( 437 void ShillServiceClientStub::NotifyObserversPropertyChanged(
572 const dbus::ObjectPath& service_path, 438 const dbus::ObjectPath& service_path,
573 const std::string& property) { 439 const std::string& property) {
574 base::DictionaryValue* dict = NULL; 440 base::DictionaryValue* dict = NULL;
575 std::string path = service_path.value(); 441 std::string path = service_path.value();
576 if (!stub_services_.GetDictionaryWithoutPathExpansion(path, &dict)) { 442 if (!stub_services_.GetDictionaryWithoutPathExpansion(path, &dict)) {
577 LOG(ERROR) << "Notify for unknown service: " << path; 443 LOG(ERROR) << "Notify for unknown service: " << path;
578 return; 444 return;
579 } 445 }
580 base::Value* value = NULL; 446 base::Value* value = NULL;
581 if (!dict->GetWithoutPathExpansion(property, &value)) { 447 if (!dict->GetWithoutPathExpansion(property, &value)) {
582 LOG(ERROR) << "Notify for unknown property: " 448 LOG(ERROR) << "Notify for unknown property: "
583 << path << " : " << property; 449 << path << " : " << property;
584 return; 450 return;
585 } 451 }
586 FOR_EACH_OBSERVER(ShillPropertyChangedObserver, 452 FOR_EACH_OBSERVER(ShillPropertyChangedObserver,
587 GetObserverList(service_path), 453 GetObserverList(service_path),
588 OnPropertyChanged(property, *value)); 454 OnPropertyChanged(property, *value));
589 } 455 }
590 456
591 base::DictionaryValue* ShillServiceClientStub::GetModifiableServiceProperties( 457 base::DictionaryValue* ShillServiceClientStub::GetModifiableServiceProperties(
592 const std::string& service_path) { 458 const std::string& service_path, bool create_if_missing) {
593 base::DictionaryValue* properties = NULL; 459 base::DictionaryValue* properties = NULL;
594 if (!stub_services_.GetDictionaryWithoutPathExpansion( 460 if (!stub_services_.GetDictionaryWithoutPathExpansion(service_path,
595 service_path, &properties)) { 461 &properties) &&
462 create_if_missing) {
596 properties = new base::DictionaryValue; 463 properties = new base::DictionaryValue;
597 stub_services_.Set(service_path, properties); 464 stub_services_.Set(service_path, properties);
598 } 465 }
599 return properties; 466 return properties;
600 } 467 }
601 468
602 ShillServiceClientStub::PropertyObserverList& 469 ShillServiceClientStub::PropertyObserverList&
603 ShillServiceClientStub::GetObserverList(const dbus::ObjectPath& device_path) { 470 ShillServiceClientStub::GetObserverList(const dbus::ObjectPath& device_path) {
604 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter = 471 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter =
605 observer_list_.find(device_path); 472 observer_list_.find(device_path);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 base::StringValue(flimflam::kActivationStateActivated), 515 base::StringValue(flimflam::kActivationStateActivated),
649 base::Bind(&base::DoNothing), 516 base::Bind(&base::DoNothing),
650 error_callback); 517 error_callback);
651 SetProperty(service_path, 518 SetProperty(service_path,
652 flimflam::kConnectableProperty, 519 flimflam::kConnectableProperty,
653 base::FundamentalValue(true), 520 base::FundamentalValue(true),
654 base::Bind(&base::DoNothing), 521 base::Bind(&base::DoNothing),
655 error_callback); 522 error_callback);
656 } 523 }
657 524
525 void ShillServiceClientStub::ContinueConnect(
526 const std::string& service_path) {
527 VLOG(1) << "ShillServiceClientStub::ContinueConnect: " << service_path;
528 base::DictionaryValue* service_properties = NULL;
529 if (!stub_services_.GetDictionary(service_path, &service_properties)) {
530 LOG(ERROR) << "Service not found: " << service_path;
531 return;
532 }
533
534 if (ContainsKey(connect_behavior_, service_path)) {
535 const base::Closure& custom_connect_behavior =
536 connect_behavior_[service_path];
537 custom_connect_behavior.Run();
538 return;
539 }
540
541 // No custom connect behavior set, continue with the default connect behavior.
542 std::string passphrase;
543 service_properties->GetStringWithoutPathExpansion(
544 flimflam::kPassphraseProperty, &passphrase);
545 if (passphrase == "failure") {
546 // Simulate a password failure.
547 SetServiceProperty(service_path,
548 flimflam::kStateProperty,
549 base::StringValue(flimflam::kStateFailure));
550 base::MessageLoop::current()->PostTask(
551 FROM_HERE,
552 base::Bind(
553 base::IgnoreResult(&ShillServiceClientStub::SetServiceProperty),
554 weak_ptr_factory_.GetWeakPtr(),
555 service_path,
556 flimflam::kErrorProperty,
557 base::StringValue(flimflam::kErrorBadPassphrase)));
558 } else {
559 // Set Online.
560 SetServiceProperty(service_path,
561 flimflam::kStateProperty,
562 base::StringValue(flimflam::kStateOnline));
563 }
564 }
565
658 } // namespace chromeos 566 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/shill_service_client_stub.h ('k') | chromeos/dbus/shill_stub_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698