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