-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Settings Split: Initial commit of InputDeviceSettingsProvider interface
Initial implementation of instantiating the InputDeviceSettingsProvider interface. This will be used by the Settings SWA to retrieve and update input device settings info. Change-Id: I866e5b3ee38593c254794ae0ae491ceb1edf1d3e Bug: b/241965700 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4234052 Reviewed-by: Zentaro Kavanagh <zentaro@chromium.org> Reviewed-by: Emily Stark <estark@chromium.org> Commit-Queue: David Padlipsky <dpad@google.com> Cr-Commit-Position: refs/heads/main@{#1107561}
- Loading branch information
1 parent
e54f862
commit ec6f43b
Showing
14 changed files
with
306 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
chrome/browser/ui/webui/settings/ash/input_device_settings/BUILD.gn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2023 The Chromium Authors | ||
# Use of this source code is governed by a BSD - style license that can be | ||
# found in the LICENSE file. | ||
|
||
import("//build/config/chromeos/ui_mode.gni") | ||
import("//mojo/public/tools/bindings/mojom.gni") | ||
|
||
assert(is_chromeos_ash) | ||
|
||
mojom("mojom") { | ||
disable_variants = true | ||
|
||
sources = [ "input_device_settings_provider.mojom" ] | ||
|
||
public_deps = [ | ||
"//ash/public/mojom:mojom", | ||
"//mojo/public/mojom/base", | ||
] | ||
} |
2 changes: 2 additions & 0 deletions
2
chrome/browser/ui/webui/settings/ash/input_device_settings/OWNERS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
per-file *.mojom=set noparent | ||
per-file *.mojom=file://ipc/SECURITY_OWNERS |
32 changes: 32 additions & 0 deletions
32
chrome/browser/ui/webui/settings/ash/input_device_settings/input_device_settings_provider.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/ui/webui/settings/ash/input_device_settings/input_device_settings_provider.h" | ||
#include "ash/constants/ash_features.h" | ||
#include "ash/public/cpp/input_device_settings_controller.h" | ||
#include "ash/public/mojom/input_device_settings.mojom.h" | ||
|
||
namespace ash::settings { | ||
|
||
InputDeviceSettingsProvider::InputDeviceSettingsProvider( | ||
InputDeviceSettingsController* controller) | ||
: controller_(controller) {} | ||
InputDeviceSettingsProvider::~InputDeviceSettingsProvider() = default; | ||
|
||
void InputDeviceSettingsProvider::BindInterface( | ||
mojo::PendingReceiver<mojom::InputDeviceSettingsProvider> receiver) { | ||
DCHECK(features::IsInputDeviceSettingsSplitEnabled()); | ||
if (receiver_.is_bound()) { | ||
receiver_.reset(); | ||
} | ||
receiver_.Bind(std::move(receiver)); | ||
} | ||
|
||
void InputDeviceSettingsProvider::GetConnectedKeyboards( | ||
GetConnectedKeyboardsCallback callback) { | ||
DCHECK(features::IsInputDeviceSettingsSplitEnabled()); | ||
std::move(callback).Run(controller_->GetConnectedKeyboards()); | ||
} | ||
|
||
} // namespace ash::settings |
38 changes: 38 additions & 0 deletions
38
chrome/browser/ui/webui/settings/ash/input_device_settings/input_device_settings_provider.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_UI_WEBUI_SETTINGS_ASH_INPUT_DEVICE_SETTINGS_INPUT_DEVICE_SETTINGS_PROVIDER_H_ | ||
#define CHROME_BROWSER_UI_WEBUI_SETTINGS_ASH_INPUT_DEVICE_SETTINGS_INPUT_DEVICE_SETTINGS_PROVIDER_H_ | ||
|
||
#include "ash/public/cpp/input_device_settings_controller.h" | ||
#include "chrome/browser/ui/webui/settings/ash/input_device_settings/input_device_settings_provider.mojom.h" | ||
#include "mojo/public/cpp/bindings/receiver.h" | ||
|
||
namespace ash::settings { | ||
|
||
class InputDeviceSettingsProvider : public mojom::InputDeviceSettingsProvider { | ||
public: | ||
explicit InputDeviceSettingsProvider( | ||
InputDeviceSettingsController* controller); | ||
|
||
~InputDeviceSettingsProvider() override; | ||
InputDeviceSettingsProvider(const InputDeviceSettingsProvider& other) = | ||
delete; | ||
InputDeviceSettingsProvider& operator=( | ||
const InputDeviceSettingsProvider& other) = delete; | ||
|
||
void BindInterface( | ||
mojo::PendingReceiver<mojom::InputDeviceSettingsProvider> receiver); | ||
|
||
// mojom::InputDeviceSettingsProvider: | ||
void GetConnectedKeyboards(GetConnectedKeyboardsCallback callback) override; | ||
|
||
private: | ||
InputDeviceSettingsController* controller_; | ||
mojo::Receiver<mojom::InputDeviceSettingsProvider> receiver_{this}; | ||
}; | ||
|
||
} // namespace ash::settings | ||
|
||
#endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_ASH_INPUT_DEVICE_SETTINGS_INPUT_DEVICE_SETTINGS_PROVIDER_H_ |
13 changes: 13 additions & 0 deletions
13
.../browser/ui/webui/settings/ash/input_device_settings/input_device_settings_provider.mojom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
module ash.settings.mojom; | ||
|
||
import "ash/public/mojom/input_device_settings.mojom"; | ||
|
||
// Interface for fetching and configuring input device settings in OSSettings. | ||
interface InputDeviceSettingsProvider { | ||
// Returns the list of currently connected keyboards. | ||
GetConnectedKeyboards() => (array<ash.mojom.Keyboard> keyboards); | ||
}; |
163 changes: 163 additions & 0 deletions
163
...er/ui/webui/settings/ash/input_device_settings/input_device_settings_provider_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/ui/webui/settings/ash/input_device_settings/input_device_settings_provider.h" | ||
|
||
#include <memory> | ||
|
||
#include "ash/constants/ash_features.h" | ||
#include "ash/public/cpp/input_device_settings_controller.h" | ||
#include "ash/public/mojom/input_device_settings.mojom-forward.h" | ||
#include "ash/public/mojom/input_device_settings.mojom-shared.h" | ||
#include "ash/public/mojom/input_device_settings.mojom.h" | ||
#include "base/containers/cxx20_erase_vector.h" | ||
#include "base/functional/bind.h" | ||
#include "base/test/scoped_feature_list.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
namespace ash::settings { | ||
namespace { | ||
const ::ash::mojom::Keyboard keyboard1 = | ||
::ash::mojom::Keyboard(/*name=*/"AT Translated Set 2", | ||
/*is_external=*/false, | ||
/*id=*/0, | ||
/*device_key=*/"fake-device-key1", | ||
/*meta_key=*/::ash::mojom::MetaKey::kLauncher, | ||
/*modifier_keys=*/{}, | ||
nullptr); | ||
const ::ash::mojom::Keyboard keyboard2 = | ||
::ash::mojom::Keyboard(/*name=*/"Logitech K580", | ||
/*is_external=*/true, | ||
/*id=*/1, | ||
/*device_key=*/"fake-device-key2", | ||
/*meta_key=*/::ash::mojom::MetaKey::kExternalMeta, | ||
/*modifier_keys=*/{}, | ||
nullptr); | ||
|
||
template <typename T> | ||
void ExpectListsEqual(std::vector<T> expected_list, | ||
std::vector<T> actual_list) { | ||
ASSERT_EQ(expected_list.size(), actual_list.size()); | ||
for (size_t i = 0; i < actual_list.size(); i++) { | ||
EXPECT_EQ(expected_list[i], actual_list[i]); | ||
} | ||
} | ||
|
||
template <typename T> | ||
std::vector<T> CloneMojomVector(const std::vector<T>& devices) { | ||
std::vector<T> devices_copy; | ||
devices_copy.reserve(devices.size()); | ||
for (const auto& device : devices) { | ||
devices_copy.push_back(device->Clone()); | ||
} | ||
return devices_copy; | ||
} | ||
|
||
class FakeInputDeviceSettingsController : public InputDeviceSettingsController { | ||
public: | ||
// InputDeviceSettingsController: | ||
std::vector<::ash::mojom::KeyboardPtr> GetConnectedKeyboards() override { | ||
return CloneMojomVector(keyboards_); | ||
} | ||
std::vector<::ash::mojom::TouchpadPtr> GetConnectedTouchpads() override { | ||
return CloneMojomVector(touchpads_); | ||
} | ||
std::vector<::ash::mojom::MousePtr> GetConnectedMice() override { | ||
return CloneMojomVector(mice_); | ||
} | ||
std::vector<::ash::mojom::PointingStickPtr> GetConnectedPointingSticks() | ||
override { | ||
return CloneMojomVector(pointing_sticks_); | ||
} | ||
|
||
void SetKeyboardSettings( | ||
DeviceId id, | ||
const ::ash::mojom::KeyboardSettings& settings) override {} | ||
void AddObserver(Observer* observer) override {} | ||
void RemoveObserver(Observer* observer) override {} | ||
|
||
void AddKeyboard(::ash::mojom::KeyboardPtr keyboard) { | ||
keyboards_.push_back(std::move(keyboard)); | ||
} | ||
void RemoveKeyboard(uint32_t device_id) { | ||
base::EraseIf(keyboards_, [device_id](const auto& keyboard) { | ||
return keyboard->id == device_id; | ||
}); | ||
} | ||
void AddMouse(::ash::mojom::MousePtr mouse) { | ||
mice_.push_back(std::move(mouse)); | ||
} | ||
void RemoveMouse(uint32_t device_id) { | ||
base::EraseIf(mice_, [device_id](const auto& mouse) { | ||
return mouse->id == device_id; | ||
}); | ||
} | ||
void AddTouchpad(::ash::mojom::TouchpadPtr touchpad) { | ||
touchpads_.push_back(std::move(touchpad)); | ||
} | ||
void RemoveTouchpad(uint32_t device_id) { | ||
base::EraseIf(touchpads_, [device_id](const auto& touchpad) { | ||
return touchpad->id == device_id; | ||
}); | ||
} | ||
void AddPointingStick(::ash::mojom::PointingStickPtr pointing_stick) { | ||
pointing_sticks_.push_back(std::move(pointing_stick)); | ||
} | ||
void RemovePointingStick(uint32_t device_id) { | ||
base::EraseIf(pointing_sticks_, [device_id](const auto& pointing_stick) { | ||
return pointing_stick->id == device_id; | ||
}); | ||
} | ||
|
||
private: | ||
std::vector<::ash::mojom::KeyboardPtr> keyboards_; | ||
std::vector<::ash::mojom::TouchpadPtr> touchpads_; | ||
std::vector<::ash::mojom::MousePtr> mice_; | ||
std::vector<::ash::mojom::PointingStickPtr> pointing_sticks_; | ||
}; | ||
|
||
} // namespace | ||
|
||
class InputDeviceSettingsProviderTest : public testing::Test { | ||
public: | ||
InputDeviceSettingsProviderTest() = default; | ||
~InputDeviceSettingsProviderTest() override = default; | ||
|
||
void SetUp() override { | ||
feature_list_ = std::make_unique<base::test::ScopedFeatureList>(); | ||
feature_list_->InitAndEnableFeature(features::kInputDeviceSettingsSplit); | ||
|
||
controller_ = std::make_unique<FakeInputDeviceSettingsController>(); | ||
provider_ = | ||
std::make_unique<InputDeviceSettingsProvider>(controller_.get()); | ||
} | ||
|
||
void TearDown() override { | ||
provider_.reset(); | ||
controller_.reset(); | ||
feature_list_.reset(); | ||
} | ||
|
||
protected: | ||
std::unique_ptr<FakeInputDeviceSettingsController> controller_; | ||
std::unique_ptr<InputDeviceSettingsProvider> provider_; | ||
std::unique_ptr<base::test::ScopedFeatureList> feature_list_; | ||
}; | ||
|
||
TEST_F(InputDeviceSettingsProviderTest, TestGetConnectedKeyboards) { | ||
std::vector<::ash::mojom::KeyboardPtr> expected_keyboards; | ||
expected_keyboards.push_back(keyboard1.Clone()); | ||
controller_->AddKeyboard(keyboard1.Clone()); | ||
provider_->GetConnectedKeyboards( | ||
base::BindOnce(ExpectListsEqual<::ash::mojom::KeyboardPtr>, | ||
CloneMojomVector(expected_keyboards))); | ||
|
||
expected_keyboards.push_back(keyboard2.Clone()); | ||
controller_->AddKeyboard(keyboard2.Clone()); | ||
provider_->GetConnectedKeyboards( | ||
base::BindOnce(ExpectListsEqual<::ash::mojom::KeyboardPtr>, | ||
CloneMojomVector(expected_keyboards))); | ||
} | ||
|
||
} // namespace ash::settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.