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

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

Issue 22364005: Added stub portalled wifi network. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: IsStubPortalledWifiEnabled() is exported. Created 7 years, 4 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') | no next file » | 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/command_line.h" 8 #include "base/command_line.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chromeos/chromeos_switches.h" 13 #include "chromeos/chromeos_switches.h"
14 #include "chromeos/dbus/dbus_thread_manager.h" 14 #include "chromeos/dbus/dbus_thread_manager.h"
15 #include "chromeos/dbus/shill_manager_client.h" 15 #include "chromeos/dbus/shill_manager_client.h"
16 #include "chromeos/dbus/shill_profile_client_stub.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_proxy.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
27 void ErrorFunction(const std::string& error_name, 30 void ErrorFunction(const std::string& error_name,
28 const std::string& error_message) { 31 const std::string& error_message) {
29 LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message; 32 LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message;
30 } 33 }
31 34
32 void PassStubListValue(const ShillServiceClient::ListValueCallback& callback, 35 void PassStubListValue(const ShillServiceClient::ListValueCallback& callback,
33 base::ListValue* value) { 36 base::ListValue* value) {
34 callback.Run(*value); 37 callback.Run(*value);
35 } 38 }
36 39
37 void PassStubServiceProperties( 40 void PassStubServiceProperties(
38 const ShillServiceClient::DictionaryValueCallback& callback, 41 const ShillServiceClient::DictionaryValueCallback& callback,
39 DBusMethodCallStatus call_status, 42 DBusMethodCallStatus call_status,
40 const base::DictionaryValue* properties) { 43 const base::DictionaryValue* properties) {
41 callback.Run(call_status, *properties); 44 callback.Run(call_status, *properties);
42 } 45 }
43 46
44 } // namespace 47 } // namespace
45 48
46 ShillServiceClientStub::ShillServiceClientStub() : weak_ptr_factory_(this) { 49 ShillServiceClientStub::ShillServiceClientStub() : weak_ptr_factory_(this) {
47 } 50 }
48 51
49 ShillServiceClientStub::~ShillServiceClientStub() { 52 ShillServiceClientStub::~ShillServiceClientStub() {
50 STLDeleteContainerPairSecondPointers( 53 STLDeleteContainerPairSecondPointers(
51 observer_list_.begin(), observer_list_.end()); 54 observer_list_.begin(), observer_list_.end());
52 } 55 }
53 56
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 // ShillServiceClient overrides. 67 // ShillServiceClient overrides.
55 68
56 void ShillServiceClientStub::AddPropertyChangedObserver( 69 void ShillServiceClientStub::AddPropertyChangedObserver(
57 const dbus::ObjectPath& service_path, 70 const dbus::ObjectPath& service_path,
58 ShillPropertyChangedObserver* observer) { 71 ShillPropertyChangedObserver* observer) {
59 GetObserverList(service_path).AddObserver(observer); 72 GetObserverList(service_path).AddObserver(observer);
60 } 73 }
61 74
62 void ShillServiceClientStub::RemovePropertyChangedObserver( 75 void ShillServiceClientStub::RemovePropertyChangedObserver(
63 const dbus::ObjectPath& service_path, 76 const dbus::ObjectPath& service_path,
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 associating_value); 198 associating_value);
186 199
187 // Set Online after a delay. 200 // Set Online after a delay.
188 base::TimeDelta delay; 201 base::TimeDelta delay;
189 if (CommandLine::ForCurrentProcess()->HasSwitch( 202 if (CommandLine::ForCurrentProcess()->HasSwitch(
190 chromeos::switches::kEnableStubInteractive)) { 203 chromeos::switches::kEnableStubInteractive)) {
191 const int kConnectDelaySeconds = 5; 204 const int kConnectDelaySeconds = 5;
192 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); 205 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds);
193 } 206 }
194 base::StringValue online_value(flimflam::kStateOnline); 207 base::StringValue online_value(flimflam::kStateOnline);
208 if (service_path.value() == kStubPortalledWifiPath)
209 online_value = base::StringValue(flimflam::kStatePortal);
195 std::string passphrase; 210 std::string passphrase;
196 service_properties->GetStringWithoutPathExpansion( 211 service_properties->GetStringWithoutPathExpansion(
197 flimflam::kPassphraseProperty, &passphrase); 212 flimflam::kPassphraseProperty, &passphrase);
198 if (passphrase == "failure") 213 if (passphrase == "failure")
199 online_value = base::StringValue(flimflam::kStateFailure); 214 online_value = base::StringValue(flimflam::kStateFailure);
200 base::MessageLoop::current()->PostDelayedTask( 215 base::MessageLoop::current()->PostDelayedTask(
201 FROM_HERE, 216 FROM_HERE,
202 base::Bind(&ShillServiceClientStub::SetProperty, 217 base::Bind(&ShillServiceClientStub::SetProperty,
203 weak_ptr_factory_.GetWeakPtr(), 218 weak_ptr_factory_.GetWeakPtr(),
204 service_path, 219 service_path,
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 } 328 }
314 329
315 // ShillServiceClient::TestInterface overrides. 330 // ShillServiceClient::TestInterface overrides.
316 331
317 void ShillServiceClientStub::AddService(const std::string& service_path, 332 void ShillServiceClientStub::AddService(const std::string& service_path,
318 const std::string& name, 333 const std::string& name,
319 const std::string& type, 334 const std::string& type,
320 const std::string& state, 335 const std::string& state,
321 bool add_to_visible_list, 336 bool add_to_visible_list,
322 bool add_to_watch_list) { 337 bool add_to_watch_list) {
323 AddServiceWithIPConfig(service_path, name, type, state, "", 338 std::string nstate = state;
339 if (CommandLine::ForCurrentProcess()->HasSwitch(
340 chromeos::switches::kDefaultStubNetworkStateIdle)) {
341 nstate = flimflam::kStateIdle;
342 }
343 AddServiceWithIPConfig(service_path, name, type, nstate, "",
324 add_to_visible_list, add_to_watch_list); 344 add_to_visible_list, add_to_watch_list);
325 } 345 }
326 346
327 void ShillServiceClientStub::AddServiceWithIPConfig( 347 void ShillServiceClientStub::AddServiceWithIPConfig(
328 const std::string& service_path, 348 const std::string& service_path,
329 const std::string& name, 349 const std::string& name,
330 const std::string& type, 350 const std::string& type,
331 const std::string& state, 351 const std::string& state,
332 const std::string& ipconfig_path, 352 const std::string& ipconfig_path,
333 bool add_to_visible_list, 353 bool add_to_visible_list,
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 flimflam::kStateIdle, 467 flimflam::kStateIdle,
448 add_to_visible, add_to_watchlist); 468 add_to_visible, add_to_watchlist);
449 SetServiceProperty("wifi2", 469 SetServiceProperty("wifi2",
450 flimflam::kSecurityProperty, 470 flimflam::kSecurityProperty,
451 base::StringValue(flimflam::kSecurityPsk)); 471 base::StringValue(flimflam::kSecurityPsk));
452 base::FundamentalValue strength_value(80); 472 base::FundamentalValue strength_value(80);
453 SetServiceProperty("wifi2", 473 SetServiceProperty("wifi2",
454 flimflam::kSignalStrengthProperty, 474 flimflam::kSignalStrengthProperty,
455 strength_value); 475 strength_value);
456 476
477 if (CommandLine::ForCurrentProcess()->HasSwitch(
478 chromeos::switches::kEnableStubPortalledWifi)) {
479 AddService(kStubPortalledWifiPath, kStubPortalledWifiName,
480 flimflam::kTypeWifi,
481 flimflam::kStatePortal,
482 add_to_visible, add_to_watchlist);
483 SetServiceProperty(kStubPortalledWifiPath,
484 flimflam::kSecurityProperty,
485 base::StringValue(flimflam::kSecurityNone));
486 }
487
457 // Wimax 488 // Wimax
458 489
459 AddService("wimax1", "wimax1", 490 AddService("wimax1", "wimax1",
460 flimflam::kTypeWimax, 491 flimflam::kTypeWimax,
461 flimflam::kStateIdle, 492 flimflam::kStateIdle,
462 add_to_visible, add_to_watchlist); 493 add_to_visible, add_to_watchlist);
463 SetServiceProperty("wimax1", 494 SetServiceProperty("wimax1",
464 flimflam::kConnectableProperty, 495 flimflam::kConnectableProperty,
465 base::FundamentalValue(true)); 496 base::FundamentalValue(true));
466 497
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 properties->GetString(flimflam::kTypeProperty, &type); 612 properties->GetString(flimflam::kTypeProperty, &type);
582 if (type != service_type) 613 if (type != service_type)
583 continue; 614 continue;
584 properties->SetWithoutPathExpansion( 615 properties->SetWithoutPathExpansion(
585 flimflam::kStateProperty, 616 flimflam::kStateProperty,
586 base::Value::CreateStringValue(flimflam::kStateIdle)); 617 base::Value::CreateStringValue(flimflam::kStateIdle));
587 } 618 }
588 } 619 }
589 620
590 } // namespace chromeos 621 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/shill_service_client_stub.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698