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

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@ and hansberry@ 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& guid,
Kyle Horimoto 2017/04/28 22:07:28 tether_network_guid
lesliewatkins 2017/04/29 00:57:54 Done.
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,
47 // call the callback, passing an empty string to signal that the connection 48 // call the callback, passing an empty string to signal that the connection
48 // did not complete successfully. 49 // did not complete successfully.
49 InvokeWifiConnectionCallback(std::string()); 50 InvokeWifiConnectionCallback(std::string());
50 } 51 }
51 52
52 ssid_ = ssid; 53 ssid_ = ssid;
53 password_ = password; 54 password_ = password;
55 guid_ = guid;
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()));
60 62
61 base::DictionaryValue properties = 63 base::DictionaryValue properties =
62 CreateWifiPropertyDictionary(ssid, password); 64 CreateWifiPropertyDictionary(ssid, password);
63 network_connect_->CreateConfiguration(&properties, false /* shared */); 65 network_connect_->CreateConfiguration(&properties, false /* shared */);
64 } 66 }
65 67
66 void WifiHotspotConnector::NetworkPropertiesUpdated( 68 void WifiHotspotConnector::NetworkPropertiesUpdated(
67 const NetworkState* network) { 69 const NetworkState* network) {
68 if (network->guid() != wifi_guid_) { 70 if (network->guid() != wifi_guid_) {
69 // If a different network has been connected, return early and wait for the 71 // If a different network has been connected, return early and wait for the
70 // network with ID |wifi_guid_| is updated. 72 // network with ID |wifi_guid_| is updated.
71 return; 73 return;
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 bool successful_association =
84 network_state_handler_->AssociateTetherNetworkStateWithWifiNetwork(
85 guid_, wifi_guid_);
86 if (successful_association) {
87 PA_LOG(INFO) << "Wifi network with ID " << wifi_guid_
88 << " is connectable. Tether network ID: \"" << guid_
Kyle Horimoto 2017/04/28 22:07:28 Add something to the log that says that the networ
lesliewatkins 2017/04/29 00:57:54 Done.
89 << "\", Wi-Fi network ID: \"" << wifi_guid_ << "\"";
90 } else {
91 PA_LOG(INFO) << "Wifi network with ID " << wifi_guid_
92 << " is connectable, but failed to associate tether network "
93 "with ID \""
94 << guid_ << "\" to Wi-Fi network with ID: \"" << wifi_guid_
95 << "\"";
96 }
97 // If the network is now connectable, associate it with a Tether network
Kyle Horimoto 2017/04/28 22:07:28 nit: Newline before this.
lesliewatkins 2017/04/29 00:57:54 Done.
98 // ASAP so that the correct icon will be displayed in the tray while the
99 // network is connecting.
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