Chromium Code Reviews| Index: content/public/browser/bluetooth_chooser.h |
| diff --git a/content/public/browser/bluetooth_chooser.h b/content/public/browser/bluetooth_chooser.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..559e33f3ac84951995cb45af7517e963226daf2a |
| --- /dev/null |
| +++ b/content/public/browser/bluetooth_chooser.h |
| @@ -0,0 +1,72 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_PUBLIC_BROWSER_BLUETOOTH_CHOOSER_H_ |
| +#define CONTENT_PUBLIC_BROWSER_BLUETOOTH_CHOOSER_H_ |
| + |
| +#include <string> |
| + |
| +#include "base/strings/string16.h" |
| +#include "content/common/content_export.h" |
| + |
| +namespace content { |
| + |
| +// Represents a way to ask the user to select a Bluetooth device from a list of |
| +// options. |
| +class CONTENT_EXPORT BluetoothChooser { |
| + public: |
| + class Observer { |
| + public: |
| + // The user cancelled the chooser instead of selecting a device. |
| + virtual void DialogCancelled(int chooser_id) = 0; |
| + // The user selected device |device_id|. |
| + virtual void DeviceSelected(int chooser_id, |
| + const std::string& device_id) = 0; |
| + |
| + // As the dialog implementations grow more user-visible buttons and knobs, |
| + // 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.
|
| + |
| + protected: |
| + ~Observer() {} |
| + }; |
| + |
| + // |observer| must outlive |this|. |chooser_id| is propagated to the Observer |
| + // methods. |
| + BluetoothChooser(Observer* observer, int chooser_id) |
| + : observer_(observer), chooser_id_(chooser_id) {} |
| + virtual ~BluetoothChooser(); |
| + |
| + // Lets the chooser tell the user the state of the Bluetooth adapter. This |
| + // defaults to POWERED_ON. |
| + enum class AdapterPresence { ABSENT, POWERED_OFF, POWERED_ON }; |
| + virtual void SetAdapterPresence(AdapterPresence presence) = 0; |
| + |
| + // Lets the chooser tell the user whether discovery is happening. This |
| + // defaults to DISCOVERING. |
| + enum class DiscoveryState { FAILED_TO_START, DISCOVERING, IDLE }; |
| + virtual void ShowDiscoveryState(DiscoveryState state) = 0; |
| + |
| + // Shows a new device in the chooser. |
| + virtual void AddDevice(const std::string& device_id, |
| + const base::string16& device_name) = 0; |
| + // 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.
|
| + // not call DeviceSelected() for a device that's been removed. |
| + virtual void RemoveDevice(const std::string& device_id) = 0; |
| + |
| + protected: |
| + // Subclasses call the observer methods through these wrappers, which add in |
| + // the chooser ID. |
| + 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.
|
| + void CallDeviceSelected(const std::string& device_id) { |
| + observer_->DeviceSelected(chooser_id_, device_id); |
| + } |
| + |
| + private: |
| + Observer* const observer_; |
| + const int chooser_id_; |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_PUBLIC_BROWSER_BLUETOOTH_CHOOSER_H_ |