| 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 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 constexpr int kGetNetworksListLimit = 100; | 30 constexpr int kGetNetworksListLimit = 100; |
| 31 constexpr uint32_t kScanCompletedMinInstanceVersion = 1; | |
| 32 constexpr uint32_t kDefaultNetworkChangedMinInstanceVersion = 2; | |
| 33 constexpr uint32_t kWifiEnabledStateChanged = 3; | |
| 34 | 31 |
| 35 chromeos::NetworkStateHandler* GetStateHandler() { | 32 chromeos::NetworkStateHandler* GetStateHandler() { |
| 36 return chromeos::NetworkHandler::Get()->network_state_handler(); | 33 return chromeos::NetworkHandler::Get()->network_state_handler(); |
| 37 } | 34 } |
| 38 | 35 |
| 39 chromeos::ManagedNetworkConfigurationHandler* GetManagedConfigurationHandler() { | 36 chromeos::ManagedNetworkConfigurationHandler* GetManagedConfigurationHandler() { |
| 40 return chromeos::NetworkHandler::Get() | 37 return chromeos::NetworkHandler::Get() |
| 41 ->managed_network_configuration_handler(); | 38 ->managed_network_configuration_handler(); |
| 42 } | 39 } |
| 43 | 40 |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 if (observing_network_state_) { | 297 if (observing_network_state_) { |
| 301 GetStateHandler()->RemoveObserver(this, FROM_HERE); | 298 GetStateHandler()->RemoveObserver(this, FROM_HERE); |
| 302 } | 299 } |
| 303 } | 300 } |
| 304 | 301 |
| 305 void ArcNetHostImpl::OnInstanceReady() { | 302 void ArcNetHostImpl::OnInstanceReady() { |
| 306 DCHECK(thread_checker_.CalledOnValidThread()); | 303 DCHECK(thread_checker_.CalledOnValidThread()); |
| 307 | 304 |
| 308 mojom::NetHostPtr host; | 305 mojom::NetHostPtr host; |
| 309 binding_.Bind(MakeRequest(&host)); | 306 binding_.Bind(MakeRequest(&host)); |
| 310 auto* instance = arc_bridge_service()->net()->GetInstanceForMethod("Init"); | 307 auto* instance = |
| 308 arc_bridge_service() |
| 309 ->net() |
| 310 ->GetInstanceForMethod<mojom::NetInstance::kInitMethodIndex>(); |
| 311 DCHECK(instance); | 311 DCHECK(instance); |
| 312 instance->Init(std::move(host)); | 312 instance->Init(std::move(host)); |
| 313 | 313 |
| 314 if (chromeos::NetworkHandler::IsInitialized()) { | 314 if (chromeos::NetworkHandler::IsInitialized()) { |
| 315 GetStateHandler()->AddObserver(this, FROM_HERE); | 315 GetStateHandler()->AddObserver(this, FROM_HERE); |
| 316 observing_network_state_ = true; | 316 observing_network_state_ = true; |
| 317 } | 317 } |
| 318 } | 318 } |
| 319 | 319 |
| 320 void ArcNetHostImpl::OnInstanceClosed() { | 320 void ArcNetHostImpl::OnInstanceClosed() { |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 chromeos::network_handler::ErrorCallback()); | 580 chromeos::network_handler::ErrorCallback()); |
| 581 callback.Run(true); | 581 callback.Run(true); |
| 582 } | 582 } |
| 583 } | 583 } |
| 584 | 584 |
| 585 void ArcNetHostImpl::StartScan() { | 585 void ArcNetHostImpl::StartScan() { |
| 586 GetStateHandler()->RequestScan(); | 586 GetStateHandler()->RequestScan(); |
| 587 } | 587 } |
| 588 | 588 |
| 589 void ArcNetHostImpl::ScanCompleted(const chromeos::DeviceState* /*unused*/) { | 589 void ArcNetHostImpl::ScanCompleted(const chromeos::DeviceState* /*unused*/) { |
| 590 auto* net_instance = arc_bridge_service()->net()->GetInstanceForMethod( | 590 auto* net_instance = arc_bridge_service() |
| 591 "ScanCompleted", kScanCompletedMinInstanceVersion); | 591 ->net() |
| 592 ->GetInstanceForMethod< |
| 593 mojom::NetInstance::kScanCompletedMethodIndex>(); |
| 592 if (!net_instance) | 594 if (!net_instance) |
| 593 return; | 595 return; |
| 594 | 596 |
| 595 net_instance->ScanCompleted(); | 597 net_instance->ScanCompleted(); |
| 596 } | 598 } |
| 597 | 599 |
| 598 void ArcNetHostImpl::GetDefaultNetwork( | 600 void ArcNetHostImpl::GetDefaultNetwork( |
| 599 const GetDefaultNetworkCallback& callback) { | 601 const GetDefaultNetworkCallback& callback) { |
| 600 const chromeos::NetworkState* default_network = | 602 const chromeos::NetworkState* default_network = |
| 601 GetStateHandler()->DefaultNetwork(); | 603 GetStateHandler()->DefaultNetwork(); |
| 602 if (!default_network) { | 604 if (!default_network) { |
| 603 VLOG(1) << "GetDefaultNetwork: no default network"; | 605 VLOG(1) << "GetDefaultNetwork: no default network"; |
| 604 callback.Run(nullptr, nullptr); | 606 callback.Run(nullptr, nullptr); |
| 605 return; | 607 return; |
| 606 } | 608 } |
| 607 VLOG(1) << "GetDefaultNetwork: default network is " | 609 VLOG(1) << "GetDefaultNetwork: default network is " |
| 608 << default_network->path(); | 610 << default_network->path(); |
| 609 std::string user_id_hash = chromeos::LoginState::Get()->primary_user_hash(); | 611 std::string user_id_hash = chromeos::LoginState::Get()->primary_user_hash(); |
| 610 GetManagedConfigurationHandler()->GetProperties( | 612 GetManagedConfigurationHandler()->GetProperties( |
| 611 user_id_hash, default_network->path(), | 613 user_id_hash, default_network->path(), |
| 612 base::Bind(&GetDefaultNetworkSuccessCallback, callback), | 614 base::Bind(&GetDefaultNetworkSuccessCallback, callback), |
| 613 base::Bind(&GetDefaultNetworkFailureCallback, callback)); | 615 base::Bind(&GetDefaultNetworkFailureCallback, callback)); |
| 614 } | 616 } |
| 615 | 617 |
| 616 void ArcNetHostImpl::DefaultNetworkSuccessCallback( | 618 void ArcNetHostImpl::DefaultNetworkSuccessCallback( |
| 617 const std::string& service_path, | 619 const std::string& service_path, |
| 618 const base::DictionaryValue& dictionary) { | 620 const base::DictionaryValue& dictionary) { |
| 619 auto* net_instance = arc_bridge_service()->net()->GetInstanceForMethod( | 621 auto* net_instance = |
| 620 "DefaultNetworkChanged", kDefaultNetworkChangedMinInstanceVersion); | 622 arc_bridge_service() |
| 623 ->net() |
| 624 ->GetInstanceForMethod< |
| 625 mojom::NetInstance::kDefaultNetworkChangedMethodIndex>(); |
| 621 if (!net_instance) | 626 if (!net_instance) |
| 622 return; | 627 return; |
| 623 | 628 |
| 624 net_instance->DefaultNetworkChanged(TranslateONCConfiguration(&dictionary), | 629 net_instance->DefaultNetworkChanged(TranslateONCConfiguration(&dictionary), |
| 625 TranslateONCConfiguration(&dictionary)); | 630 TranslateONCConfiguration(&dictionary)); |
| 626 } | 631 } |
| 627 | 632 |
| 628 void ArcNetHostImpl::DefaultNetworkChanged( | 633 void ArcNetHostImpl::DefaultNetworkChanged( |
| 629 const chromeos::NetworkState* network) { | 634 const chromeos::NetworkState* network) { |
| 630 if (!network) { | 635 if (!network) { |
| 631 VLOG(1) << "No default network"; | 636 VLOG(1) << "No default network"; |
| 632 auto* net_instance = arc_bridge_service()->net()->GetInstanceForMethod( | 637 auto* net_instance = |
| 633 "DefaultNetworkChanged", kDefaultNetworkChangedMinInstanceVersion); | 638 arc_bridge_service() |
| 639 ->net() |
| 640 ->GetInstanceForMethod< |
| 641 mojom::NetInstance::kDefaultNetworkChangedMethodIndex>(); |
| 634 if (net_instance) | 642 if (net_instance) |
| 635 net_instance->DefaultNetworkChanged(nullptr, nullptr); | 643 net_instance->DefaultNetworkChanged(nullptr, nullptr); |
| 636 return; | 644 return; |
| 637 } | 645 } |
| 638 | 646 |
| 639 VLOG(1) << "New default network: " << network->path(); | 647 VLOG(1) << "New default network: " << network->path(); |
| 640 std::string user_id_hash = chromeos::LoginState::Get()->primary_user_hash(); | 648 std::string user_id_hash = chromeos::LoginState::Get()->primary_user_hash(); |
| 641 GetManagedConfigurationHandler()->GetProperties( | 649 GetManagedConfigurationHandler()->GetProperties( |
| 642 user_id_hash, network->path(), | 650 user_id_hash, network->path(), |
| 643 base::Bind(&ArcNetHostImpl::DefaultNetworkSuccessCallback, | 651 base::Bind(&ArcNetHostImpl::DefaultNetworkSuccessCallback, |
| 644 weak_factory_.GetWeakPtr()), | 652 weak_factory_.GetWeakPtr()), |
| 645 base::Bind(&DefaultNetworkFailureCallback)); | 653 base::Bind(&DefaultNetworkFailureCallback)); |
| 646 } | 654 } |
| 647 | 655 |
| 648 void ArcNetHostImpl::DeviceListChanged() { | 656 void ArcNetHostImpl::DeviceListChanged() { |
| 649 auto* net_instance = arc_bridge_service()->net()->GetInstanceForMethod( | 657 auto* net_instance = |
| 650 "WifiEnabledStateChanged", kWifiEnabledStateChanged); | 658 arc_bridge_service() |
| 659 ->net() |
| 660 ->GetInstanceForMethod< |
| 661 mojom::NetInstance::kWifiEnabledStateChangedMethodIndex>(); |
| 651 if (!net_instance) | 662 if (!net_instance) |
| 652 return; | 663 return; |
| 653 | 664 |
| 654 bool is_enabled = GetStateHandler()->IsTechnologyEnabled( | 665 bool is_enabled = GetStateHandler()->IsTechnologyEnabled( |
| 655 chromeos::NetworkTypePattern::WiFi()); | 666 chromeos::NetworkTypePattern::WiFi()); |
| 656 net_instance->WifiEnabledStateChanged(is_enabled); | 667 net_instance->WifiEnabledStateChanged(is_enabled); |
| 657 } | 668 } |
| 658 | 669 |
| 659 void ArcNetHostImpl::OnShuttingDown() { | 670 void ArcNetHostImpl::OnShuttingDown() { |
| 660 DCHECK(observing_network_state_); | 671 DCHECK(observing_network_state_); |
| 661 GetStateHandler()->RemoveObserver(this, FROM_HERE); | 672 GetStateHandler()->RemoveObserver(this, FROM_HERE); |
| 662 observing_network_state_ = false; | 673 observing_network_state_ = false; |
| 663 } | 674 } |
| 664 | 675 |
| 665 } // namespace arc | 676 } // namespace arc |
| OLD | NEW |