OLD | NEW |
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 "chrome/browser/chromeos/tether/tether_service.h" | 5 #include "chrome/browser/chromeos/tether/tether_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 chromeos::NetworkStateHandler:: | 176 chromeos::NetworkStateHandler:: |
177 TechnologyState::TECHNOLOGY_ENABLED) { | 177 TechnologyState::TECHNOLOGY_ENABLED) { |
178 is_enabled = true; | 178 is_enabled = true; |
179 } else { | 179 } else { |
180 is_enabled = was_pref_enabled; | 180 is_enabled = was_pref_enabled; |
181 } | 181 } |
182 | 182 |
183 if (is_enabled != was_pref_enabled) { | 183 if (is_enabled != was_pref_enabled) { |
184 profile_->GetPrefs()->SetBoolean(prefs::kInstantTetheringEnabled, | 184 profile_->GetPrefs()->SetBoolean(prefs::kInstantTetheringEnabled, |
185 is_enabled); | 185 is_enabled); |
186 UpdateTetherTechnologyState(); | |
187 } | 186 } |
| 187 UpdateTetherTechnologyState(); |
188 } | 188 } |
189 | 189 |
190 void TetherService::OnPrefsChanged() { | 190 void TetherService::OnPrefsChanged() { |
191 UpdateTetherTechnologyState(); | 191 UpdateTetherTechnologyState(); |
192 } | 192 } |
193 | 193 |
194 bool TetherService::HasSyncedTetherHosts() const { | 194 bool TetherService::HasSyncedTetherHosts() const { |
195 return !cryptauth_service_->GetCryptAuthDeviceManager() | 195 return !cryptauth_service_->GetCryptAuthDeviceManager() |
196 ->GetTetherHosts() | 196 ->GetTetherHosts() |
197 .empty(); | 197 .empty(); |
(...skipping 15 matching lines...) Expand all Loading... |
213 | 213 |
214 chromeos::NetworkStateHandler::TechnologyState | 214 chromeos::NetworkStateHandler::TechnologyState |
215 TetherService::GetTetherTechnologyState() { | 215 TetherService::GetTetherTechnologyState() { |
216 if (shut_down_ || suspended_ || session_manager_client_->IsScreenLocked() || | 216 if (shut_down_ || suspended_ || session_manager_client_->IsScreenLocked() || |
217 !HasSyncedTetherHosts()) { | 217 !HasSyncedTetherHosts()) { |
218 return chromeos::NetworkStateHandler::TechnologyState:: | 218 return chromeos::NetworkStateHandler::TechnologyState:: |
219 TECHNOLOGY_UNAVAILABLE; | 219 TECHNOLOGY_UNAVAILABLE; |
220 } else if (!IsAllowedByPolicy()) { | 220 } else if (!IsAllowedByPolicy()) { |
221 return chromeos::NetworkStateHandler::TechnologyState:: | 221 return chromeos::NetworkStateHandler::TechnologyState:: |
222 TECHNOLOGY_PROHIBITED; | 222 TECHNOLOGY_PROHIBITED; |
223 } else if (!IsBluetoothAvailable()) { | 223 } else if (!IsBluetoothAvailable() || IsCellularAvailableButNotEnabled()) { |
224 // TODO (hansberry): This unfortunately results in a weird UI state for | 224 // If Cellular technology is available, then Tether technology is treated |
225 // Settings where the toggle is clickable but immediately becomes disabled | 225 // as a subset of Cellular, and it should only be enabled when Cellular |
226 // after enabling it. Possible solution: grey out the toggle and tell the | 226 // technology is enabled. |
227 // user to turn Bluetooth on? | 227 // TODO (hansberry): When !IsBluetoothAvailable(), this results in a weird |
| 228 // UI state for Settings where the toggle is clickable but immediately |
| 229 // becomes disabled after enabling it. Possible solution: grey out the |
| 230 // toggle and tell the user to turn Bluetooth on? |
228 return chromeos::NetworkStateHandler::TechnologyState:: | 231 return chromeos::NetworkStateHandler::TechnologyState:: |
229 TECHNOLOGY_UNINITIALIZED; | 232 TECHNOLOGY_UNINITIALIZED; |
230 } else if (!IsEnabledbyPreference()) { | 233 } else if (!IsEnabledbyPreference()) { |
231 return chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_AVAILABLE; | 234 return chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_AVAILABLE; |
232 } | 235 } |
233 | 236 |
234 return chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED; | 237 return chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED; |
235 } | 238 } |
236 | 239 |
237 void TetherService::OnBluetoothAdapterFetched( | 240 void TetherService::OnBluetoothAdapterFetched( |
238 scoped_refptr<device::BluetoothAdapter> adapter) { | 241 scoped_refptr<device::BluetoothAdapter> adapter) { |
239 if (shut_down_) | 242 if (shut_down_) |
240 return; | 243 return; |
241 adapter_ = adapter; | 244 adapter_ = adapter; |
242 adapter_->AddObserver(this); | 245 adapter_->AddObserver(this); |
243 UpdateTetherTechnologyState(); | 246 UpdateTetherTechnologyState(); |
244 } | 247 } |
245 | 248 |
246 bool TetherService::IsBluetoothAvailable() const { | 249 bool TetherService::IsBluetoothAvailable() const { |
247 return adapter_.get() && adapter_->IsPresent() && adapter_->IsPowered(); | 250 return adapter_.get() && adapter_->IsPresent() && adapter_->IsPowered(); |
248 } | 251 } |
249 | 252 |
| 253 bool TetherService::IsCellularAvailableButNotEnabled() const { |
| 254 return (network_state_handler_->IsTechnologyAvailable( |
| 255 chromeos::NetworkTypePattern::Cellular()) && |
| 256 !network_state_handler_->IsTechnologyEnabled( |
| 257 chromeos::NetworkTypePattern::Cellular())); |
| 258 } |
| 259 |
250 bool TetherService::IsAllowedByPolicy() const { | 260 bool TetherService::IsAllowedByPolicy() const { |
251 return profile_->GetPrefs()->GetBoolean(prefs::kInstantTetheringAllowed); | 261 return profile_->GetPrefs()->GetBoolean(prefs::kInstantTetheringAllowed); |
252 } | 262 } |
253 | 263 |
254 bool TetherService::IsEnabledbyPreference() const { | 264 bool TetherService::IsEnabledbyPreference() const { |
255 return profile_->GetPrefs()->GetBoolean(prefs::kInstantTetheringEnabled); | 265 return profile_->GetPrefs()->GetBoolean(prefs::kInstantTetheringEnabled); |
256 } | 266 } |
OLD | NEW |