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

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

Powered by Google App Engine
This is Rietveld 408576698