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( |
Andrew T Wilson (Slow)
2016/04/13 13:55:10
Are we always guaranteed to get an OnBluetoothPoli
Ivan Šandrk
2016/04/14 18:08:47
No guarantee. That's why now OnBluetoothPolicyChan
|
+ 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; |
Andrew T Wilson (Slow)
2016/04/13 13:55:10
Should allow_bluetooth really default to false (we
Ivan Šandrk
2016/04/13 17:19:04
Done.
|
+ cros_settings_->GetBoolean(kAllowBluetooth, &allow_bluetooth); |
+ |
+ // !allow_bluetooth because we have a switch in logic |
Andrew T Wilson (Slow)
2016/04/13 13:55:10
I'd suggest moving the !allow_bluetooth logic into
Ivan Šandrk
2016/04/13 17:19:04
Done.
|
+ // (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) { |
Andrew T Wilson (Slow)
2016/04/13 13:55:10
This doesn't reference any member data in Bluetoot
Ivan Šandrk
2016/04/14 18:08:47
Done.
|
+ adapter->SetDisabled(bt_disabled); |
+} |
+ |
+} // namespace chromeos |