OLD | NEW |
---|---|
(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 | |
OLD | NEW |