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

Side by Side Diff: chromeos/network/shill_property_handler.cc

Issue 1431563005: Handle prohibited technologies in device policy ONC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove dependencies for NetworkHandler in ShillPropertyHandlerTest.ProhibitedTechnologies Created 5 years, 1 month 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/network/shill_property_handler.h" 5 #include "chromeos/network/shill_property_handler.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/format_macros.h" 10 #include "base/format_macros.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/strings/string_util.h"
12 #include "base/values.h" 13 #include "base/values.h"
13 #include "chromeos/dbus/dbus_thread_manager.h" 14 #include "chromeos/dbus/dbus_thread_manager.h"
14 #include "chromeos/dbus/shill_device_client.h" 15 #include "chromeos/dbus/shill_device_client.h"
15 #include "chromeos/dbus/shill_ipconfig_client.h" 16 #include "chromeos/dbus/shill_ipconfig_client.h"
16 #include "chromeos/dbus/shill_manager_client.h" 17 #include "chromeos/dbus/shill_manager_client.h"
17 #include "chromeos/dbus/shill_profile_client.h" 18 #include "chromeos/dbus/shill_profile_client.h"
18 #include "chromeos/dbus/shill_service_client.h" 19 #include "chromeos/dbus/shill_service_client.h"
20 #include "chromeos/network/managed_network_configuration_handler.h"
21 #include "chromeos/network/network_handler.h"
22 #include "chromeos/network/network_handler_callbacks.h"
19 #include "chromeos/network/network_state.h" 23 #include "chromeos/network/network_state.h"
20 #include "components/device_event_log/device_event_log.h" 24 #include "components/device_event_log/device_event_log.h"
21 #include "dbus/object_path.h" 25 #include "dbus/object_path.h"
22 #include "third_party/cros_system_api/dbus/service_constants.h" 26 #include "third_party/cros_system_api/dbus/service_constants.h"
23 27
24 namespace { 28 namespace {
25 29
26 // Limit the number of services or devices we observe. Since they are listed in 30 // Limit the number of services or devices we observe. Since they are listed in
27 // priority order, it should be reasonable to ignore services past this. 31 // priority order, it should be reasonable to ignore services past this.
28 const size_t kMaxObserved = 100; 32 const size_t kMaxObserved = 100;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 Handler handler_; 101 Handler handler_;
98 102
99 DISALLOW_COPY_AND_ASSIGN(ShillPropertyObserver); 103 DISALLOW_COPY_AND_ASSIGN(ShillPropertyObserver);
100 }; 104 };
101 105
102 //------------------------------------------------------------------------------ 106 //------------------------------------------------------------------------------
103 // ShillPropertyHandler 107 // ShillPropertyHandler
104 108
105 ShillPropertyHandler::ShillPropertyHandler(Listener* listener) 109 ShillPropertyHandler::ShillPropertyHandler(Listener* listener)
106 : listener_(listener), 110 : listener_(listener),
107 shill_manager_(DBusThreadManager::Get()->GetShillManagerClient()) { 111 shill_manager_(DBusThreadManager::Get()->GetShillManagerClient()) {}
108 }
109 112
110 ShillPropertyHandler::~ShillPropertyHandler() { 113 ShillPropertyHandler::~ShillPropertyHandler() {
111 // Delete network service observers. 114 // Delete network service observers.
112 STLDeleteContainerPairSecondPointers(observed_networks_.begin(), 115 STLDeleteContainerPairSecondPointers(observed_networks_.begin(),
113 observed_networks_.end()); 116 observed_networks_.end());
114 STLDeleteContainerPairSecondPointers(observed_devices_.begin(), 117 STLDeleteContainerPairSecondPointers(observed_devices_.begin(),
115 observed_devices_.end()); 118 observed_devices_.end());
116 CHECK(shill_manager_ == DBusThreadManager::Get()->GetShillManagerClient()); 119 CHECK(shill_manager_ == DBusThreadManager::Get()->GetShillManagerClient());
117 shill_manager_->RemovePropertyChangedObserver(this); 120 shill_manager_->RemovePropertyChangedObserver(this);
121 if (LoginState::IsInitialized())
122 LoginState::Get()->RemoveObserver(this);
118 } 123 }
119 124
120 void ShillPropertyHandler::Init() { 125 void ShillPropertyHandler::Init() {
121 UpdateManagerProperties(); 126 UpdateManagerProperties();
122 shill_manager_->AddPropertyChangedObserver(this); 127 shill_manager_->AddPropertyChangedObserver(this);
128 if (LoginState::IsInitialized())
129 LoginState::Get()->AddObserver(this);
123 } 130 }
124 131
125 void ShillPropertyHandler::UpdateManagerProperties() { 132 void ShillPropertyHandler::UpdateManagerProperties() {
126 NET_LOG(EVENT) << "UpdateManagerProperties"; 133 NET_LOG(EVENT) << "UpdateManagerProperties";
127 shill_manager_->GetProperties(base::Bind( 134 shill_manager_->GetProperties(base::Bind(
128 &ShillPropertyHandler::ManagerPropertiesCallback, AsWeakPtr())); 135 &ShillPropertyHandler::ManagerPropertiesCallback, AsWeakPtr()));
129 } 136 }
130 137
131 bool ShillPropertyHandler::IsTechnologyAvailable( 138 bool ShillPropertyHandler::IsTechnologyAvailable(
132 const std::string& technology) const { 139 const std::string& technology) const {
(...skipping 13 matching lines...) Expand all
146 bool ShillPropertyHandler::IsTechnologyUninitialized( 153 bool ShillPropertyHandler::IsTechnologyUninitialized(
147 const std::string& technology) const { 154 const std::string& technology) const {
148 return uninitialized_technologies_.count(technology) != 0; 155 return uninitialized_technologies_.count(technology) != 0;
149 } 156 }
150 157
151 void ShillPropertyHandler::SetTechnologyEnabled( 158 void ShillPropertyHandler::SetTechnologyEnabled(
152 const std::string& technology, 159 const std::string& technology,
153 bool enabled, 160 bool enabled,
154 const network_handler::ErrorCallback& error_callback) { 161 const network_handler::ErrorCallback& error_callback) {
155 if (enabled) { 162 if (enabled) {
163 if (in_user_session_ &&
164 prohibited_technologies_.find(technology) !=
165 prohibited_technologies_.end()) {
166 chromeos::network_handler::RunErrorCallback(
167 error_callback, "", "prohibited_technologies",
168 "Ignored: Attempt to enable prohibited network technology " +
169 technology);
170 return;
171 }
156 enabling_technologies_.insert(technology); 172 enabling_technologies_.insert(technology);
157 shill_manager_->EnableTechnology( 173 shill_manager_->EnableTechnology(
158 technology, base::Bind(&base::DoNothing), 174 technology, base::Bind(&base::DoNothing),
159 base::Bind(&ShillPropertyHandler::EnableTechnologyFailed, AsWeakPtr(), 175 base::Bind(&ShillPropertyHandler::EnableTechnologyFailed, AsWeakPtr(),
160 technology, error_callback)); 176 technology, error_callback));
161 } else { 177 } else {
162 // Immediately clear locally from enabled and enabling lists. 178 // Immediately clear locally from enabled and enabling lists.
163 enabled_technologies_.erase(technology); 179 enabled_technologies_.erase(technology);
164 enabling_technologies_.erase(technology); 180 enabling_technologies_.erase(technology);
165 shill_manager_->DisableTechnology( 181 shill_manager_->DisableTechnology(
166 technology, base::Bind(&base::DoNothing), 182 technology, base::Bind(&base::DoNothing),
167 base::Bind(&network_handler::ShillErrorCallbackFunction, 183 base::Bind(&network_handler::ShillErrorCallbackFunction,
168 "SetTechnologyEnabled Failed", technology, error_callback)); 184 "SetTechnologyEnabled Failed", technology, error_callback));
169 } 185 }
170 } 186 }
171 187
188 void ShillPropertyHandler::SetProhibitedTechnologies(
189 const std::vector<std::string>& prohibited_technologies,
190 const network_handler::ErrorCallback& error_callback) {
191 // Remove technologies from the other lists.
192 for (const auto& technology : prohibited_technologies)
193 prohibited_technologies_.insert(technology);
194 for (auto iter_prohibited_technology = prohibited_technologies_.begin();
195 iter_prohibited_technology != prohibited_technologies_.end();) {
196 if (std::find(prohibited_technologies.begin(),
197 prohibited_technologies.end(),
198 *iter_prohibited_technology) == prohibited_technologies.end())
199 iter_prohibited_technology =
200 prohibited_technologies_.erase(iter_prohibited_technology);
201 else
202 iter_prohibited_technology++;
203 }
204 SetProhibitedTechnologiesEnforced(in_user_session_ && user_policy_applied_);
205 }
206
207 void ShillPropertyHandler::SetProhibitedTechnologiesEnforced(bool enforced) {
208 std::vector<std::string> prohibited_technologies;
209 if (enforced) {
210 prohibited_technologies.assign(prohibited_technologies_.begin(),
211 prohibited_technologies_.end());
212
213 for (const auto& technology : prohibited_technologies_) {
214 enabling_technologies_.erase(technology);
215 enabled_technologies_.erase(technology);
216 shill_manager_->DisableTechnology(
217 technology, base::Bind(&base::DoNothing),
218 base::Bind(&network_handler::ShillErrorCallbackFunction,
219 "DisableTechnology Failed", technology,
220 network_handler::ErrorCallback()));
221 }
222 }
223
224 // Send updated prohibited technology list to shill.
225 const std::string prohibited_list =
226 base::JoinString(prohibited_technologies, ",");
227 base::StringValue value(prohibited_list);
228 shill_manager_->SetProperty(
229 "ProhibitedTechnologies", value, base::Bind(&base::DoNothing),
230 base::Bind(&network_handler::ShillErrorCallbackFunction,
231 "SetTechnologiesProhibited Failed", prohibited_list,
232 network_handler::ErrorCallback()));
233 }
234
235 void ShillPropertyHandler::LoggedInStateChanged() {
236 bool is_logged_in = LoginState::Get()->IsUserLoggedIn();
237 in_user_session_ = is_logged_in;
238 SetProhibitedTechnologiesEnforced(in_user_session_ && user_policy_applied_);
239 }
240
241 void ShillPropertyHandler::UserPolicyApplied() {
242 user_policy_applied_ = true;
243 SetProhibitedTechnologiesEnforced(in_user_session_ && user_policy_applied_);
244 }
245
172 void ShillPropertyHandler::SetCheckPortalList( 246 void ShillPropertyHandler::SetCheckPortalList(
173 const std::string& check_portal_list) { 247 const std::string& check_portal_list) {
174 base::StringValue value(check_portal_list); 248 base::StringValue value(check_portal_list);
175 shill_manager_->SetProperty( 249 shill_manager_->SetProperty(
176 shill::kCheckPortalListProperty, value, base::Bind(&base::DoNothing), 250 shill::kCheckPortalListProperty, value, base::Bind(&base::DoNothing),
177 base::Bind(&network_handler::ShillErrorCallbackFunction, 251 base::Bind(&network_handler::ShillErrorCallbackFunction,
178 "SetCheckPortalList Failed", "Manager", 252 "SetCheckPortalList Failed", "Manager",
179 network_handler::ErrorCallback())); 253 network_handler::ErrorCallback()));
180 } 254 }
181 255
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 NET_LOG(EVENT) << "Failed to get IP Config properties: " << ip_config_path 590 NET_LOG(EVENT) << "Failed to get IP Config properties: " << ip_config_path
517 << ": " << call_status << ", For: " << path; 591 << ": " << call_status << ", For: " << path;
518 return; 592 return;
519 } 593 }
520 NET_LOG(EVENT) << "IP Config properties received: " << path; 594 NET_LOG(EVENT) << "IP Config properties received: " << path;
521 listener_->UpdateIPConfigProperties(type, path, ip_config_path, properties); 595 listener_->UpdateIPConfigProperties(type, path, ip_config_path, properties);
522 } 596 }
523 597
524 } // namespace internal 598 } // namespace internal
525 } // namespace chromeos 599 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698