Chromium Code Reviews| 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..b6379d83da18f9043652d79894d35b9304193b96 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/policy/bluetooth_policy_handler.cc |
| @@ -0,0 +1,56 @@ |
| +// 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/memory/ref_counted.h" |
| +#include "chromeos/settings/cros_settings_names.h" |
| +#include "chromeos/settings/cros_settings_provider.h" |
| +#include "device/bluetooth/bluetooth_adapter.h" |
| +#include "device/bluetooth/bluetooth_adapter_factory.h" |
| + |
| +namespace policy { |
| + |
| +namespace { |
| + |
| +void SetBluetoothPolicy(bool allow_bluetooth, |
| + scoped_refptr<device::BluetoothAdapter> adapter) { |
| + if (!allow_bluetooth) |
| + adapter->Shutdown(); |
|
scheib
2016/04/18 17:10:57
If all references to the adapter are released then
Ivan Šandrk
2016/04/19 15:53:58
Done.
|
| +} |
| + |
| +} // namespace |
| + |
| +BluetoothPolicyHandler::BluetoothPolicyHandler( |
| + chromeos::CrosSettings* cros_settings) |
| + : cros_settings_(cros_settings), weak_factory_(this) { |
| + bluetooth_policy_subscription_ = cros_settings_->AddSettingsObserver( |
| + chromeos::kAllowBluetooth, |
| + base::Bind(&BluetoothPolicyHandler::OnBluetoothPolicyChanged, |
| + weak_factory_.GetWeakPtr())); |
| + |
| + // Fire it once so we're sure we get an invocation on startup. |
| + OnBluetoothPolicyChanged(); |
| +} |
| + |
| +BluetoothPolicyHandler::~BluetoothPolicyHandler() {} |
| + |
| +void BluetoothPolicyHandler::OnBluetoothPolicyChanged() { |
| + chromeos::CrosSettingsProvider::TrustedStatus status = |
| + cros_settings_->PrepareTrustedValues( |
| + base::Bind(&BluetoothPolicyHandler::OnBluetoothPolicyChanged, |
| + weak_factory_.GetWeakPtr())); |
| + if (status != chromeos::CrosSettingsProvider::TRUSTED) |
| + return; |
| + |
| + // Get the updated policy. |
| + bool allow_bluetooth = true; |
| + cros_settings_->GetBoolean(chromeos::kAllowBluetooth, &allow_bluetooth); |
| + |
| + device::BluetoothAdapterFactory::GetAdapter( |
| + base::Bind(&SetBluetoothPolicy, allow_bluetooth)); |
| +} |
| + |
| +} // namespace policy |