OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/policy/bluetooth_policy_handler.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/callback.h" |
| 9 #include "chromeos/settings/cros_settings_names.h" |
| 10 #include "chromeos/settings/cros_settings_provider.h" |
| 11 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 12 |
| 13 namespace chromeos { |
| 14 |
| 15 BluetoothPolicyHandler::BluetoothPolicyHandler(CrosSettings* cros_settings) |
| 16 : cros_settings_(cros_settings), weak_factory_(this) { |
| 17 bluetooth_policy_subscription_ = cros_settings_->AddSettingsObserver( |
| 18 kAllowBluetooth, |
| 19 base::Bind(&BluetoothPolicyHandler::OnBluetoothPolicyChanged, |
| 20 weak_factory_.GetWeakPtr())); |
| 21 } |
| 22 |
| 23 BluetoothPolicyHandler::~BluetoothPolicyHandler() {} |
| 24 |
| 25 void BluetoothPolicyHandler::OnBluetoothPolicyChanged() { |
| 26 CrosSettingsProvider::TrustedStatus status = |
| 27 cros_settings_->PrepareTrustedValues( |
| 28 base::Bind(&BluetoothPolicyHandler::OnBluetoothPolicyChanged, |
| 29 weak_factory_.GetWeakPtr())); |
| 30 if (status != CrosSettingsProvider::TRUSTED) |
| 31 return; |
| 32 |
| 33 // Get the updated policy. |
| 34 bool allow_bluetooth = false; |
| 35 cros_settings_->GetBoolean(kAllowBluetooth, &allow_bluetooth); |
| 36 |
| 37 // !allow_bluetooth because we have a switch in logic |
| 38 // (allow bluetooth -> disable bluetooth) |
| 39 device::BluetoothAdapterFactory::GetAdapter( |
| 40 base::Bind(&BluetoothPolicyHandler::SetBluetoothPolicy, |
| 41 weak_factory_.GetWeakPtr(), !allow_bluetooth)); |
| 42 } |
| 43 |
| 44 void BluetoothPolicyHandler::SetBluetoothPolicy( |
| 45 bool bt_disabled, scoped_refptr<device::BluetoothAdapter> adapter) { |
| 46 adapter->SetDisabled(bt_disabled); |
| 47 } |
| 48 |
| 49 } // namespace chromeos |
OLD | NEW |