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

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: Bartfab's nits 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/memory/ref_counted.h"
9 #include "chromeos/settings/cros_settings_names.h"
10 #include "chromeos/settings/cros_settings_provider.h"
11 #include "device/bluetooth/bluetooth_adapter.h"
12 #include "device/bluetooth/bluetooth_adapter_factory.h"
13
14 namespace policy {
15
16 namespace {
17
18 void SetBluetoothPolicy(bool allow_bluetooth,
19 scoped_refptr<device::BluetoothAdapter> adapter) {
20 if (!allow_bluetooth)
21 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.
22 }
23
24 } // namespace
25
26 BluetoothPolicyHandler::BluetoothPolicyHandler(
27 chromeos::CrosSettings* cros_settings)
28 : cros_settings_(cros_settings), weak_factory_(this) {
29 bluetooth_policy_subscription_ = cros_settings_->AddSettingsObserver(
30 chromeos::kAllowBluetooth,
31 base::Bind(&BluetoothPolicyHandler::OnBluetoothPolicyChanged,
32 weak_factory_.GetWeakPtr()));
33
34 // Fire it once so we're sure we get an invocation on startup.
35 OnBluetoothPolicyChanged();
36 }
37
38 BluetoothPolicyHandler::~BluetoothPolicyHandler() {}
39
40 void BluetoothPolicyHandler::OnBluetoothPolicyChanged() {
41 chromeos::CrosSettingsProvider::TrustedStatus status =
42 cros_settings_->PrepareTrustedValues(
43 base::Bind(&BluetoothPolicyHandler::OnBluetoothPolicyChanged,
44 weak_factory_.GetWeakPtr()));
45 if (status != chromeos::CrosSettingsProvider::TRUSTED)
46 return;
47
48 // Get the updated policy.
49 bool allow_bluetooth = true;
50 cros_settings_->GetBoolean(chromeos::kAllowBluetooth, &allow_bluetooth);
51
52 device::BluetoothAdapterFactory::GetAdapter(
53 base::Bind(&SetBluetoothPolicy, allow_bluetooth));
54 }
55
56 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698