Commit a63540fa authored by Nancy Wang's avatar Nancy Wang Committed by Chromium LUCI CQ

Reland "Remove the app related full restore data when the app is removed."

This reverts commit eb018628.

Reason for revert: <INSERT REASONING HERE>
The reason for https://bugs.chromium.org/p/chromium/issues/detail?id=1164559 is not because of this CL, but CL:2606404.

So I reland this CL, and will submit a CL to disable those unit tests, then fix them.

Original change's description:
> Revert "Remove the app related full restore data when the app is removed."
>
> This reverts commit 50bc0376.
>
> Reason for revert: https://bugs.chromium.org/p/chromium/issues/detail?id=1164559
>
> Original change's description:
> > Remove the app related full restore data when the app is removed.
> >
> > Add the class FullRestoreDataHandler to observe AppRegistryCache. When
> > the app is removed, remove the full restore data from both
> > FullRestoreReadHandler and FullRestoreSaveHandler.
> >
> > BUG=1146900
> >
> > Change-Id: Ie55b6310e3e302ac4829b7c76c10880928266651
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2608045
> > Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
> > Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
> > Reviewed-by: Dominick Ng <dominickn@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#841611}
>
> TBR=xiyuan@chromium.org,dominickn@chromium.org,chromium-scoped@luci-project-accounts.iam.gserviceaccount.com,nancylingwang@chromium.org
>
> Change-Id: Ib46d03a047b6c8145805ed2ba40e5c48c12d5d17
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: 1146900
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2618763
> Reviewed-by: Dale Curtis <dalecurtis@chromium.org>
> Commit-Queue: Dale Curtis <dalecurtis@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#841721}

TBR=xiyuan@chromium.org,dalecurtis@chromium.org,dominickn@chromium.org,chromium-scoped@luci-project-accounts.iam.gserviceaccount.com,nancylingwang@chromium.org

# Not skipping CQ checks because this is a reland.

Bug: 1146900
Change-Id: I1a58775fd9bd5e31062e6b43adf79a2e5cb19a7a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2619403Reviewed-by: default avatarNancy Wang <nancylingwang@chromium.org>
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841834}
parent 1a337ff9
......@@ -1460,6 +1460,8 @@ source_set("chromeos") {
"first_run/first_run.h",
"full_restore/app_launch_handler.cc",
"full_restore/app_launch_handler.h",
"full_restore/full_restore_data_handler.cc",
"full_restore/full_restore_data_handler.h",
"full_restore/full_restore_prefs.cc",
"full_restore/full_restore_prefs.h",
"full_restore/full_restore_service.cc",
......
// 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/full_restore/full_restore_data_handler.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "components/full_restore/full_restore_read_handler.h"
#include "components/full_restore/full_restore_save_handler.h"
#include "components/services/app_service/public/cpp/app_update.h"
namespace chromeos {
namespace full_restore {
FullRestoreDataHandler::FullRestoreDataHandler(Profile* profile)
: profile_(profile) {
DCHECK(
apps::AppServiceProxyFactory::IsAppServiceAvailableForProfile(profile_));
Observe(&apps::AppServiceProxyFactory::GetForProfile(profile_)
->AppRegistryCache());
}
FullRestoreDataHandler::~FullRestoreDataHandler() = default;
void FullRestoreDataHandler::OnAppUpdate(const apps::AppUpdate& update) {
if (!update.ReadinessChanged() ||
update.Readiness() != apps::mojom::Readiness::kUninstalledByUser) {
return;
}
// If the user uninstalls an app, then installs it again at the system
// startup phase, its restore data will be removed if the app isn't reopened.
::full_restore::FullRestoreReadHandler* read_handler =
::full_restore::FullRestoreReadHandler::GetInstance();
read_handler->RemoveApp(profile_->GetPath(), update.AppId());
::full_restore::FullRestoreSaveHandler::GetInstance()->RemoveApp(
profile_->GetPath(), update.AppId());
}
void FullRestoreDataHandler::OnAppRegistryCacheWillBeDestroyed(
apps::AppRegistryCache* cache) {
apps::AppRegistryCache::Observer::Observe(nullptr);
}
} // namespace full_restore
} // namespace chromeos
// 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_FULL_RESTORE_FULL_RESTORE_DATA_HANDLER_H_
#define CHROME_BROWSER_CHROMEOS_FULL_RESTORE_FULL_RESTORE_DATA_HANDLER_H_
#include "components/services/app_service/public/cpp/app_registry_cache.h"
class Profile;
namespace chromeos {
namespace full_restore {
// The FullRestoreDataHandler class observes AppRegistryCache to remove the app
// launching and app windows when the app is removed.
class FullRestoreDataHandler : public apps::AppRegistryCache::Observer {
public:
explicit FullRestoreDataHandler(Profile* profile);
~FullRestoreDataHandler() override;
FullRestoreDataHandler(const FullRestoreDataHandler&) = delete;
FullRestoreDataHandler& operator=(const FullRestoreDataHandler&) = delete;
// apps::AppRegistryCache::Observer:
void OnAppUpdate(const apps::AppUpdate& update) override;
void OnAppRegistryCacheWillBeDestroyed(
apps::AppRegistryCache* cache) override;
private:
Profile* profile_ = nullptr;
base::WeakPtrFactory<FullRestoreDataHandler> weak_ptr_factory_{this};
};
} // namespace full_restore
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_FULL_RESTORE_FULL_RESTORE_DATA_HANDLER_H_
......@@ -8,6 +8,7 @@
#include "base/strings/string_util.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/chromeos/full_restore/app_launch_handler.h"
#include "chrome/browser/chromeos/full_restore/full_restore_data_handler.h"
#include "chrome/browser/chromeos/full_restore/full_restore_prefs.h"
#include "chrome/browser/chromeos/full_restore/full_restore_service_factory.h"
#include "chrome/browser/chromeos/full_restore/new_user_restore_pref_handler.h"
......@@ -40,7 +41,9 @@ const int kMaxConsecutiveRestoreSelectionCount = 3;
FullRestoreService::FullRestoreService(Profile* profile)
: profile_(profile),
app_launch_handler_(std::make_unique<AppLaunchHandler>(profile_)) {
app_launch_handler_(std::make_unique<AppLaunchHandler>(profile_)),
restore_data_handler_(
std::make_unique<FullRestoreDataHandler>(profile_)) {
// If the system crashed before reboot, show the restore notification.
if (profile->GetLastSessionExitType() == Profile::EXIT_CRASHED) {
ShowRestoreNotification(kRestoreForCrashNotificationId);
......
......@@ -18,6 +18,7 @@ namespace chromeos {
namespace full_restore {
class AppLaunchHandler;
class FullRestoreDataHandler;
class NewUserRestorePrefHandler;
extern const char kRestoreForCrashNotificationId[];
......@@ -71,6 +72,8 @@ class FullRestoreService : public KeyedService {
// restore data.
std::unique_ptr<AppLaunchHandler> app_launch_handler_;
std::unique_ptr<FullRestoreDataHandler> restore_data_handler_;
base::WeakPtrFactory<FullRestoreService> weak_ptr_factory_{this};
};
......
......@@ -37,6 +37,15 @@ void FullRestoreReadHandler::ReadFromFile(const base::FilePath& profile_path,
std::move(callback)));
}
void FullRestoreReadHandler::RemoveApp(const base::FilePath& profile_path,
const std::string& app_id) {
auto it = profile_path_to_restore_data_.find(profile_path);
if (it == profile_path_to_restore_data_.end())
return;
it->second->RemoveApp(app_id);
}
void FullRestoreReadHandler::OnGetRestoreData(
const base::FilePath& profile_path,
Callback callback,
......
......@@ -43,6 +43,10 @@ class COMPONENT_EXPORT(FULL_RESTORE) FullRestoreReadHandler {
// calls |callback| when the reading operation is done.
void ReadFromFile(const base::FilePath& profile_path, Callback callback);
// Removes app launching and app windows for an app with the given |app_id|
// from |profile_path_to_restore_data_| for |profile_path| .
void RemoveApp(const base::FilePath& profile_path, const std::string& app_id);
private:
// Invoked when reading the restore data from |profile_path| is finished, and
// calls |callback| to notify that the reading operation is done.
......
......@@ -142,6 +142,19 @@ void FullRestoreSaveHandler::Flush(const base::FilePath& profile_path) {
weak_factory_.GetWeakPtr(), profile_path));
}
void FullRestoreSaveHandler::RemoveApp(const base::FilePath& profile_path,
const std::string& app_id) {
auto it = profile_path_to_restore_data_.find(profile_path);
if (it == profile_path_to_restore_data_.end())
return;
it->second.RemoveApp(app_id);
pending_save_profile_paths_.insert(profile_path);
MaybeStartSaveTimer();
}
void FullRestoreSaveHandler::MaybeStartSaveTimer() {
if (!save_timer_.IsRunning() && save_running_.empty()) {
save_timer_.Start(FROM_HERE, kSaveDelay,
......
......@@ -65,6 +65,10 @@ class COMPONENT_EXPORT(FULL_RESTORE) FullRestoreSaveHandler
// data.
void Flush(const base::FilePath& profile_path);
// Removes app launching and app windows for an app with the given |app_id|
// from |file_path_to_restore_data_| for |profile_path| .
void RemoveApp(const base::FilePath& profile_path, const std::string& app_id);
base::OneShotTimer* GetTimerForTesting() { return &save_timer_; }
private:
......
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