Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Side by Side Diff: components/arc/net/arc_net_host_impl.cc

Issue 2347293002: arc: Add InstanceHelper::GetInstanceForMethod() (Closed)
Patch Set: git cl format/lint Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 27
28 namespace { 28 namespace {
29 29
30 const int kGetNetworksListLimit = 100; 30 constexpr int kGetNetworksListLimit = 100;
31 constexpr uint32_t kDefaultMinInstanceVersion = 0;
Yusuke Sato 2016/09/16 23:58:49 same, remove?
Luis Héctor Chávez 2016/09/17 00:30:53 Acknowledged.
32 constexpr uint32_t kDefaultNetworkChangedMinInstanceVersion = 2;
33 constexpr uint32_t kDeviceListChangedMinInstanceVersion = 3;
Yusuke Sato 2016/09/16 23:58:49 I think this should be renamed to kWifiEnabledStat
Luis Héctor Chávez 2016/09/17 00:30:53 Done.
31 34
32 chromeos::NetworkStateHandler* GetStateHandler() { 35 chromeos::NetworkStateHandler* GetStateHandler() {
33 return chromeos::NetworkHandler::Get()->network_state_handler(); 36 return chromeos::NetworkHandler::Get()->network_state_handler();
34 } 37 }
35 38
36 chromeos::ManagedNetworkConfigurationHandler* GetManagedConfigurationHandler() { 39 chromeos::ManagedNetworkConfigurationHandler* GetManagedConfigurationHandler() {
37 return chromeos::NetworkHandler::Get() 40 return chromeos::NetworkHandler::Get()
38 ->managed_network_configuration_handler(); 41 ->managed_network_configuration_handler();
39 } 42 }
40 43
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 chromeos::network_handler::ErrorCallback()); 568 chromeos::network_handler::ErrorCallback());
566 callback.Run(true); 569 callback.Run(true);
567 } 570 }
568 } 571 }
569 572
570 void ArcNetHostImpl::StartScan() { 573 void ArcNetHostImpl::StartScan() {
571 GetStateHandler()->RequestScan(); 574 GetStateHandler()->RequestScan();
572 } 575 }
573 576
574 void ArcNetHostImpl::ScanCompleted(const chromeos::DeviceState* /*unused*/) { 577 void ArcNetHostImpl::ScanCompleted(const chromeos::DeviceState* /*unused*/) {
575 if (!arc_bridge_service()->net()->instance()) { 578 auto* net_instance = arc_bridge_service()->net()->GetInstanceForVersion(
576 VLOG(2) << "NetInstance not ready yet"; 579 kDefaultMinInstanceVersion, "ScanCompleted");
580 if (!net_instance)
577 return; 581 return;
578 }
579 if (arc_bridge_service()->net()->version() < 1) {
580 VLOG(1) << "NetInstance does not support ScanCompleted.";
581 return;
582 }
583 582
584 arc_bridge_service()->net()->instance()->ScanCompleted(); 583 net_instance->ScanCompleted();
585 } 584 }
586 585
587 void ArcNetHostImpl::GetDefaultNetwork( 586 void ArcNetHostImpl::GetDefaultNetwork(
588 const GetDefaultNetworkCallback& callback) { 587 const GetDefaultNetworkCallback& callback) {
589 const chromeos::NetworkState* default_network = 588 const chromeos::NetworkState* default_network =
590 GetStateHandler()->DefaultNetwork(); 589 GetStateHandler()->DefaultNetwork();
591 if (!default_network) { 590 if (!default_network) {
592 VLOG(1) << "GetDefaultNetwork: no default network"; 591 VLOG(1) << "GetDefaultNetwork: no default network";
593 callback.Run(nullptr, nullptr); 592 callback.Run(nullptr, nullptr);
594 return; 593 return;
595 } 594 }
596 VLOG(1) << "GetDefaultNetwork: default network is " 595 VLOG(1) << "GetDefaultNetwork: default network is "
597 << default_network->path(); 596 << default_network->path();
598 std::string user_id_hash = chromeos::LoginState::Get()->primary_user_hash(); 597 std::string user_id_hash = chromeos::LoginState::Get()->primary_user_hash();
599 GetManagedConfigurationHandler()->GetProperties( 598 GetManagedConfigurationHandler()->GetProperties(
600 user_id_hash, default_network->path(), 599 user_id_hash, default_network->path(),
601 base::Bind(&GetDefaultNetworkSuccessCallback, callback), 600 base::Bind(&GetDefaultNetworkSuccessCallback, callback),
602 base::Bind(&GetDefaultNetworkFailureCallback, callback)); 601 base::Bind(&GetDefaultNetworkFailureCallback, callback));
603 } 602 }
604 603
605 void ArcNetHostImpl::DefaultNetworkSuccessCallback( 604 void ArcNetHostImpl::DefaultNetworkSuccessCallback(
606 const std::string& service_path, 605 const std::string& service_path,
607 const base::DictionaryValue& dictionary) { 606 const base::DictionaryValue& dictionary) {
608 if (!arc_bridge_service()->net()->instance()) { 607 auto* net_instance = arc_bridge_service()->net()->GetInstanceForVersion(
609 VLOG(2) << "NetInstance is null."; 608 kDefaultMinInstanceVersion, "GetDefaultNetwork");
Yusuke Sato 2016/09/16 23:58:49 * Not sure why kDefaultMinInstanceVersion is used
Luis Héctor Chávez 2016/09/17 00:30:53 The thing is that there are two "optional" paramet
609 if (!net_instance)
610 return; 610 return;
611 } 611
612 arc_bridge_service()->net()->instance()->DefaultNetworkChanged( 612 net_instance->DefaultNetworkChanged(TranslateONCConfiguration(&dictionary),
613 TranslateONCConfiguration(&dictionary), 613 TranslateONCConfiguration(&dictionary));
614 TranslateONCConfiguration(&dictionary));
615 } 614 }
616 615
617 void ArcNetHostImpl::DefaultNetworkChanged( 616 void ArcNetHostImpl::DefaultNetworkChanged(
618 const chromeos::NetworkState* network) { 617 const chromeos::NetworkState* network) {
619 if (arc_bridge_service()->net()->version() < 2) { 618 auto* net_instance = arc_bridge_service()->net()->GetInstanceForVersion(
Yusuke Sato 2016/09/16 23:58:49 I think you can move this to line 624.
Luis Héctor Chávez 2016/09/17 00:30:54 Done.
620 VLOG(1) << "ArcBridgeService does not support DefaultNetworkChanged."; 619 kDefaultNetworkChangedMinInstanceVersion, "DefaultNetworkChanged");
620 if (!net_instance)
621 return;
622
623 if (!network) {
624 VLOG(1) << "No default network";
625 net_instance->DefaultNetworkChanged(nullptr, nullptr);
621 return; 626 return;
622 } 627 }
623 628
624 if (!network) {
625 VLOG(1) << "No default network";
626 arc_bridge_service()->net()->instance()->DefaultNetworkChanged(nullptr,
627 nullptr);
628 return;
629 }
630
631 VLOG(1) << "New default network: " << network->path(); 629 VLOG(1) << "New default network: " << network->path();
632 std::string user_id_hash = chromeos::LoginState::Get()->primary_user_hash(); 630 std::string user_id_hash = chromeos::LoginState::Get()->primary_user_hash();
633 GetManagedConfigurationHandler()->GetProperties( 631 GetManagedConfigurationHandler()->GetProperties(
634 user_id_hash, network->path(), 632 user_id_hash, network->path(),
635 base::Bind(&arc::ArcNetHostImpl::DefaultNetworkSuccessCallback, 633 base::Bind(&arc::ArcNetHostImpl::DefaultNetworkSuccessCallback,
636 weak_factory_.GetWeakPtr()), 634 weak_factory_.GetWeakPtr()),
637 base::Bind(&DefaultNetworkFailureCallback)); 635 base::Bind(&DefaultNetworkFailureCallback));
638 } 636 }
639 637
640 void ArcNetHostImpl::DeviceListChanged() { 638 void ArcNetHostImpl::DeviceListChanged() {
641 if (arc_bridge_service()->net()->version() < 3) { 639 auto* net_instance = arc_bridge_service()->net()->GetInstanceForVersion(
642 VLOG(1) << "ArcBridgeService does not support DeviceListChanged."; 640 kDeviceListChangedMinInstanceVersion, "DeviceListChanged");
Yusuke Sato 2016/09/16 23:58:49 kWifiEnabledStateChanged, "WifiEnabledStateChanged
Luis Héctor Chávez 2016/09/17 00:30:53 Done.
641 if (!net_instance)
643 return; 642 return;
644 }
645 643
646 bool is_enabled = GetStateHandler()->IsTechnologyEnabled( 644 bool is_enabled = GetStateHandler()->IsTechnologyEnabled(
647 chromeos::NetworkTypePattern::WiFi()); 645 chromeos::NetworkTypePattern::WiFi());
648 arc_bridge_service()->net()->instance()->WifiEnabledStateChanged(is_enabled); 646 net_instance->WifiEnabledStateChanged(is_enabled);
649 } 647 }
650 648
651 void ArcNetHostImpl::OnShuttingDown() { 649 void ArcNetHostImpl::OnShuttingDown() {
652 GetStateHandler()->RemoveObserver(this, FROM_HERE); 650 GetStateHandler()->RemoveObserver(this, FROM_HERE);
653 } 651 }
654 652
655 } // namespace arc 653 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698