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

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: khorimoto@ comments Created 3 years, 7 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"
(...skipping 18 matching lines...) Expand all
29 network_state_handler_->AddObserver(this, FROM_HERE); 29 network_state_handler_->AddObserver(this, FROM_HERE);
30 } 30 }
31 31
32 WifiHotspotConnector::~WifiHotspotConnector() { 32 WifiHotspotConnector::~WifiHotspotConnector() {
33 network_state_handler_->RemoveObserver(this, FROM_HERE); 33 network_state_handler_->RemoveObserver(this, FROM_HERE);
34 } 34 }
35 35
36 void WifiHotspotConnector::ConnectToWifiHotspot( 36 void WifiHotspotConnector::ConnectToWifiHotspot(
37 const std::string& ssid, 37 const std::string& ssid,
38 const std::string& password, 38 const std::string& password,
39 const std::string& tether_network_guid,
39 const WifiConnectionCallback& callback) { 40 const WifiConnectionCallback& callback) {
40 DCHECK(!ssid.empty()); 41 DCHECK(!ssid.empty());
41 // Note: |password| can be empty in some cases. 42 // Note: |password| can be empty in some cases.
42 43
43 if (!callback_.is_null()) { 44 if (!callback_.is_null()) {
44 DCHECK(timer_->IsRunning()); 45 DCHECK(timer_->IsRunning());
45 46
46 // If another connection attempt was underway but had not yet completed, 47 // If another connection attempt was underway but had not yet completed,
48 // disassociate that network with the Tether network and
Kyle Horimoto 2017/05/03 01:53:33 nit: "disassociates with" is incorrect grammatical
lesliewatkins 2017/05/03 22:00:24 Done.
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
Kyle Horimoto 2017/05/03 01:53:33 nit: Some of this fits on the previous line. Try t
lesliewatkins 2017/05/03 22:00:24 Done.
48 // did not complete successfully. 50 // did not complete successfully.
51 bool successful_disassociation =
52 network_state_handler_->DisassociateTetherNetworkStateWithWifiNetwork(
53 tether_network_guid_, wifi_network_guid_);
54 if (successful_disassociation) {
55 PA_LOG(INFO) << "Wifi network with ID " << wifi_network_guid_
Kyle Horimoto 2017/05/03 01:53:33 Just make this one sentence: Wifi network with ID
lesliewatkins 2017/05/03 22:00:24 Done.
56 << " successfully disassociated "
57 "with Tether network. Tether network ID: \""
58 << tether_network_guid_ << "\", Wi-Fi network ID: \""
59 << wifi_network_guid_ << "\"";
60 } else {
61 PA_LOG(INFO) << "Wifi network with ID " << wifi_network_guid_
62 << " failed to disassociate tether network "
63 "with ID \""
64 << tether_network_guid_ << "\" to Wi-Fi network with ID: \""
65 << wifi_network_guid_ << "\"";
66 }
67
49 InvokeWifiConnectionCallback(std::string()); 68 InvokeWifiConnectionCallback(std::string());
50 } 69 }
51 70
52 ssid_ = ssid; 71 ssid_ = ssid;
53 password_ = password; 72 password_ = password;
54 wifi_guid_ = base::GenerateGUID(); 73 tether_network_guid_ = tether_network_guid;
74 wifi_network_guid_ = base::GenerateGUID();
55 callback_ = callback; 75 callback_ = callback;
56 timer_->Start(FROM_HERE, 76 timer_->Start(FROM_HERE,
57 base::TimeDelta::FromSeconds(kConnectionTimeoutSeconds), 77 base::TimeDelta::FromSeconds(kConnectionTimeoutSeconds),
58 base::Bind(&WifiHotspotConnector::OnConnectionTimeout, 78 base::Bind(&WifiHotspotConnector::OnConnectionTimeout,
59 weak_ptr_factory_.GetWeakPtr())); 79 weak_ptr_factory_.GetWeakPtr()));
60 80
61 base::DictionaryValue properties = 81 base::DictionaryValue properties =
62 CreateWifiPropertyDictionary(ssid, password); 82 CreateWifiPropertyDictionary(ssid, password);
63 network_connect_->CreateConfiguration(&properties, false /* shared */); 83 network_connect_->CreateConfiguration(&properties, false /* shared */);
64 } 84 }
65 85
66 void WifiHotspotConnector::NetworkPropertiesUpdated( 86 void WifiHotspotConnector::NetworkPropertiesUpdated(
67 const NetworkState* network) { 87 const NetworkState* network) {
68 if (network->guid() != wifi_guid_) { 88 if (network->guid() != wifi_network_guid_) {
69 // If a different network has been connected, return early and wait for the 89 // If a different network has been connected, return early and wait for the
70 // network with ID |wifi_guid_| is updated. 90 // network with ID |wifi_network_guid_| is updated.
71 return; 91 return;
72 } 92 }
73 93
74 if (network->IsConnectedState()) { 94 if (network->IsConnectedState()) {
75 // If a connection occurred, notify observers and exit early. 95 // If a connection occurred, notify observers and exit early.
76 InvokeWifiConnectionCallback(wifi_guid_); 96 InvokeWifiConnectionCallback(wifi_network_guid_);
77 return; 97 return;
78 } 98 }
79 99
80 if (network->connectable()) { 100 if (network->connectable()) {
81 // If the network is now connectable, initiate a connection to it. 101 bool successful_association =
82 network_connect_->ConnectToNetworkId(wifi_guid_); 102 network_state_handler_->AssociateTetherNetworkStateWithWifiNetwork(
103 tether_network_guid_, wifi_network_guid_);
104 if (successful_association) {
105 PA_LOG(INFO) << "Wifi network with ID " << wifi_network_guid_
106 << " is connectable, and successfully associated "
107 "with Tether network. Tether network ID: \""
108 << tether_network_guid_ << "\", Wi-Fi network ID: \""
109 << wifi_network_guid_ << "\"";
110 } else {
111 PA_LOG(INFO) << "Wifi network with ID " << wifi_network_guid_
112 << " is connectable, but failed to associate tether network "
113 "with ID \""
114 << tether_network_guid_ << "\" to Wi-Fi network with ID: \""
115 << wifi_network_guid_ << "\"";
116 }
117
118 // If the network is now connectable, associate it with a Tether network
Kyle Horimoto 2017/05/03 01:53:33 Move this comment to above the AssociateTetherNetw
lesliewatkins 2017/05/03 22:00:24 Done.
lesliewatkins 2017/05/03 22:00:24 Done, but this is basically reverting back to: htt
Kyle Horimoto 2017/05/03 22:47:28 It's not reverting back to that. You changed the w
lesliewatkins 2017/05/04 01:40:16 Done.
119 // ASAP so that the correct icon will be displayed in the tray while the
120 // network is connecting.
121 network_connect_->ConnectToNetworkId(wifi_network_guid_);
83 } 122 }
84 } 123 }
85 124
86 void WifiHotspotConnector::InvokeWifiConnectionCallback( 125 void WifiHotspotConnector::InvokeWifiConnectionCallback(
87 const std::string& wifi_guid) { 126 const std::string& wifi_guid) {
88 DCHECK(!callback_.is_null()); 127 DCHECK(!callback_.is_null());
89 128
90 // |wifi_guid| may be a reference to |wifi_guid_|, so make a copy of it first 129 // |wifi_guid| may be a reference to |wifi_network_guid_|, so make a copy of
91 // before clearing it below. 130 // it first before clearing it below.
92 std::string wifi_guid_copy = wifi_guid; 131 std::string wifi_network_guid_copy = wifi_guid;
93 132
94 ssid_.clear(); 133 ssid_.clear();
95 password_.clear(); 134 password_.clear();
96 wifi_guid_.clear(); 135 wifi_network_guid_.clear();
97 136
98 timer_->Stop(); 137 timer_->Stop();
99 138
100 callback_.Run(wifi_guid_copy); 139 callback_.Run(wifi_network_guid_copy);
101 callback_.Reset(); 140 callback_.Reset();
102 } 141 }
103 142
104 base::DictionaryValue WifiHotspotConnector::CreateWifiPropertyDictionary( 143 base::DictionaryValue WifiHotspotConnector::CreateWifiPropertyDictionary(
105 const std::string& ssid, 144 const std::string& ssid,
106 const std::string& password) { 145 const std::string& password) {
107 PA_LOG(INFO) << "Creating network configuration. " 146 PA_LOG(INFO) << "Creating network configuration. "
108 << "SSID: " << ssid << ", " 147 << "SSID: " << ssid << ", "
109 << "Password: " << password << ", " 148 << "Password: " << password << ", "
110 << "Wi-Fi network GUID: " << wifi_guid_; 149 << "Wi-Fi network GUID: " << wifi_network_guid_;
111 150
112 base::DictionaryValue properties; 151 base::DictionaryValue properties;
113 152
114 shill_property_util::SetSSID(ssid, &properties); 153 shill_property_util::SetSSID(ssid, &properties);
115 properties.SetStringWithoutPathExpansion(shill::kGuidProperty, wifi_guid_); 154 properties.SetStringWithoutPathExpansion(shill::kGuidProperty,
155 wifi_network_guid_);
116 properties.SetBooleanWithoutPathExpansion(shill::kAutoConnectProperty, false); 156 properties.SetBooleanWithoutPathExpansion(shill::kAutoConnectProperty, false);
117 properties.SetStringWithoutPathExpansion(shill::kTypeProperty, 157 properties.SetStringWithoutPathExpansion(shill::kTypeProperty,
118 shill::kTypeWifi); 158 shill::kTypeWifi);
119 properties.SetBooleanWithoutPathExpansion(shill::kSaveCredentialsProperty, 159 properties.SetBooleanWithoutPathExpansion(shill::kSaveCredentialsProperty,
120 true); 160 true);
121 161
122 if (password.empty()) { 162 if (password.empty()) {
123 properties.SetStringWithoutPathExpansion(shill::kSecurityClassProperty, 163 properties.SetStringWithoutPathExpansion(shill::kSecurityClassProperty,
124 shill::kSecurityNone); 164 shill::kSecurityNone);
125 } else { 165 } else {
(...skipping 10 matching lines...) Expand all
136 InvokeWifiConnectionCallback(std::string()); 176 InvokeWifiConnectionCallback(std::string());
137 } 177 }
138 178
139 void WifiHotspotConnector::SetTimerForTest(std::unique_ptr<base::Timer> timer) { 179 void WifiHotspotConnector::SetTimerForTest(std::unique_ptr<base::Timer> timer) {
140 timer_ = std::move(timer); 180 timer_ = std::move(timer);
141 } 181 }
142 182
143 } // namespace tether 183 } // namespace tether
144 184
145 } // namespace chromeos 185 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698