| 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" |
| 11 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "chrome/browser/chromeos/net/tether_notification_presenter.h" | 12 #include "chrome/browser/chromeos/net/tether_notification_presenter.h" |
| 12 #include "chrome/browser/chromeos/tether/tether_service_factory.h" | 13 #include "chrome/browser/chromeos/tether/tether_service_factory.h" |
| 13 #include "chrome/browser/cryptauth/chrome_cryptauth_service_factory.h" | 14 #include "chrome/browser/cryptauth/chrome_cryptauth_service_factory.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 17 #include "chromeos/chromeos_switches.h" | 18 #include "chromeos/chromeos_switches.h" |
| 18 #include "chromeos/components/tether/initializer.h" | 19 #include "chromeos/components/tether/initializer.h" |
| 19 #include "chromeos/network/network_connect.h" | 20 #include "chromeos/network/network_connect.h" |
| 20 #include "chromeos/network/network_type_pattern.h" | 21 #include "chromeos/network/network_type_pattern.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 | 63 |
| 63 cryptauth_service_->GetCryptAuthDeviceManager()->AddObserver(this); | 64 cryptauth_service_->GetCryptAuthDeviceManager()->AddObserver(this); |
| 64 | 65 |
| 65 network_state_handler_->AddObserver(this, FROM_HERE); | 66 network_state_handler_->AddObserver(this, FROM_HERE); |
| 66 | 67 |
| 67 registrar_.Init(profile_->GetPrefs()); | 68 registrar_.Init(profile_->GetPrefs()); |
| 68 registrar_.Add(prefs::kInstantTetheringAllowed, | 69 registrar_.Add(prefs::kInstantTetheringAllowed, |
| 69 base::Bind(&TetherService::OnPrefsChanged, | 70 base::Bind(&TetherService::OnPrefsChanged, |
| 70 weak_ptr_factory_.GetWeakPtr())); | 71 weak_ptr_factory_.GetWeakPtr())); |
| 71 | 72 |
| 72 device::BluetoothAdapterFactory::GetAdapter( | 73 // GetAdapter may call OnBluetoothAdapterFetched immediately which can cause |
| 73 base::Bind(&TetherService::OnBluetoothAdapterFetched, | 74 // problems with the Fake implementation since the class is not fully |
| 74 weak_ptr_factory_.GetWeakPtr())); | 75 // constructed yet. Post the GetAdapter call to avoid this. |
| 76 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 77 FROM_HERE, |
| 78 base::Bind(device::BluetoothAdapterFactory::GetAdapter, |
| 79 base::Bind(&TetherService::OnBluetoothAdapterFetched, |
| 80 weak_ptr_factory_.GetWeakPtr()))); |
| 75 } | 81 } |
| 76 | 82 |
| 77 TetherService::~TetherService() {} | 83 TetherService::~TetherService() {} |
| 78 | 84 |
| 79 void TetherService::StartTetherIfEnabled() { | 85 void TetherService::StartTetherIfEnabled() { |
| 80 if (GetTetherTechnologyState() != | 86 if (GetTetherTechnologyState() != |
| 81 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED) { | 87 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED) { |
| 82 return; | 88 return; |
| 83 } | 89 } |
| 84 | 90 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 return adapter_.get() && adapter_->IsPresent() && adapter_->IsPowered(); | 245 return adapter_.get() && adapter_->IsPresent() && adapter_->IsPowered(); |
| 240 } | 246 } |
| 241 | 247 |
| 242 bool TetherService::IsAllowedByPolicy() const { | 248 bool TetherService::IsAllowedByPolicy() const { |
| 243 return profile_->GetPrefs()->GetBoolean(prefs::kInstantTetheringAllowed); | 249 return profile_->GetPrefs()->GetBoolean(prefs::kInstantTetheringAllowed); |
| 244 } | 250 } |
| 245 | 251 |
| 246 bool TetherService::IsEnabledbyPreference() const { | 252 bool TetherService::IsEnabledbyPreference() const { |
| 247 return profile_->GetPrefs()->GetBoolean(prefs::kInstantTetheringEnabled); | 253 return profile_->GetPrefs()->GetBoolean(prefs::kInstantTetheringEnabled); |
| 248 } | 254 } |
| OLD | NEW |