Commit f07ca660 authored by James Cook's avatar James Cook Committed by Chromium LUCI CQ

lacros: Add mojo API for controlling metrics upload consent, part 1

Per discussions with product and legal, we want to continue to use a
single metrics reporting / crash upload consent on Chrome OS, for both
the OS and the lacros browser. Notes at go/lacros-crash-consent

Per design doc at go/lacros-metrics-consent, the initial value is
sent as part of LacrosInitParams, which is available early in lacros
startup. Lacros then registers itself over mojo as an observer for
future changes. The observer is fired immediately when added to avoid
a possible race condition.

Future CLs will implement:
* lacros -> ash communication if the user disables metrics in browser
  settings
* Better interactions with device vs. user policy controls

Bug: 1148604, 1143851
Test: added to unit_tests and lacros_chrome_browsertests

Change-Id: Ib6431d33acab6cb8d4e95584a7d95288dc52ea27
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2570045Reviewed-by: default avatarJorge Lucangeli Obes <jorgelo@chromium.org>
Reviewed-by: default avatarErik Chen <erikchen@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#834531}
parent 9919e90d
......@@ -4581,6 +4581,8 @@ static_library("browser") {
"lacros/immersive_context_lacros.h",
"lacros/lacros_chrome_service_delegate_impl.cc",
"lacros/lacros_chrome_service_delegate_impl.h",
"lacros/metrics_reporting_observer.cc",
"lacros/metrics_reporting_observer.h",
"lacros/snap_controller_lacros.cc",
"lacros/snap_controller_lacros.h",
"lacros/system_logs/lacros_system_log_fetcher.cc",
......
......@@ -6,6 +6,7 @@
#include "base/check.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/lacros/metrics_reporting_observer.h"
#include "content/public/common/result_codes.h"
ChromeBrowserMainPartsLacros::ChromeBrowserMainPartsLacros(
......@@ -20,9 +21,12 @@ int ChromeBrowserMainPartsLacros::PreEarlyInitialization() {
if (result != content::RESULT_CODE_NORMAL_EXIT)
return result;
// The observer sets the initial metrics consent state, then observes ash
// for updates. Create it here because local state is required to check for
// policy overrides.
DCHECK(g_browser_process->local_state());
// TODO(https://crbug.com/1148604): Inherit metrics consent from ash. Do it
// here because local state is required to check for policy overrides.
metrics_reporting_observer_ = std::make_unique<MetricsReportingObserver>();
metrics_reporting_observer_->Init();
return content::RESULT_CODE_NORMAL_EXIT;
}
......@@ -5,8 +5,12 @@
#ifndef CHROME_BROWSER_CHROME_BROWSER_MAIN_PARTS_LACROS_H_
#define CHROME_BROWSER_CHROME_BROWSER_MAIN_PARTS_LACROS_H_
#include <memory>
#include "chrome/browser/chrome_browser_main_linux.h"
class MetricsReportingObserver;
// Startup and shutdown code for Lacros. See ChromeBrowserMainParts for details.
class ChromeBrowserMainPartsLacros : public ChromeBrowserMainPartsLinux {
public:
......@@ -19,6 +23,9 @@ class ChromeBrowserMainPartsLacros : public ChromeBrowserMainPartsLinux {
// ChromeBrowserMainParts:
int PreEarlyInitialization() override;
private:
std::unique_ptr<MetricsReportingObserver> metrics_reporting_observer_;
};
#endif // CHROME_BROWSER_CHROME_BROWSER_MAIN_PARTS_LACROS_H_
......@@ -1055,6 +1055,8 @@ source_set("chromeos") {
"crosapi/keystore_service_ash.h",
"crosapi/message_center_ash.cc",
"crosapi/message_center_ash.h",
"crosapi/metrics_reporting_ash.cc",
"crosapi/metrics_reporting_ash.h",
"crosapi/screen_manager_ash.cc",
"crosapi/screen_manager_ash.h",
"crosapi/select_file_ash.cc",
......@@ -3444,6 +3446,7 @@ source_set("unit_tests") {
"crosapi/account_manager_ash_unittest.cc",
"crosapi/browser_util_unittest.cc",
"crosapi/message_center_ash_unittest.cc",
"crosapi/metrics_reporting_ash_unittest.cc",
"crosapi/test_mojo_connection_manager_unittest.cc",
"crostini/ansible/ansible_management_service_unittest.cc",
"crostini/crostini_disk_unittest.cc",
......
......@@ -18,6 +18,7 @@
#include "chrome/browser/chromeos/crosapi/file_manager_ash.h"
#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/screen_manager_ash.h"
#include "chrome/browser/chromeos/crosapi/select_file_ash.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
......@@ -40,6 +41,8 @@ namespace crosapi {
AshChromeServiceImpl::AshChromeServiceImpl(
mojo::PendingReceiver<mojom::AshChromeService> pending_receiver)
: receiver_(this, std::move(pending_receiver)),
metrics_reporting_ash_(std::make_unique<MetricsReportingAsh>(
g_browser_process->local_state())),
screen_manager_ash_(std::make_unique<ScreenManagerAsh>()),
cert_database_ash_(std::make_unique<CertDatabaseAsh>()) {
// TODO(hidehiko): Remove non-critical log from here.
......@@ -105,6 +108,11 @@ void AshChromeServiceImpl::BindMessageCenter(
message_center_ash_ = std::make_unique<MessageCenterAsh>(std::move(receiver));
}
void AshChromeServiceImpl::BindMetricsReporting(
mojo::PendingReceiver<mojom::MetricsReporting> receiver) {
metrics_reporting_ash_->BindReceiver(std::move(receiver));
}
void AshChromeServiceImpl::BindSelectFile(
mojo::PendingReceiver<mojom::SelectFile> receiver) {
// TODO(https://crbug.com/1148448): Convert this to allow multiple,
......
......@@ -19,6 +19,7 @@ class FeedbackAsh;
class FileManagerAsh;
class KeystoreServiceAsh;
class MessageCenterAsh;
class MetricsReportingAsh;
class ScreenManagerAsh;
class SelectFileAsh;
......@@ -39,6 +40,8 @@ class AshChromeServiceImpl : public mojom::AshChromeService {
mojo::PendingReceiver<mojom::KeystoreService> receiver) override;
void BindMessageCenter(
mojo::PendingReceiver<mojom::MessageCenter> receiver) override;
void BindMetricsReporting(
mojo::PendingReceiver<mojom::MetricsReporting> receiver) override;
void BindScreenManager(
mojo::PendingReceiver<mojom::ScreenManager> receiver) override;
void BindSelectFile(
......@@ -66,6 +69,7 @@ class AshChromeServiceImpl : public mojom::AshChromeService {
std::unique_ptr<FileManagerAsh> file_manager_ash_;
std::unique_ptr<KeystoreServiceAsh> keystore_service_ash_;
std::unique_ptr<MessageCenterAsh> message_center_ash_;
std::unique_ptr<MetricsReportingAsh> metrics_reporting_ash_;
std::unique_ptr<ScreenManagerAsh> screen_manager_ash_;
std::unique_ptr<SelectFileAsh> select_file_ash_;
std::unique_ptr<FeedbackAsh> feedback_ash_;
......
......@@ -161,7 +161,7 @@ bool IsLacrosWindow(const aura::Window* window) {
base::flat_map<base::Token, uint32_t> GetInterfaceVersions() {
static_assert(
crosapi::mojom::AshChromeService::Version_ == 7,
crosapi::mojom::AshChromeService::Version_ == 8,
"if you add a new crosapi, please add it to the version map here");
InterfaceVersions versions;
AddVersion<crosapi::mojom::AccountManager>(&versions);
......@@ -171,6 +171,7 @@ base::flat_map<base::Token, uint32_t> GetInterfaceVersions() {
AddVersion<crosapi::mojom::FileManager>(&versions);
AddVersion<crosapi::mojom::KeystoreService>(&versions);
AddVersion<crosapi::mojom::MessageCenter>(&versions);
AddVersion<crosapi::mojom::MetricsReporting>(&versions);
AddVersion<crosapi::mojom::ScreenManager>(&versions);
AddVersion<crosapi::mojom::SnapshotCapturer>(&versions);
AddVersion<device::mojom::HidConnection>(&versions);
......
// 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/chromeos/crosapi/metrics_reporting_ash.h"
#include <utility>
#include "base/bind.h"
#include "base/check.h"
#include "chromeos/crosapi/mojom/metrics_reporting.mojom.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/prefs/pref_service.h"
namespace crosapi {
MetricsReportingAsh::MetricsReportingAsh(PrefService* local_state)
: local_state_(local_state) {
DCHECK(local_state_);
pref_change_registrar_.Init(local_state_);
// base::Unretained() is safe because PrefChangeRegistrar removes all
// observers when it is destroyed.
pref_change_registrar_.Add(metrics::prefs::kMetricsReportingEnabled,
base::Bind(&MetricsReportingAsh::NotifyObservers,
base::Unretained(this)));
}
MetricsReportingAsh::~MetricsReportingAsh() = default;
void MetricsReportingAsh::BindReceiver(
mojo::PendingReceiver<mojom::MetricsReporting> receiver) {
receivers_.Add(this, std::move(receiver));
}
void MetricsReportingAsh::AddObserver(
mojo::PendingRemote<mojom::MetricsReportingObserver> observer) {
mojo::Remote<mojom::MetricsReportingObserver> remote(std::move(observer));
// Fire the observer with the initial value.
bool enabled = IsMetricsReportingEnabled();
remote->OnMetricsReportingChanged(enabled);
// Store the observer for future notifications.
observers_.Add(std::move(remote));
}
void MetricsReportingAsh::SetMetricsReportingEnabled(
bool enabled,
SetMetricsReportingEnabledCallback callback) {
// TODO(https://crbug.com/1148604): Implement this.
NOTIMPLEMENTED();
std::move(callback).Run();
}
void MetricsReportingAsh::NotifyObservers() {
bool enabled = IsMetricsReportingEnabled();
for (auto& observer : observers_) {
observer->OnMetricsReportingChanged(enabled);
}
}
bool MetricsReportingAsh::IsMetricsReportingEnabled() const {
return local_state_->GetBoolean(metrics::prefs::kMetricsReportingEnabled);
}
} // 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.
#ifndef CHROME_BROWSER_CHROMEOS_CROSAPI_METRICS_REPORTING_ASH_H_
#define CHROME_BROWSER_CHROMEOS_CROSAPI_METRICS_REPORTING_ASH_H_
#include "chromeos/crosapi/mojom/metrics_reporting.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;
namespace crosapi {
// The ash-chrome implementation of the MetricsReporting crosapi interface.
// This class must only be used from the main thread.
class MetricsReportingAsh : public mojom::MetricsReporting {
public:
// |local_state| is injected for testing. In production it is the global
// local state PrefService, owned by g_browser_process.
explicit MetricsReportingAsh(PrefService* local_state);
MetricsReportingAsh(const MetricsReportingAsh&) = delete;
MetricsReportingAsh& operator=(const MetricsReportingAsh&) = delete;
~MetricsReportingAsh() override;
void BindReceiver(mojo::PendingReceiver<mojom::MetricsReporting> receiver);
// crosapi::mojom::MetricsReporting:
void AddObserver(
mojo::PendingRemote<mojom::MetricsReportingObserver> observer) override;
void SetMetricsReportingEnabled(
bool enabled,
SetMetricsReportingEnabledCallback callback) override;
private:
// Notifies all observers of the current metrics state.
void NotifyObservers();
// Returns whether metrics reporting is enabled.
bool IsMetricsReportingEnabled() const;
// In production, owned by g_browser_process, which outlives this object.
PrefService* const local_state_;
// Observes the metrics enabled pref.
PrefChangeRegistrar pref_change_registrar_;
// This class supports any number of connections.
mojo::ReceiverSet<mojom::MetricsReporting> receivers_;
// This class supports any number of observers.
mojo::RemoteSet<mojom::MetricsReportingObserver> observers_;
};
} // namespace crosapi
#endif // CHROME_BROWSER_CHROMEOS_CROSAPI_METRICS_REPORTING_ASH_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 "chrome/browser/chromeos/crosapi/metrics_reporting_ash.h"
#include "base/test/task_environment.h"
#include "chrome/test/base/scoped_testing_local_state.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chromeos/crosapi/mojom/message_center.mojom.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/prefs/pref_service.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::MetricsReportingObserver {
public:
TestObserver() = default;
TestObserver(const TestObserver&) = delete;
TestObserver& operator=(const TestObserver&) = delete;
~TestObserver() override = default;
// crosapi::mojom::MetricsReportingObserver:
void OnMetricsReportingChanged(bool enabled) override {
metrics_enabled_ = enabled;
}
// Public because this is test code.
base::Optional<bool> metrics_enabled_;
mojo::Receiver<mojom::MetricsReportingObserver> receiver_{this};
};
TEST(MetricsReportingAshTest, Basics) {
base::test::TaskEnvironment task_environment;
// Simulate metrics reporting enabled.
ScopedTestingLocalState local_state(TestingBrowserProcess::GetGlobal());
local_state.Get()->SetBoolean(metrics::prefs::kMetricsReportingEnabled, true);
// Construct the object under test.
MetricsReportingAsh metrics_reporting_ash(local_state.Get());
mojo::Remote<mojom::MetricsReporting> metrics_reporting_remote;
metrics_reporting_ash.BindReceiver(
metrics_reporting_remote.BindNewPipeAndPassReceiver());
// Adding an observer results in it being fired with the current state.
TestObserver observer;
metrics_reporting_remote->AddObserver(
observer.receiver_.BindNewPipeAndPassRemote());
metrics_reporting_remote.FlushForTesting();
ASSERT_TRUE(observer.metrics_enabled_.has_value());
EXPECT_TRUE(observer.metrics_enabled_.value());
// Disabling metrics reporting in ash fires the observer with the new value.
observer.metrics_enabled_.reset();
local_state.Get()->SetBoolean(metrics::prefs::kMetricsReportingEnabled,
false);
observer.receiver_.FlushForTesting();
ASSERT_TRUE(observer.metrics_enabled_.has_value());
EXPECT_FALSE(observer.metrics_enabled_.value());
// TODO(https://crbug.com/1148604): Test SetMetricsReportingConsent() once
// that function is implemented.
}
} // namespace
} // namespace crosapi
......@@ -12,13 +12,21 @@ namespace first_run {
namespace internal {
void DoPostImportPlatformSpecificTasks(Profile* profile) {
const crosapi::mojom::LacrosInitParams* init_params =
chromeos::LacrosChromeServiceImpl::Get()->init_params();
auto* lacros_service = chromeos::LacrosChromeServiceImpl::Get();
// The code below is only needed for legacy ash where the metrics reporting
// API is not available.
// TODO(https://crbug.com/1155751): Remove this check and the code below when
// all lacros clients are on OS 89 or later.
if (lacros_service->IsMetricsReportingAvailable())
return;
// Lacros skips the first run dialog because Chrome is the default browser on
// Chrome OS and metrics consent is chosen during the Chrome OS out of box
// setup experience. Lacros inherits first-run metrics consent from ash over
// mojo. After first-run lacros handles metrics consent via settings.
ChangeMetricsReportingState(init_params->ash_metrics_enabled);
ChangeMetricsReportingState(
lacros_service->init_params()->ash_metrics_enabled);
}
bool ShowPostInstallEULAIfNeeded(installer::InitialPreferences* install_prefs) {
......
// 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/optional.h"
#include "base/run_loop.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chromeos/crosapi/mojom/metrics_reporting.mojom.h"
#include "chromeos/lacros/lacros_chrome_service_impl.h"
#include "content/public/test/browser_test.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace crosapi {
namespace {
class TestObserver : public mojom::MetricsReportingObserver {
public:
TestObserver() = default;
TestObserver(const TestObserver&) = delete;
TestObserver& operator=(const TestObserver&) = delete;
~TestObserver() override = default;
// crosapi::mojom::MetricsReportingObserver:
void OnMetricsReportingChanged(bool enabled) override {
metrics_enabled_ = enabled;
if (on_changed_run_loop_)
on_changed_run_loop_->Quit();
}
// Public because this is test code.
base::Optional<bool> metrics_enabled_;
base::RunLoop* on_changed_run_loop_ = nullptr;
mojo::Receiver<mojom::MetricsReportingObserver> receiver_{this};
};
using MetricsReportingLacrosBrowserTest = InProcessBrowserTest;
IN_PROC_BROWSER_TEST_F(MetricsReportingLacrosBrowserTest, Basics) {
auto* lacros_service = chromeos::LacrosChromeServiceImpl::Get();
ASSERT_TRUE(lacros_service);
// We don't assert the initial metrics state because it might vary depending
// on the ash build type (official vs. not).
const bool ash_metrics_enabled =
lacros_service->init_params()->ash_metrics_enabled;
mojo::Remote<mojom::MetricsReporting> metrics_reporting;
lacros_service->BindMetricsReporting(
metrics_reporting.BindNewPipeAndPassReceiver());
// Adding an observer fires it.
base::RunLoop run_loop1;
TestObserver observer1;
observer1.on_changed_run_loop_ = &run_loop1;
metrics_reporting->AddObserver(
observer1.receiver_.BindNewPipeAndPassRemote());
run_loop1.Run();
ASSERT_TRUE(observer1.metrics_enabled_.has_value());
EXPECT_EQ(ash_metrics_enabled, observer1.metrics_enabled_.value());
// Adding another observer fires it as well.
base::RunLoop run_loop2;
TestObserver observer2;
observer2.on_changed_run_loop_ = &run_loop2;
metrics_reporting->AddObserver(
observer2.receiver_.BindNewPipeAndPassRemote());
run_loop2.Run();
ASSERT_TRUE(observer2.metrics_enabled_.has_value());
EXPECT_EQ(ash_metrics_enabled, observer2.metrics_enabled_.value());
// TODO(https://crbug.com/1148604): Test SetMetricsReportingConsent() once
// that function is implemented.
}
} // namespace
} // 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/metrics_reporting_observer.h"
#include "base/bind.h"
#include "chrome/browser/metrics/metrics_reporting_state.h"
#include "chromeos/lacros/lacros_chrome_service_impl.h"
MetricsReportingObserver::MetricsReportingObserver() = default;
MetricsReportingObserver::~MetricsReportingObserver() = default;
void MetricsReportingObserver::Init() {
auto* lacros_service = chromeos::LacrosChromeServiceImpl::Get();
if (!lacros_service->IsMetricsReportingAvailable()) {
LOG(WARNING) << "MetricsReporting API not available";
return;
}
// Set the initial state.
ChangeMetricsReportingState(
lacros_service->init_params()->ash_metrics_enabled);
// Add this object as an observer. The observer will fire with the current
// state in ash, to avoid races where ash might change state between the
// initial state above from lacros startup and the observer being added.
lacros_service->BindMetricsReporting(
metrics_reporting_remote_.BindNewPipeAndPassReceiver());
metrics_reporting_remote_->AddObserver(receiver_.BindNewPipeAndPassRemote());
}
void MetricsReportingObserver::OnMetricsReportingChanged(bool enabled) {
ChangeMetricsReportingState(enabled);
}
// 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_METRICS_REPORTING_OBSERVER_H_
#define CHROME_BROWSER_LACROS_METRICS_REPORTING_OBSERVER_H_
#include "chromeos/crosapi/mojom/metrics_reporting.mojom.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
// Observes ash-chrome for changes in metrics reporting consent state. The UX
// goal is to have a single "shared" metrics reporting state across the OS and
// browser. Ash owns the canonical state, so lacros observes it for changes.
class MetricsReportingObserver
: public crosapi::mojom::MetricsReportingObserver {
public:
MetricsReportingObserver();
MetricsReportingObserver(const MetricsReportingObserver&) = delete;
MetricsReportingObserver& operator=(const MetricsReportingObserver&) = delete;
~MetricsReportingObserver() override;
void Init();
// crosapi::mojom::MetricsObserver:
void OnMetricsReportingChanged(bool enabled) override;
private:
// Mojo connection to ash.
mojo::Remote<crosapi::mojom::MetricsReporting> metrics_reporting_remote_;
// Receives mojo messages from ash.
mojo::Receiver<crosapi::mojom::MetricsReportingObserver> receiver_{this};
};
#endif // CHROME_BROWSER_LACROS_METRICS_REPORTING_OBSERVER_H_
......@@ -3216,6 +3216,7 @@ if (is_chromeos_lacros) {
"../browser/lacros/keystore_service_lacros_browsertest.cc",
"../browser/lacros/media_session_lacros_browsertest.cc",
"../browser/lacros/message_center_lacros_browsertest.cc",
"../browser/lacros/metrics_reporting_lacros_browsertest.cc",
"../browser/lacros/screen_manager_lacros_browsertest.cc",
]
......
......@@ -14,6 +14,7 @@ mojom("mojom") {
"file_manager.mojom",
"keystore_service.mojom",
"message_center.mojom",
"metrics_reporting.mojom",
"notification.mojom",
"screen_manager.mojom",
"select_file.mojom",
......
......@@ -10,6 +10,7 @@ import "chromeos/crosapi/mojom/feedback.mojom";
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/screen_manager.mojom";
import "chromeos/crosapi/mojom/select_file.mojom";
import "mojo/public/mojom/base/big_string.mojom";
......@@ -40,8 +41,8 @@ struct LacrosInfo {
// milestone when you added it, to help us reason about compatibility between
// lacros-chrome and older ash-chrome binaries.
//
// Next version: 8
// Next method id: 13
// Next version: 9
// Next method id: 14
[Stable, Uuid="8b79c34f-2bf8-4499-979a-b17cac522c1e"]
interface AshChromeService {
// Binds Chrome OS Account Manager for Identity management.
......@@ -62,6 +63,11 @@ interface AshChromeService {
// Added in M86.
BindMessageCenter@3(pending_receiver<MessageCenter> receiver);
// Binds the MetricsReporting interface for metrics reporting consent.
// Added in M89.
[MinVersion=8]
BindMetricsReporting@13(pending_receiver<MetricsReporting> 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;
// Interface for observers of metrics reporting consent. Implemented by
// lacros-chrome. Used by ash-chrome to send update notifications.
[Stable, Uuid="3bfcacbc-ab16-4731-9e11-3523983915d0"]
interface MetricsReportingObserver {
// Called when the metrics reporting state changes.
OnMetricsReportingChanged@0(bool enabled);
};
// Interface for metrics reporting consent. Implemented by ash-chrome.
// Next version: 1
// Next method id: 2
[Stable, Uuid="a2336315-84ad-413f-9190-9eb2906408f6"]
interface MetricsReporting {
// Adds an observer for metrics-related state. The observer is fired
// immediately with the current state.
AddObserver@0(pending_remote<MetricsReportingObserver> observer);
// Sets the OS-level metrics reporting consent. This also affects crash
// report uploads. Lacros is allowed to do this for UX reasons. We have a
// toggle for metrics consent in lacros browser settings, in addition to the
// one in OS settings, and we want to keep both. Returns a value for possible
// future extension.
SetMetricsReportingEnabled@1(bool enabled) => ();
};
......@@ -213,6 +213,12 @@ class LacrosChromeServiceNeverBlockingState
std::move(pending_receiver));
}
void BindMetricsReportingReceiver(
mojo::PendingReceiver<crosapi::mojom::MetricsReporting> receiver) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
ash_chrome_service_->BindMetricsReporting(std::move(receiver));
}
base::WeakPtr<LacrosChromeServiceNeverBlockingState> GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
......@@ -516,6 +522,22 @@ void LacrosChromeServiceImpl::BindMediaControllerManager(
weak_sequenced_state_, std::move(remote)));
}
bool LacrosChromeServiceImpl::IsMetricsReportingAvailable() {
base::Optional<uint32_t> version = AshChromeServiceVersion();
return version && version.value() >= AshChromeService::MethodMinVersions::
kBindMetricsReportingMinVersion;
}
void LacrosChromeServiceImpl::BindMetricsReporting(
mojo::PendingReceiver<crosapi::mojom::MetricsReporting> receiver) {
DCHECK(IsMetricsReportingAvailable());
never_blocking_sequence_->PostTask(
FROM_HERE,
base::BindOnce(
&LacrosChromeServiceNeverBlockingState::BindMetricsReportingReceiver,
weak_sequenced_state_, std::move(receiver)));
}
bool LacrosChromeServiceImpl::IsCertDbAvailable() {
base::Optional<uint32_t> version = AshChromeServiceVersion();
return version &&
......
......@@ -19,6 +19,7 @@
#include "chromeos/crosapi/mojom/feedback.mojom.h"
#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/screen_manager.mojom.h"
#include "chromeos/crosapi/mojom/select_file.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
......@@ -162,6 +163,14 @@ class COMPONENT_EXPORT(CHROMEOS_LACROS) LacrosChromeServiceImpl {
void BindMediaControllerManager(
mojo::PendingReceiver<media_session::mojom::MediaControllerManager>
remote);
// Whether the MetricsReporting API is available.
bool IsMetricsReportingAvailable();
// Binds a receiver for the MetricsReporting API. May be called on any thread.
void BindMetricsReporting(
mojo::PendingReceiver<crosapi::mojom::MetricsReporting> receiver);
// cert_database_remote() can only be used when this method returns true;
bool IsCertDbAvailable();
......
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