mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
Remove std::filesystem from nearby/sharing.
PiperOrigin-RevId: 761743090
This commit is contained in:
committed by
Copybara-Service
parent
e822493662
commit
90b7e76a24
@@ -36,11 +36,23 @@ std::wstring FilePath::ToWideString() const {
|
||||
return path_.wstring();
|
||||
}
|
||||
|
||||
bool FilePath::IsEmpty() const {
|
||||
return path_.empty();
|
||||
}
|
||||
|
||||
FilePath& FilePath::append(const FilePath& subpath) {
|
||||
path_ /= subpath.path_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
FilePath FilePath::GetFileName() const {
|
||||
return FromPath(path_.filename());
|
||||
}
|
||||
|
||||
FilePath FilePath::GetExtension() const {
|
||||
return FromPath(path_.extension());
|
||||
}
|
||||
|
||||
FilePath FilePath::GetParentPath() const {
|
||||
return FilePath(path_.parent_path().wstring());
|
||||
}
|
||||
|
||||
@@ -48,9 +48,19 @@ class FilePath {
|
||||
// Returns the path as a unicode string.
|
||||
std::wstring ToWideString() const;
|
||||
|
||||
// Returns true if the path is empty.
|
||||
bool IsEmpty() const;
|
||||
|
||||
// Appends the given `subpath` to this path using a path separator..
|
||||
FilePath& append(const FilePath& subpath);
|
||||
|
||||
// Returns the last component of this path.
|
||||
FilePath GetFileName() const;
|
||||
|
||||
// Returns the extension of the last component of this path.
|
||||
// The return extension includes the "." prefix.
|
||||
FilePath GetExtension() const;
|
||||
|
||||
// Returns the path of the parent directory of this path.
|
||||
FilePath GetParentPath() const;
|
||||
|
||||
@@ -59,6 +69,12 @@ class FilePath {
|
||||
|
||||
friend auto operator<=>(const FilePath& lhs, const FilePath& rhs) = default;
|
||||
|
||||
// Hash function for absl containers.
|
||||
template <typename H>
|
||||
friend H AbslHashValue(H h, const FilePath& path) {
|
||||
return H::combine(std::move(h), path.path_);
|
||||
}
|
||||
|
||||
private:
|
||||
std::filesystem::path path_;
|
||||
};
|
||||
|
||||
@@ -69,6 +69,27 @@ TEST(FilePathTest, FromUnicodeLinuxToWideString) {
|
||||
EXPECT_EQ(path.ToWideString(), L"/usr/local/home/奥巴马/Documents");
|
||||
}
|
||||
|
||||
TEST(FilePathTest, IsEmptySuccess) {
|
||||
FilePath path;
|
||||
EXPECT_TRUE(path.IsEmpty());
|
||||
FilePath path2("/usr/local/home/奥巴马/Documents/test.pdf");
|
||||
EXPECT_FALSE(path2.IsEmpty());
|
||||
}
|
||||
|
||||
TEST(FilePathTest, GetExtensionEmpty) {
|
||||
FilePath path("/usr/local/home/test/Documents/test.");
|
||||
EXPECT_EQ(path.GetExtension().ToString(), ".");
|
||||
}
|
||||
|
||||
TEST(FilePathTest, GetExtensionSuccess) {
|
||||
FilePath path("/usr/local/home/test/Documents/test.奥巴马");
|
||||
EXPECT_EQ(path.GetExtension().ToString(), ".奥巴马");
|
||||
}
|
||||
TEST(FilePathTest, GetFileNameSuccess) {
|
||||
FilePath path("/usr/local/home/test/奥巴马.pdf");
|
||||
EXPECT_EQ(path.GetFileName().ToString(), "奥巴马.pdf");
|
||||
}
|
||||
|
||||
TEST(FilePathTest, AppendSuccess) {
|
||||
FilePath path("/usr/local/home/奥巴马/Documents");
|
||||
FilePath sub_path("贝拉克/temp");
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "internal/base/files.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <filesystem> // NOLINT(build/c++17)
|
||||
#include <optional>
|
||||
@@ -130,4 +131,14 @@ bool CopyFileSafely(const std::filesystem::path& old_path,
|
||||
return true;
|
||||
}
|
||||
|
||||
std::optional<size_t> GetAvailableDiskSpaceInBytes(const FilePath& path) {
|
||||
std::error_code error_code;
|
||||
std::filesystem::space_info space_info =
|
||||
std::filesystem::space(path.GetPath(), error_code);
|
||||
if (error_code.value() == 0) {
|
||||
return space_info.available;
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
} // namespace nearby::sharing
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#ifndef THIRD_PARTY_NEARBY_INTERNAL_BASE_FILES_H_
|
||||
#define THIRD_PARTY_NEARBY_INTERNAL_BASE_FILES_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <filesystem> // NOLINT(build/c++17)
|
||||
#include <optional>
|
||||
@@ -65,6 +66,11 @@ bool CreateHardLink(const std::filesystem::path& target,
|
||||
bool CopyFileSafely(const std::filesystem::path& old_path,
|
||||
const std::filesystem::path& new_path);
|
||||
|
||||
// Returns the available disk space in bytes for the given path.
|
||||
// Returns nullopt if the path does not exist or if the space cannot be
|
||||
// determined.
|
||||
std::optional<size_t> GetAvailableDiskSpaceInBytes(const FilePath& path);
|
||||
|
||||
} // namespace nearby::sharing
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_INTERNAL_BASE_FILES_H_
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "internal/platform/device_info_impl.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <filesystem> // NOLINT
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
@@ -78,13 +77,7 @@ FilePath DeviceInfoImpl::GetLogPath() const {
|
||||
|
||||
std::optional<size_t> DeviceInfoImpl::GetAvailableDiskSpaceInBytes(
|
||||
const FilePath& path) const {
|
||||
std::error_code error_code;
|
||||
std::filesystem::space_info space_info =
|
||||
std::filesystem::space(path.GetPath(), error_code);
|
||||
if (error_code.value() == 0) {
|
||||
return space_info.available;
|
||||
}
|
||||
return std::nullopt;
|
||||
return nearby::sharing::GetAvailableDiskSpaceInBytes(path);
|
||||
}
|
||||
|
||||
bool DeviceInfoImpl::IsScreenLocked() const {
|
||||
|
||||
+9
-5
@@ -18,10 +18,10 @@ cc_library(
|
||||
name = "connection_types",
|
||||
hdrs = ["nearby_connections_types.h"],
|
||||
deps = [
|
||||
"//internal/base:file_path",
|
||||
"//internal/base:files",
|
||||
"//internal/crypto_cros", # buildcleaner: keep
|
||||
"//internal/interop:authentication_status",
|
||||
"//sharing/common:compatible_u8_string",
|
||||
"@com_google_absl//absl/random",
|
||||
"@com_google_absl//absl/strings:string_view",
|
||||
"@com_google_absl//absl/time",
|
||||
@@ -51,9 +51,9 @@ cc_library(
|
||||
"//sharing:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
"//internal/base:file_path",
|
||||
"//internal/network:url",
|
||||
"//proto:sharing_enums_cc_proto",
|
||||
"//sharing/common:compatible_u8_string",
|
||||
"//sharing/common:enum",
|
||||
"//sharing/internal/base",
|
||||
"//sharing/proto:wire_format_cc_proto",
|
||||
@@ -85,11 +85,11 @@ cc_library(
|
||||
],
|
||||
deps = [
|
||||
":connection_types",
|
||||
"//internal/base:file_path",
|
||||
"//internal/network:url",
|
||||
"//sharing/common:enum",
|
||||
"//sharing/internal/public:logging",
|
||||
"//sharing/proto:enums_cc_proto",
|
||||
"//sharing/proto:wire_format_cc_proto",
|
||||
"@com_google_absl//absl/container:flat_hash_set",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_absl//absl/strings:str_format",
|
||||
@@ -224,7 +224,6 @@ cc_library(
|
||||
"//proto:sharing_enums_cc_proto",
|
||||
"//sharing/analytics",
|
||||
"//sharing/certificates",
|
||||
"//sharing/common:compatible_u8_string",
|
||||
"//sharing/internal/api:platform",
|
||||
"//sharing/internal/public:logging",
|
||||
"//sharing/proto:enums_cc_proto",
|
||||
@@ -318,6 +317,7 @@ cc_library(
|
||||
"//internal/base",
|
||||
"//internal/base:bluetooth_address",
|
||||
"//internal/base:file_path",
|
||||
"//internal/base:files",
|
||||
"//internal/flags:nearby_flags",
|
||||
"//internal/network:url",
|
||||
"//internal/platform:base",
|
||||
@@ -328,7 +328,6 @@ cc_library(
|
||||
"//sharing/analytics",
|
||||
"//sharing/certificates",
|
||||
"//sharing/common",
|
||||
"//sharing/common:compatible_u8_string",
|
||||
"//sharing/common:enum",
|
||||
"//sharing/contacts",
|
||||
"//sharing/fast_initiation:nearby_fast_initiation",
|
||||
@@ -380,6 +379,7 @@ cc_library(
|
||||
":transfer_metadata",
|
||||
":types",
|
||||
"//internal/base",
|
||||
"//internal/base:file_path",
|
||||
"//internal/platform:types",
|
||||
"//sharing/common:enum",
|
||||
"//sharing/internal/api:platform",
|
||||
@@ -533,6 +533,8 @@ cc_test(
|
||||
":connection_types",
|
||||
":nearby_sharing_service",
|
||||
":types",
|
||||
"//internal/base:file_path",
|
||||
"//internal/base:files",
|
||||
"//internal/flags:nearby_flags",
|
||||
"//internal/platform/implementation/g3", # fixdeps: keep
|
||||
"//internal/test",
|
||||
@@ -788,6 +790,7 @@ cc_test(
|
||||
deps = [
|
||||
":attachment_compare",
|
||||
":attachments",
|
||||
"//internal/base:file_path",
|
||||
"//proto:sharing_enums_cc_proto",
|
||||
"@com_github_protobuf_matchers//protobuf-matchers",
|
||||
"@com_google_googletest//:gtest_main",
|
||||
@@ -820,6 +823,7 @@ cc_test(
|
||||
":transfer_metadata_matchers",
|
||||
":types",
|
||||
"//internal/analytics:mock_event_logger",
|
||||
"//internal/base:file_path",
|
||||
"//internal/network:url",
|
||||
"//internal/platform/implementation/g3", # fixdeps: keep
|
||||
"//internal/test",
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
#include "sharing/attachment_container.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <filesystem> // NOLINT
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "protobuf-matchers/protocol-buffer-matchers.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "proto/sharing_enums.pb.h"
|
||||
#include "sharing/attachment_compare.h" // IWYU pragma: keep
|
||||
#include "sharing/file_attachment.h"
|
||||
@@ -62,8 +62,7 @@ class AttachmentContainerTest : public ::testing::Test {
|
||||
nearby::sharing::service::proto::WifiCredentialsMetadata::WPA_PSK,
|
||||
"somepassword", true, /*batch_id=*/99707L,
|
||||
AttachmentSourceType::ATTACHMENT_SOURCE_PASTE) {
|
||||
file1_.set_file_path(
|
||||
std::filesystem::u8path("/usr/local/tmp/someFileName.jpg"));
|
||||
file1_.set_file_path(FilePath{"/usr/local/tmp/someFileName.jpg"});
|
||||
}
|
||||
|
||||
TextAttachment text1_;
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <filesystem> // NOLINT(build/c++17)
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
@@ -30,6 +29,7 @@
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "sharing/common/nearby_share_enums.h"
|
||||
#include "sharing/internal/public/logging.h"
|
||||
#include "sharing/nearby_connections_manager.h"
|
||||
@@ -316,20 +316,19 @@ void FakeNearbyConnectionsManager::SetCustomSavePath(
|
||||
custom_save_path_ = custom_save_path;
|
||||
}
|
||||
|
||||
absl::flat_hash_set<std::filesystem::path>
|
||||
absl::flat_hash_set<FilePath>
|
||||
FakeNearbyConnectionsManager::GetAndClearUnknownFilePathsToDelete() {
|
||||
absl::flat_hash_set<std::filesystem::path> file_paths_to_delete =
|
||||
file_paths_to_delete_;
|
||||
absl::flat_hash_set<FilePath> file_paths_to_delete = file_paths_to_delete_;
|
||||
file_paths_to_delete_.clear();
|
||||
return file_paths_to_delete;
|
||||
}
|
||||
|
||||
absl::flat_hash_set<std::filesystem::path>
|
||||
absl::flat_hash_set<FilePath>
|
||||
FakeNearbyConnectionsManager::GetUnknownFilePathsToDeleteForTesting() {
|
||||
return file_paths_to_delete_;
|
||||
}
|
||||
void FakeNearbyConnectionsManager::AddUnknownFilePathsToDeleteForTesting(
|
||||
std::filesystem::path file_path) {
|
||||
FilePath file_path) {
|
||||
file_paths_to_delete_.insert(file_path);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <filesystem> // NOLINT(build/c++17)
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
@@ -31,7 +30,9 @@
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "sharing/common/nearby_share_enums.h"
|
||||
#include "sharing/nearby_connection.h"
|
||||
#include "sharing/nearby_connections_manager.h"
|
||||
#include "sharing/nearby_connections_types.h"
|
||||
|
||||
@@ -74,8 +75,7 @@ class FakeNearbyConnectionsManager : public NearbyConnectionsManager {
|
||||
absl::string_view endpoint_id) override;
|
||||
void UpgradeBandwidth(absl::string_view endpoint_id) override;
|
||||
void SetCustomSavePath(absl::string_view custom_save_path) override;
|
||||
absl::flat_hash_set<std::filesystem::path>
|
||||
GetAndClearUnknownFilePathsToDelete() override;
|
||||
absl::flat_hash_set<FilePath> GetAndClearUnknownFilePathsToDelete() override;
|
||||
|
||||
// Testing methods
|
||||
void SetRawAuthenticationToken(absl::string_view endpoint_id,
|
||||
@@ -134,9 +134,8 @@ class FakeNearbyConnectionsManager : public NearbyConnectionsManager {
|
||||
return !incoming_payloads_.empty();
|
||||
}
|
||||
|
||||
absl::flat_hash_set<std::filesystem::path>
|
||||
GetUnknownFilePathsToDeleteForTesting();
|
||||
void AddUnknownFilePathsToDeleteForTesting(std::filesystem::path file_path);
|
||||
absl::flat_hash_set<FilePath> GetUnknownFilePathsToDeleteForTesting();
|
||||
void AddUnknownFilePathsToDeleteForTesting(FilePath file_path);
|
||||
|
||||
// Add `connection` to list of connections as if it was accepted.
|
||||
void AcceptConnection(std::vector<uint8_t> endpoint_info,
|
||||
@@ -183,7 +182,7 @@ class FakeNearbyConnectionsManager : public NearbyConnectionsManager {
|
||||
mutable absl::Mutex incoming_payloads_mutex_;
|
||||
std::map<int64_t, std::unique_ptr<Payload>> incoming_payloads_
|
||||
ABSL_GUARDED_BY(incoming_payloads_mutex_);
|
||||
absl::flat_hash_set<std::filesystem::path> file_paths_to_delete_;
|
||||
absl::flat_hash_set<FilePath> file_paths_to_delete_;
|
||||
std::string Dump() const override;
|
||||
};
|
||||
|
||||
|
||||
@@ -15,16 +15,15 @@
|
||||
#include "sharing/file_attachment.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <filesystem> // NOLINT(build/c++17)
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/strings/match.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "proto/sharing_enums.pb.h"
|
||||
#include "sharing/attachment.h"
|
||||
#include "sharing/common/compatible_u8_string.h"
|
||||
#include "sharing/common/nearby_share_enums.h"
|
||||
#include "sharing/internal/base/mime.h"
|
||||
#include "sharing/proto/wire_format.pb.h"
|
||||
@@ -49,8 +48,8 @@ FileAttachment::Type FileAttachmentTypeFromMimeType(
|
||||
return service::proto::FileMetadata::UNKNOWN;
|
||||
}
|
||||
|
||||
std::string MimeTypeFromPath(const std::filesystem::path& path) {
|
||||
std::string extension = path.extension().string();
|
||||
std::string MimeTypeFromPath(const FilePath& path) {
|
||||
std::string extension = path.GetExtension().ToString();
|
||||
return extension.empty() ? "application/octet-stream"
|
||||
: nearby::utils::GetWellKnownMimeTypeFromExtension(
|
||||
extension.substr(1));
|
||||
@@ -58,17 +57,15 @@ std::string MimeTypeFromPath(const std::filesystem::path& path) {
|
||||
|
||||
} // namespace
|
||||
|
||||
FileAttachment::FileAttachment(std::filesystem::path file_path,
|
||||
absl::string_view mime_type,
|
||||
FileAttachment::FileAttachment(FilePath file_path, absl::string_view mime_type,
|
||||
std::string parent_folder, int32_t batch_id,
|
||||
AttachmentSourceType source_type)
|
||||
: Attachment(Attachment::Family::kFile, /*size=*/0, batch_id, source_type),
|
||||
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)) {
|
||||
file_name_ =
|
||||
GetCompatibleU8String(file_path_.value_or(L"").filename().u8string());
|
||||
file_name_ = file_path.GetFileName().ToString();
|
||||
file_path_ = std::move(file_path);
|
||||
}
|
||||
|
||||
FileAttachment::FileAttachment(int64_t id, int64_t size, std::string file_name,
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
#define THIRD_PARTY_NEARBY_SHARING_FILE_ATTACHMENT_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <filesystem> // NOLINT(build/c++17)
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#if defined(_WIN32)
|
||||
#if defined(PLATFORM_UNKNOWN)
|
||||
#define UNDEF_PLATFORM_UNKNOWN
|
||||
@@ -49,7 +49,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 = "",
|
||||
FilePath file_path, absl::string_view mime_type = "",
|
||||
std::string parent_folder = "", int32_t batch_id = 0,
|
||||
location::nearby::proto::sharing::AttachmentSourceType source_type =
|
||||
location::nearby::proto::sharing::ATTACHMENT_SOURCE_UNKNOWN);
|
||||
@@ -68,7 +68,7 @@ class FileAttachment : public Attachment {
|
||||
absl::string_view mime_type() const { return mime_type_; }
|
||||
absl::string_view parent_folder() const { return parent_folder_; }
|
||||
Type type() const { return type_; }
|
||||
const std::optional<std::filesystem::path>& file_path() const {
|
||||
const std::optional<FilePath>& file_path() const {
|
||||
return file_path_;
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ class FileAttachment : public Attachment {
|
||||
absl::string_view GetDescription() const override;
|
||||
ShareType GetShareType() const override;
|
||||
|
||||
void set_file_path(std::optional<std::filesystem::path> path) {
|
||||
void set_file_path(std::optional<FilePath> path) {
|
||||
file_path_ = std::move(path);
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ class FileAttachment : public Attachment {
|
||||
std::string file_name_;
|
||||
std::string mime_type_;
|
||||
Type type_;
|
||||
std::optional<std::filesystem::path> file_path_;
|
||||
std::optional<FilePath> file_path_;
|
||||
std::string parent_folder_;
|
||||
};
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "sharing/incoming_share_session.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <filesystem> // NOLINT
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
@@ -32,7 +31,6 @@
|
||||
#include "internal/platform/task_runner.h"
|
||||
#include "sharing/analytics/analytics_recorder.h"
|
||||
#include "sharing/attachment_container.h"
|
||||
#include "sharing/common/compatible_u8_string.h"
|
||||
#include "sharing/constants.h"
|
||||
#include "sharing/file_attachment.h"
|
||||
#include "sharing/internal/public/logging.h"
|
||||
@@ -307,9 +305,8 @@ bool IncomingShareSession::UpdateFilePayloadPaths() {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto file_path = incoming_payload->content.file_payload.file.path;
|
||||
VLOG(1) << __func__ << ": Updated file_path="
|
||||
<< GetCompatibleU8String(file_path.u8string());
|
||||
FilePath file_path = incoming_payload->content.file_payload.file.path;
|
||||
VLOG(1) << __func__ << ": Updated file_path=" << file_path.ToString();
|
||||
file.set_file_path(file_path);
|
||||
}
|
||||
return result;
|
||||
@@ -406,7 +403,7 @@ std::vector<FilePath> IncomingShareSession::GetPayloadFilePaths()
|
||||
attachment_payload_map();
|
||||
for (const auto& file : container.GetFileAttachments()) {
|
||||
if (!file.file_path().has_value()) continue;
|
||||
FilePath file_path = FilePath::FromPath(*file.file_path());
|
||||
FilePath file_path = *file.file_path();
|
||||
VLOG(1) << __func__ << ": file_path=" << file_path.ToString();
|
||||
if (attachment_paylod_map.find(file.id()) == attachment_paylod_map.end()) {
|
||||
continue;
|
||||
|
||||
@@ -90,7 +90,7 @@ constexpr absl::string_view kEndpointId = "ABCD";
|
||||
std::unique_ptr<Payload> CreateFilePayload(int64_t payload_id,
|
||||
FilePath file_path) {
|
||||
auto file_payload =
|
||||
std::make_unique<Payload>(InputFile(file_path.GetPath()));
|
||||
std::make_unique<Payload>(InputFile(file_path.ToString()));
|
||||
file_payload->id = payload_id;
|
||||
return file_payload;
|
||||
}
|
||||
@@ -887,10 +887,10 @@ TEST_F(IncomingShareSessionTest, PayloadTransferUpdateCompleteWithSuccess) {
|
||||
EXPECT_THAT(*metadata, HasStatus(TransferMetadata::Status::kComplete));
|
||||
EXPECT_THAT(
|
||||
session_.attachment_container().GetFileAttachments()[0].file_path(),
|
||||
Eq(file1_path.GetPath()));
|
||||
Eq(file1_path));
|
||||
EXPECT_THAT(
|
||||
session_.attachment_container().GetFileAttachments()[1].file_path(),
|
||||
Eq(file2_path.GetPath()));
|
||||
Eq(file2_path));
|
||||
EXPECT_THAT(
|
||||
session_.attachment_container().GetTextAttachments()[0].text_body(),
|
||||
Eq(text_content1));
|
||||
@@ -969,10 +969,10 @@ TEST_F(IncomingShareSessionTest, PayloadTransferUpdateCancelled) {
|
||||
EXPECT_THAT(*metadata, HasStatus(TransferMetadata::Status::kCancelled));
|
||||
EXPECT_THAT(
|
||||
session_.attachment_container().GetFileAttachments()[0].file_path(),
|
||||
Eq(file1_path.GetPath()));
|
||||
Eq(file1_path));
|
||||
EXPECT_THAT(
|
||||
session_.attachment_container().GetFileAttachments()[1].file_path(),
|
||||
Eq(file2_path.GetPath()));
|
||||
Eq(file2_path));
|
||||
EXPECT_THAT(
|
||||
connections_manager_.connection_endpoint_info(kEndpointId).has_value(),
|
||||
IsTrue());
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <filesystem> // NOLINT(build/c++17)
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
@@ -27,6 +26,7 @@
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/span.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "sharing/common/nearby_share_enums.h"
|
||||
#include "sharing/nearby_connection.h"
|
||||
#include "sharing/nearby_connections_types.h"
|
||||
@@ -157,7 +157,7 @@ class NearbyConnectionsManager {
|
||||
virtual void SetCustomSavePath(absl::string_view custom_save_path) = 0;
|
||||
|
||||
// Gets the file paths to delete and clear the hash set.
|
||||
virtual absl::flat_hash_set<std::filesystem::path>
|
||||
virtual absl::flat_hash_set<FilePath>
|
||||
GetAndClearUnknownFilePathsToDelete() = 0;
|
||||
|
||||
// Dump internal state for debugging purposes.
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <filesystem> // NOLINT(build/c++17)
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
@@ -28,10 +27,10 @@
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "absl/functional/bind_front.h"
|
||||
#include "absl/meta/type_traits.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "absl/types/span.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "internal/flags/nearby_flags.h"
|
||||
#include "internal/platform/device_info.h"
|
||||
#include "internal/platform/mutex_lock.h"
|
||||
@@ -825,7 +824,7 @@ void NearbyConnectionsManagerImpl::DeleteUnknownFilePayloadAndCancel(
|
||||
|
||||
void NearbyConnectionsManagerImpl::ProcessUnknownFilePathsToDelete(
|
||||
PayloadStatus status, PayloadContent::Type type,
|
||||
const std::filesystem::path& path) {
|
||||
const FilePath& path) {
|
||||
// Unknown payload comes as kInProgress and kCanceled status with kFile type
|
||||
// from NearbyConnections. Delete it.
|
||||
if ((status == PayloadStatus::kCanceled ||
|
||||
@@ -977,13 +976,13 @@ void NearbyConnectionsManagerImpl::SetCustomSavePath(
|
||||
});
|
||||
}
|
||||
|
||||
absl::flat_hash_set<std::filesystem::path>
|
||||
absl::flat_hash_set<FilePath>
|
||||
NearbyConnectionsManagerImpl::GetUnknownFilePathsToDelete() {
|
||||
MutexLock lock(&mutex_);
|
||||
return file_paths_to_delete_;
|
||||
}
|
||||
|
||||
absl::flat_hash_set<std::filesystem::path>
|
||||
absl::flat_hash_set<FilePath>
|
||||
NearbyConnectionsManagerImpl::GetAndClearUnknownFilePathsToDelete() {
|
||||
MutexLock lock(&mutex_);
|
||||
auto file_paths_to_delete = std::move(file_paths_to_delete_);
|
||||
@@ -991,20 +990,19 @@ NearbyConnectionsManagerImpl::GetAndClearUnknownFilePathsToDelete() {
|
||||
return file_paths_to_delete;
|
||||
}
|
||||
|
||||
absl::flat_hash_set<std::filesystem::path>
|
||||
absl::flat_hash_set<FilePath>
|
||||
NearbyConnectionsManagerImpl::GetUnknownFilePathsToDeleteForTesting() {
|
||||
return GetUnknownFilePathsToDelete();
|
||||
}
|
||||
|
||||
void NearbyConnectionsManagerImpl::AddUnknownFilePathsToDeleteForTesting(
|
||||
std::filesystem::path file_path) {
|
||||
FilePath file_path) {
|
||||
MutexLock lock(&mutex_);
|
||||
file_paths_to_delete_.insert(file_path);
|
||||
}
|
||||
|
||||
void NearbyConnectionsManagerImpl::ProcessUnknownFilePathsToDeleteForTesting(
|
||||
PayloadStatus status, PayloadContent::Type type,
|
||||
const std::filesystem::path& path) {
|
||||
PayloadStatus status, PayloadContent::Type type, const FilePath& path) {
|
||||
ProcessUnknownFilePathsToDelete(status, type, path);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <filesystem> // NOLINT(build/c++17)
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
@@ -27,6 +26,7 @@
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "internal/platform/device_info.h"
|
||||
#include "internal/platform/mutex.h"
|
||||
#include "internal/platform/task_runner.h"
|
||||
@@ -87,20 +87,18 @@ class NearbyConnectionsManagerImpl : public NearbyConnectionsManager {
|
||||
absl::string_view endpoint_id) override;
|
||||
void UpgradeBandwidth(absl::string_view endpoint_id) override;
|
||||
void SetCustomSavePath(absl::string_view custom_save_path) override;
|
||||
absl::flat_hash_set<std::filesystem::path>
|
||||
GetAndClearUnknownFilePathsToDelete() override;
|
||||
absl::flat_hash_set<FilePath> GetAndClearUnknownFilePathsToDelete() override;
|
||||
std::string Dump() const override;
|
||||
|
||||
NearbyConnectionsService* GetNearbyConnectionsService() const {
|
||||
return nearby_connections_service_.get();
|
||||
}
|
||||
|
||||
absl::flat_hash_set<std::filesystem::path>
|
||||
GetUnknownFilePathsToDeleteForTesting();
|
||||
void AddUnknownFilePathsToDeleteForTesting(std::filesystem::path file_path);
|
||||
void ProcessUnknownFilePathsToDeleteForTesting(
|
||||
PayloadStatus status, PayloadContent::Type type,
|
||||
const std::filesystem::path& path);
|
||||
absl::flat_hash_set<FilePath> GetUnknownFilePathsToDeleteForTesting();
|
||||
void AddUnknownFilePathsToDeleteForTesting(FilePath file_path);
|
||||
void ProcessUnknownFilePathsToDeleteForTesting(PayloadStatus status,
|
||||
PayloadContent::Type type,
|
||||
const FilePath& path);
|
||||
void OnPayloadTransferUpdateForTesting(absl::string_view endpoint_id,
|
||||
const PayloadTransferUpdate& update);
|
||||
void OnPayloadReceivedForTesting(absl::string_view endpoint_id,
|
||||
@@ -129,9 +127,9 @@ class NearbyConnectionsManagerImpl : public NearbyConnectionsManager {
|
||||
ConnectionsStatus status);
|
||||
void ProcessUnknownFilePathsToDelete(PayloadStatus status,
|
||||
PayloadContent::Type type,
|
||||
const std::filesystem::path& path);
|
||||
const FilePath& path);
|
||||
void DeleteUnknownFilePayloadAndCancel(Payload& payload);
|
||||
absl::flat_hash_set<std::filesystem::path> GetUnknownFilePathsToDelete();
|
||||
absl::flat_hash_set<FilePath> GetUnknownFilePathsToDelete();
|
||||
|
||||
std::optional<std::weak_ptr<PayloadStatusListener>> GetStatusListenerForId(
|
||||
int64_t payload_id) const ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
@@ -208,8 +206,7 @@ class NearbyConnectionsManagerImpl : public NearbyConnectionsManager {
|
||||
ABSL_GUARDED_BY(mutex_);
|
||||
|
||||
// A set of file paths to delete.
|
||||
absl::flat_hash_set<std::filesystem::path> file_paths_to_delete_
|
||||
ABSL_GUARDED_BY(mutex_);
|
||||
absl::flat_hash_set<FilePath> file_paths_to_delete_ ABSL_GUARDED_BY(mutex_);
|
||||
};
|
||||
|
||||
} // namespace sharing
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <filesystem> // NOLINT(build/c++17)
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
@@ -35,6 +34,8 @@
|
||||
#include "absl/time/time.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "absl/types/span.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "internal/base/files.h"
|
||||
#include "internal/flags/nearby_flags.h"
|
||||
#include "internal/test/fake_clock.h"
|
||||
#include "internal/test/fake_device_info.h"
|
||||
@@ -86,8 +87,8 @@ constexpr uint8_t kBluetoothMacAddress[] = {0x00, 0x00, 0xe6, 0x88, 0x64, 0x13};
|
||||
constexpr char kInvalidBluetoothMacAddress[] = {0x07, 0x07, 0x07};
|
||||
constexpr absl::Duration kSynchronizationTimeOut = absl::Milliseconds(200);
|
||||
|
||||
void InitializeTemporaryFile(std::filesystem::path& file) {
|
||||
std::FILE* output_fp = std::fopen(file.string().c_str(), "wb+");
|
||||
void InitializeTemporaryFile(FilePath& file) {
|
||||
std::FILE* output_fp = std::fopen(file.GetPath().c_str(), "wb+");
|
||||
ASSERT_NE(output_fp, nullptr);
|
||||
EXPECT_EQ(std::fwrite(kPayload, 1, sizeof(kPayload), output_fp),
|
||||
sizeof(kPayload));
|
||||
@@ -387,8 +388,7 @@ class NearbyConnectionsManagerImplTest : public testing::Test {
|
||||
const std::vector<uint8_t> expected_payload(std::begin(kPayload),
|
||||
std::end(kPayload));
|
||||
|
||||
std::filesystem::path file(std::filesystem::temp_directory_path() /
|
||||
"file.jpg");
|
||||
FilePath file = GetTemporaryDirectory()->append(FilePath("file.jpg"));
|
||||
InitializeTemporaryFile(file);
|
||||
|
||||
absl::Notification notification;
|
||||
@@ -405,7 +405,7 @@ class NearbyConnectionsManagerImplTest : public testing::Test {
|
||||
FilePayload file_payload = std::move(payload->content.file_payload);
|
||||
std::vector<uint8_t> payload_bytes(file_payload.size);
|
||||
std::FILE* payload_fp =
|
||||
std::fopen(file_payload.file.path.string().c_str(), "rb");
|
||||
std::fopen(file_payload.file.path.GetPath().c_str(), "rb");
|
||||
ASSERT_NE(payload_fp, nullptr);
|
||||
EXPECT_EQ(std::fread(payload_bytes.data(), 1, file_payload.size,
|
||||
payload_fp),
|
||||
@@ -419,7 +419,7 @@ class NearbyConnectionsManagerImplTest : public testing::Test {
|
||||
|
||||
// Manually setup payload id, because the tested id is not generated from
|
||||
// file name.
|
||||
auto payload = std::make_unique<Payload>(InputFile(file));
|
||||
auto payload = std::make_unique<Payload>(InputFile(file.ToString()));
|
||||
payload->id = payload_id;
|
||||
|
||||
nearby_connections_manager_->Send(kRemoteEndpointId, std::move(payload),
|
||||
@@ -1403,18 +1403,16 @@ TEST_F(NearbyConnectionsManagerImplTest,
|
||||
nearby_connections_manager_->RegisterPayloadStatusListener(
|
||||
kPayloadId3, payload_listener->GetWeakPtr());
|
||||
|
||||
std::filesystem::path file1(std::filesystem::temp_directory_path() /
|
||||
"file1.jpg");
|
||||
std::filesystem::path file2(std::filesystem::temp_directory_path() /
|
||||
"file2.jpg");
|
||||
FilePath file1 = GetTemporaryDirectory()->append(FilePath("file1.jpg"));
|
||||
FilePath file2 = GetTemporaryDirectory()->append(FilePath("file2.jpg"));
|
||||
|
||||
InitializeTemporaryFile(file1);
|
||||
InitializeTemporaryFile(file2);
|
||||
|
||||
payload_listener_remote.payload_cb(kRemoteEndpointId,
|
||||
Payload(kPayloadId, InputFile(file1)));
|
||||
payload_listener_remote.payload_cb(kRemoteEndpointId,
|
||||
Payload(kPayloadId2, InputFile(file2)));
|
||||
payload_listener_remote.payload_cb(
|
||||
kRemoteEndpointId, Payload(kPayloadId, InputFile(file1.ToString())));
|
||||
payload_listener_remote.payload_cb(
|
||||
kRemoteEndpointId, Payload(kPayloadId2, InputFile(file2.ToString())));
|
||||
|
||||
const std::vector<uint8_t> byte_payload(std::begin(kBytePayload),
|
||||
std::end(kBytePayload));
|
||||
@@ -1521,12 +1519,11 @@ TEST_F(NearbyConnectionsManagerImplTest, IncomingFilePayload) {
|
||||
const std::vector<uint8_t> expected_payload(std::begin(kPayload),
|
||||
std::end(kPayload));
|
||||
|
||||
std::filesystem::path file(std::filesystem::temp_directory_path() /
|
||||
"file.jpg");
|
||||
FilePath file = GetTemporaryDirectory()->append(FilePath("file.jpg"));
|
||||
InitializeTemporaryFile(file);
|
||||
|
||||
payload_listener_remote.payload_cb(kRemoteEndpointId,
|
||||
Payload(kPayloadId, InputFile(file)));
|
||||
payload_listener_remote.payload_cb(
|
||||
kRemoteEndpointId, Payload(kPayloadId, InputFile(file.ToString())));
|
||||
|
||||
absl::Notification payload_notification;
|
||||
EXPECT_CALL(*payload_listener, OnStatusUpdate(::testing::_)).WillOnce([&]() {
|
||||
@@ -1546,7 +1543,7 @@ TEST_F(NearbyConnectionsManagerImplTest, IncomingFilePayload) {
|
||||
ASSERT_TRUE(payload->content.is_file());
|
||||
std::vector<uint8_t> payload_bytes(payload->content.file_payload.size);
|
||||
std::FILE* payload_fp = std::fopen(
|
||||
payload->content.file_payload.file.path.string().c_str(), "rb");
|
||||
payload->content.file_payload.file.path.GetPath().c_str(), "rb");
|
||||
ASSERT_NE(payload_fp, nullptr);
|
||||
EXPECT_EQ(std::fread(payload_bytes.data(), 1,
|
||||
payload->content.file_payload.size, payload_fp),
|
||||
@@ -1572,12 +1569,11 @@ TEST_F(NearbyConnectionsManagerImplTest, ClearIncomingPayloads) {
|
||||
nearby_connections_manager_->RegisterPayloadStatusListener(
|
||||
kPayloadId, payload_listener->GetWeakPtr());
|
||||
|
||||
std::filesystem::path file(std::filesystem::temp_directory_path() /
|
||||
"file.jpg");
|
||||
FilePath file = GetTemporaryDirectory()->append(FilePath("file.jpg"));
|
||||
InitializeTemporaryFile(file);
|
||||
|
||||
payload_listener_remote.payload_cb(kRemoteEndpointId,
|
||||
Payload(kPayloadId, InputFile(file)));
|
||||
payload_listener_remote.payload_cb(
|
||||
kRemoteEndpointId, Payload(kPayloadId, InputFile(file.ToString())));
|
||||
|
||||
absl::Notification payload_notification;
|
||||
EXPECT_CALL(*payload_listener, OnStatusUpdate(::testing::_)).WillOnce([&]() {
|
||||
@@ -1804,13 +1800,13 @@ TEST_F(NearbyConnectionsManagerImplTest,
|
||||
|
||||
TEST_F(NearbyConnectionsManagerImplTest, UnknownFilePathsToDelete) {
|
||||
nearby_connections_manager_->AddUnknownFilePathsToDeleteForTesting(
|
||||
"test1.txt");
|
||||
FilePath("test1.txt"));
|
||||
nearby_connections_manager_->AddUnknownFilePathsToDeleteForTesting(
|
||||
"test2.txt");
|
||||
FilePath("test2.txt"));
|
||||
auto unknown_file_paths =
|
||||
nearby_connections_manager_->GetUnknownFilePathsToDeleteForTesting();
|
||||
nearby_connections_manager_->AddUnknownFilePathsToDeleteForTesting(
|
||||
"test3.txt");
|
||||
FilePath("test3.txt"));
|
||||
|
||||
// Test if we get copy of container.
|
||||
EXPECT_NE(unknown_file_paths.size(), 3);
|
||||
@@ -1821,7 +1817,8 @@ TEST_F(NearbyConnectionsManagerImplTest, UnknownFilePathsToDelete) {
|
||||
unknown_file_paths =
|
||||
nearby_connections_manager_->GetUnknownFilePathsToDeleteForTesting();
|
||||
EXPECT_THAT(unknown_file_paths,
|
||||
UnorderedElementsAre("test1.txt", "test2.txt", "test3.txt"));
|
||||
UnorderedElementsAre(FilePath("test1.txt"), FilePath("test2.txt"),
|
||||
FilePath("test3.txt")));
|
||||
nearby_connections_manager_->GetAndClearUnknownFilePathsToDelete();
|
||||
EXPECT_TRUE(
|
||||
nearby_connections_manager_->GetUnknownFilePathsToDeleteForTesting()
|
||||
@@ -1829,9 +1826,9 @@ TEST_F(NearbyConnectionsManagerImplTest, UnknownFilePathsToDelete) {
|
||||
|
||||
// Test GetAndClearUnknownFilePathsToDelete
|
||||
nearby_connections_manager_->AddUnknownFilePathsToDeleteForTesting(
|
||||
"test1.txt");
|
||||
FilePath("test1.txt"));
|
||||
nearby_connections_manager_->AddUnknownFilePathsToDeleteForTesting(
|
||||
"test2.txt");
|
||||
FilePath("test2.txt"));
|
||||
unknown_file_paths =
|
||||
nearby_connections_manager_->GetAndClearUnknownFilePathsToDelete();
|
||||
EXPECT_EQ(unknown_file_paths.size(), 2);
|
||||
@@ -1851,16 +1848,15 @@ TEST_F(NearbyConnectionsManagerImplTest,
|
||||
ASSERT_TRUE(OnIncomingConnection(connection_listener_remote,
|
||||
incoming_connection_listener,
|
||||
payload_listener_remote) != nullptr);
|
||||
std::filesystem::path file(std::filesystem::temp_directory_path() /
|
||||
"file.jpg");
|
||||
payload_listener_remote.payload_cb(kRemoteEndpointId,
|
||||
Payload(kPayloadId, InputFile(file)));
|
||||
FilePath file = GetTemporaryDirectory()->append(FilePath("file.jpg"));
|
||||
payload_listener_remote.payload_cb(
|
||||
kRemoteEndpointId, Payload(kPayloadId, InputFile(file.ToString())));
|
||||
|
||||
nearby_connections_manager_->OnPayloadTransferUpdateForTesting(
|
||||
kRemoteEndpointId,
|
||||
PayloadTransferUpdate(kPayloadId, PayloadStatus::kCanceled, kTotalSize,
|
||||
/*bytes_transferred=*/kTotalSize));
|
||||
absl::flat_hash_set<std::filesystem::path> unknown_file_paths =
|
||||
absl::flat_hash_set<FilePath> unknown_file_paths =
|
||||
nearby_connections_manager_->GetUnknownFilePathsToDeleteForTesting();
|
||||
EXPECT_EQ(unknown_file_paths.size(), 1);
|
||||
nearby_connections_manager_->GetAndClearUnknownFilePathsToDelete();
|
||||
@@ -1885,10 +1881,9 @@ TEST_F(NearbyConnectionsManagerImplTest, OnPayloadReceivedForUnknownFile) {
|
||||
ASSERT_TRUE(OnIncomingConnection(connection_listener_remote,
|
||||
incoming_connection_listener,
|
||||
payload_listener_remote) != nullptr);
|
||||
std::filesystem::path file(std::filesystem::temp_directory_path() /
|
||||
"file.jpg");
|
||||
payload_listener_remote.payload_cb(kRemoteEndpointId,
|
||||
Payload(kPayloadId, InputFile(file)));
|
||||
FilePath file = GetTemporaryDirectory()->append(FilePath("file.jpg"));
|
||||
payload_listener_remote.payload_cb(
|
||||
kRemoteEndpointId, Payload(kPayloadId, InputFile(file.ToString())));
|
||||
|
||||
// Flag is on. Add unknown file paths with kCanceled to the list.
|
||||
NearbyFlags::GetInstance().OverrideBoolFlagValue(
|
||||
@@ -1896,13 +1891,12 @@ TEST_F(NearbyConnectionsManagerImplTest, OnPayloadReceivedForUnknownFile) {
|
||||
kDeleteUnexpectedReceivedFileFix,
|
||||
true);
|
||||
nearby_connections_manager_->ClearIncomingPayloads();
|
||||
Payload payload(kPayloadId, InputFile(file));
|
||||
Payload payload(kPayloadId, InputFile(file.ToString()));
|
||||
nearby_connections_manager_->OnPayloadReceivedForTesting(kRemoteEndpointId,
|
||||
payload);
|
||||
|
||||
std::filesystem::path file2(std::filesystem::temp_directory_path() /
|
||||
"file2.jpg");
|
||||
Payload payload2(kPayloadId, InputFile(file2));
|
||||
FilePath file2 = GetTemporaryDirectory()->append(FilePath("file2.jpg"));
|
||||
Payload payload2(kPayloadId, InputFile(file2.ToString()));
|
||||
nearby_connections_manager_->OnPayloadReceivedForTesting(kRemoteEndpointId,
|
||||
payload2);
|
||||
auto unknown_file_paths =
|
||||
@@ -1914,9 +1908,8 @@ TEST_F(NearbyConnectionsManagerImplTest, OnPayloadReceivedForUnknownFile) {
|
||||
std::make_shared<testing::NiceMock<MockPayloadStatusListener>>();
|
||||
nearby_connections_manager_->RegisterPayloadStatusListener(
|
||||
kPayloadId, payload_listener->GetWeakPtr());
|
||||
std::filesystem::path file3(std::filesystem::temp_directory_path() /
|
||||
"file3.jpg");
|
||||
Payload payload3(kPayloadId, InputFile(file3));
|
||||
FilePath file3 = GetTemporaryDirectory()->append(FilePath("file3.jpg"));
|
||||
Payload payload3(kPayloadId, InputFile(file3.ToString()));
|
||||
nearby_connections_manager_->OnPayloadReceivedForTesting(kRemoteEndpointId,
|
||||
payload3);
|
||||
unknown_file_paths =
|
||||
@@ -1946,10 +1939,9 @@ TEST_F(NearbyConnectionsManagerImplTest,
|
||||
nearby_connections_manager_->RegisterPayloadStatusListener(
|
||||
kPayloadId, payload_listener->GetWeakPtr());
|
||||
|
||||
std::filesystem::path file(std::filesystem::temp_directory_path() /
|
||||
"file.jpg");
|
||||
FilePath file = GetTemporaryDirectory()->append(FilePath("file.jpg"));
|
||||
|
||||
Payload payload(kPayloadId, InputFile(file));
|
||||
Payload payload(kPayloadId, InputFile(file.ToString()));
|
||||
nearby_connections_manager_->OnPayloadReceivedForTesting(kRemoteEndpointId,
|
||||
payload);
|
||||
|
||||
@@ -1978,9 +1970,8 @@ TEST_F(NearbyConnectionsManagerImplTest,
|
||||
payload_notification.Notify();
|
||||
});
|
||||
|
||||
std::filesystem::path file2(std::filesystem::temp_directory_path() /
|
||||
"file2.jpg");
|
||||
Payload payload2(kPayloadId, InputFile(file2));
|
||||
FilePath file2 = GetTemporaryDirectory()->append(FilePath("file2.jpg"));
|
||||
Payload payload2(kPayloadId, InputFile(file2.ToString()));
|
||||
nearby_connections_manager_->OnPayloadReceivedForTesting(kRemoteEndpointId,
|
||||
payload2);
|
||||
unknown_file_paths =
|
||||
@@ -1994,11 +1985,10 @@ TEST_F(NearbyConnectionsManagerImplTest,
|
||||
}
|
||||
|
||||
TEST_F(NearbyConnectionsManagerImplTest, ProcessUnknownFilePathsToDelete) {
|
||||
std::filesystem::path file(std::filesystem::temp_directory_path() /
|
||||
"file.jpg");
|
||||
FilePath file = GetTemporaryDirectory()->append(FilePath("file.jpg"));
|
||||
nearby_connections_manager_->ProcessUnknownFilePathsToDeleteForTesting(
|
||||
PayloadStatus::kCanceled, PayloadContent::Type::kFile, file);
|
||||
absl::flat_hash_set<std::filesystem::path> unknown_file_paths =
|
||||
absl::flat_hash_set<FilePath> unknown_file_paths =
|
||||
nearby_connections_manager_->GetUnknownFilePathsToDeleteForTesting();
|
||||
EXPECT_EQ(unknown_file_paths.size(), 1);
|
||||
nearby_connections_manager_->GetAndClearUnknownFilePathsToDelete();
|
||||
|
||||
@@ -16,14 +16,12 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <filesystem> // NOLINT(build/c++17)
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "internal/platform/file.h"
|
||||
#include "sharing/common/compatible_u8_string.h"
|
||||
#include "sharing/internal/public/logging.h"
|
||||
#include "sharing/nearby_connections_types.h"
|
||||
|
||||
@@ -58,10 +56,9 @@ NcPayload ConvertToServicePayload(Payload payload) {
|
||||
switch (payload.content.type) {
|
||||
case PayloadContent::Type::kFile: {
|
||||
int64_t file_size = payload.content.file_payload.size;
|
||||
std::string file_path = GetCompatibleU8String(
|
||||
payload.content.file_payload.file.path.u8string());
|
||||
std::string file_name = GetCompatibleU8String(
|
||||
payload.content.file_payload.file.path.filename().u8string());
|
||||
std::string file_path = payload.content.file_payload.file.path.ToString();
|
||||
std::string file_name =
|
||||
payload.content.file_payload.file.path.GetFileName().ToString();
|
||||
std::string parent_folder = payload.content.file_payload.parent_folder;
|
||||
std::replace(parent_folder.begin(), parent_folder.end(), '\\', '/');
|
||||
VLOG(1) << __func__ << ": NC Payload file_path=" << file_path
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <filesystem> // NOLINT(build/c++17)
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <optional>
|
||||
@@ -28,9 +27,9 @@
|
||||
#include "absl/random/random.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "internal/base/files.h"
|
||||
#include "internal/interop/authentication_status.h"
|
||||
#include "sharing/common/compatible_u8_string.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace sharing {
|
||||
@@ -358,11 +357,10 @@ enum class DistanceInfo {
|
||||
|
||||
struct InputFile {
|
||||
InputFile() = default;
|
||||
explicit InputFile(std::string path) {
|
||||
this->path = std::filesystem::u8path(path);
|
||||
}
|
||||
explicit InputFile(absl::string_view file_path)
|
||||
: path(file_path) {}
|
||||
|
||||
std::filesystem::path path;
|
||||
FilePath path;
|
||||
};
|
||||
|
||||
// A simple payload containing raw bytes.
|
||||
@@ -412,10 +410,10 @@ struct Payload {
|
||||
|
||||
explicit Payload(InputFile file,
|
||||
absl::string_view parent_folder = absl::string_view()) {
|
||||
id = std::hash<std::string>()(GetCompatibleU8String(file.path.u8string()));
|
||||
id = std::hash<std::string>()(file.path.ToString());
|
||||
|
||||
content.type = PayloadContent::Type::kFile;
|
||||
std::optional<uintmax_t> size = GetFileSize(file.path);
|
||||
std::optional<uintmax_t> size = GetFileSize(file.path.GetPath());
|
||||
if (size.has_value()) {
|
||||
content.file_payload.size = *size;
|
||||
}
|
||||
@@ -433,7 +431,7 @@ struct Payload {
|
||||
absl::string_view parent_folder = absl::string_view())
|
||||
: id(id) {
|
||||
content.type = PayloadContent::Type::kFile;
|
||||
std::optional<uintmax_t> size = GetFileSize(file.path);
|
||||
std::optional<uintmax_t> size = GetFileSize(file.path.GetPath());
|
||||
if (size.has_value()) {
|
||||
content.file_payload.size = *size;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "sharing/nearby_file_handler.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <filesystem> // NOLINT(build/c++17)
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
@@ -29,7 +28,6 @@
|
||||
#include "internal/base/file_path.h"
|
||||
#include "internal/base/files.h"
|
||||
#include "internal/platform/task_runner_impl.h"
|
||||
#include "sharing/common/compatible_u8_string.h"
|
||||
#include "sharing/internal/api/sharing_platform.h"
|
||||
#include "sharing/internal/public/logging.h"
|
||||
|
||||
@@ -41,13 +39,13 @@ using ::nearby::sharing::api::SharingPlatform;
|
||||
|
||||
// Called on the FileTaskRunner to actually open the files passed.
|
||||
std::vector<NearbyFileHandler::FileInfo> DoOpenFiles(
|
||||
absl::Span<const std::filesystem::path> file_paths) {
|
||||
absl::Span<const FilePath> file_paths) {
|
||||
std::vector<NearbyFileHandler::FileInfo> files;
|
||||
for (const auto& file_path : file_paths) {
|
||||
std::optional<uintmax_t> size = GetFileSize(file_path);
|
||||
std::optional<uintmax_t> size = GetFileSize(file_path.GetPath());
|
||||
if (!size.has_value()) {
|
||||
LOG(ERROR) << __func__ << ": Failed to open file. File="
|
||||
<< GetCompatibleU8String(file_path.u8string());
|
||||
LOG(ERROR) << __func__
|
||||
<< ": Failed to open file. File=" << file_path.ToString();
|
||||
return {};
|
||||
}
|
||||
files.push_back({*size, file_path});
|
||||
@@ -64,7 +62,7 @@ NearbyFileHandler::NearbyFileHandler(SharingPlatform& platform)
|
||||
|
||||
NearbyFileHandler::~NearbyFileHandler() = default;
|
||||
|
||||
void NearbyFileHandler::OpenFiles(std::vector<std::filesystem::path> file_paths,
|
||||
void NearbyFileHandler::OpenFiles(std::vector<FilePath> file_paths,
|
||||
OpenFilesCallback callback) {
|
||||
sequenced_task_runner_->PostTask(
|
||||
[callback = std::move(callback), file_paths = std::move(file_paths)]() {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <filesystem> // NOLINT(build/c++17)
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
@@ -36,7 +35,7 @@ class NearbyFileHandler {
|
||||
public:
|
||||
struct FileInfo {
|
||||
uint64_t size;
|
||||
std::filesystem::path file_path;
|
||||
FilePath file_path;
|
||||
};
|
||||
|
||||
using OpenFilesCallback = std::function<void(std::vector<FileInfo>)>;
|
||||
@@ -47,8 +46,7 @@ class NearbyFileHandler {
|
||||
|
||||
// Open the files given in |file_paths| and return the opened files sizes via
|
||||
// |callback|. If any file fails to open, return an empty list.
|
||||
void OpenFiles(std::vector<std::filesystem::path> file_paths,
|
||||
OpenFilesCallback callback);
|
||||
void OpenFiles(std::vector<FilePath> file_paths, OpenFilesCallback callback);
|
||||
|
||||
void DeleteFilesFromDisk(std::vector<FilePath> file_paths,
|
||||
DeleteFilesFromDiskCallback callback);
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdio>
|
||||
#include <filesystem> // NOLINT(build/c++17)
|
||||
#include <vector>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
@@ -32,8 +31,8 @@ namespace sharing {
|
||||
namespace {
|
||||
using ::nearby::sharing::api::MockSharingPlatform;
|
||||
|
||||
bool CreateFile(std::filesystem::path file_path) {
|
||||
std::FILE* file = std::fopen(file_path.c_str(), "w+");
|
||||
bool CreateFile(FilePath& file_path) {
|
||||
std::FILE* file = std::fopen(file_path.GetPath().c_str(), "w+");
|
||||
if (file == nullptr) {
|
||||
return false;
|
||||
}
|
||||
@@ -46,8 +45,8 @@ TEST(NearbyFileHandler, OpenFiles) {
|
||||
NearbyFileHandler nearby_file_handler(mock_platform);
|
||||
absl::Notification notification;
|
||||
std::vector<NearbyFileHandler::FileInfo> result;
|
||||
std::filesystem::path test_file =
|
||||
std::filesystem::temp_directory_path() / "nearby_nfh_test_abc.jpg";
|
||||
FilePath test_file =
|
||||
GetTemporaryDirectory()->append(FilePath("nearby_nfh_test_abc.jpg"));
|
||||
|
||||
ASSERT_TRUE(CreateFile(test_file));
|
||||
nearby_file_handler.OpenFiles(
|
||||
@@ -59,7 +58,7 @@ TEST(NearbyFileHandler, OpenFiles) {
|
||||
|
||||
notification.WaitForNotificationWithTimeout(absl::Seconds(1));
|
||||
EXPECT_EQ(result.size(), 1);
|
||||
ASSERT_TRUE(RemoveFile(test_file));
|
||||
ASSERT_TRUE(RemoveFile(test_file.GetPath()));
|
||||
}
|
||||
|
||||
TEST(NearbyFileHandler, DeleteAFileFromDisk) {
|
||||
@@ -67,7 +66,7 @@ TEST(NearbyFileHandler, DeleteAFileFromDisk) {
|
||||
NearbyFileHandler nearby_file_handler(mock_platform);
|
||||
FilePath test_file =
|
||||
GetTemporaryDirectory()->append(FilePath("nearby_nfh_test_abc.jpg"));
|
||||
ASSERT_TRUE(CreateFile(test_file.GetPath()));
|
||||
ASSERT_TRUE(CreateFile(test_file));
|
||||
std::vector<FilePath> file_paths;
|
||||
file_paths.push_back(test_file);
|
||||
nearby_file_handler.DeleteFilesFromDisk(file_paths, []() {});
|
||||
@@ -104,7 +103,7 @@ TEST(NearbyFileHandler, TestCallback) {
|
||||
NearbyFileHandler nearby_file_handler(mock_platform);
|
||||
FilePath test_file =
|
||||
GetTemporaryDirectory()->append(FilePath("nearby_nfh_test_abc.jpg"));
|
||||
ASSERT_TRUE(CreateFile(test_file.GetPath()));
|
||||
ASSERT_TRUE(CreateFile(test_file));
|
||||
std::vector<FilePath> file_paths;
|
||||
file_paths.push_back(test_file);
|
||||
nearby_file_handler.DeleteFilesFromDisk(
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include <array>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <filesystem> // NOLINT(build/c++17)
|
||||
#include <functional>
|
||||
#include <ios>
|
||||
#include <memory>
|
||||
@@ -761,7 +760,7 @@ void NearbySharingServiceImpl::SendAttachments(
|
||||
}
|
||||
for (const FileAttachment& attachment :
|
||||
attachment_container->GetFileAttachments()) {
|
||||
if (!attachment.file_path() || attachment.file_path()->empty()) {
|
||||
if (!attachment.file_path() || attachment.file_path()->IsEmpty()) {
|
||||
LOG(WARNING) << __func__ << ": Got file attachment without path";
|
||||
std::move(status_codes_callback)(StatusCodes::kInvalidArgument);
|
||||
return;
|
||||
@@ -2830,8 +2829,7 @@ void NearbySharingServiceImpl::OnReceivedIntroduction(
|
||||
session->session_id(), session->share_target(),
|
||||
/*referrer_package=*/std::nullopt, session->os_type());
|
||||
|
||||
if (IsOutOfStorage(device_info_,
|
||||
std::filesystem::u8path(settings_->GetCustomSavePath()),
|
||||
if (IsOutOfStorage(device_info_, FilePath{settings_->GetCustomSavePath()},
|
||||
session->attachment_container().GetStorageSize())) {
|
||||
Fail(*session, TransferMetadata::Status::kNotEnoughSpace);
|
||||
LOG(WARNING) << __func__
|
||||
@@ -3134,7 +3132,7 @@ void NearbySharingServiceImpl::RemoveIncomingPayloads(
|
||||
for (auto it = file_paths_to_delete.begin(); it != file_paths_to_delete.end();
|
||||
++it) {
|
||||
VLOG(1) << __func__ << ": Has unknown file path to delete.";
|
||||
files_for_deletion.push_back(FilePath::FromPath(*it));
|
||||
files_for_deletion.push_back(*it);
|
||||
}
|
||||
std::vector<FilePath> payload_file_path = session.GetPayloadFilePaths();
|
||||
files_for_deletion.insert(files_for_deletion.end(), payload_file_path.begin(),
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include <cctype>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <filesystem> // NOLINT(build/c++17)
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
@@ -270,9 +269,9 @@ constexpr absl::Duration kCertificateDownloadDuringDiscoveryPeriod =
|
||||
absl::Seconds(10);
|
||||
|
||||
std::unique_ptr<Payload> GetFilePayload(int64_t payload_id) {
|
||||
std::filesystem::path path =
|
||||
std::filesystem::temp_directory_path() / absl::StrCat(payload_id);
|
||||
InputFile input_file{path};
|
||||
FilePath path =
|
||||
GetTemporaryDirectory()->append(FilePath(absl::StrCat(payload_id)));
|
||||
InputFile input_file{path.ToString()};
|
||||
return std::make_unique<Payload>(input_file);
|
||||
}
|
||||
|
||||
@@ -374,7 +373,7 @@ std::unique_ptr<AttachmentContainer> CreateTextAttachments(
|
||||
}
|
||||
|
||||
std::unique_ptr<AttachmentContainer> CreateFileAttachments(
|
||||
std::vector<std::filesystem::path> file_paths) {
|
||||
std::vector<FilePath> file_paths) {
|
||||
auto attachment_container = std::make_unique<AttachmentContainer>();
|
||||
for (auto& file_path : file_paths) {
|
||||
attachment_container->AddFileAttachment(
|
||||
@@ -1188,7 +1187,7 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
fake_nearby_connections_manager_->GetRegisteredPayloadStatusListener(
|
||||
kFilePayloadId);
|
||||
|
||||
std::filesystem::path file_path;
|
||||
FilePath file_path;
|
||||
absl::Notification success_notification;
|
||||
EXPECT_CALL(callback, OnTransferUpdate(testing::_, testing::_, testing::_))
|
||||
.WillOnce(testing::Invoke([&](const ShareTarget& share_target,
|
||||
@@ -1231,7 +1230,7 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
EXPECT_FALSE(fake_nearby_connections_manager_->has_incoming_payloads());
|
||||
|
||||
// Remove test file.
|
||||
std::filesystem::remove(file_path);
|
||||
RemoveFile(file_path.GetPath());
|
||||
}
|
||||
|
||||
void FlushTesting() {
|
||||
@@ -1259,10 +1258,10 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
|
||||
FakeAccountManager& account_manager() { return fake_account_manager_; }
|
||||
|
||||
std::filesystem::path CreateTestFile(absl::string_view name,
|
||||
FilePath CreateTestFile(absl::string_view name,
|
||||
const std::vector<uint8_t>& content) {
|
||||
std::filesystem::path path = std::filesystem::temp_directory_path() / name;
|
||||
std::FILE* file = std::fopen(path.string().c_str(), "w+");
|
||||
FilePath path = GetTemporaryDirectory()->append(FilePath(name));
|
||||
std::FILE* file = std::fopen(path.GetPath().c_str(), "w+");
|
||||
std::fwrite(content.data(), 1, content.size(), file);
|
||||
std::fclose(file);
|
||||
return path;
|
||||
@@ -3470,7 +3469,7 @@ TEST_F(NearbySharingServiceImplTest, SendFileWithEmptyPath) {
|
||||
DiscoverShareTarget(transfer_callback, discovery_callback);
|
||||
ScopedSendSurface s(service_.get(), &transfer_callback);
|
||||
|
||||
EXPECT_EQ(SendAttachments(target_id, CreateFileAttachments({""})),
|
||||
EXPECT_EQ(SendAttachments(target_id, CreateFileAttachments({FilePath{""}})),
|
||||
NearbySharingServiceImpl::StatusCodes::kInvalidArgument);
|
||||
}
|
||||
|
||||
@@ -3482,7 +3481,7 @@ TEST_P(NearbySharingServiceImplSendFailureTest, SendFilesRemoteFailure) {
|
||||
ScopedSendSurface s(service_.get(), &transfer_callback);
|
||||
|
||||
std::vector<uint8_t> test_data = {'T', 'e', 's', 't'};
|
||||
std::filesystem::path path = CreateTestFile("text.txt", test_data);
|
||||
FilePath path = CreateTestFile("text.txt", test_data);
|
||||
|
||||
absl::Notification notification;
|
||||
ExpectTransferUpdates(transfer_callback, target_id,
|
||||
@@ -3631,7 +3630,7 @@ TEST_F(NearbySharingServiceImplTest, SendFilesSuccess) {
|
||||
|
||||
std::vector<uint8_t> test_data = {'T', 'e', 's', 't'};
|
||||
std::string file_name = "test.txt";
|
||||
std::filesystem::path path = CreateTestFile(file_name, test_data);
|
||||
FilePath path = CreateTestFile(file_name, test_data);
|
||||
|
||||
absl::Notification introduction_notification;
|
||||
ExpectTransferUpdates(transfer_callback, target_id,
|
||||
@@ -3673,8 +3672,8 @@ TEST_F(NearbySharingServiceImplTest, SendFilesSuccess) {
|
||||
// Expect the file payload to be sent in the end.
|
||||
PayloadInfo info = GetWrittenPayload();
|
||||
ASSERT_TRUE(info.payload->content.is_file());
|
||||
std::filesystem::path file = info.payload->content.file_payload.file.path;
|
||||
ASSERT_TRUE(std::filesystem::exists(file));
|
||||
FilePath file = info.payload->content.file_payload.file.path;
|
||||
ASSERT_TRUE(FileExists(file.GetPath()));
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, SendWifiCredentialsSuccess) {
|
||||
@@ -5028,14 +5027,15 @@ TEST_F(NearbySharingServiceImplTest, NoAdvertisingWhenHidden) {
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, RemoveIncomingPayloads) {
|
||||
fake_nearby_connections_manager_->AddUnknownFilePathsToDeleteForTesting(
|
||||
"test1.txt");
|
||||
FilePath{"test1.txt"});
|
||||
fake_nearby_connections_manager_->AddUnknownFilePathsToDeleteForTesting(
|
||||
"test2.txt");
|
||||
FilePath{"test2.txt"});
|
||||
auto unknown_file_paths_to_delete =
|
||||
fake_nearby_connections_manager_->GetUnknownFilePathsToDeleteForTesting();
|
||||
EXPECT_EQ(unknown_file_paths_to_delete.size(), 2);
|
||||
EXPECT_THAT(unknown_file_paths_to_delete,
|
||||
UnorderedElementsAre("test1.txt", "test2.txt"));
|
||||
EXPECT_THAT(
|
||||
unknown_file_paths_to_delete,
|
||||
UnorderedElementsAre(FilePath("test1.txt"), FilePath("test2.txt")));
|
||||
nearby::analytics::MockEventLogger mock_event_logger;
|
||||
analytics::AnalyticsRecorder analytics_recorder{/*vendor_id=*/0,
|
||||
&mock_event_logger};
|
||||
@@ -5054,9 +5054,9 @@ TEST_F(NearbySharingServiceImplTest, RemoveIncomingPayloads) {
|
||||
|
||||
// Test GetAndClearUnknownFilePathsToDelete
|
||||
fake_nearby_connections_manager_->AddUnknownFilePathsToDeleteForTesting(
|
||||
"test1.txt");
|
||||
FilePath{"test1.txt"});
|
||||
fake_nearby_connections_manager_->AddUnknownFilePathsToDeleteForTesting(
|
||||
"test2.txt");
|
||||
FilePath{"test2.txt"});
|
||||
unknown_file_paths_to_delete =
|
||||
fake_nearby_connections_manager_->GetAndClearUnknownFilePathsToDelete();
|
||||
EXPECT_EQ(unknown_file_paths_to_delete.size(), 2);
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "sharing/nearby_sharing_settings.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <filesystem> // NOLINT(build/c++17)
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
@@ -30,7 +29,6 @@
|
||||
#include "internal/platform/device_info.h"
|
||||
#include "proto/sharing_enums.pb.h"
|
||||
#include "sharing/analytics/analytics_recorder.h"
|
||||
#include "sharing/common/compatible_u8_string.h"
|
||||
#include "sharing/common/nearby_share_enums.h"
|
||||
#include "sharing/common/nearby_share_prefs.h"
|
||||
#include "sharing/internal/api/preference_manager.h"
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <filesystem> // NOLINT(build/c++17)
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -138,10 +137,10 @@ std::string GetDeviceId(
|
||||
return std::string(endpoint_id);
|
||||
}
|
||||
|
||||
bool IsOutOfStorage(DeviceInfo& device_info, std::filesystem::path file_path,
|
||||
bool IsOutOfStorage(DeviceInfo& device_info, FilePath file_path,
|
||||
int64_t storage_required) {
|
||||
std::optional<size_t> available_storage =
|
||||
device_info.GetAvailableDiskSpaceInBytes(FilePath::FromPath(file_path));
|
||||
device_info.GetAvailableDiskSpaceInBytes(file_path);
|
||||
|
||||
if (!available_storage.has_value()) {
|
||||
return false;
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#define THIRD_PARTY_NEARBY_SHARING_NEARBY_SHARING_UTIL_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <filesystem> // NOLINT(build/c++17)
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -24,6 +23,7 @@
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/platform/device_info.h"
|
||||
#include "proto/sharing_enums.pb.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "sharing/advertisement.h"
|
||||
#include "sharing/certificates/nearby_share_decrypted_public_certificate.h"
|
||||
#include "sharing/common/nearby_share_enums.h"
|
||||
@@ -36,8 +36,8 @@ namespace nearby::sharing {
|
||||
// device_info - Nearby Share DeviceInfo
|
||||
// file_path - The path is to store sharing contents.
|
||||
// storage_required - required storage space.
|
||||
bool IsOutOfStorage(nearby::DeviceInfo& device_info,
|
||||
std::filesystem::path file_path, int64_t storage_required);
|
||||
bool IsOutOfStorage(nearby::DeviceInfo& device_info, FilePath file_path,
|
||||
int64_t storage_required);
|
||||
|
||||
// Decodes certificate to find MAC address encoded in it.
|
||||
std::optional<std::vector<uint8_t>> GetBluetoothMacAddressFromCertificate(
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <filesystem> // NOLINT
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
@@ -28,6 +27,7 @@
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "internal/platform/clock.h"
|
||||
#include "internal/platform/task_runner.h"
|
||||
#include "sharing/analytics/analytics_recorder.h"
|
||||
@@ -160,8 +160,8 @@ void OutgoingShareSession::OnConnectionDisconnected() {
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::filesystem::path> OutgoingShareSession::GetFilePaths() const {
|
||||
std::vector<std::filesystem::path> file_paths;
|
||||
std::vector<FilePath> OutgoingShareSession::GetFilePaths() const {
|
||||
std::vector<FilePath> file_paths;
|
||||
file_paths.reserve(attachment_container().GetFileAttachments().size());
|
||||
for (const FileAttachment& file_attachment :
|
||||
attachment_container().GetFileAttachments()) {
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#define THIRD_PARTY_NEARBY_SHARING_OUTGOING_SHARE_SESSION_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <filesystem> // NOLINT
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
@@ -27,6 +26,7 @@
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "internal/platform/clock.h"
|
||||
#include "internal/platform/task_runner.h"
|
||||
#include "sharing/analytics/analytics_recorder.h"
|
||||
@@ -84,7 +84,7 @@ class OutgoingShareSession : public ShareSession {
|
||||
PairedKeyVerificationRunner::PairedKeyVerificationResult result,
|
||||
location::nearby::proto::sharing::OSType share_target_os_type);
|
||||
|
||||
std::vector<std::filesystem::path> GetFilePaths() const;
|
||||
std::vector<FilePath> GetFilePaths() const;
|
||||
|
||||
void CreateTextPayloads();
|
||||
void CreateWifiCredentialsPayloads();
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "absl/time/time.h"
|
||||
#include "internal/analytics/mock_event_logger.h"
|
||||
#include "internal/analytics/sharing_log_matchers.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "internal/network/url.h"
|
||||
#include "internal/test/fake_clock.h"
|
||||
#include "internal/test/fake_device_info.h"
|
||||
@@ -95,13 +96,14 @@ class OutgoingShareSessionTest : public ::testing::Test {
|
||||
"A bit of text body", "Some text title", "text/html"),
|
||||
text2_(nearby::sharing::service::proto::TextMetadata::ADDRESS,
|
||||
"A bit of text body 2", "Some text title 2", "text/plain"),
|
||||
file1_("/usr/local/tmp/someFileName.jpg", "/usr/local/parent"),
|
||||
file2_("/usr/local/tmp/someFileName2.jpg", "/usr/local/parent2"),
|
||||
file1_(FilePath("/usr/local/tmp/someFileName.jpg"), /*mime_type=*/"",
|
||||
/*parent_folder=*/"/usr/local/parent"),
|
||||
file2_(FilePath("/usr/local/tmp/someFileName2.jpg"), /*mime_type=*/"",
|
||||
/*parent_folder=*/"/usr/local/parent2"),
|
||||
wifi1_(
|
||||
"GoogleGuest",
|
||||
nearby::sharing::service::proto::WifiCredentialsMetadata::WPA_PSK,
|
||||
"somepassword", /*is_hidden=*/true) {
|
||||
}
|
||||
"somepassword", /*is_hidden=*/true) {}
|
||||
|
||||
std::unique_ptr<AttachmentContainer> CreateDefaultAttachmentContainer() {
|
||||
return std::make_unique<AttachmentContainer>(
|
||||
|
||||
Reference in New Issue
Block a user