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

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: Fix, sync. 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
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()->
61 HasSwitch(chromeos::switches::kEnableStubPortalledWifi)) {
62 return false;
63 }
64 return (path == kStubPortalledWifiPath);
oshima 2013/08/07 16:01:12 nit: nuke ()
ygorshenin1 2013/08/08 08:05:57 Done.
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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 flimflam::kStateProperty, 196 flimflam::kStateProperty,
184 associating_value); 197 associating_value);
185 198
186 // Set Online after a delay. 199 // Set Online after a delay.
187 base::TimeDelta delay; 200 base::TimeDelta delay;
188 if (CommandLine::ForCurrentProcess()->HasSwitch( 201 if (CommandLine::ForCurrentProcess()->HasSwitch(
189 chromeos::switches::kEnableStubInteractive)) { 202 chromeos::switches::kEnableStubInteractive)) {
190 const int kConnectDelaySeconds = 5; 203 const int kConnectDelaySeconds = 5;
191 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); 204 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds);
192 } 205 }
193 base::StringValue online_value(flimflam::kStateOnline); 206 base::StringValue online_value(
207 service_path.value() == kStubPortalledWifiPath ?
208 flimflam::kStatePortal : flimflam::kStateOnline);
194 base::MessageLoop::current()->PostDelayedTask( 209 base::MessageLoop::current()->PostDelayedTask(
195 FROM_HERE, 210 FROM_HERE,
196 base::Bind(&ShillServiceClientStub::SetProperty, 211 base::Bind(&ShillServiceClientStub::SetProperty,
197 weak_ptr_factory_.GetWeakPtr(), 212 weak_ptr_factory_.GetWeakPtr(),
198 service_path, 213 service_path,
199 flimflam::kStateProperty, 214 flimflam::kStateProperty,
200 online_value, 215 online_value,
201 base::Bind(&base::DoNothing), 216 base::Bind(&base::DoNothing),
202 error_callback), 217 error_callback),
203 delay); 218 delay);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 } 309 }
295 310
296 // ShillServiceClient::TestInterface overrides. 311 // ShillServiceClient::TestInterface overrides.
297 312
298 void ShillServiceClientStub::AddService(const std::string& service_path, 313 void ShillServiceClientStub::AddService(const std::string& service_path,
299 const std::string& name, 314 const std::string& name,
300 const std::string& type, 315 const std::string& type,
301 const std::string& state, 316 const std::string& state,
302 bool add_to_visible_list, 317 bool add_to_visible_list,
303 bool add_to_watch_list) { 318 bool add_to_watch_list) {
304 AddServiceWithIPConfig(service_path, name, type, state, "", 319 std::string nstate = state;
320 if (CommandLine::ForCurrentProcess()->
321 HasSwitch(chromeos::switches::kDefaultStubNetworkStateIdle)) {
oshima 2013/08/07 16:01:12 nit: indent like this CommandLine::ForCurrentProc
ygorshenin1 2013/08/08 08:05:57 Done.
322 nstate = flimflam::kStateIdle;
323 }
324 AddServiceWithIPConfig(service_path, name, type, nstate, "",
305 add_to_visible_list, add_to_watch_list); 325 add_to_visible_list, add_to_watch_list);
306 } 326 }
307 327
308 void ShillServiceClientStub::AddServiceWithIPConfig( 328 void ShillServiceClientStub::AddServiceWithIPConfig(
309 const std::string& service_path, 329 const std::string& service_path,
310 const std::string& name, 330 const std::string& name,
311 const std::string& type, 331 const std::string& type,
312 const std::string& state, 332 const std::string& state,
313 const std::string& ipconfig_path, 333 const std::string& ipconfig_path,
314 bool add_to_visible_list, 334 bool add_to_visible_list,
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 flimflam::kStateIdle, 448 flimflam::kStateIdle,
429 add_to_visible, add_to_watchlist); 449 add_to_visible, add_to_watchlist);
430 SetServiceProperty("wifi2", 450 SetServiceProperty("wifi2",
431 flimflam::kSecurityProperty, 451 flimflam::kSecurityProperty,
432 base::StringValue(flimflam::kSecurityPsk)); 452 base::StringValue(flimflam::kSecurityPsk));
433 base::FundamentalValue strength_value(80); 453 base::FundamentalValue strength_value(80);
434 SetServiceProperty("wifi2", 454 SetServiceProperty("wifi2",
435 flimflam::kSignalStrengthProperty, 455 flimflam::kSignalStrengthProperty,
436 strength_value); 456 strength_value);
437 457
458 if (CommandLine::ForCurrentProcess()->
459 HasSwitch(chromeos::switches::kEnableStubPortalledWifi)) {
oshima 2013/08/07 16:01:12 ditto
ygorshenin1 2013/08/08 08:05:57 Done.
460 AddService(kStubPortalledWifiPath, kStubPortalledWifiName,
461 flimflam::kTypeWifi,
462 flimflam::kStatePortal,
463 add_to_visible, add_to_watchlist);
464 SetServiceProperty(kStubPortalledWifiPath,
465 flimflam::kSecurityProperty,
466 base::StringValue(flimflam::kSecurityNone));
467 }
468
438 // Wimax 469 // Wimax
439 470
440 AddService("wimax1", "wimax1", 471 AddService("wimax1", "wimax1",
441 flimflam::kTypeWimax, 472 flimflam::kTypeWimax,
442 flimflam::kStateIdle, 473 flimflam::kStateIdle,
443 add_to_visible, add_to_watchlist); 474 add_to_visible, add_to_watchlist);
444 SetServiceProperty("wimax1", 475 SetServiceProperty("wimax1",
445 flimflam::kConnectableProperty, 476 flimflam::kConnectableProperty,
446 base::FundamentalValue(true)); 477 base::FundamentalValue(true));
447 478
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 properties->GetString(flimflam::kTypeProperty, &type); 593 properties->GetString(flimflam::kTypeProperty, &type);
563 if (type != service_type) 594 if (type != service_type)
564 continue; 595 continue;
565 properties->SetWithoutPathExpansion( 596 properties->SetWithoutPathExpansion(
566 flimflam::kStateProperty, 597 flimflam::kStateProperty,
567 base::Value::CreateStringValue(flimflam::kStateIdle)); 598 base::Value::CreateStringValue(flimflam::kStateIdle));
568 } 599 }
569 } 600 }
570 601
571 } // namespace chromeos 602 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698