Chromium Code Reviews| Index: chromeos/network/prohibited_technologies_handler.cc |
| diff --git a/chromeos/network/prohibited_technologies_handler.cc b/chromeos/network/prohibited_technologies_handler.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..183f49f363bc9486524e1dc3c74ed02b3c46b01c |
| --- /dev/null |
| +++ b/chromeos/network/prohibited_technologies_handler.cc |
| @@ -0,0 +1,87 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chromeos/network/prohibited_technologies_handler.h" |
| + |
| +#include "chromeos/network/managed_network_configuration_handler.h" |
| +#include "chromeos/network/network_state_handler.h" |
| + |
| +namespace chromeos { |
| + |
| +ProhibitedTechnologiesHandler::ProhibitedTechnologiesHandler() |
| + : managed_network_configuration_handler_(nullptr){}; |
|
stevenjb
2015/11/11 18:07:31
Need to intialize other members. Better yet, use N
fqj
2015/11/12 10:23:01
Done.
|
| + |
| +ProhibitedTechnologiesHandler::~ProhibitedTechnologiesHandler() { |
| + if (managed_network_configuration_handler_) |
| + managed_network_configuration_handler_->RemoveObserver(this); |
| + if (LoginState::IsInitialized()) |
| + LoginState::Get()->RemoveObserver(this); |
| +} |
| + |
| +void ProhibitedTechnologiesHandler::Init( |
| + ManagedNetworkConfigurationHandler* managed_network_configuration_handler, |
| + NetworkStateHandler* network_state_handler) { |
| + if (LoginState::IsInitialized()) { |
| + LoginState::Get()->AddObserver(this); |
| + } |
|
stevenjb
2015/11/11 18:07:31
nit: no {}
fqj
2015/11/12 10:23:01
Done.
|
| + |
| + managed_network_configuration_handler_ = |
| + managed_network_configuration_handler; |
| + if (managed_network_configuration_handler_) |
| + managed_network_configuration_handler_->AddObserver(this); |
| + network_state_handler_ = network_state_handler; |
| + |
| + // Clear the list of prohibited network technologies. As a user logout always |
| + // triggers a browser process restart, Init() is always invoked to reallow any |
| + // network technology forbidden for the previous user. |
| + network_state_handler_->SetProhibitedTechnologies( |
| + std::vector<std::string>(), chromeos::network_handler::ErrorCallback()); |
| + |
| + if (LoginState::IsInitialized()) |
| + LoggedInStateChanged(); |
| +} |
| + |
| +void ProhibitedTechnologiesHandler::LoggedInStateChanged() { |
| + user_logged_in_ = LoginState::Get()->IsUserLoggedIn(); |
| + EnforceProhibitedTechnologies(user_logged_in_ && user_policy_applied_); |
| +} |
| + |
| +void ProhibitedTechnologiesHandler::PoliciesChanged( |
| + const std::string& userhash) {} |
| + |
| +void ProhibitedTechnologiesHandler::PoliciesApplied( |
| + const std::string& userhash) { |
| + if (userhash.empty()) |
| + return; |
| + user_policy_applied_ = true; |
| + EnforceProhibitedTechnologies(user_logged_in_ && user_policy_applied_); |
|
stevenjb
2015/11/11 18:07:31
&& user_policy_applied_ is unnecessary since it is
fqj
2015/11/12 10:23:01
Done.
|
| +} |
| + |
| +void ProhibitedTechnologiesHandler::SetProhibitedTechnologies( |
| + const std::vector<std::string>& prohibited_technologies) { |
| + prohibited_technologies_.assign(prohibited_technologies.begin(), |
| + prohibited_technologies.end()); |
| + EnforceProhibitedTechnologies(user_logged_in_ && user_policy_applied_); |
| +} |
| + |
| +void ProhibitedTechnologiesHandler::EnforceProhibitedTechnologies( |
| + bool enforced) { |
| + if (enforced) { |
| + network_state_handler_->SetProhibitedTechnologies( |
| + prohibited_technologies_, network_handler::ErrorCallback()); |
| + } else { |
| + network_state_handler_->SetProhibitedTechnologies( |
| + std::vector<std::string>(), network_handler::ErrorCallback()); |
| + } |
| +} |
| + |
| +std::vector<std::string> |
| +ProhibitedTechnologiesHandler::GetCurrentlyProhibitedTechnologies() { |
| + if (user_logged_in_ && user_policy_applied_) |
| + return prohibited_technologies_; |
| + else |
|
stevenjb
2015/11/11 18:07:31
no else after return
fqj
2015/11/12 10:23:01
Done.
|
| + return std::vector<std::string>(); |
| +} |
| + |
| +} // namespace chromeos |