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

Side by Side Diff: chromeos/components/tether/wifi_hotspot_connector.cc

Issue 2819303002: Changed wifi arcs to mobile bars for Tether network. (Closed)
Patch Set: Created 3 years, 8 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "chromeos/components/tether/wifi_hotspot_connector.h" 5 #include "chromeos/components/tether/wifi_hotspot_connector.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/guid.h" 8 #include "base/guid.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "chromeos/network/network_connect.h" 10 #include "chromeos/network/network_connect.h"
11 #include "chromeos/network/network_handler.h" 11 #include "chromeos/network/network_handler.h"
12 #include "chromeos/network/network_state.h" 12 #include "chromeos/network/network_state.h"
13 #include "chromeos/network/network_state_handler.h" 13 #include "chromeos/network/network_state_handler.h"
14 #include "chromeos/network/shill_property_util.h" 14 #include "chromeos/network/shill_property_util.h"
15 #include "components/proximity_auth/logging/logging.h" 15 #include "components/proximity_auth/logging/logging.h"
16 #include "third_party/cros_system_api/dbus/shill/dbus-constants.h" 16 #include "third_party/cros_system_api/dbus/shill/dbus-constants.h"
17 17
18 namespace chromeos { 18 namespace chromeos {
19 19
20 namespace tether { 20 namespace tether {
21 21
22 WifiHotspotConnector::WifiHotspotConnector( 22 WifiHotspotConnector::WifiHotspotConnector(
23 NetworkStateHandler* network_state_handler, 23 NetworkStateHandler* network_state_handler,
24 NetworkConnect* network_connect) 24 NetworkConnect* network_connect,
25 : network_state_handler_(network_state_handler), 25 ActiveHost* active_host)
26 : active_host_(active_host),
27 network_state_handler_(network_state_handler),
26 network_connect_(network_connect), 28 network_connect_(network_connect),
27 timer_(base::MakeUnique<base::OneShotTimer>()), 29 timer_(base::MakeUnique<base::OneShotTimer>()),
28 weak_ptr_factory_(this) { 30 weak_ptr_factory_(this) {
29 network_state_handler_->AddObserver(this, FROM_HERE); 31 network_state_handler_->AddObserver(this, FROM_HERE);
30 } 32 }
31 33
32 WifiHotspotConnector::~WifiHotspotConnector() { 34 WifiHotspotConnector::~WifiHotspotConnector() {
33 network_state_handler_->RemoveObserver(this, FROM_HERE); 35 network_state_handler_->RemoveObserver(this, FROM_HERE);
34 } 36 }
35 37
36 void WifiHotspotConnector::ConnectToWifiHotspot( 38 void WifiHotspotConnector::ConnectToWifiHotspot(
37 const std::string& ssid, 39 const std::string& ssid,
38 const std::string& password, 40 const std::string& password,
39 const WifiConnectionCallback& callback) { 41 const WifiConnectionCallback& callback) {
40 DCHECK(!ssid.empty()); 42 DCHECK(!ssid.empty());
41 // Note: |password| can be empty in some cases. 43 // Note: |password| can be empty in some cases.
42 44
43 if (!callback_.is_null()) { 45 if (!callback_.is_null()) {
44 DCHECK(timer_->IsRunning()); 46 DCHECK(timer_->IsRunning());
45 47
46 // If another connection attempt was underway but had not yet completed, 48 // If another connection attempt was underway but had not yet completed,
47 // call the callback, passing an empty string to signal that the connection 49 // call the callback, passing an empty string to signal that the connection
48 // did not complete successfully. 50 // did not complete successfully.
49 InvokeWifiConnectionCallback(std::string()); 51 InvokeWifiConnectionCallback(std::string());
Kyle Horimoto 2017/04/17 19:50:04 Now that you make the call to AssociateTetherNetwo
lesliewatkins 2017/04/27 00:33:53 I think this is done using NetworkStateHandler::Re
Kyle Horimoto 2017/04/27 01:30:07 Nope - that function removes the network entirely.
Kyle Horimoto 2017/04/28 22:07:28 This still hasn't been addressed.
lesliewatkins 2017/04/29 00:57:53 Done.
50 } 52 }
51 53
52 ssid_ = ssid; 54 ssid_ = ssid;
53 password_ = password; 55 password_ = password;
54 wifi_guid_ = base::GenerateGUID(); 56 wifi_guid_ = base::GenerateGUID();
55 callback_ = callback; 57 callback_ = callback;
56 timer_->Start(FROM_HERE, 58 timer_->Start(FROM_HERE,
57 base::TimeDelta::FromSeconds(kConnectionTimeoutSeconds), 59 base::TimeDelta::FromSeconds(kConnectionTimeoutSeconds),
58 base::Bind(&WifiHotspotConnector::OnConnectionTimeout, 60 base::Bind(&WifiHotspotConnector::OnConnectionTimeout,
59 weak_ptr_factory_.GetWeakPtr())); 61 weak_ptr_factory_.GetWeakPtr()));
(...skipping 12 matching lines...) Expand all
72 } 74 }
73 75
74 if (network->IsConnectedState()) { 76 if (network->IsConnectedState()) {
75 // If a connection occurred, notify observers and exit early. 77 // If a connection occurred, notify observers and exit early.
76 InvokeWifiConnectionCallback(wifi_guid_); 78 InvokeWifiConnectionCallback(wifi_guid_);
77 return; 79 return;
78 } 80 }
79 81
80 if (network->connectable()) { 82 if (network->connectable()) {
81 // If the network is now connectable, initiate a connection to it. 83 // If the network is now connectable, initiate a connection to it.
84 std::string tether_guid = active_host_->GetTetherNetworkGuid();
85 bool successful_association =
86 network_state_handler_->AssociateTetherNetworkStateWithWifiNetwork(
87 tether_guid, wifi_guid_);
88 if (successful_association) {
89 PA_LOG(INFO) << "Wifi network with ID " << wifi_guid_
90 << " is connectable. Tether network ID: \"" << tether_guid
91 << "\", Wi-Fi network ID: \"" << wifi_guid_ << "\"";
92 } else {
93 PA_LOG(INFO) << "Wifi network with ID " << wifi_guid_
94 << " is connectable, but failed to associate tether network "
95 "with ID \""
96 << tether_guid << "\" to Wi-Fi network with ID: \""
97 << wifi_guid_ << "\"";
98 }
99
82 network_connect_->ConnectToNetworkId(wifi_guid_); 100 network_connect_->ConnectToNetworkId(wifi_guid_);
83 } 101 }
84 } 102 }
85 103
86 void WifiHotspotConnector::InvokeWifiConnectionCallback( 104 void WifiHotspotConnector::InvokeWifiConnectionCallback(
87 const std::string& wifi_guid) { 105 const std::string& wifi_guid) {
88 DCHECK(!callback_.is_null()); 106 DCHECK(!callback_.is_null());
89 107
90 // |wifi_guid| may be a reference to |wifi_guid_|, so make a copy of it first 108 // |wifi_guid| may be a reference to |wifi_guid_|, so make a copy of it first
91 // before clearing it below. 109 // before clearing it below.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 InvokeWifiConnectionCallback(std::string()); 154 InvokeWifiConnectionCallback(std::string());
137 } 155 }
138 156
139 void WifiHotspotConnector::SetTimerForTest(std::unique_ptr<base::Timer> timer) { 157 void WifiHotspotConnector::SetTimerForTest(std::unique_ptr<base::Timer> timer) {
140 timer_ = std::move(timer); 158 timer_ = std::move(timer);
141 } 159 }
142 160
143 } // namespace tether 161 } // namespace tether
144 162
145 } // namespace chromeos 163 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698