Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: chrome/browser/chromeos/policy/bluetooth_policy_handler.cc

Issue 1784333002: Add Device Policy Handler for Bluetooth, and allow disabling the Bluetooth adapter on Chrome OS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed IsDisabled for now, added conditional compilation (cros only) Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/policy/bluetooth_policy_handler.h"
6
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "chromeos/settings/cros_settings_names.h"
10 #include "chromeos/settings/cros_settings_provider.h"
11 #include "device/bluetooth/bluetooth_adapter_factory.h"
12
13 namespace chromeos {
14
15 BluetoothPolicyHandler::BluetoothPolicyHandler(CrosSettings* cros_settings)
16 : cros_settings_(cros_settings), weak_factory_(this) {
17 bluetooth_policy_subscription_ = cros_settings_->AddSettingsObserver(
18 kAllowBluetooth,
19 base::Bind(&BluetoothPolicyHandler::OnBluetoothPolicyChanged,
20 weak_factory_.GetWeakPtr()));
21 }
22
23 BluetoothPolicyHandler::~BluetoothPolicyHandler() {}
24
25 void BluetoothPolicyHandler::OnBluetoothPolicyChanged() {
26 CrosSettingsProvider::TrustedStatus status =
27 cros_settings_->PrepareTrustedValues(
28 base::Bind(&BluetoothPolicyHandler::OnBluetoothPolicyChanged,
29 weak_factory_.GetWeakPtr()));
30 if (status != CrosSettingsProvider::TRUSTED)
31 return;
32
33 // Get the updated policy.
34 bool allow_bluetooth = false;
35 cros_settings_->GetBoolean(kAllowBluetooth, &allow_bluetooth);
36
37 // !allow_bluetooth because we have a switch in logic
38 // (allow bluetooth -> disable bluetooth)
39 device::BluetoothAdapterFactory::GetAdapter(
40 base::Bind(&BluetoothPolicyHandler::SetBluetoothPolicy,
41 weak_factory_.GetWeakPtr(), !allow_bluetooth));
42 }
43
44 void BluetoothPolicyHandler::SetBluetoothPolicy(
45 bool bt_disabled, scoped_refptr<device::BluetoothAdapter> adapter) {
46 adapter->SetDisabled(bt_disabled);
47 }
48
49 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698