OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_BLUETOOTH_BLUETOOTH_CHOOSER_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_BLUETOOTH_BLUETOOTH_CHOOSER_CONTROLLER_H_ |
6 #define CHROME_BROWSER_UI_BLUETOOTH_BLUETOOTH_CHOOSER_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_BLUETOOTH_BLUETOOTH_CHOOSER_CONTROLLER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 10 matching lines...) Expand all Loading... | |
21 // It can be used by WebBluetooth API to get the user's permission to | 21 // It can be used by WebBluetooth API to get the user's permission to |
22 // access a Bluetooth device. It is owned by ChooserBubbleDelegate. | 22 // access a Bluetooth device. It is owned by ChooserBubbleDelegate. |
23 class BluetoothChooserController : public ChooserController { | 23 class BluetoothChooserController : public ChooserController { |
24 public: | 24 public: |
25 explicit BluetoothChooserController( | 25 explicit BluetoothChooserController( |
26 content::RenderFrameHost* owner, | 26 content::RenderFrameHost* owner, |
27 const content::BluetoothChooser::EventHandler& event_handler); | 27 const content::BluetoothChooser::EventHandler& event_handler); |
28 ~BluetoothChooserController() override; | 28 ~BluetoothChooserController() override; |
29 | 29 |
30 // ChooserController: | 30 // ChooserController: |
31 bool ShouldShowIconBeforeText() const override; | |
31 base::string16 GetNoOptionsText() const override; | 32 base::string16 GetNoOptionsText() const override; |
32 base::string16 GetOkButtonLabel() const override; | 33 base::string16 GetOkButtonLabel() const override; |
33 size_t NumOptions() const override; | 34 size_t NumOptions() const override; |
35 int GetSignalStrengthLevel(size_t index) const override; | |
34 base::string16 GetOption(size_t index) const override; | 36 base::string16 GetOption(size_t index) const override; |
35 void RefreshOptions() override; | 37 void RefreshOptions() override; |
36 base::string16 GetStatus() const override; | 38 base::string16 GetStatus() const override; |
37 void Select(size_t index) override; | 39 void Select(size_t index) override; |
38 void Cancel() override; | 40 void Cancel() override; |
39 void Close() override; | 41 void Close() override; |
40 void OpenHelpCenterUrl() const override; | 42 void OpenHelpCenterUrl() const override; |
41 | 43 |
42 // Update the state of the Bluetooth adapter. | 44 // Update the state of the Bluetooth adapter. |
43 void OnAdapterPresenceChanged( | 45 void OnAdapterPresenceChanged( |
44 content::BluetoothChooser::AdapterPresence presence); | 46 content::BluetoothChooser::AdapterPresence presence); |
45 | 47 |
46 // Update the Bluetooth discovery state and let the user know whether | 48 // Update the Bluetooth discovery state and let the user know whether |
47 // discovery is happening. | 49 // discovery is happening. |
48 void OnDiscoveryStateChanged(content::BluetoothChooser::DiscoveryState state); | 50 void OnDiscoveryStateChanged(content::BluetoothChooser::DiscoveryState state); |
49 | 51 |
50 // Shows a new device in the chooser or updates its information. | 52 // Shows a new device in the chooser or updates its information. |
51 void AddOrUpdateDevice(const std::string& device_id, | 53 void AddOrUpdateDevice(const std::string& device_id, |
52 bool should_update_name, | 54 bool should_update_name, |
53 const base::string16& device_name, | 55 const base::string16& device_name, |
54 bool is_gatt_connected, | 56 bool is_gatt_connected, |
55 bool is_paired, | 57 bool is_paired, |
56 const int8_t* rssi); | 58 int signal_strength_level); |
Jeffrey Yasskin
2016/08/20 00:03:29
Say what the bounds on the signal strength are (-1
juncai
2016/08/20 01:17:02
Done.
| |
57 | 59 |
58 // Tells the chooser that a device is no longer available. | 60 // Tells the chooser that a device is no longer available. |
59 void RemoveDevice(const std::string& device_id); | 61 void RemoveDevice(const std::string& device_id); |
60 | 62 |
61 // Called when |event_handler_| is no longer valid and should not be used | 63 // Called when |event_handler_| is no longer valid and should not be used |
62 // any more. | 64 // any more. |
63 void ResetEventHandler(); | 65 void ResetEventHandler(); |
64 | 66 |
65 private: | 67 private: |
68 struct BluetoothDeviceInfo { | |
69 std::string id; | |
70 int signal_strength_level; | |
71 }; | |
72 | |
66 // Clears |device_names_and_ids_| and |device_name_counts_|. Called when | 73 // Clears |device_names_and_ids_| and |device_name_counts_|. Called when |
67 // Bluetooth adapter is turned on or off, or when re-scan happens. | 74 // Bluetooth adapter is turned on or off, or when re-scan happens. |
68 void ClearAllDevices(); | 75 void ClearAllDevices(); |
69 | 76 |
70 std::vector<std::string> device_ids_; | 77 std::vector<BluetoothDeviceInfo> devices_; |
71 std::unordered_map<std::string, base::string16> device_id_to_name_map_; | 78 std::unordered_map<std::string, base::string16> device_id_to_name_map_; |
72 // Maps from device name to number of devices with that name. | 79 // Maps from device name to number of devices with that name. |
73 std::unordered_map<base::string16, int> device_name_counts_; | 80 std::unordered_map<base::string16, int> device_name_counts_; |
74 | 81 |
75 content::BluetoothChooser::EventHandler event_handler_; | 82 content::BluetoothChooser::EventHandler event_handler_; |
76 base::string16 no_devices_text_; | 83 base::string16 no_devices_text_; |
77 base::string16 status_text_; | 84 base::string16 status_text_; |
78 | 85 |
79 DISALLOW_COPY_AND_ASSIGN(BluetoothChooserController); | 86 DISALLOW_COPY_AND_ASSIGN(BluetoothChooserController); |
80 }; | 87 }; |
81 | 88 |
82 #endif // CHROME_BROWSER_UI_BLUETOOTH_BLUETOOTH_CHOOSER_CONTROLLER_H_ | 89 #endif // CHROME_BROWSER_UI_BLUETOOTH_BLUETOOTH_CHOOSER_CONTROLLER_H_ |
OLD | NEW |