| 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 28 matching lines...) Expand all Loading... |
| 39 registry->RegisterBooleanPref(prefs::kInstantTetheringAllowed, true); | 39 registry->RegisterBooleanPref(prefs::kInstantTetheringAllowed, true); |
| 40 registry->RegisterBooleanPref(prefs::kInstantTetheringEnabled, true); | 40 registry->RegisterBooleanPref(prefs::kInstantTetheringEnabled, true); |
| 41 chromeos::tether::Initializer::RegisterProfilePrefs(registry); | 41 chromeos::tether::Initializer::RegisterProfilePrefs(registry); |
| 42 } | 42 } |
| 43 | 43 |
| 44 // static | 44 // static |
| 45 bool TetherService::IsFeatureFlagEnabled() { | 45 bool TetherService::IsFeatureFlagEnabled() { |
| 46 return base::FeatureList::IsEnabled(features::kInstantTethering); | 46 return base::FeatureList::IsEnabled(features::kInstantTethering); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void TetherService::InitializerDelegate::InitializeTether( |
| 50 cryptauth::CryptAuthService* cryptauth_service, |
| 51 std::unique_ptr<chromeos::tether::NotificationPresenter> |
| 52 notification_presenter, |
| 53 PrefService* pref_service, |
| 54 ProfileOAuth2TokenService* token_service, |
| 55 chromeos::NetworkStateHandler* network_state_handler, |
| 56 chromeos::ManagedNetworkConfigurationHandler* |
| 57 managed_network_configuration_handler, |
| 58 chromeos::NetworkConnect* network_connect, |
| 59 chromeos::NetworkConnectionHandler* network_connection_handler) { |
| 60 chromeos::tether::Initializer::Init( |
| 61 cryptauth_service, std::move(notification_presenter), pref_service, |
| 62 token_service, network_state_handler, |
| 63 managed_network_configuration_handler, network_connect, |
| 64 network_connection_handler); |
| 65 } |
| 66 |
| 67 void TetherService::InitializerDelegate::ShutdownTether() { |
| 68 chromeos::tether::Initializer::Shutdown(); |
| 69 } |
| 70 |
| 49 TetherService::TetherService( | 71 TetherService::TetherService( |
| 50 Profile* profile, | 72 Profile* profile, |
| 51 chromeos::PowerManagerClient* power_manager_client, | 73 chromeos::PowerManagerClient* power_manager_client, |
| 52 chromeos::SessionManagerClient* session_manager_client, | 74 chromeos::SessionManagerClient* session_manager_client, |
| 53 cryptauth::CryptAuthService* cryptauth_service, | 75 cryptauth::CryptAuthService* cryptauth_service, |
| 54 chromeos::NetworkStateHandler* network_state_handler) | 76 chromeos::NetworkStateHandler* network_state_handler) |
| 55 : profile_(profile), | 77 : profile_(profile), |
| 56 power_manager_client_(power_manager_client), | 78 power_manager_client_(power_manager_client), |
| 57 session_manager_client_(session_manager_client), | 79 session_manager_client_(session_manager_client), |
| 58 cryptauth_service_(cryptauth_service), | 80 cryptauth_service_(cryptauth_service), |
| 59 network_state_handler_(network_state_handler), | 81 network_state_handler_(network_state_handler), |
| 82 initializer_delegate_(base::MakeUnique<InitializerDelegate>()), |
| 60 weak_ptr_factory_(this) { | 83 weak_ptr_factory_(this) { |
| 61 power_manager_client_->AddObserver(this); | 84 power_manager_client_->AddObserver(this); |
| 62 session_manager_client_->AddObserver(this); | 85 session_manager_client_->AddObserver(this); |
| 63 | 86 |
| 64 cryptauth_service_->GetCryptAuthDeviceManager()->AddObserver(this); | 87 cryptauth_service_->GetCryptAuthDeviceManager()->AddObserver(this); |
| 65 | 88 |
| 66 network_state_handler_->AddObserver(this, FROM_HERE); | 89 network_state_handler_->AddObserver(this, FROM_HERE); |
| 67 | 90 |
| 68 registrar_.Init(profile_->GetPrefs()); | 91 registrar_.Init(profile_->GetPrefs()); |
| 69 registrar_.Add(prefs::kInstantTetheringAllowed, | 92 registrar_.Add(prefs::kInstantTetheringAllowed, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 85 void TetherService::StartTetherIfEnabled() { | 108 void TetherService::StartTetherIfEnabled() { |
| 86 if (GetTetherTechnologyState() != | 109 if (GetTetherTechnologyState() != |
| 87 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED) { | 110 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED) { |
| 88 return; | 111 return; |
| 89 } | 112 } |
| 90 | 113 |
| 91 auto notification_presenter = | 114 auto notification_presenter = |
| 92 base::MakeUnique<chromeos::tether::TetherNotificationPresenter>( | 115 base::MakeUnique<chromeos::tether::TetherNotificationPresenter>( |
| 93 profile_, message_center::MessageCenter::Get(), | 116 profile_, message_center::MessageCenter::Get(), |
| 94 chromeos::NetworkConnect::Get()); | 117 chromeos::NetworkConnect::Get()); |
| 95 chromeos::tether::Initializer::Init( | 118 initializer_delegate_->InitializeTether( |
| 96 cryptauth_service_, std::move(notification_presenter), | 119 cryptauth_service_, std::move(notification_presenter), |
| 97 profile_->GetPrefs(), | 120 profile_->GetPrefs(), |
| 98 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), | 121 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), |
| 99 network_state_handler_, | 122 network_state_handler_, |
| 100 chromeos::NetworkHandler::Get()->managed_network_configuration_handler(), | 123 chromeos::NetworkHandler::Get()->managed_network_configuration_handler(), |
| 101 chromeos::NetworkConnect::Get(), | 124 chromeos::NetworkConnect::Get(), |
| 102 chromeos::NetworkHandler::Get()->network_connection_handler()); | 125 chromeos::NetworkHandler::Get()->network_connection_handler()); |
| 103 } | 126 } |
| 104 | 127 |
| 105 void TetherService::StopTether() { | 128 void TetherService::StopTether() { |
| 106 chromeos::tether::Initializer::Shutdown(); | 129 initializer_delegate_->ShutdownTether(); |
| 107 } | 130 } |
| 108 | 131 |
| 109 void TetherService::Shutdown() { | 132 void TetherService::Shutdown() { |
| 110 if (shut_down_) | 133 if (shut_down_) |
| 111 return; | 134 return; |
| 112 | 135 |
| 113 shut_down_ = true; | 136 shut_down_ = true; |
| 114 | 137 |
| 115 power_manager_client_->RemoveObserver(this); | 138 power_manager_client_->RemoveObserver(this); |
| 116 session_manager_client_->RemoveObserver(this); | 139 session_manager_client_->RemoveObserver(this); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 UpdateTetherTechnologyState(); | 214 UpdateTetherTechnologyState(); |
| 192 } | 215 } |
| 193 | 216 |
| 194 bool TetherService::HasSyncedTetherHosts() const { | 217 bool TetherService::HasSyncedTetherHosts() const { |
| 195 return !cryptauth_service_->GetCryptAuthDeviceManager() | 218 return !cryptauth_service_->GetCryptAuthDeviceManager() |
| 196 ->GetTetherHosts() | 219 ->GetTetherHosts() |
| 197 .empty(); | 220 .empty(); |
| 198 } | 221 } |
| 199 | 222 |
| 200 void TetherService::UpdateTetherTechnologyState() { | 223 void TetherService::UpdateTetherTechnologyState() { |
| 201 chromeos::NetworkStateHandler::TechnologyState tether_technology_state = | 224 chromeos::NetworkStateHandler::TechnologyState new_tether_technology_state = |
| 202 GetTetherTechnologyState(); | 225 GetTetherTechnologyState(); |
| 203 | 226 |
| 204 network_state_handler_->SetTetherTechnologyState(tether_technology_state); | 227 network_state_handler_->SetTetherTechnologyState(new_tether_technology_state); |
| 205 | 228 |
| 206 if (tether_technology_state == | 229 if (new_tether_technology_state == |
| 207 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED) { | 230 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED) { |
| 208 StartTetherIfEnabled(); | 231 StartTetherIfEnabled(); |
| 209 } else { | 232 } else { |
| 210 StopTether(); | 233 StopTether(); |
| 211 } | 234 } |
| 212 } | 235 } |
| 213 | 236 |
| 214 chromeos::NetworkStateHandler::TechnologyState | 237 chromeos::NetworkStateHandler::TechnologyState |
| 215 TetherService::GetTetherTechnologyState() { | 238 TetherService::GetTetherTechnologyState() { |
| 216 if (shut_down_ || suspended_ || session_manager_client_->IsScreenLocked() || | 239 if (shut_down_ || suspended_ || session_manager_client_->IsScreenLocked() || |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 chromeos::NetworkTypePattern::Cellular())); | 280 chromeos::NetworkTypePattern::Cellular())); |
| 258 } | 281 } |
| 259 | 282 |
| 260 bool TetherService::IsAllowedByPolicy() const { | 283 bool TetherService::IsAllowedByPolicy() const { |
| 261 return profile_->GetPrefs()->GetBoolean(prefs::kInstantTetheringAllowed); | 284 return profile_->GetPrefs()->GetBoolean(prefs::kInstantTetheringAllowed); |
| 262 } | 285 } |
| 263 | 286 |
| 264 bool TetherService::IsEnabledbyPreference() const { | 287 bool TetherService::IsEnabledbyPreference() const { |
| 265 return profile_->GetPrefs()->GetBoolean(prefs::kInstantTetheringEnabled); | 288 return profile_->GetPrefs()->GetBoolean(prefs::kInstantTetheringEnabled); |
| 266 } | 289 } |
| 290 |
| 291 void TetherService::SetInitializerDelegateForTest( |
| 292 std::unique_ptr<InitializerDelegate> initializer_delegate) { |
| 293 initializer_delegate_ = std::move(initializer_delegate); |
| 294 } |
| OLD | NEW |