| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2014 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/network/prohibited_technologies_handler.h" |
| 6 |
| 7 #include "chromeos/network/managed_network_configuration_handler.h" |
| 8 #include "chromeos/network/network_state_handler.h" |
| 9 #include "chromeos/network/network_util.h" |
| 10 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 11 |
| 12 namespace chromeos { |
| 13 |
| 14 ProhibitedTechnologiesHandler::ProhibitedTechnologiesHandler() {} |
| 15 |
| 16 ProhibitedTechnologiesHandler::~ProhibitedTechnologiesHandler() { |
| 17 if (managed_network_configuration_handler_) |
| 18 managed_network_configuration_handler_->RemoveObserver(this); |
| 19 if (LoginState::IsInitialized()) |
| 20 LoginState::Get()->RemoveObserver(this); |
| 21 } |
| 22 |
| 23 void ProhibitedTechnologiesHandler::Init( |
| 24 ManagedNetworkConfigurationHandler* managed_network_configuration_handler, |
| 25 NetworkStateHandler* network_state_handler) { |
| 26 if (LoginState::IsInitialized()) |
| 27 LoginState::Get()->AddObserver(this); |
| 28 |
| 29 managed_network_configuration_handler_ = |
| 30 managed_network_configuration_handler; |
| 31 if (managed_network_configuration_handler_) |
| 32 managed_network_configuration_handler_->AddObserver(this); |
| 33 network_state_handler_ = network_state_handler; |
| 34 |
| 35 // Clear the list of prohibited network technologies. As a user logout always |
| 36 // triggers a browser process restart, Init() is always invoked to reallow any |
| 37 // network technology forbidden for the previous user. |
| 38 network_state_handler_->SetProhibitedTechnologies( |
| 39 std::vector<std::string>(), chromeos::network_handler::ErrorCallback()); |
| 40 |
| 41 if (LoginState::IsInitialized()) |
| 42 LoggedInStateChanged(); |
| 43 } |
| 44 |
| 45 void ProhibitedTechnologiesHandler::LoggedInStateChanged() { |
| 46 user_logged_in_ = LoginState::Get()->IsUserLoggedIn(); |
| 47 EnforceProhibitedTechnologies(); |
| 48 } |
| 49 |
| 50 void ProhibitedTechnologiesHandler::PoliciesChanged( |
| 51 const std::string& userhash) {} |
| 52 |
| 53 void ProhibitedTechnologiesHandler::PoliciesApplied( |
| 54 const std::string& userhash) { |
| 55 if (userhash.empty()) |
| 56 return; |
| 57 user_policy_applied_ = true; |
| 58 EnforceProhibitedTechnologies(); |
| 59 } |
| 60 |
| 61 void ProhibitedTechnologiesHandler::SetProhibitedTechnologies( |
| 62 const base::ListValue* prohibited_list) { |
| 63 // Build up prohibited network type list and save it for furthur use when |
| 64 // enforced |
| 65 prohibited_technologies_.clear(); |
| 66 for (const base::Value* item : *prohibited_list) { |
| 67 std::string prohibited_technology; |
| 68 item->GetAsString(&prohibited_technology); |
| 69 std::string translated_tech = |
| 70 network_util::TranslateONCTypeToShill(prohibited_technology); |
| 71 if (!translated_tech.empty()) |
| 72 prohibited_technologies_.push_back(translated_tech); |
| 73 } |
| 74 EnforceProhibitedTechnologies(); |
| 75 } |
| 76 |
| 77 void ProhibitedTechnologiesHandler::EnforceProhibitedTechnologies() { |
| 78 if (user_logged_in_ && user_policy_applied_) { |
| 79 network_state_handler_->SetProhibitedTechnologies( |
| 80 prohibited_technologies_, network_handler::ErrorCallback()); |
| 81 if (std::find(prohibited_technologies_.begin(), |
| 82 prohibited_technologies_.end(), |
| 83 shill::kTypeEthernet) != prohibited_technologies_.end()) |
| 84 return; |
| 85 } else { |
| 86 // This is done to make sure prohibited technologies are cleared |
| 87 // before user policy is applied. |
| 88 network_state_handler_->SetProhibitedTechnologies( |
| 89 std::vector<std::string>(), network_handler::ErrorCallback()); |
| 90 } |
| 91 |
| 92 // Enable ethernet back as user doesn't have a place to enable it back |
| 93 // if user shuts down directly in a user session. As shill will persist |
| 94 // ProhibitedTechnologies which may include ethernet, making users can |
| 95 // not find Ethernet at next boot or logging out unless user log out first |
| 96 // and then shutdown. |
| 97 if (network_state_handler_->IsTechnologyAvailable( |
| 98 NetworkTypePattern::Ethernet()) && |
| 99 !network_state_handler_->IsTechnologyEnabled( |
| 100 NetworkTypePattern::Ethernet())) |
| 101 network_state_handler_->SetTechnologyEnabled( |
| 102 NetworkTypePattern::Ethernet(), true, network_handler::ErrorCallback()); |
| 103 } |
| 104 |
| 105 std::vector<std::string> |
| 106 ProhibitedTechnologiesHandler::GetCurrentlyProhibitedTechnologies() { |
| 107 if (user_logged_in_ && user_policy_applied_) |
| 108 return prohibited_technologies_; |
| 109 return std::vector<std::string>(); |
| 110 } |
| 111 |
| 112 } // namespace chromeos |
| OLD | NEW |