Skip to content

Commit

Permalink
Implement update menu to trigger Lacros Data Migration.
Browse files Browse the repository at this point in the history
If Lacros Data Migration can run, but it is not yet,
we show the "update" icon at three-dot menu.
Clicking it will check the disk space, and if it is enough
relaunch Chrome to enter Lacros Data Migration mode.
Otherwise, display the error message.

BUG=1296174
TEST=Ran locally.

Change-Id: Ied1dde0fc758b50353212d1ea2ea5ed5e9cf095d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3468884
Reviewed-by: Trent Apted <tapted@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Yuta Hijikata <ythjkt@chromium.org>
Commit-Queue: Hidehiko Abe <hidehiko@chromium.org>
Cr-Commit-Position: refs/heads/main@{#984294}
  • Loading branch information
Hidehiko Abe authored and Chromium LUCI CQ committed Mar 23, 2022
1 parent 0f6cd5b commit eb06dc9
Show file tree
Hide file tree
Showing 17 changed files with 285 additions and 40 deletions.
4 changes: 4 additions & 0 deletions chrome/app/chrome_command_ids.h
Expand Up @@ -224,6 +224,10 @@
#define IDC_CHROME_TIPS 40263
#define IDC_CHROME_WHATS_NEW 40264

#if BUILDFLAG(IS_CHROMEOS_ASH)
#define IDC_LACROS_DATA_MIGRATION 40265
#endif

// Spell-check
// Insert any additional suggestions before _LAST; these have to be consecutive.
#define IDC_SPELLCHECK_SUGGESTION_0 41000
Expand Down
8 changes: 8 additions & 0 deletions chrome/app/chromeos_strings.grdp
Expand Up @@ -4274,6 +4274,14 @@
This is taking longer than expected, you can skip or wait until it's done.
</message>

<!-- Lacros data migration triggering UI. -->
<message name="IDS_LACROS_DATA_MIGRATION_RELAUNCH" desc="Message shown as a menu to relaunch Chrome in order to trigger data migration.">
Relaunch to update
</message>
<message name="IDS_LACROS_DATA_MIGRATION_OUT_OF_DISK_ERROR_TEXT" desc="Message shown when a user clicks 'Relaunch to update' button, but failed to restart due to out of disk space.">
There isn't enough space on this device to complete this update. Clear up <ph name="NECESSARY_SPACE">$1<ex>10 MB</ex></ph> on your device and try again.
</message>

<!-- Print Job Notification -->
<message name="IDS_PRINT_JOB_NOTIFICATION_DISPLAY_SOURCE" desc="The context title of printing notification.">
Print
Expand Down
@@ -0,0 +1 @@
22d35e002ba5b79cf11750e10feeba7f56c6bd5b
@@ -0,0 +1 @@
c376bfc2362a32dc3e72a9261ea6a1d4430228f6
12 changes: 6 additions & 6 deletions chrome/browser/ash/crosapi/browser_data_migrator.h
Expand Up @@ -201,6 +201,12 @@ class BrowserDataMigratorImpl : public BrowserDataMigrator {
// Clears the value of `kMigrationStep` in Local State.
static void ClearMigrationStep(PrefService* local_state);

// Resets the number of migration attempts for the user stored in
// `kMigrationAttemptCountPref.
static void ClearMigrationAttemptCountForUser(
PrefService* local_state,
const std::string& user_id_hash);

private:
FRIEND_TEST_ALL_PREFIXES(BrowserDataMigratorImplTest,
ManipulateMigrationAttemptCount);
Expand Down Expand Up @@ -245,12 +251,6 @@ class BrowserDataMigratorImpl : public BrowserDataMigrator {
static int GetMigrationAttemptCountForUser(PrefService* local_state,
const std::string& user_id_hash);

// Resets the number of migration attempts for the user stored in
// `kMigrationAttemptCountPref.
static void ClearMigrationAttemptCountForUser(
PrefService* local_state,
const std::string& user_id_hash);

// Called from `MaybeRestartToMigrate()` to proceed with restarting to start
// the migration. It returns true if D-Bus call was successful.
static bool RestartToMigrate(const AccountId& account_id,
Expand Down
19 changes: 19 additions & 0 deletions chrome/browser/ash/crosapi/browser_util.cc
Expand Up @@ -438,6 +438,25 @@ bool IsLacrosEnabledForMigration(const User* user,
return base::FeatureList::IsEnabled(chromeos::features::kLacrosSupport);
}

bool IsProfileMigrationAvailable() {
user_manager::UserManager* user_manager = user_manager::UserManager::Get();
const user_manager::User* user = user_manager->GetPrimaryUser();
// |user| may be nullptr on unittests.
if (!user || !IsProfileMigrationEnabled(user->GetAccountId()))
return false;

if (!IsLacrosEnabledForMigration(user, PolicyInitState::kAfterInit))
return false;

// If migration is already completed, it is not necessary to run again.
if (IsProfileMigrationCompletedForUser(user_manager->GetLocalState(),
user->username_hash())) {
return false;
}

return true;
}

bool IsLacrosSupportFlagAllowed() {
return IsLacrosAllowedToBeEnabled() &&
(GetCachedLacrosAvailability() == LacrosAvailability::kUserChoice);
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/ash/crosapi/browser_util.h
Expand Up @@ -276,6 +276,9 @@ void ClearLacrosAvailabilityCacheForTest();

bool IsProfileMigrationEnabled(const AccountId& account_id);

// Returns true if the profile migration can run, but not yet completed.
bool IsProfileMigrationAvailable();

// Checks if profile migration has been completed. This is reset if profile
// migration is initiated for example due to lacros data directory being wiped.
bool IsProfileMigrationCompletedForUser(PrefService* local_state,
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/ui/BUILD.gn
Expand Up @@ -2148,6 +2148,8 @@ static_library("ui") {
"ash/assistant/search_and_assistant_enabled_checker.h",
"ash/back_gesture_contextual_nudge_delegate.cc",
"ash/back_gesture_contextual_nudge_delegate.h",
"ash/browser_data_migration_error_dialog.cc",
"ash/browser_data_migration_error_dialog.h",
"ash/calendar/calendar_client_impl.cc",
"ash/calendar/calendar_client_impl.h",
"ash/calendar/calendar_keyed_service.cc",
Expand Down
25 changes: 25 additions & 0 deletions chrome/browser/ui/ash/browser_data_migration_error_dialog.cc
@@ -0,0 +1,25 @@
// Copyright 2022 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/ui/ash/browser_data_migration_error_dialog.h"

#include <string>

#include "chrome/browser/ui/simple_message_box.h"
#include "chrome/grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/text/bytes_formatting.h"
#include "ui/gfx/native_widget_types.h"

namespace ash {

void OpenBrowserDataMigrationErrorDialog(uint64_t required_size) {
chrome::ShowWarningMessageBox(
gfx::kNullNativeWindow, std::u16string(),
l10n_util::GetStringFUTF16(
IDS_LACROS_DATA_MIGRATION_OUT_OF_DISK_ERROR_TEXT,
ui::FormatBytes(static_cast<int64_t>(required_size))));
}

} // namespace ash
18 changes: 18 additions & 0 deletions chrome/browser/ui/ash/browser_data_migration_error_dialog.h
@@ -0,0 +1,18 @@
// Copyright 2022 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_UI_ASH_BROWSER_DATA_MIGRATION_ERROR_DIALOG_H_
#define CHROME_BROWSER_UI_ASH_BROWSER_DATA_MIGRATION_ERROR_DIALOG_H_

#include <stdint.h>

namespace ash {

// Displays an error dialog to tell browser_data_migration error
// due to out-of-disk.
void OpenBrowserDataMigrationErrorDialog(uint64_t required_size);

} // namespace ash

#endif // CHROME_BROWSER_UI_ASH_BROWSER_DATA_MIGRATION_ERROR_DIALOG_H_
30 changes: 30 additions & 0 deletions chrome/browser/ui/browser_command_controller.cc
Expand Up @@ -85,10 +85,13 @@
#endif

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/crosapi/browser_data_migrator.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/ui/ash/browser_data_migration_error_dialog.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h"
#include "chrome/browser/ui/browser_commands_chromeos.h"
#include "components/session_manager/core/session_manager.h"
#include "components/user_manager/user_manager.h"
#endif

// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
Expand Down Expand Up @@ -791,6 +794,30 @@ bool BrowserCommandController::ExecuteCommandWithDisposition(
case IDC_UPGRADE_DIALOG:
OpenUpdateChromeDialog(browser_);
break;
#if BUILDFLAG(IS_CHROMEOS_ASH)
case IDC_LACROS_DATA_MIGRATION: {
auto* user_manager = user_manager::UserManager::Get();
const auto* user = user_manager->GetPrimaryUser();
DCHECK(user);
// Unset local state holding the internal state of the previous migration
// attempts used to avoid the infinite loop of the migration.
// Because user explicitly triggered the migration so we should try to
// run it always.
ash::BrowserDataMigratorImpl::ClearMigrationStep(
user_manager->GetLocalState());
ash::BrowserDataMigratorImpl::ClearMigrationAttemptCountForUser(
user_manager->GetLocalState(), user->username_hash());
ash::BrowserDataMigratorImpl::MaybeRestartToMigrateWithDiskCheck(
user->GetAccountId(), user->username_hash(),
base::BindOnce(
[](bool result, const absl::optional<uint64_t>& required_size) {
if (!result && required_size.has_value())
ash::OpenBrowserDataMigrationErrorDialog(*required_size);
}));
break;
}
#endif // BUILDFLAG(IS_CHROMEOS_ASH)

case IDC_HELP_PAGE_VIA_KEYBOARD:
ShowHelp(browser_, HELP_SOURCE_KEYBOARD);
break;
Expand Down Expand Up @@ -1162,6 +1189,9 @@ void BrowserCommandController::InitCommandState() {

// These are always enabled; the menu determines their menu item visibility.
command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true);
#if BUILDFLAG(IS_CHROMEOS_ASH)
command_updater_.UpdateCommandEnabled(IDC_LACROS_DATA_MIGRATION, true);
#endif

// Distill current page.
command_updater_.UpdateCommandEnabled(IDC_DISTILL_PAGE,
Expand Down
14 changes: 13 additions & 1 deletion chrome/browser/ui/toolbar/app_menu_icon_controller.cc
Expand Up @@ -6,6 +6,7 @@

#include "base/check_op.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/ui/global_error/global_error_service_factory.h"
Expand All @@ -14,6 +15,10 @@
#include "components/version_info/channel.h"
#include "ui/gfx/paint_vector_icon.h"

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/crosapi/browser_util.h"
#endif

namespace {

// Maps an upgrade level to a severity level. When |show_very_low_upgrade_level|
Expand Down Expand Up @@ -102,6 +107,13 @@ void AppMenuIconController::UpdateDelegate() {

AppMenuIconController::TypeAndSeverity
AppMenuIconController::GetTypeAndSeverity() const {
#if BUILDFLAG(IS_CHROMEOS_ASH)
// In ash-chrome, the upgrade icon styling is used for upgrading the browser
// from ash-chrome to lacros-chrome.
// It can be done if Profile can be migrated into Lacros.
if (crosapi::browser_util::IsProfileMigrationAvailable())
return {IconType::UPGRADE_NOTIFICATION, Severity::LOW};
#else
if (browser_defaults::kShowUpgradeMenuItem &&
upgrade_detector_->notify_upgrade()) {
UpgradeDetector::UpgradeNotificationAnnoyanceLevel level =
Expand All @@ -120,7 +132,7 @@ AppMenuIconController::GetTypeAndSeverity() const {
// and the bubble icon.
return {IconType::GLOBAL_ERROR, Severity::MEDIUM};
}

#endif
return {IconType::NONE, Severity::NONE};
}

Expand Down

0 comments on commit eb06dc9

Please sign in to comment.