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..1702d27f2f6533ed915b1deb9a7b8320f43de0dc |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/policy/bluetooth_policy_handler.cc |
| @@ -0,0 +1,52 @@ |
| +// 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() { |
|
ortuno
2016/04/13 21:12:21
You didn't answer atwilson's question: "Are we alw
Ivan Šandrk
2016/04/14 18:08:47
Answered it now. C/P:
No guarantee. That's why now
|
| + 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 = true; |
| + cros_settings_->GetBoolean(kAllowBluetooth, &allow_bluetooth); |
| + |
| + // device::BluetoothAdapterFactory::GetAdapter( |
|
scheib
2016/04/13 19:47:44
Don't leave commented out code.
Ivan Šandrk
2016/04/14 18:08:47
Once again sorry for the half-baked code, wanted t
|
| + // base::Bind(&BluetoothPolicyHandler::SetBluetoothPolicy, |
| + // weak_factory_.GetWeakPtr(), allow_bluetooth)); |
| + device::BluetoothAdapterFactory::GetAdapter( |
| + base::Bind(&BluetoothPolicyHandler::SetBluetoothPolicy, |
| + nullptr, allow_bluetooth)); |
| +} |
| + |
| +void BluetoothPolicyHandler::SetBluetoothPolicy( |
| + bool allow_bluetooth, scoped_refptr<device::BluetoothAdapter> adapter) { |
| + // !allow_bluetooth because we have a switch in logic |
| + // (allow bluetooth -> disable bluetooth) |
| + adapter->SetDisabled(!allow_bluetooth); |
| +} |
| + |
| +} // namespace chromeos |