| Index: chrome/browser/chromeos/policy/bluetooth_policy_handler.cc
|
| diff --git a/chrome/browser/chromeos/policy/bluetooth_policy_handler.cc b/chrome/browser/chromeos/policy/bluetooth_policy_handler.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2096dfbb0218ea317a5b6bf52525ce4cf0acb59a
|
| --- /dev/null
|
| +++ b/chrome/browser/chromeos/policy/bluetooth_policy_handler.cc
|
| @@ -0,0 +1,49 @@
|
| +// Copyright (c) 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/chromeos/policy/bluetooth_policy_handler.h"
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/callback.h"
|
| +#include "chromeos/settings/cros_settings_names.h"
|
| +#include "chromeos/settings/cros_settings_provider.h"
|
| +#include "device/bluetooth/bluetooth_adapter_factory.h"
|
| +
|
| +namespace chromeos {
|
| +
|
| +BluetoothPolicyHandler::BluetoothPolicyHandler(CrosSettings* cros_settings)
|
| + : cros_settings_(cros_settings), weak_factory_(this) {
|
| + bluetooth_policy_subscription_ = cros_settings_->AddSettingsObserver(
|
| + kAllowBluetooth,
|
| + base::Bind(&BluetoothPolicyHandler::OnBluetoothPolicyChanged,
|
| + weak_factory_.GetWeakPtr()));
|
| +}
|
| +
|
| +BluetoothPolicyHandler::~BluetoothPolicyHandler() {}
|
| +
|
| +void BluetoothPolicyHandler::OnBluetoothPolicyChanged() {
|
| + CrosSettingsProvider::TrustedStatus status =
|
| + cros_settings_->PrepareTrustedValues(
|
| + base::Bind(&BluetoothPolicyHandler::OnBluetoothPolicyChanged,
|
| + weak_factory_.GetWeakPtr()));
|
| + if (status != CrosSettingsProvider::TRUSTED)
|
| + return;
|
| +
|
| + // Get the updated policy.
|
| + bool allow_bluetooth = false;
|
| + cros_settings_->GetBoolean(kAllowBluetooth, &allow_bluetooth);
|
| +
|
| + // !allow_bluetooth because we have a switch in logic
|
| + // (allow bluetooth -> disable bluetooth)
|
| + device::BluetoothAdapterFactory::GetAdapter(
|
| + base::Bind(&BluetoothPolicyHandler::SetBluetoothPolicy,
|
| + weak_factory_.GetWeakPtr(), !allow_bluetooth));
|
| +}
|
| +
|
| +void BluetoothPolicyHandler::SetBluetoothPolicy(
|
| + bool bt_disabled, scoped_refptr<device::BluetoothAdapter> adapter) {
|
| + adapter->SetDisabled(bt_disabled);
|
| +}
|
| +
|
| +} // namespace chromeos
|
|
|