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

Side by Side Diff: chromeos/dbus/shill_stub_helper.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, 2 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chromeos/dbus/shill_stub_helper.h"
6
7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "chromeos/chromeos_switches.h"
10 #include "chromeos/dbus/dbus_thread_manager.h"
11 #include "chromeos/dbus/shill_device_client.h"
12 #include "chromeos/dbus/shill_manager_client.h"
13 #include "chromeos/dbus/shill_profile_client.h"
14 #include "chromeos/dbus/shill_profile_client_stub.h"
15 #include "chromeos/dbus/shill_service_client.h"
16 #include "third_party/cros_system_api/dbus/service_constants.h"
17
18 namespace chromeos {
19 namespace shill_stub_helper {
20
21 namespace {
22
23 const char kStubPortalledWifiName[] = "Portalled Wifi";
24 const char kStubPortalledWifiPath[] = "portalled_wifi";
25
26 void UpdatePortalledWifiState() {
27 ShillServiceClient::TestInterface* services =
28 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
29
30 services->SetServiceProperty(kStubPortalledWifiPath,
31 flimflam::kStateProperty,
32 base::StringValue(flimflam::kStatePortal));
33 }
34
35 } // namespace
36
37 const char kSharedProfilePath[] = "/profile/default";
38
39 bool IsStubPortalledWifiEnabled(const std::string& path) {
40 if (!CommandLine::ForCurrentProcess()->HasSwitch(
41 chromeos::switches::kEnableStubPortalledWifi)) {
42 return false;
43 }
44 return path == kStubPortalledWifiPath;
45 }
46
47 void SetupDefaultEnvironment() {
48 ShillServiceClient::TestInterface* services =
49 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
50 ShillProfileClient::TestInterface* profiles =
51 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface();
52 ShillManagerClient::TestInterface* manager =
53 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface();
54 ShillDeviceClient::TestInterface* devices =
55 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface();
56 if (!services || !profiles || !manager | !devices)
57 return;
58
59 // Stub Technologies.
60 if (!CommandLine::ForCurrentProcess()->HasSwitch(
61 chromeos::switches::kDisableStubEthernet)) {
62 manager->AddTechnology(flimflam::kTypeEthernet, true);
63 }
64 manager->AddTechnology(flimflam::kTypeWifi, true);
65 manager->AddTechnology(flimflam::kTypeCellular, true);
66 manager->AddTechnology(flimflam::kTypeWimax, true);
67
68 profiles->AddProfile(kSharedProfilePath, std::string());
69
70 // Add a wifi device.
71 devices->AddDevice("stub_wifi_device1", flimflam::kTypeWifi, "/device/wifi1");
72
73 // Add a cellular device. Used in SMS stub.
74 devices->AddDevice(
75 "stub_cellular_device1", flimflam::kTypeCellular, "/device/cellular1");
76 devices->SetDeviceProperty("stub_cellular_device1",
77 flimflam::kCarrierProperty,
78 base::StringValue(shill::kCarrierSprint));
79
80 // Add a wimax device.
81 devices->AddDevice(
82 "stub_wimax_device1", flimflam::kTypeWimax, "/device/wimax1");
83
84 const bool add_to_visible = true;
85 const bool add_to_watchlist = true;
86
87 if (!CommandLine::ForCurrentProcess()->HasSwitch(
88 chromeos::switches::kDisableStubEthernet)) {
89 services->AddService("eth1", "eth1",
90 flimflam::kTypeEthernet,
91 flimflam::kStateOnline,
92 add_to_visible, add_to_watchlist);
93 profiles->AddService(kSharedProfilePath, "eth1");
94 }
95
96 // Wifi
97
98 services->AddService("wifi1",
99 "wifi1",
100 flimflam::kTypeWifi,
101 flimflam::kStateOnline,
102 add_to_visible, add_to_watchlist);
103 services->SetServiceProperty("wifi1",
104 flimflam::kSecurityProperty,
105 base::StringValue(flimflam::kSecurityWep));
106 profiles->AddService(kSharedProfilePath, "wifi1");
107
108 services->AddService("wifi2",
109 "wifi2_PSK",
110 flimflam::kTypeWifi,
111 flimflam::kStateIdle,
112 add_to_visible, add_to_watchlist);
113 services->SetServiceProperty("wifi2",
114 flimflam::kSecurityProperty,
115 base::StringValue(flimflam::kSecurityPsk));
116 base::FundamentalValue strength_value(80);
117 services->SetServiceProperty(
118 "wifi2", flimflam::kSignalStrengthProperty, strength_value);
119 profiles->AddService(kSharedProfilePath, "wifi2");
120
121 if (CommandLine::ForCurrentProcess()->HasSwitch(
122 chromeos::switches::kEnableStubPortalledWifi)) {
123 services->AddService(kStubPortalledWifiPath,
124 kStubPortalledWifiName,
125 flimflam::kTypeWifi,
126 flimflam::kStatePortal,
127 add_to_visible, add_to_watchlist);
128 services->SetServiceProperty(kStubPortalledWifiPath,
129 flimflam::kSecurityProperty,
130 base::StringValue(flimflam::kSecurityNone));
131 services->SetConnectBehavior(kStubPortalledWifiPath,
132 base::Bind(&UpdatePortalledWifiState));
133 services->SetServiceProperty(kStubPortalledWifiPath,
134 flimflam::kConnectableProperty,
135 base::FundamentalValue(true));
136 }
137
138 // Wimax
139
140 services->AddService("wimax1",
141 "wimax1",
142 flimflam::kTypeWimax,
143 flimflam::kStateIdle,
144 add_to_visible, add_to_watchlist);
145 services->SetServiceProperty(
146 "wimax1", flimflam::kConnectableProperty, base::FundamentalValue(true));
147
148 // Cellular
149
150 services->AddService("cellular1",
151 "cellular1",
152 flimflam::kTypeCellular,
153 flimflam::kStateIdle,
154 add_to_visible, add_to_watchlist);
155 base::StringValue technology_value(flimflam::kNetworkTechnologyGsm);
156 services->SetServiceProperty(
157 "cellular1", flimflam::kNetworkTechnologyProperty, technology_value);
158 services->SetServiceProperty(
159 "cellular1",
160 flimflam::kActivationStateProperty,
161 base::StringValue(flimflam::kActivationStateNotActivated));
162 services->SetServiceProperty("cellular1",
163 flimflam::kRoamingStateProperty,
164 base::StringValue(flimflam::kRoamingStateHome));
165
166 // VPN
167
168 // Set the "Provider" dictionary properties. Note: when setting these in
169 // Shill, "Provider.Type", etc keys are used, but when reading the values
170 // "Provider" . "Type", etc keys are used. Here we are setting the values
171 // that will be read (by the UI, tests, etc).
172 base::DictionaryValue provider_properties;
173 provider_properties.SetString(flimflam::kTypeProperty,
174 flimflam::kProviderOpenVpn);
175 provider_properties.SetString(flimflam::kHostProperty, "vpn_host");
176
177 services->AddService("vpn1",
178 "vpn1",
179 flimflam::kTypeVPN,
180 flimflam::kStateOnline,
181 add_to_visible, add_to_watchlist);
182 services->SetServiceProperty(
183 "vpn1", flimflam::kProviderProperty, provider_properties);
184 profiles->AddService(kSharedProfilePath, "vpn1");
185
186 services->AddService("vpn2",
187 "vpn2",
188 flimflam::kTypeVPN,
189 flimflam::kStateOffline,
190 add_to_visible, add_to_watchlist);
191 services->SetServiceProperty(
192 "vpn2", flimflam::kProviderProperty, provider_properties);
193
194 manager->SortManagerServices();
195 }
196
197 } // namespace shill_stub_helper
198 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/shill_stub_helper.h ('k') | chromeos/network/network_configuration_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698