Commit de375584 authored by James Cook's avatar James Cook Committed by Commit Bot

lacros: Skip first run dialog and inherit metrics consent from ash

Lacros does not need to show the first run dialog. On Chrome OS,
metrics consent is chosen during device setup as part of the
out-of-box experience. Also, Chrome is the default browser.

However, we can't just skip the dialog. We need to respect the user's
metrics consent choice. Therefore we pass the initial value for
metrics consent from ash-chrome to lacros-chrome over mojo.

For users on an ash version that doesn't send the user's metrics
choice, continue to show the dialog.

For lacros project info, see //docs/lacros.md or go/lacros

Bug: 1129954
Change-Id: I545c9ed264c5a8c619f1ec8032dda307dee79d45
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2422475
Commit-Queue: James Cook <jamescook@chromium.org>
Reviewed-by: default avatarErik Chen <erikchen@chromium.org>
Reviewed-by: default avatarGreg Thompson <grt@chromium.org>
Reviewed-by: default avatarGreg Kerr <kerrnel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809957}
parent ac0b6058
......@@ -3994,11 +3994,15 @@ static_library("browser") {
sources += [
"chrome_browser_main_posix.cc",
"chrome_browser_main_posix.h",
"first_run/first_run_internal_posix.cc",
"importer/firefox_profile_lock_posix.cc",
"process_singleton_posix.cc",
"task_manager/sampling/shared_sampler_posix.cc",
]
# TODO(crbug.com/1052397): Rename chromeos_is_browser_only to is_lacros.
if (!chromeos_is_browser_only) {
sources += [ "first_run/first_run_internal_posix.cc" ]
}
}
}
......@@ -4347,6 +4351,7 @@ static_library("browser") {
if (chromeos_is_browser_only) {
assert(enable_native_notifications)
sources += [
"first_run/first_run_internal_lacros.cc",
"lacros/lacros_chrome_service_delegate_impl.cc",
"lacros/lacros_chrome_service_delegate_impl.h",
"metrics/lacros_metrics_provider.cc",
......
......@@ -12,10 +12,14 @@
#include "base/process/process_handle.h"
#include "base/strings/string_util.h"
#include "base/system/sys_info.h"
#include "chrome/browser/browser_process.h"
#include "chrome/common/channel_info.h"
#include "chrome/common/chrome_paths.h"
#include "chromeos/crosapi/mojom/crosapi.mojom.h"
#include "components/exo/shell_surface_util.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/user_manager/user.h"
#include "components/user_manager/user_manager.h"
#include "components/user_manager/user_type.h"
......@@ -49,6 +53,16 @@ bool IsUserTypeAllowed(const User* user) {
}
}
mojom::LacrosInitParamsPtr GetLacrosInitParams() {
auto params = mojom::LacrosInitParams::New();
params->ash_chrome_service_version =
crosapi::mojom::AshChromeService::Version_;
params->ash_metrics_enabled_has_value = true;
params->ash_metrics_enabled = g_browser_process->local_state()->GetBoolean(
metrics::prefs::kMetricsReportingEnabled);
return params;
}
} // namespace
const char kLaunchOnLoginPref[] = "lacros.launch_on_login";
......@@ -120,10 +134,7 @@ SendMojoInvitationToLacrosChrome(
invitation.AttachMessagePipe(0 /* token */), /*version=*/0));
lacros_chrome_service.set_disconnect_handler(
std::move(mojo_disconnected_callback));
auto params = crosapi::mojom::LacrosInitParams::New();
params->ash_chrome_service_version =
crosapi::mojom::AshChromeService::Version_;
lacros_chrome_service->Init(std::move(params));
lacros_chrome_service->Init(GetLacrosInitParams());
lacros_chrome_service->RequestAshChromeServiceReceiver(
std::move(ash_chrome_service_callback));
mojo::OutgoingInvitation::Send(std::move(invitation),
......
......@@ -55,8 +55,6 @@ bool IsLacrosWindow(const aura::Window* window);
// Invite the lacros-chrome to the mojo universe.
// Queue messages to establish the mojo connection, so that the passed IPC is
// available already when lacros-chrome accepts the invitation.
// TODO(crbug.com/1115092): Pass the initialization parameter over mojo
// connection.
mojo::Remote<crosapi::mojom::LacrosChromeService>
SendMojoInvitationToLacrosChrome(
mojo::PlatformChannelEndpoint local_endpoint,
......
......@@ -20,6 +20,8 @@
#include "base/test/multiprocess_test.h"
#include "base/test/task_environment.h"
#include "base/test/test_timeouts.h"
#include "chrome/test/base/scoped_testing_local_state.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chromeos/crosapi/mojom/crosapi.mojom.h"
#include "mojo/public/cpp/platform/named_platform_channel.h"
#include "mojo/public/cpp/platform/platform_channel.h"
......@@ -70,20 +72,22 @@ class TestLacrosChromeService : public crosapi::mojom::LacrosChromeService {
mojo::Remote<crosapi::mojom::AshChromeService> ash_chrome_service_;
};
class TestMojoConnectionManagerTest : public testing::Test {
public:
TestMojoConnectionManagerTest() = default;
~TestMojoConnectionManagerTest() override = default;
};
using TestMojoConnectionManagerTest = testing::Test;
TEST_F(TestMojoConnectionManagerTest, ConnectWithLacrosChrome) {
// Constructing LacrosInitParams requires local state prefs.
ScopedTestingLocalState local_state(TestingBrowserProcess::GetGlobal());
// Create temp dir before task environment, just in case lingering tasks need
// to access it.
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
// Use IO type to support the FileDescriptorWatcher API on POSIX.
base::test::TaskEnvironment task_environment{
base::test::TaskEnvironment::MainThreadType::IO};
// Ash-chrome queues an invitation, drop a socket and wait for connection.
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
std::string socket_path =
temp_dir.GetPath().MaybeAsASCII() + "/lacros.socket";
......
......@@ -17,6 +17,7 @@
#include "base/test/metrics/histogram_tester.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/component_loader.h"
#include "chrome/browser/first_run/first_run.h"
......@@ -56,7 +57,7 @@ IN_PROC_BROWSER_TEST_F(FirstRunBrowserTest, SetShouldShowWelcomePage) {
EXPECT_FALSE(ShouldShowWelcomePage());
}
#if !defined(OS_CHROMEOS)
#if !defined(OS_CHROMEOS) && !BUILDFLAG(IS_LACROS)
namespace {
// A generic test class to be subclassed by test classes testing specific
......@@ -418,6 +419,6 @@ INSTANTIATE_TEST_SUITE_P(FirstRunMasterPrefsVariationsSeedTests,
FirstRunMasterPrefsVariationsSeedTest,
testing::Bool());
#endif // !defined(OS_CHROMEOS)
#endif // !defined(OS_CHROMEOS) && !BUILDFLAG(IS_LACROS)
} // namespace first_run
// 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/first_run/first_run_internal.h"
#include "build/branding_buildflags.h"
#include "chrome/browser/first_run/first_run_dialog.h"
#include "chrome/browser/metrics/metrics_reporting_state.h"
#include "chromeos/crosapi/mojom/crosapi.mojom.h"
#include "chromeos/lacros/lacros_chrome_service_impl.h"
namespace first_run {
namespace internal {
void DoPostImportPlatformSpecificTasks(Profile* profile) {
const crosapi::mojom::LacrosInitParams* init_params =
chromeos::LacrosChromeServiceImpl::Get()->init_params();
// For old versions of ash that don't send the metrics state, always show
// the first run dialog. We don't worry about policy control because lacros
// doesn't support that yet, and this code will be removed before policy
// support is added.
// TODO(https://crbug.com/1131164): Remove after M87 beta, when all supported
// ash versions will set |ash_metrics_enabled| true or false.
if (!init_params->ash_metrics_enabled_has_value) {
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
ShowFirstRunDialog(profile);
#endif
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);
}
bool ShowPostInstallEULAIfNeeded(installer::InitialPreferences* install_prefs) {
// Just continue. The EULA is only used on Windows.
return true;
}
} // namespace internal
} // namespace first_run
......@@ -2917,7 +2917,7 @@ if (!is_android) {
if (is_mac || is_win || is_chromeos) {
sources += [ "../browser/extensions/api/networking_cast_private/networking_cast_private_apitest.cc" ]
}
if (is_desktop_linux || is_mac) {
if ((is_desktop_linux && !chromeos_is_browser_only) || is_mac) {
sources +=
[ "../browser/first_run/first_run_internal_posix_browsertest.cc" ]
}
......
......@@ -61,6 +61,17 @@ struct LacrosInitParams {
// call.
[MinVersion=1]
uint32 ash_chrome_service_version@0;
// Whether |ash_metrics_enabled| has a value. See struct comment.
[MinVersion=2]
bool ash_metrics_enabled_has_value@1;
// Whether metrics are enabled in ash-chrome. On lacros first run we inherit
// metrics consent from ash, because on Chrome OS metrics consent is chosen
// during the out-of-box experience. After first run lacros handles metrics
// consent via settings.
[MinVersion=2]
bool ash_metrics_enabled@2;
};
// LacrosChromeService defines the APIs that live in lacros-chrome and
......
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