Commit a2607609 authored by Joel Hockey's avatar Joel Hockey Committed by Chromium LUCI CQ

Add Prefs crosapi

Allow lacros to get, set, and be notified for changes in ash prefs.

Bug: 1161413
Bug: 1163288
Change-Id: Ie086018acf4d7fa8378a968415f76792543a2f39
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2607983
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Reviewed-by: default avatarErik Chen <erikchen@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841295}
parent 0dc7e8ba
......@@ -4611,6 +4611,8 @@ static_library("browser") {
"lacros/cert_db_initializer_impl.h",
"lacros/client_cert_store_lacros.cc",
"lacros/client_cert_store_lacros.h",
"lacros/crosapi_pref_observer.cc",
"lacros/crosapi_pref_observer.h",
"lacros/feedback_util.cc",
"lacros/feedback_util.h",
"lacros/immersive_context_lacros.cc",
......
......@@ -1075,6 +1075,8 @@ source_set("chromeos") {
"crosapi/message_center_ash.h",
"crosapi/metrics_reporting_ash.cc",
"crosapi/metrics_reporting_ash.h",
"crosapi/prefs_ash.cc",
"crosapi/prefs_ash.h",
"crosapi/screen_manager_ash.cc",
"crosapi/screen_manager_ash.h",
"crosapi/select_file_ash.cc",
......@@ -3504,6 +3506,7 @@ source_set("unit_tests") {
"crosapi/browser_util_unittest.cc",
"crosapi/message_center_ash_unittest.cc",
"crosapi/metrics_reporting_ash_unittest.cc",
"crosapi/prefs_ash_unittest.cc",
"crosapi/test_mojo_connection_manager_unittest.cc",
"crostini/ansible/ansible_management_service_unittest.cc",
"crostini/crostini_disk_unittest.cc",
......
......@@ -20,6 +20,7 @@
#include "chrome/browser/chromeos/crosapi/keystore_service_ash.h"
#include "chrome/browser/chromeos/crosapi/message_center_ash.h"
#include "chrome/browser/chromeos/crosapi/metrics_reporting_ash.h"
#include "chrome/browser/chromeos/crosapi/prefs_ash.h"
#include "chrome/browser/chromeos/crosapi/screen_manager_ash.h"
#include "chrome/browser/chromeos/crosapi/select_file_ash.h"
#include "chrome/browser/chromeos/crosapi/test_controller_ash.h"
......@@ -45,6 +46,9 @@ AshChromeServiceImpl::AshChromeServiceImpl(
: receiver_(this, std::move(pending_receiver)),
metrics_reporting_ash_(std::make_unique<MetricsReportingAsh>(
g_browser_process->local_state())),
prefs_ash_(std::make_unique<PrefsAsh>(
g_browser_process->local_state(),
ProfileManager::GetPrimaryUserProfile()->GetPrefs())),
screen_manager_ash_(std::make_unique<ScreenManagerAsh>()),
cert_database_ash_(std::make_unique<CertDatabaseAsh>()),
test_controller_ash_(std::make_unique<TestControllerAsh>()),
......@@ -175,6 +179,11 @@ void AshChromeServiceImpl::BindClipboard(
clipboard_ash_->BindReceiver(std::move(receiver));
}
void AshChromeServiceImpl::BindPrefs(
mojo::PendingReceiver<mojom::Prefs> receiver) {
prefs_ash_->BindReceiver(std::move(receiver));
}
void AshChromeServiceImpl::OnLacrosStartup(mojom::LacrosInfoPtr lacros_info) {
BrowserManager::Get()->set_lacros_version(lacros_info->lacros_version);
}
......
......@@ -21,6 +21,7 @@ class FileManagerAsh;
class KeystoreServiceAsh;
class MessageCenterAsh;
class MetricsReportingAsh;
class PrefsAsh;
class ScreenManagerAsh;
class SelectFileAsh;
class TestControllerAsh;
......@@ -47,6 +48,7 @@ class AshChromeServiceImpl : public mojom::AshChromeService {
mojo::PendingReceiver<mojom::MessageCenter> receiver) override;
void BindMetricsReporting(
mojo::PendingReceiver<mojom::MetricsReporting> receiver) override;
void BindPrefs(mojo::PendingReceiver<mojom::Prefs> receiver) override;
void BindScreenManager(
mojo::PendingReceiver<mojom::ScreenManager> receiver) override;
void BindSelectFile(
......@@ -75,6 +77,7 @@ class AshChromeServiceImpl : public mojom::AshChromeService {
std::unique_ptr<KeystoreServiceAsh> keystore_service_ash_;
std::unique_ptr<MessageCenterAsh> message_center_ash_;
std::unique_ptr<MetricsReportingAsh> metrics_reporting_ash_;
std::unique_ptr<PrefsAsh> prefs_ash_;
std::unique_ptr<ScreenManagerAsh> screen_manager_ash_;
std::unique_ptr<SelectFileAsh> select_file_ash_;
std::unique_ptr<FeedbackAsh> feedback_ash_;
......
......@@ -198,7 +198,7 @@ bool IsLacrosWindow(const aura::Window* window) {
base::flat_map<base::Token, uint32_t> GetInterfaceVersions() {
static_assert(
crosapi::mojom::AshChromeService::Version_ == 10,
crosapi::mojom::AshChromeService::Version_ == 11,
"if you add a new crosapi, please add it to the version map here");
InterfaceVersions versions;
AddVersion<crosapi::mojom::AccountManager>(&versions);
......@@ -210,6 +210,7 @@ base::flat_map<base::Token, uint32_t> GetInterfaceVersions() {
AddVersion<crosapi::mojom::KeystoreService>(&versions);
AddVersion<crosapi::mojom::MessageCenter>(&versions);
AddVersion<crosapi::mojom::MetricsReporting>(&versions);
AddVersion<crosapi::mojom::Prefs>(&versions);
AddVersion<crosapi::mojom::ScreenManager>(&versions);
AddVersion<crosapi::mojom::SnapshotCapturer>(&versions);
AddVersion<crosapi::mojom::TestController>(&versions);
......
// Copyright 2021 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.
#include "chrome/browser/chromeos/crosapi/prefs_ash.h"
#include <utility>
#include "ash/public/cpp/ash_pref_names.h"
#include "base/bind.h"
#include "base/check.h"
#include "chromeos/crosapi/mojom/prefs.mojom.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/prefs/pref_service.h"
namespace crosapi {
PrefsAsh::PrefsAsh(PrefService* local_state, PrefService* profile_prefs)
: local_state_(local_state), profile_prefs_(profile_prefs) {
DCHECK(local_state_);
DCHECK(profile_prefs_);
local_state_registrar_.Init(local_state_);
profile_prefs_registrar_.Init(profile_prefs_);
}
PrefsAsh::~PrefsAsh() = default;
void PrefsAsh::BindReceiver(mojo::PendingReceiver<mojom::Prefs> receiver) {
receivers_.Add(this, std::move(receiver));
}
void PrefsAsh::GetPref(mojom::PrefPath path, GetPrefCallback callback) {
auto state = GetState(path);
const base::Value* value =
state ? state->pref_service->Get(state->path) : nullptr;
std::move(callback).Run(value ? base::Optional<base::Value>(value->Clone())
: base::nullopt);
}
void PrefsAsh::SetPref(mojom::PrefPath path,
base::Value value,
SetPrefCallback callback) {
auto state = GetState(path);
if (state) {
state->pref_service->Set(state->path, value);
}
std::move(callback).Run();
}
void PrefsAsh::AddObserver(mojom::PrefPath path,
mojo::PendingRemote<mojom::PrefObserver> observer) {
auto state = GetState(path);
const base::Value* value =
state ? state->pref_service->Get(state->path) : nullptr;
if (!value) {
return;
}
// Fire the observer with the initial value.
mojo::Remote<mojom::PrefObserver> remote(std::move(observer));
remote->OnPrefChanged(value->Clone());
if (!state->registrar->IsObserved(state->path)) {
// Unretained() is safe since PrefChangeRegistrar and RemoteSet within
// observers_ are owned by this and wont invoke if PrefsAsh is destroyed.
state->registrar->Add(state->path,
base::BindRepeating(&PrefsAsh::OnPrefChanged,
base::Unretained(this), path));
observers_[path].set_disconnect_handler(base::BindRepeating(
&PrefsAsh::OnDisconnect, base::Unretained(this), path));
}
observers_[path].Add(std::move(remote));
}
base::Optional<PrefsAsh::State> PrefsAsh::GetState(mojom::PrefPath path) {
switch (path) {
case mojom::PrefPath::kMetricsReportingEnabled:
return State{local_state_, &local_state_registrar_,
metrics::prefs::kMetricsReportingEnabled};
case mojom::PrefPath::kAccessibilitySpokenFeedbackEnabled:
return State{profile_prefs_, &profile_prefs_registrar_,
ash::prefs::kAccessibilitySpokenFeedbackEnabled};
default:
LOG(WARNING) << "Unknown pref path: " << path;
return base::nullopt;
}
}
void PrefsAsh::OnPrefChanged(mojom::PrefPath path) {
auto state = GetState(path);
const base::Value* value =
state ? state->pref_service->Get(state->path) : nullptr;
if (value) {
for (auto& observer : observers_[path]) {
observer->OnPrefChanged(value->Clone());
}
}
}
void PrefsAsh::OnDisconnect(mojom::PrefPath path, mojo::RemoteSetElementId id) {
const auto& it = observers_.find(path);
if (it != observers_.end() && it->second.empty()) {
if (auto state = GetState(path)) {
state->registrar->Remove(state->path);
}
observers_.erase(it);
}
}
} // namespace crosapi
// Copyright 2021 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 CHROME_BROWSER_CHROMEOS_CROSAPI_PREFS_ASH_H_
#define CHROME_BROWSER_CHROMEOS_CROSAPI_PREFS_ASH_H_
#include <map>
#include <memory>
#include <utility>
#include "base/gtest_prod_util.h"
#include "base/optional.h"
#include "chromeos/crosapi/mojom/prefs.mojom.h"
#include "components/prefs/pref_change_registrar.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote_set.h"
class PrefService;
class PrefChangeRegistrar;
namespace crosapi {
// The ash-chrome implementation of the Prefs crosapi interface.
// This class must only be used from the main thread.
class PrefsAsh : public mojom::Prefs {
public:
PrefsAsh(PrefService* local_state, PrefService* profile_prefs);
PrefsAsh(const PrefsAsh&) = delete;
PrefsAsh& operator=(const PrefsAsh&) = delete;
~PrefsAsh() override;
void BindReceiver(mojo::PendingReceiver<mojom::Prefs> receiver);
// crosapi::mojom::Prefs:
void GetPref(mojom::PrefPath path, GetPrefCallback callback) override;
void SetPref(mojom::PrefPath path,
base::Value value,
SetPrefCallback callback) override;
void AddObserver(mojom::PrefPath path,
mojo::PendingRemote<mojom::PrefObserver> observer) override;
private:
FRIEND_TEST_ALL_PREFIXES(PrefsAshTest, LocalStatePrefs);
struct State {
PrefService* pref_service;
PrefChangeRegistrar* registrar;
std::string path;
};
base::Optional<State> GetState(mojom::PrefPath path);
void OnPrefChanged(mojom::PrefPath path);
void OnDisconnect(mojom::PrefPath path, mojo::RemoteSetElementId id);
// In production, owned by g_browser_process, which outlives this object.
PrefService* const local_state_;
// From GetPrimaryUserProfile()->GetPrefs(), which outlives this object.
PrefService* const profile_prefs_;
PrefChangeRegistrar local_state_registrar_;
PrefChangeRegistrar profile_prefs_registrar_;
// This class supports any number of connections.
mojo::ReceiverSet<mojom::Prefs> receivers_;
// This class supports any number of observers.
std::map<mojom::PrefPath, mojo::RemoteSet<mojom::PrefObserver>> observers_;
};
} // namespace crosapi
#endif // CHROME_BROWSER_CHROMEOS_CROSAPI_PREFS_ASH_H_
// Copyright 2021 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.
#include "chrome/browser/chromeos/crosapi/prefs_ash.h"
#include <memory>
#include "ash/public/cpp/ash_pref_names.h"
#include "base/optional.h"
#include "base/test/bind.h"
#include "chrome/test/base/scoped_testing_local_state.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
#include "content/public/test/browser_task_environment.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace crosapi {
namespace {
class TestObserver : public mojom::PrefObserver {
public:
TestObserver() = default;
TestObserver(const TestObserver&) = delete;
TestObserver& operator=(const TestObserver&) = delete;
~TestObserver() override = default;
// crosapi::mojom::PrefObserver:
void OnPrefChanged(base::Value value) override { value_ = std::move(value); }
base::Optional<base::Value> value_;
mojo::Receiver<mojom::PrefObserver> receiver_{this};
};
} // namespace
class PrefsAshTest : public testing::Test {
public:
PrefsAshTest()
: scoped_testing_local_state_(TestingBrowserProcess::GetGlobal()),
local_state_(scoped_testing_local_state_.Get()),
profile_prefs_(profile_.GetPrefs()) {}
PrefsAshTest(const PrefsAshTest&) = delete;
PrefsAshTest& operator=(const PrefsAshTest&) = delete;
~PrefsAshTest() override = default;
content::BrowserTaskEnvironment task_environment_;
ScopedTestingLocalState scoped_testing_local_state_;
TestingProfile profile_;
PrefService* const local_state_;
PrefService* const profile_prefs_;
};
TEST_F(PrefsAshTest, LocalStatePrefs) {
local_state_->SetBoolean(metrics::prefs::kMetricsReportingEnabled, false);
PrefsAsh prefs_ash(local_state_, profile_prefs_);
mojo::Remote<mojom::Prefs> prefs_remote;
prefs_ash.BindReceiver(prefs_remote.BindNewPipeAndPassReceiver());
mojom::PrefPath path = mojom::PrefPath::kMetricsReportingEnabled;
// Get returns value.
base::Value get_value;
prefs_remote->GetPref(
path, base::BindLambdaForTesting([&](base::Optional<base::Value> value) {
get_value = std::move(*value);
}));
prefs_remote.FlushForTesting();
EXPECT_FALSE(get_value.GetBool());
// Set updates value.
prefs_remote->SetPref(path, base::Value(true), base::DoNothing());
prefs_remote.FlushForTesting();
EXPECT_TRUE(
local_state_->GetBoolean(metrics::prefs::kMetricsReportingEnabled));
// Adding an observer results in it being fired with the current state.
EXPECT_FALSE(prefs_ash.local_state_registrar_.IsObserved(
metrics::prefs::kMetricsReportingEnabled));
auto observer1 = std::make_unique<TestObserver>();
prefs_remote->AddObserver(path,
observer1->receiver_.BindNewPipeAndPassRemote());
prefs_remote.FlushForTesting();
EXPECT_TRUE(observer1->value_->GetBool());
EXPECT_TRUE(prefs_ash.local_state_registrar_.IsObserved(
metrics::prefs::kMetricsReportingEnabled));
EXPECT_EQ(1, prefs_ash.observers_[path].size());
// Multiple observers is ok.
auto observer2 = std::make_unique<TestObserver>();
prefs_remote->AddObserver(path,
observer2->receiver_.BindNewPipeAndPassRemote());
prefs_remote.FlushForTesting();
EXPECT_TRUE(observer2->value_->GetBool());
EXPECT_EQ(2, prefs_ash.observers_[path].size());
// Observer should be notified when value changes.
local_state_->SetBoolean(metrics::prefs::kMetricsReportingEnabled, false);
task_environment_.RunUntilIdle();
EXPECT_FALSE(observer1->value_->GetBool());
EXPECT_FALSE(observer2->value_->GetBool());
// Disconnect should remove PrefChangeRegistrar.
observer1.reset();
prefs_remote.FlushForTesting();
EXPECT_EQ(1, prefs_ash.observers_[path].size());
observer2.reset();
prefs_remote.FlushForTesting();
EXPECT_EQ(0, prefs_ash.observers_[path].size());
EXPECT_FALSE(prefs_ash.local_state_registrar_.IsObserved(
metrics::prefs::kMetricsReportingEnabled));
}
TEST_F(PrefsAshTest, ProfilePrefs) {
profile_prefs_->SetBoolean(ash::prefs::kAccessibilitySpokenFeedbackEnabled,
false);
PrefsAsh prefs_ash(local_state_, profile_prefs_);
mojo::Remote<mojom::Prefs> prefs_remote;
prefs_ash.BindReceiver(prefs_remote.BindNewPipeAndPassReceiver());
mojom::PrefPath path = mojom::PrefPath::kAccessibilitySpokenFeedbackEnabled;
// Get returns value.
base::Value get_value;
prefs_remote->GetPref(
path, base::BindLambdaForTesting([&](base::Optional<base::Value> value) {
get_value = std::move(*value);
}));
prefs_remote.FlushForTesting();
EXPECT_FALSE(get_value.GetBool());
// Set updates value.
prefs_remote->SetPref(path, base::Value(true), base::DoNothing());
prefs_remote.FlushForTesting();
EXPECT_TRUE(profile_prefs_->GetBoolean(
ash::prefs::kAccessibilitySpokenFeedbackEnabled));
// Adding an observer results in it being fired with the current state.
TestObserver observer;
prefs_remote->AddObserver(path,
observer.receiver_.BindNewPipeAndPassRemote());
prefs_remote.FlushForTesting();
EXPECT_TRUE(observer.value_->GetBool());
}
TEST_F(PrefsAshTest, GetUnknown) {
PrefsAsh prefs_ash(local_state_, profile_prefs_);
mojo::Remote<mojom::Prefs> prefs_remote;
prefs_ash.BindReceiver(prefs_remote.BindNewPipeAndPassReceiver());
mojom::PrefPath path = mojom::PrefPath::kUnknown;
// Get for an unknown value returns base::nullopt.
bool has_value = true;
prefs_remote->GetPref(
path, base::BindLambdaForTesting([&](base::Optional<base::Value> value) {
has_value = value.has_value();
}));
prefs_remote.FlushForTesting();
EXPECT_FALSE(has_value);
// Set or AddObserver for an unknown value does nothing.
prefs_remote->SetPref(path, base::Value(false), base::DoNothing());
TestObserver observer;
prefs_remote->AddObserver(path,
observer.receiver_.BindNewPipeAndPassRemote());
prefs_remote.FlushForTesting();
EXPECT_FALSE(observer.value_.has_value());
}
} // namespace crosapi
// Copyright 2020 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.
#include "chrome/browser/lacros/crosapi_pref_observer.h"
#include "base/callback.h"
#include "chromeos/lacros/lacros_chrome_service_impl.h"
CrosapiPrefObserver::CrosapiPrefObserver(crosapi::mojom::PrefPath path,
PrefChangedCallback callback)
: callback_(std::move(callback)) {
auto* lacros_service = chromeos::LacrosChromeServiceImpl::Get();
if (!lacros_service->IsPrefsAvailable()) {
LOG(WARNING) << "crosapi: Prefs API not available";
return;
}
lacros_service->prefs_remote()->AddObserver(
path, receiver_.BindNewPipeAndPassRemote());
}
CrosapiPrefObserver::~CrosapiPrefObserver() = default;
void CrosapiPrefObserver::OnPrefChanged(base::Value value) {
callback_.Run(std::move(value));
}
// Copyright 2020 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 CHROME_BROWSER_LACROS_CROSAPI_PREF_OBSERVER_H_
#define CHROME_BROWSER_LACROS_CROSAPI_PREF_OBSERVER_H_
#include "base/callback_forward.h"
#include "base/gtest_prod_util.h"
#include "base/values.h"
#include "chromeos/crosapi/mojom/prefs.mojom.h"
#include "mojo/public/cpp/bindings/receiver.h"
// Helper to simplify the crosapi::mojom::PrefObserver API.
// Observes ash-chrome for changes in specified pref.
class CrosapiPrefObserver : public crosapi::mojom::PrefObserver {
public:
using PrefChangedCallback = base::RepeatingCallback<void(base::Value value)>;
CrosapiPrefObserver(crosapi::mojom::PrefPath path,
PrefChangedCallback callback);
CrosapiPrefObserver(const CrosapiPrefObserver&) = delete;
CrosapiPrefObserver& operator=(const CrosapiPrefObserver&) = delete;
~CrosapiPrefObserver() override;
private:
FRIEND_TEST_ALL_PREFIXES(CrosapiPrefObserverLacrosBrowserTest, Basics);
// crosapi::mojom::PrefObserver:
void OnPrefChanged(base::Value value) override;
PrefChangedCallback callback_;
// Receives mojo messages from ash.
mojo::Receiver<crosapi::mojom::PrefObserver> receiver_{this};
};
#endif // CHROME_BROWSER_LACROS_CROSAPI_PREF_OBSERVER_H_
// Copyright 2020 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.
#include "base/run_loop.h"
#include "base/test/bind.h"
#include "base/values.h"
#include "chrome/browser/lacros/crosapi_pref_observer.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "content/public/test/browser_test.h"
using CrosapiPrefObserverLacrosBrowserTest = InProcessBrowserTest;
// Tests multiple observers reading ash::kAccessibilitySpokenFeedbackEnabled.
// TODO(crbug.com/1157314): Not safe to run with other test since this assumes
// the pref is false and does not change during test.
IN_PROC_BROWSER_TEST_F(CrosapiPrefObserverLacrosBrowserTest, Basics) {
// Register an observer.
bool value1 = true;
base::RunLoop run_loop1;
CrosapiPrefObserver observer1(
crosapi::mojom::PrefPath::kAccessibilitySpokenFeedbackEnabled,
base::BindLambdaForTesting([&](base::Value value) {
value1 = value.GetBool();
run_loop1.Quit();
}));
run_loop1.Run();
EXPECT_FALSE(value1);
// Additional observers are OK.
bool value2 = true;
base::RunLoop run_loop2;
CrosapiPrefObserver observer2(
crosapi::mojom::PrefPath::kAccessibilitySpokenFeedbackEnabled,
base::BindLambdaForTesting([&](base::Value value) {
value2 = value.GetBool();
run_loop2.Quit();
}));
run_loop2.Run();
EXPECT_FALSE(value2);
// OnPrefChanged should fire callback.
observer1.OnPrefChanged(base::Value(true));
EXPECT_TRUE(value1);
EXPECT_FALSE(value2);
}
......@@ -3238,6 +3238,7 @@ if (is_chromeos_lacros) {
"../browser/lacros/browser_test_util.cc",
"../browser/lacros/browser_test_util.h",
"../browser/lacros/clipboard_lacros_browsertest.cc",
"../browser/lacros/crosapi_pref_observer_lacros_browsertest.cc",
"../browser/lacros/file_manager_lacros_browsertest.cc",
"../browser/lacros/keystore_service_lacros_browsertest.cc",
"../browser/lacros/media_session_lacros_browsertest.cc",
......
......@@ -17,6 +17,7 @@ mojom("mojom") {
"message_center.mojom",
"metrics_reporting.mojom",
"notification.mojom",
"prefs.mojom",
"screen_manager.mojom",
"select_file.mojom",
"test_controller.mojom",
......
......@@ -12,6 +12,7 @@ import "chromeos/crosapi/mojom/file_manager.mojom";
import "chromeos/crosapi/mojom/keystore_service.mojom";
import "chromeos/crosapi/mojom/message_center.mojom";
import "chromeos/crosapi/mojom/metrics_reporting.mojom";
import "chromeos/crosapi/mojom/prefs.mojom";
import "chromeos/crosapi/mojom/screen_manager.mojom";
import "chromeos/crosapi/mojom/select_file.mojom";
import "chromeos/crosapi/mojom/test_controller.mojom";
......@@ -43,8 +44,8 @@ struct LacrosInfo {
// milestone when you added it, to help us reason about compatibility between
// lacros-chrome and older ash-chrome binaries.
//
// Next version: 11
// Next method id: 16
// Next version: 12
// Next method id: 17
[Stable, Uuid="8b79c34f-2bf8-4499-979a-b17cac522c1e"]
interface AshChromeService {
// Binds Chrome OS Account Manager for Identity management.
......@@ -79,6 +80,10 @@ interface AshChromeService {
[MinVersion=8]
BindMetricsReporting@13(pending_receiver<MetricsReporting> receiver);
// Binds the prefs service which allows get, set, and notify update of prefs.
// Added in M89.
[MinVersion=11] BindPrefs@16(pending_receiver<Prefs> receiver);
// Binds the ScreenManager interface for interacting with windows, screens and
// displays.
// Added in M86.
......
// Copyright 2020 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.
module crosapi.mojom;
import "mojo/public/mojom/base/values.mojom";
// Pref paths.
[Stable, Extensible]
enum PrefPath {
kUnknown = 0,
// M89: metrics::prefs::kMetricsReportingEnabled (local state).
kMetricsReportingEnabled = 1,
// M89: ash::prefs::kAccessibilitySpokenFeedbackEnabled (profile).
kAccessibilitySpokenFeedbackEnabled = 2,
};
// Interface for pref observers. Implemented by lacros-chrome. Used by
// ash-chrome to send pref updates.
[Stable, Uuid="07d804d1-3d8d-4da1-b9b9-05f8a6bfe4c4"]
interface PrefObserver {
// Called when an observed pref changes.
OnPrefChanged@0(mojo_base.mojom.Value value);
};
// Interface for prefs. Implemented by ash-chrome.
// Next version: 1
// Next method id: 3
[Stable, Uuid="815df607-0596-46f7-9ed9-14683b4826a3"]
interface Prefs {
// Gets the specified ash pref. Returns empty if ash-chrome does not have path
// registered, or if the pref is not found.
GetPref@0(PrefPath path) => (mojo_base.mojom.Value? value);
// Sets the specified ash pref. Does nothing if ash-chrome does not have path
// registered.
SetPref@1(PrefPath path, mojo_base.mojom.Value value) => ();
// Adds an observer for ash pref. The observer is fired immediately with the
// current value. Multiple observers may be registered for any given pref.
// Does nothing if ash-chrome does not have path registered.
AddObserver@2(PrefPath path, pending_remote<PrefObserver> observer);
};
......@@ -244,6 +244,12 @@ class LacrosChromeServiceNeverBlockingState
ash_chrome_service_->BindMetricsReporting(std::move(receiver));
}
void BindPrefsReceiver(
mojo::PendingReceiver<crosapi::mojom::Prefs> pending_receiver) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
ash_chrome_service_->BindPrefs(std::move(pending_receiver));
}
void BindTestControllerReceiver(
mojo::PendingReceiver<crosapi::mojom::TestController> pending_receiver) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
......@@ -454,6 +460,16 @@ void LacrosChromeServiceImpl::BindReceiver(
&LacrosChromeServiceNeverBlockingState::BindClipboardReceiver,
weak_sequenced_state_, std::move(pending_receiver)));
}
if (IsPrefsAvailable()) {
mojo::PendingReceiver<crosapi::mojom::Prefs> pending_receiver =
prefs_remote_.BindNewPipeAndPassReceiver();
never_blocking_sequence_->PostTask(
FROM_HERE,
base::BindOnce(
&LacrosChromeServiceNeverBlockingState::BindPrefsReceiver,
weak_sequenced_state_, std::move(pending_receiver)));
}
}
// static
......@@ -625,6 +641,13 @@ bool LacrosChromeServiceImpl::IsCertDbAvailable() {
AshChromeService::MethodMinVersions::kBindCertDatabaseMinVersion;
}
bool LacrosChromeServiceImpl::IsPrefsAvailable() {
base::Optional<uint32_t> version = AshChromeServiceVersion();
return version &&
version.value() >=
AshChromeService::MethodMinVersions::kBindPrefsMinVersion;
}
bool LacrosChromeServiceImpl::IsOnLacrosStartupAvailable() {
base::Optional<uint32_t> version = AshChromeServiceVersion();
return version &&
......
......@@ -20,6 +20,7 @@
#include "chromeos/crosapi/mojom/keystore_service.mojom.h"
#include "chromeos/crosapi/mojom/message_center.mojom.h"
#include "chromeos/crosapi/mojom/metrics_reporting.mojom.h"
#include "chromeos/crosapi/mojom/prefs.mojom.h"
#include "chromeos/crosapi/mojom/screen_manager.mojom.h"
#include "chromeos/crosapi/mojom/select_file.mojom.h"
#include "chromeos/crosapi/mojom/test_controller.mojom.h"
......@@ -213,6 +214,17 @@ class COMPONENT_EXPORT(CHROMEOS_LACROS) LacrosChromeServiceImpl {
return clipboard_remote_;
}
// Whether the Prefs API is available.
bool IsPrefsAvailable();
// This must be called on the affine sequence. It exposes a remote that can
// be used to interface with Prefs.
mojo::Remote<crosapi::mojom::Prefs>& prefs_remote() {
DCHECK_CALLED_ON_VALID_SEQUENCE(affine_sequence_checker_);
DCHECK(IsPrefsAvailable());
return prefs_remote_;
}
// --------------------------------------------------------------------------
// Some clients will want to use mojo::Remotes on arbitrary sequences (e.g.
// background threads). The following methods allow the client to construct a
......@@ -307,6 +319,7 @@ class COMPONENT_EXPORT(CHROMEOS_LACROS) LacrosChromeServiceImpl {
mojo::Remote<crosapi::mojom::FileManager> file_manager_remote_;
mojo::Remote<crosapi::mojom::TestController> test_controller_remote_;
mojo::Remote<crosapi::mojom::Clipboard> clipboard_remote_;
mojo::Remote<crosapi::mojom::Prefs> prefs_remote_;
// This member is instantiated on the affine sequence alongside the
// constructor. All subsequent invocations of this member, including
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment