desk_model_observer.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2021 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. #ifndef COMPONENTS_DESKS_STORAGE_CORE_DESK_MODEL_OBSERVER_H_
  5. #define COMPONENTS_DESKS_STORAGE_CORE_DESK_MODEL_OBSERVER_H_
  6. #include <string>
  7. #include <vector>
  8. namespace ash {
  9. class DeskTemplate;
  10. }
  11. namespace desks_storage {
  12. // Observer for the Desk model. In the observer methods care should
  13. // be taken to not modify the model.
  14. class DeskModelObserver {
  15. public:
  16. DeskModelObserver() = default;
  17. DeskModelObserver(const DeskModelObserver&) = delete;
  18. DeskModelObserver& operator=(const DeskModelObserver&) = delete;
  19. // Invoked when the model has finished loading. Until this method is called it
  20. // is unsafe to use the model.
  21. virtual void DeskModelLoaded() = 0;
  22. // Invoked when the model is about to be destroyed. Gives observes which may
  23. // outlive the model a chance to stop observing. Not pure virtual because it
  24. // needs to be called from the destructor.
  25. virtual void OnDeskModelDestroying() {}
  26. // Invoked when desk templates are added/updated, removed remotely via sync.
  27. // This is the mechanism for the sync server to push changes in the state of
  28. // the model to clients.
  29. virtual void EntriesAddedOrUpdatedRemotely(
  30. const std::vector<const ash::DeskTemplate*>& new_entries) = 0;
  31. virtual void EntriesRemovedRemotely(
  32. const std::vector<std::string>& uuids) = 0;
  33. // Invoked when desk templates are added/updated, removed locally.
  34. virtual void EntriesAddedOrUpdatedLocally(
  35. const std::vector<const ash::DeskTemplate*>& new_entries) = 0;
  36. virtual void EntriesRemovedLocally(const std::vector<std::string>& uuids) = 0;
  37. protected:
  38. virtual ~DeskModelObserver() = default;
  39. };
  40. } // namespace desks_storage
  41. #endif // COMPONENTS_DESKS_STORAGE_CORE_DESK_MODEL_OBSERVER_H_