user_note.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2022 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_USER_NOTES_MODEL_USER_NOTE_H_
  5. #define COMPONENTS_USER_NOTES_MODEL_USER_NOTE_H_
  6. #include <string>
  7. #include "base/memory/safe_ref.h"
  8. #include "base/memory/weak_ptr.h"
  9. #include "base/unguessable_token.h"
  10. #include "components/user_notes/model/user_note_body.h"
  11. #include "components/user_notes/model/user_note_metadata.h"
  12. #include "components/user_notes/model/user_note_target.h"
  13. namespace user_notes {
  14. // Model class for a note.
  15. class UserNote {
  16. public:
  17. explicit UserNote(const base::UnguessableToken& id,
  18. std::unique_ptr<UserNoteMetadata> metadata,
  19. std::unique_ptr<UserNoteBody> body,
  20. std::unique_ptr<UserNoteTarget> target);
  21. ~UserNote();
  22. UserNote(const UserNote&) = delete;
  23. UserNote& operator=(const UserNote&) = delete;
  24. base::SafeRef<UserNote> GetSafeRef() const;
  25. const base::UnguessableToken& id() const { return id_; }
  26. const UserNoteMetadata& metadata() const { return *metadata_; }
  27. const UserNoteBody& body() const { return *body_; }
  28. const UserNoteTarget& target() const { return *target_; }
  29. // Consumes the provided model to update this one.
  30. void Update(std::unique_ptr<UserNote> new_model);
  31. private:
  32. // The unique (among the user's notes) ID for this note.
  33. base::UnguessableToken id_;
  34. std::unique_ptr<UserNoteMetadata> metadata_;
  35. std::unique_ptr<UserNoteBody> body_;
  36. std::unique_ptr<UserNoteTarget> target_;
  37. base::WeakPtrFactory<UserNote> weak_ptr_factory_{this};
  38. };
  39. } // namespace user_notes
  40. #endif // COMPONENTS_USER_NOTES_MODEL_USER_NOTE_H_