Chromium Code Reviews| 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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(); |
| 198 } | 198 } |
| 199 | 199 |
| 200 void TetherService::UpdateTetherTechnologyState() { | 200 void TetherService::UpdateTetherTechnologyState() { |
| 201 chromeos::NetworkStateHandler::TechnologyState tether_technology_state = | 201 bool was_tether_enabled = network_state_handler_->IsTechnologyEnabled( |
| 202 chromeos::NetworkTypePattern::Tether()); | |
| 203 | |
| 204 chromeos::NetworkStateHandler::TechnologyState new_tether_technology_state = | |
| 202 GetTetherTechnologyState(); | 205 GetTetherTechnologyState(); |
| 203 | 206 |
| 204 network_state_handler_->SetTetherTechnologyState(tether_technology_state); | 207 network_state_handler_->SetTetherTechnologyState(new_tether_technology_state); |
| 205 | 208 |
| 206 if (tether_technology_state == | 209 if (!was_tether_enabled && |
|
Ryan Hansberry
2017/06/26 23:55:08
Please add a test.
Kyle Horimoto
2017/06/27 00:56:01
Added tests. When testing, I realized that this is
| |
| 207 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED) { | 210 new_tether_technology_state == |
| 211 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED) { | |
| 212 // Start if the feature is enabled and was not previously running. | |
| 208 StartTetherIfEnabled(); | 213 StartTetherIfEnabled(); |
| 209 } else { | 214 } else if (was_tether_enabled && |
| 215 new_tether_technology_state != | |
| 216 chromeos::NetworkStateHandler::TechnologyState:: | |
| 217 TECHNOLOGY_ENABLED) { | |
| 218 // Stop if the feature is not enabled and was previously running. | |
| 210 StopTether(); | 219 StopTether(); |
| 211 } | 220 } |
| 212 } | 221 } |
| 213 | 222 |
| 214 chromeos::NetworkStateHandler::TechnologyState | 223 chromeos::NetworkStateHandler::TechnologyState |
| 215 TetherService::GetTetherTechnologyState() { | 224 TetherService::GetTetherTechnologyState() { |
| 216 if (shut_down_ || suspended_ || session_manager_client_->IsScreenLocked() || | 225 if (shut_down_ || suspended_ || session_manager_client_->IsScreenLocked() || |
| 217 !HasSyncedTetherHosts()) { | 226 !HasSyncedTetherHosts()) { |
| 218 return chromeos::NetworkStateHandler::TechnologyState:: | 227 return chromeos::NetworkStateHandler::TechnologyState:: |
| 219 TECHNOLOGY_UNAVAILABLE; | 228 TECHNOLOGY_UNAVAILABLE; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 chromeos::NetworkTypePattern::Cellular())); | 266 chromeos::NetworkTypePattern::Cellular())); |
| 258 } | 267 } |
| 259 | 268 |
| 260 bool TetherService::IsAllowedByPolicy() const { | 269 bool TetherService::IsAllowedByPolicy() const { |
| 261 return profile_->GetPrefs()->GetBoolean(prefs::kInstantTetheringAllowed); | 270 return profile_->GetPrefs()->GetBoolean(prefs::kInstantTetheringAllowed); |
| 262 } | 271 } |
| 263 | 272 |
| 264 bool TetherService::IsEnabledbyPreference() const { | 273 bool TetherService::IsEnabledbyPreference() const { |
| 265 return profile_->GetPrefs()->GetBoolean(prefs::kInstantTetheringEnabled); | 274 return profile_->GetPrefs()->GetBoolean(prefs::kInstantTetheringEnabled); |
| 266 } | 275 } |
| OLD | NEW |