app_restore_info.cc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/app_restore/app_restore_info.h"
  5. #include "base/containers/contains.h"
  6. #include "base/no_destructor.h"
  7. #include "components/account_id/account_id.h"
  8. namespace app_restore {
  9. // static
  10. AppRestoreInfo* AppRestoreInfo::GetInstance() {
  11. static base::NoDestructor<AppRestoreInfo> app_restore_info;
  12. return app_restore_info.get();
  13. }
  14. AppRestoreInfo::AppRestoreInfo() = default;
  15. AppRestoreInfo::~AppRestoreInfo() = default;
  16. void AppRestoreInfo::AddObserver(Observer* observer) {
  17. observers_.AddObserver(observer);
  18. }
  19. void AppRestoreInfo::RemoveObserver(Observer* observer) {
  20. observers_.RemoveObserver(observer);
  21. }
  22. bool AppRestoreInfo::CanPerformRestore(const AccountId& account_id) {
  23. return base::Contains(restore_prefs_, account_id);
  24. }
  25. void AppRestoreInfo::SetRestorePref(const AccountId& account_id,
  26. bool could_restore) {
  27. if (could_restore == CanPerformRestore(account_id))
  28. return;
  29. if (could_restore)
  30. restore_prefs_.insert(account_id);
  31. else
  32. restore_prefs_.erase(account_id);
  33. for (auto& observer : observers_)
  34. observer.OnRestorePrefChanged(account_id, could_restore);
  35. }
  36. void AppRestoreInfo::OnAppLaunched(aura::Window* window) {
  37. for (auto& observer : observers_)
  38. observer.OnAppLaunched(window);
  39. }
  40. void AppRestoreInfo::OnWindowInitialized(aura::Window* window) {
  41. for (auto& observer : observers_)
  42. observer.OnWindowInitialized(window);
  43. }
  44. void AppRestoreInfo::OnWidgetInitialized(views::Widget* widget) {
  45. for (auto& observer : observers_)
  46. observer.OnWidgetInitialized(widget);
  47. }
  48. void AppRestoreInfo::OnParentWindowToValidContainer(aura::Window* window) {
  49. for (auto& observer : observers_)
  50. observer.OnParentWindowToValidContainer(window);
  51. }
  52. } // namespace app_restore