From 5a1bfcb904fc9d2546d220a7bf3e7b205b26333a Mon Sep 17 00:00:00 2001 From: Anay Wadhera Date: Mon, 9 Sep 2024 12:57:28 -0700 Subject: [PATCH] Add a new constructor for FileAttachment to support precomputation of mime type and attachment type. PiperOrigin-RevId: 672643121 --- sharing/file_attachment.cc | 3 ++- sharing/file_attachment.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sharing/file_attachment.cc b/sharing/file_attachment.cc index 7ec995f7..3917e76e 100644 --- a/sharing/file_attachment.cc +++ b/sharing/file_attachment.cc @@ -56,10 +56,11 @@ std::string MimeTypeFromPath(const std::filesystem::path& path) { } // namespace FileAttachment::FileAttachment(std::filesystem::path file_path, + absl::string_view mime_type, std::string parent_folder, int32_t batch_id, SourceType source_type) : Attachment(Attachment::Family::kFile, /*size=*/0, batch_id, source_type), - mime_type_(MimeTypeFromPath(file_path)), + mime_type_(mime_type.empty() ? MimeTypeFromPath(file_path) : mime_type), type_(FileAttachmentTypeFromMimeType(mime_type_)), file_path_(std::move(file_path)), parent_folder_(std::move(parent_folder)) { diff --git a/sharing/file_attachment.h b/sharing/file_attachment.h index 9bc1e28e..b156b23d 100644 --- a/sharing/file_attachment.h +++ b/sharing/file_attachment.h @@ -36,6 +36,7 @@ class FileAttachment : public Attachment { using Type = nearby::sharing::service::proto::FileMetadata::Type; explicit FileAttachment(std::filesystem::path file_path, + absl::string_view mime_type = "", std::string parent_folder = "", int32_t batch_id = 0, SourceType source_type = SourceType::kUnknown); FileAttachment(int64_t id, int64_t size, std::string file_name,