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/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() { | |
ortuno
2016/04/13 21:12:21
You didn't answer atwilson's question: "Are we alw
Ivan Šandrk
2016/04/14 18:08:47
Answered it now. C/P:
No guarantee. That's why now
| |
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 = true; | |
35 cros_settings_->GetBoolean(kAllowBluetooth, &allow_bluetooth); | |
36 | |
37 // device::BluetoothAdapterFactory::GetAdapter( | |
scheib
2016/04/13 19:47:44
Don't leave commented out code.
Ivan Šandrk
2016/04/14 18:08:47
Once again sorry for the half-baked code, wanted t
| |
38 // base::Bind(&BluetoothPolicyHandler::SetBluetoothPolicy, | |
39 // weak_factory_.GetWeakPtr(), allow_bluetooth)); | |
40 device::BluetoothAdapterFactory::GetAdapter( | |
41 base::Bind(&BluetoothPolicyHandler::SetBluetoothPolicy, | |
42 nullptr, allow_bluetooth)); | |
43 } | |
44 | |
45 void BluetoothPolicyHandler::SetBluetoothPolicy( | |
46 bool allow_bluetooth, scoped_refptr<device::BluetoothAdapter> adapter) { | |
47 // !allow_bluetooth because we have a switch in logic | |
48 // (allow bluetooth -> disable bluetooth) | |
49 adapter->SetDisabled(!allow_bluetooth); | |
50 } | |
51 | |
52 } // namespace chromeos | |
OLD | NEW |