mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
Add UpdateFileOriginMetadata.
PiperOrigin-RevId: 657632869
This commit is contained in:
committed by
Copybara-Service
parent
b77797857b
commit
68d432c5a8
@@ -210,6 +210,7 @@ cc_library(
|
||||
"//sharing/analytics",
|
||||
"//sharing/certificates",
|
||||
"//sharing/common:compatible_u8_string",
|
||||
"//sharing/internal/api:platform",
|
||||
"//sharing/internal/public:logging",
|
||||
"//sharing/proto:wire_format_cc_proto",
|
||||
"@com_google_absl//absl/container:flat_hash_map",
|
||||
@@ -604,6 +605,7 @@ cc_test(
|
||||
":share_session",
|
||||
"//internal/base:files",
|
||||
"//internal/platform/implementation/g3", # fixdeps: keep
|
||||
"//sharing/internal/api:mock_sharing_platform",
|
||||
"@com_github_protobuf_matchers//protobuf-matchers",
|
||||
"@com_google_absl//absl/synchronization",
|
||||
"@com_google_absl//absl/time",
|
||||
|
||||
@@ -15,8 +15,10 @@
|
||||
#ifndef THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_MOCK_SHARING_PLATFORM_H_
|
||||
#define THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_MOCK_SHARING_PLATFORM_H_
|
||||
|
||||
#include <filesystem> // NOLINT
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "absl/status/status.h"
|
||||
@@ -101,6 +103,8 @@ class MockSharingPlatform : public SharingPlatform {
|
||||
(nearby::sharing::analytics::AnalyticsRecorder *
|
||||
analytics_recorder),
|
||||
(override));
|
||||
MOCK_METHOD(bool, UpdateFileOriginMetadata, (
|
||||
std::vector<std::filesystem::path>& file_paths), (override));
|
||||
};
|
||||
|
||||
} // namespace nearby::sharing::api
|
||||
|
||||
@@ -15,8 +15,10 @@
|
||||
#ifndef THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_SHARING_PLATFORM_H_
|
||||
#define THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_SHARING_PLATFORM_H_
|
||||
|
||||
#include <filesystem> // NOLINT
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
@@ -96,6 +98,12 @@ class SharingPlatform {
|
||||
virtual std::unique_ptr<SharingRpcClientFactory>
|
||||
CreateSharingRpcClientFactory(
|
||||
nearby::sharing::analytics::AnalyticsRecorder* analytics_recorder) = 0;
|
||||
|
||||
// On platforms where it is supported, tag the transferred files as
|
||||
// originating from an untrusted source.
|
||||
// Returns true on success.
|
||||
virtual bool UpdateFileOriginMetadata(
|
||||
std::vector<std::filesystem::path>& file_paths) = 0;
|
||||
};
|
||||
} // namespace nearby::sharing::api
|
||||
|
||||
|
||||
@@ -29,12 +29,15 @@
|
||||
#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"
|
||||
|
||||
namespace nearby {
|
||||
namespace sharing {
|
||||
namespace {
|
||||
|
||||
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) {
|
||||
@@ -53,7 +56,8 @@ std::vector<NearbyFileHandler::FileInfo> DoOpenFiles(
|
||||
|
||||
} // namespace
|
||||
|
||||
NearbyFileHandler::NearbyFileHandler() {
|
||||
NearbyFileHandler::NearbyFileHandler(SharingPlatform& platform)
|
||||
: platform_(platform) {
|
||||
sequenced_task_runner_ = std::make_unique<TaskRunnerImpl>(1);
|
||||
}
|
||||
|
||||
@@ -103,10 +107,9 @@ void NearbyFileHandler::UpdateFilesOriginMetadata(
|
||||
std::vector<std::filesystem::path> file_paths,
|
||||
absl::AnyInvocable<void(bool success)> callback) {
|
||||
sequenced_task_runner_->PostTask(
|
||||
[callback = std::move(callback),
|
||||
[this, callback = std::move(callback),
|
||||
file_paths = std::move(file_paths)]() mutable {
|
||||
// TODO(b/350744369): Implement this.
|
||||
std::move(callback)(true);
|
||||
std::move(callback)(platform_.UpdateFileOriginMetadata(file_paths));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "internal/platform/task_runner.h"
|
||||
#include "sharing/internal/api/sharing_platform.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace sharing {
|
||||
@@ -40,7 +41,7 @@ class NearbyFileHandler {
|
||||
using OpenFilesCallback = std::function<void(std::vector<FileInfo>)>;
|
||||
using DeleteFilesFromDiskCallback = std::function<void()>;
|
||||
|
||||
NearbyFileHandler();
|
||||
explicit NearbyFileHandler(nearby::sharing::api::SharingPlatform& platform);
|
||||
~NearbyFileHandler();
|
||||
|
||||
// Open the files given in |file_paths| and return the opened files sizes via
|
||||
@@ -58,6 +59,7 @@ class NearbyFileHandler {
|
||||
absl::AnyInvocable<void(bool success)> callback);
|
||||
|
||||
private:
|
||||
nearby::sharing::api::SharingPlatform& platform_;
|
||||
std::unique_ptr<TaskRunner> sequenced_task_runner_;
|
||||
};
|
||||
|
||||
|
||||
@@ -24,10 +24,12 @@
|
||||
#include "absl/time/clock.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "internal/base/files.h"
|
||||
#include "sharing/internal/api/mock_sharing_platform.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace sharing {
|
||||
namespace {
|
||||
using ::nearby::sharing::api::MockSharingPlatform;
|
||||
|
||||
bool CreateFile(std::filesystem::path file_path) {
|
||||
std::FILE* file = std::fopen(file_path.string().c_str(), "w+");
|
||||
@@ -39,7 +41,8 @@ bool CreateFile(std::filesystem::path file_path) {
|
||||
}
|
||||
|
||||
TEST(NearbyFileHandler, OpenFiles) {
|
||||
NearbyFileHandler nearby_file_handler;
|
||||
MockSharingPlatform mock_platform;
|
||||
NearbyFileHandler nearby_file_handler(mock_platform);
|
||||
absl::Notification notification;
|
||||
std::vector<NearbyFileHandler::FileInfo> result;
|
||||
std::filesystem::path test_file =
|
||||
@@ -59,7 +62,8 @@ TEST(NearbyFileHandler, OpenFiles) {
|
||||
}
|
||||
|
||||
TEST(NearbyFileHandler, DeleteAFileFromDisk) {
|
||||
NearbyFileHandler nearby_file_handler;
|
||||
MockSharingPlatform mock_platform;
|
||||
NearbyFileHandler nearby_file_handler(mock_platform);
|
||||
std::filesystem::path test_file =
|
||||
std::filesystem::temp_directory_path() / "nearby_nfh_test_abc.jpg";
|
||||
ASSERT_TRUE(CreateFile(test_file));
|
||||
@@ -72,7 +76,8 @@ TEST(NearbyFileHandler, DeleteAFileFromDisk) {
|
||||
}
|
||||
|
||||
TEST(NearbyFileHandler, DeleteMultipleFilesFromDisk) {
|
||||
NearbyFileHandler nearby_file_handler;
|
||||
MockSharingPlatform mock_platform;
|
||||
NearbyFileHandler nearby_file_handler(mock_platform);
|
||||
std::filesystem::path test_file =
|
||||
std::filesystem::temp_directory_path() / "nearby_nfh_test_abc.jpg";
|
||||
std::filesystem::path test_file2 =
|
||||
@@ -93,8 +98,9 @@ TEST(NearbyFileHandler, DeleteMultipleFilesFromDisk) {
|
||||
}
|
||||
|
||||
TEST(NearbyFileHandler, TestCallback) {
|
||||
MockSharingPlatform mock_platform;
|
||||
std::atomic_bool received_callback = false;
|
||||
NearbyFileHandler nearby_file_handler;
|
||||
NearbyFileHandler nearby_file_handler(mock_platform);
|
||||
std::filesystem::path test_file =
|
||||
std::filesystem::temp_directory_path() / "nearby_nfh_test_abc.jpg";
|
||||
ASSERT_TRUE(CreateFile(test_file));
|
||||
|
||||
@@ -226,6 +226,7 @@ NearbySharingServiceImpl::NearbySharingServiceImpl(
|
||||
local_device_data_manager_.get(), analytics_recorder_.get())),
|
||||
service_extension_(std::make_unique<NearbySharingServiceExtension>(
|
||||
context_, settings_.get())),
|
||||
file_handler_(sharing_platform),
|
||||
app_info_(sharing_platform.CreateAppInfo()) {
|
||||
NL_DCHECK(decoder_);
|
||||
NL_DCHECK(nearby_connections_manager_);
|
||||
|
||||
@@ -115,6 +115,7 @@ using ::nearby::sharing::service::proto::TextMetadata;
|
||||
using ::nearby::sharing::service::proto::V1Frame;
|
||||
using ::testing::InSequence;
|
||||
using ::testing::NiceMock;
|
||||
using ::testing::Return;
|
||||
using ::testing::ReturnRef;
|
||||
using ::testing::StrictMock;
|
||||
using ::testing::UnorderedElementsAre;
|
||||
@@ -380,6 +381,8 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
.WillByDefault(ReturnRef(preference_manager_));
|
||||
ON_CALL(mock_sharing_platform_, GetAccountManager)
|
||||
.WillByDefault(ReturnRef(fake_account_manager_));
|
||||
ON_CALL(mock_sharing_platform_, UpdateFileOriginMetadata)
|
||||
.WillByDefault(Return(true));
|
||||
auto mock_app_info = std::make_unique<StrictMock<MockAppInfo>>();
|
||||
mock_app_info_ = mock_app_info.get();
|
||||
EXPECT_CALL(mock_sharing_platform_, CreateAppInfo())
|
||||
|
||||
Reference in New Issue
Block a user