Chromium Code Reviews| 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(){}; | |
|
stevenjb
2015/11/12 18:20:38
' ' before {} (and generally run 'git cl format')
fqj
2015/11/13 13:53:49
Done.
| |
| 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 saves it for furthur use when | |
|
stevenjb
2015/11/12 18:20:38
s/saves/save/
fqj
2015/11/13 13:53:49
Done.
| |
| 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 bool enable_ethernet = true; | |
| 79 if (user_logged_in_ && user_policy_applied_) { | |
| 80 network_state_handler_->SetProhibitedTechnologies( | |
| 81 prohibited_technologies_, network_handler::ErrorCallback()); | |
| 82 if (std::find(prohibited_technologies_.begin(), | |
| 83 prohibited_technologies_.end(), | |
| 84 shill::kTypeEthernet) != prohibited_technologies_.end()) | |
| 85 enable_ethernet = false; | |
|
stevenjb
2015/11/12 18:20:38
Why not just return here? Then you can remove the
fqj
2015/11/13 13:53:49
Done with "return"
I don't think else can be remo
stevenjb
2015/11/13 18:26:56
Right again, sorry, missed the nested if. Too many
| |
| 86 } else { | |
|
stevenjb
2015/11/12 18:20:38
nit: Add a comment that this is done to ensure tha
fqj
2015/11/13 13:53:49
Done.
| |
| 87 network_state_handler_->SetProhibitedTechnologies( | |
| 88 std::vector<std::string>(), network_handler::ErrorCallback()); | |
| 89 } | |
| 90 | |
| 91 // Enable ethernet back as user doesn't have a place to enable it back | |
| 92 // if user shuts down directly in a user session. As shill will persist | |
| 93 // ProhibitedTechnologies which may include ethernet, making users can | |
| 94 // not find Ethernet at next boot or logging out unless user log out first | |
| 95 // and then shutdown. | |
| 96 if (enable_ethernet && | |
| 97 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 |