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..5478c21b9478a6d27a36cd9c473b94040631e1e4 |
--- /dev/null |
+++ b/chrome/browser/chromeos/policy/bluetooth_policy_handler.cc |
@@ -0,0 +1,59 @@ |
+// 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 "chrome/browser/chromeos/settings/cros_settings.h" |
bartfab (slow)
2016/04/18 13:43:44
Nit: Already included by header file.
Ivan Šandrk
2016/04/18 15:09:18
Done.
|
+#include "chromeos/settings/cros_settings_names.h" |
+#include "chromeos/settings/cros_settings_provider.h" |
+#include "device/bluetooth/bluetooth_adapter_factory.h" |
+ |
+namespace chromeos { |
+ |
+namespace { |
+ |
+// Helper function used in device::BluetoothAdapterFactory::GetAdapter |
bartfab (slow)
2016/04/18 13:43:44
Nit: Comments are nice but I think this method is
Ivan Šandrk
2016/04/18 15:09:18
Done.
|
+// callback, this is the function that actually calls |Shutdown|. |
+void SetBluetoothPolicy(bool allow_bluetooth, |
+ scoped_refptr<device::BluetoothAdapter> adapter) { |
bartfab (slow)
2016/04/18 13:43:44
Nit: #include "device/bluetooth/bluetooth_adapter.
Ivan Šandrk
2016/04/18 15:09:18
Done.
|
+ // !allow_bluetooth because we have a switch in logic |
bartfab (slow)
2016/04/18 13:43:44
Nit: This is quite obvious. No need for a comment.
Ivan Šandrk
2016/04/18 15:09:18
Done.
|
+ // (allow bluetooth -> disable bluetooth) |
+ if (!allow_bluetooth) |
+ adapter->Shutdown(); |
+} |
+ |
+} // namespace |
+ |
+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())); |
+ |
+ // Fire it once so we're sure we get an invocation on startup. |
+ OnBluetoothPolicyChanged(); |
+} |
+ |
+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 = true; |
+ cros_settings_->GetBoolean(kAllowBluetooth, &allow_bluetooth); |
+ |
+ device::BluetoothAdapterFactory::GetAdapter( |
+ base::Bind(&SetBluetoothPolicy, allow_bluetooth)); |
+} |
+ |
+} // namespace chromeos |