OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 #ifndef CONTENT_PUBLIC_BROWSER_BLUETOOTH_CHOOSER_H_ | |
6 #define CONTENT_PUBLIC_BROWSER_BLUETOOTH_CHOOSER_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/strings/string16.h" | |
11 #include "content/common/content_export.h" | |
12 | |
13 namespace content { | |
14 | |
15 // Represents a way to ask the user to select a Bluetooth device from a list of | |
16 // options. | |
17 class CONTENT_EXPORT BluetoothChooser { | |
18 public: | |
19 class Observer { | |
20 public: | |
21 // The user cancelled the chooser instead of selecting a device. | |
22 virtual void DialogCancelled(int chooser_id) = 0; | |
23 // The user selected device |device_id|. | |
24 virtual void DeviceSelected(int chooser_id, | |
25 const std::string& device_id) = 0; | |
26 | |
27 // As the dialog implementations grow more user-visible buttons and knobs, | |
28 // those knobs will cause new functions to be called here. | |
jam
2015/08/25 15:49:21
are you certain that we will add more here? i.e. b
Jeffrey Yasskin
2015/08/25 17:13:13
Yeah, we have at least "enable the adapter", "star
Jeffrey Yasskin
2015/08/25 20:55:58
Switched to a callback.
| |
29 | |
30 protected: | |
31 ~Observer() {} | |
32 }; | |
33 | |
34 // |observer| must outlive |this|. |chooser_id| is propagated to the Observer | |
35 // methods. | |
36 BluetoothChooser(Observer* observer, int chooser_id) | |
37 : observer_(observer), chooser_id_(chooser_id) {} | |
38 virtual ~BluetoothChooser(); | |
39 | |
40 // Lets the chooser tell the user the state of the Bluetooth adapter. This | |
41 // defaults to POWERED_ON. | |
42 enum class AdapterPresence { ABSENT, POWERED_OFF, POWERED_ON }; | |
43 virtual void SetAdapterPresence(AdapterPresence presence) = 0; | |
44 | |
45 // Lets the chooser tell the user whether discovery is happening. This | |
46 // defaults to DISCOVERING. | |
47 enum class DiscoveryState { FAILED_TO_START, DISCOVERING, IDLE }; | |
48 virtual void ShowDiscoveryState(DiscoveryState state) = 0; | |
49 | |
50 // Shows a new device in the chooser. | |
51 virtual void AddDevice(const std::string& device_id, | |
52 const base::string16& device_name) = 0; | |
53 // Tells the chooser that a device is no longer available. The chooser should | |
jam
2015/08/25 15:49:21
nit: blank line before
Jeffrey Yasskin
2015/08/25 17:13:13
Done.
| |
54 // not call DeviceSelected() for a device that's been removed. | |
55 virtual void RemoveDevice(const std::string& device_id) = 0; | |
56 | |
57 protected: | |
58 // Subclasses call the observer methods through these wrappers, which add in | |
59 // the chooser ID. | |
60 void CallDialogCancelled() { observer_->DialogCancelled(chooser_id_); } | |
jam
2015/08/25 15:49:21
this is against the content style guide: https://w
Jeffrey Yasskin
2015/08/25 17:13:14
This seems in line with other interfaces in conten
Jeffrey Yasskin
2015/08/25 20:55:58
Moot, now that there's a callback.
| |
61 void CallDeviceSelected(const std::string& device_id) { | |
62 observer_->DeviceSelected(chooser_id_, device_id); | |
63 } | |
64 | |
65 private: | |
66 Observer* const observer_; | |
67 const int chooser_id_; | |
68 }; | |
69 | |
70 } // namespace content | |
71 | |
72 #endif // CONTENT_PUBLIC_BROWSER_BLUETOOTH_CHOOSER_H_ | |
OLD | NEW |