1 // Copyright 2017 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/permissions/fake_bluetooth_chooser_controller.h"
7 #include "base/check_op.h"
8 #include "base/notreached.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "components/strings/grit/components_strings.h"
11 #include "ui/base/l10n/l10n_util.h"
13 namespace permissions {
15 FakeBluetoothChooserController::FakeBluetoothChooserController(
16 std::vector<FakeDevice> devices)
18 l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_PROMPT,
20 devices_(std::move(devices)) {}
22 FakeBluetoothChooserController::~FakeBluetoothChooserController() {}
24 bool FakeBluetoothChooserController::ShouldShowIconBeforeText() const {
28 bool FakeBluetoothChooserController::ShouldShowReScanButton() const {
32 std::u16string FakeBluetoothChooserController::GetNoOptionsText() const {
33 return l10n_util::GetStringUTF16(
34 IDS_BLUETOOTH_DEVICE_CHOOSER_NO_DEVICES_FOUND_PROMPT);
37 std::u16string FakeBluetoothChooserController::GetOkButtonLabel() const {
38 return l10n_util::GetStringUTF16(
39 IDS_BLUETOOTH_DEVICE_CHOOSER_PAIR_BUTTON_TEXT);
42 std::pair<std::u16string, std::u16string>
43 FakeBluetoothChooserController::GetThrobberLabelAndTooltip() const {
45 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_SCANNING_LABEL),
46 l10n_util::GetStringUTF16(
47 IDS_BLUETOOTH_DEVICE_CHOOSER_SCANNING_LABEL_TOOLTIP)};
50 bool FakeBluetoothChooserController::TableViewAlwaysDisabled() const {
51 return table_view_always_disabled_;
54 size_t FakeBluetoothChooserController::NumOptions() const {
55 return devices_.size();
58 int FakeBluetoothChooserController::GetSignalStrengthLevel(size_t index) const {
59 return devices_.at(index).signal_strength;
62 std::u16string FakeBluetoothChooserController::GetOption(size_t index) const {
63 return base::ASCIIToUTF16(devices_.at(index).name);
66 bool FakeBluetoothChooserController::IsConnected(size_t index) const {
67 return devices_.at(index).connected;
70 bool FakeBluetoothChooserController::IsPaired(size_t index) const {
71 return devices_.at(index).paired;
74 void FakeBluetoothChooserController::SetBluetoothStatus(
75 BluetoothStatus status) {
76 const bool available = status != BluetoothStatus::UNAVAILABLE;
77 view()->OnAdapterEnabledChanged(available);
79 view()->OnRefreshStateChanged(status == BluetoothStatus::SCANNING);
82 void FakeBluetoothChooserController::SetBluetoothPermission(
83 bool has_permission) {
84 view()->OnAdapterAuthorizationChanged(has_permission);
87 void FakeBluetoothChooserController::AddDevice(FakeDevice device) {
88 devices_.push_back(device);
89 view()->OnOptionAdded(devices_.size() - 1);
92 void FakeBluetoothChooserController::RemoveDevice(size_t index) {
93 DCHECK_GT(devices_.size(), index);
94 devices_.erase(devices_.begin() + index);
95 view()->OnOptionRemoved(index);
98 void FakeBluetoothChooserController::UpdateDevice(size_t index,
99 FakeDevice new_device) {
100 DCHECK_GT(devices_.size(), index);
101 devices_[index] = new_device;
102 view()->OnOptionUpdated(index);
105 } // namespace permissions