| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/arc/net/arc_net_host_impl.h" | 5 #include "components/arc/net/arc_net_host_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/posix/eintr_wrapper.h" | 14 #include "base/posix/eintr_wrapper.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "chromeos/login/login_state.h" | 17 #include "chromeos/login/login_state.h" |
| 18 #include "chromeos/network/managed_network_configuration_handler.h" | 18 #include "chromeos/network/managed_network_configuration_handler.h" |
| 19 #include "chromeos/network/network_connection_handler.h" | 19 #include "chromeos/network/network_connection_handler.h" |
| 20 #include "chromeos/network/network_handler.h" | 20 #include "chromeos/network/network_handler.h" |
| 21 #include "chromeos/network/network_state.h" | 21 #include "chromeos/network/network_state.h" |
| 22 #include "chromeos/network/network_state_handler.h" | 22 #include "chromeos/network/network_state_handler.h" |
| 23 #include "chromeos/network/network_type_pattern.h" | 23 #include "chromeos/network/network_type_pattern.h" |
| 24 #include "chromeos/network/network_util.h" | 24 #include "chromeos/network/network_util.h" |
| 25 #include "chromeos/network/onc/onc_utils.h" | 25 #include "chromeos/network/onc/onc_utils.h" |
| 26 #include "components/arc/arc_bridge_service.h" | 26 #include "components/arc/arc_bridge_service.h" |
| 27 #include "components/user_manager/user_manager.h" |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 constexpr int kGetNetworksListLimit = 100; | 31 constexpr int kGetNetworksListLimit = 100; |
| 31 | 32 |
| 32 chromeos::NetworkStateHandler* GetStateHandler() { | 33 chromeos::NetworkStateHandler* GetStateHandler() { |
| 33 return chromeos::NetworkHandler::Get()->network_state_handler(); | 34 return chromeos::NetworkHandler::Get()->network_state_handler(); |
| 34 } | 35 } |
| 35 | 36 |
| 36 chromeos::ManagedNetworkConfigurationHandler* GetManagedConfigurationHandler() { | 37 chromeos::ManagedNetworkConfigurationHandler* GetManagedConfigurationHandler() { |
| 37 return chromeos::NetworkHandler::Get() | 38 return chromeos::NetworkHandler::Get() |
| 38 ->managed_network_configuration_handler(); | 39 ->managed_network_configuration_handler(); |
| 39 } | 40 } |
| 40 | 41 |
| 41 chromeos::NetworkConnectionHandler* GetNetworkConnectionHandler() { | 42 chromeos::NetworkConnectionHandler* GetNetworkConnectionHandler() { |
| 42 return chromeos::NetworkHandler::Get()->network_connection_handler(); | 43 return chromeos::NetworkHandler::Get()->network_connection_handler(); |
| 43 } | 44 } |
| 44 | 45 |
| 45 bool IsDeviceOwner() { | 46 bool IsDeviceOwner() { |
| 46 // Check whether the logged-in Chrome OS user is allowed to add or | 47 // Check whether the logged-in Chrome OS user is allowed to add or remove WiFi |
| 47 // remove WiFi networks. | 48 // networks. The user account state changes immediately after boot. There is a |
| 48 return chromeos::LoginState::Get()->GetLoggedInUserType() == | 49 // small window when this may return an incorrect state. However, after things |
| 49 chromeos::LoginState::LOGGED_IN_USER_OWNER; | 50 // settle down this is guranteed to reflect the correct user account state. |
| 51 return user_manager::UserManager::Get()->GetActiveUser()->GetAccountId() == |
| 52 user_manager::UserManager::Get()->GetOwnerAccountId(); |
| 50 } | 53 } |
| 51 | 54 |
| 52 std::string GetStringFromOncDictionary(const base::DictionaryValue* dict, | 55 std::string GetStringFromOncDictionary(const base::DictionaryValue* dict, |
| 53 const char* key, | 56 const char* key, |
| 54 bool required) { | 57 bool required) { |
| 55 std::string value; | 58 std::string value; |
| 56 dict->GetString(key, &value); | 59 dict->GetString(key, &value); |
| 57 if (required && value.empty()) | 60 if (required && value.empty()) |
| 58 VLOG(1) << "Required parameter " << key << " was not found."; | 61 VLOG(1) << "Required parameter " << key << " was not found."; |
| 59 return value; | 62 return value; |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 net_instance->WifiEnabledStateChanged(is_enabled); | 657 net_instance->WifiEnabledStateChanged(is_enabled); |
| 655 } | 658 } |
| 656 | 659 |
| 657 void ArcNetHostImpl::OnShuttingDown() { | 660 void ArcNetHostImpl::OnShuttingDown() { |
| 658 DCHECK(observing_network_state_); | 661 DCHECK(observing_network_state_); |
| 659 GetStateHandler()->RemoveObserver(this, FROM_HERE); | 662 GetStateHandler()->RemoveObserver(this, FROM_HERE); |
| 660 observing_network_state_ = false; | 663 observing_network_state_ = false; |
| 661 } | 664 } |
| 662 | 665 |
| 663 } // namespace arc | 666 } // namespace arc |
| OLD | NEW |