mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
This adds parent path and file name to the Payload constructor. This will affect chrome.
PiperOrigin-RevId: 435223740
This commit is contained in:
committed by
Copybara-Service
parent
31b2aae6c5
commit
517d77f5aa
@@ -161,7 +161,8 @@ class GNCInputStreamFromNSStream : public InputStream {
|
||||
PayloadId payloadId = payload.identifier;
|
||||
// Add the pair of payloadId and fileURL to the map in the GNCCore.
|
||||
[_core insertURLToMapWithPayloadID:payloadId urlToSend:fileURL];
|
||||
Payload corePayload(payloadId, InputFile(payloadId, fileSize));
|
||||
InputFile inputFile(payloadId, fileSize);
|
||||
Payload corePayload(payloadId, std::move(inputFile));
|
||||
progress.totalUnitCount = fileSize;
|
||||
return [self sendPayload:std::move(corePayload)
|
||||
size:fileSize
|
||||
|
||||
@@ -37,18 +37,21 @@ namespace location {
|
||||
namespace nearby {
|
||||
namespace api {
|
||||
|
||||
namespace {
|
||||
std::string GetPayloadPath(PayloadId payload_id) {
|
||||
std::string ImplementationPlatform::GetDownloadPath(std::string& parent_folder,
|
||||
std::string& file_name) {
|
||||
// This is to get a file path, e.g. /tmp/[payload_id], for the storage of payload file.
|
||||
// NOTE: Per
|
||||
// https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html
|
||||
// Files saved in the /tmp directory will be deleted by the system. Callers should be responsible
|
||||
// for copying the files to the permanent storage.
|
||||
NSString* payloadIdString = ObjCStringFromCppString(std::to_string(payload_id));
|
||||
// TODO(jfcarroll): This needs to be done correctly, we now have a file name and parent folder,
|
||||
// they should be combined with the default download path
|
||||
NSString* payloadIdString = ObjCStringFromCppString(file_name);
|
||||
return CppStringFromObjCString(
|
||||
[NSTemporaryDirectory() stringByAppendingPathComponent:payloadIdString]);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
OSName ImplementationPlatform::GetCurrentOS() { return OSName::kiOS; }
|
||||
|
||||
// Atomics:
|
||||
std::unique_ptr<AtomicBoolean> ImplementationPlatform::CreateAtomicBoolean(bool initial_value) {
|
||||
@@ -78,6 +81,7 @@ std::unique_ptr<ConditionVariable> ImplementationPlatform::CreateConditionVariab
|
||||
return std::make_unique<ios::ConditionVariable>(static_cast<ios::Mutex*>(mutex));
|
||||
}
|
||||
|
||||
ABSL_DEPRECATED("This interface will be deleted in the near future.")
|
||||
std::unique_ptr<InputFile> ImplementationPlatform::CreateInputFile(PayloadId payload_id,
|
||||
std::int64_t total_size) {
|
||||
// Extract the NSURL object with payload_id from |GNCCore| which stores the maps. If the retrieved
|
||||
@@ -86,14 +90,28 @@ std::unique_ptr<InputFile> ImplementationPlatform::CreateInputFile(PayloadId pay
|
||||
GNCCore* core = GNCGetCore();
|
||||
NSURL* url = [core extractURLWithPayloadID:payload_id];
|
||||
if (url != nil) {
|
||||
return absl::make_unique<ios::InputFile>(url);
|
||||
return std::make_unique<ios::InputFile>(url);
|
||||
} else {
|
||||
return shared::IOFile::CreateInputFile(GetPayloadPath(payload_id), total_size);
|
||||
std::string parent_folder("");
|
||||
std::string file_name(std::to_string(payload_id));
|
||||
return shared::IOFile::CreateInputFile(GetDownloadPath(parent_folder, file_name), total_size);
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<InputFile> ImplementationPlatform::CreateInputFile(absl::string_view file_path,
|
||||
size_t size) {
|
||||
return shared::IOFile::CreateInputFile(file_path, size);
|
||||
}
|
||||
|
||||
ABSL_DEPRECATED("This interface will be deleted in the near future.")
|
||||
std::unique_ptr<OutputFile> ImplementationPlatform::CreateOutputFile(PayloadId payload_id) {
|
||||
return shared::IOFile::CreateOutputFile(GetPayloadPath(payload_id));
|
||||
std::string parent_folder("");
|
||||
std::string file_name(std::to_string(payload_id));
|
||||
return shared::IOFile::CreateOutputFile(GetDownloadPath(parent_folder, file_name));
|
||||
}
|
||||
|
||||
std::unique_ptr<OutputFile> ImplementationPlatform::CreateOutputFile(absl::string_view file_path) {
|
||||
return shared::IOFile::CreateOutputFile(file_path);
|
||||
}
|
||||
|
||||
std::unique_ptr<LogMessage> ImplementationPlatform::CreateLogMessage(
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/platform/implementation/input_file.h"
|
||||
|
||||
namespace location {
|
||||
@@ -27,6 +28,8 @@ namespace ios {
|
||||
class InputFile : public api::InputFile {
|
||||
public:
|
||||
explicit InputFile(NSURL *nsURL);
|
||||
explicit InputFile(absl::string_view file_path, std::int64_t size);
|
||||
|
||||
~InputFile() override = default;
|
||||
InputFile(InputFile &&) = default;
|
||||
InputFile &operator=(InputFile &&) = default;
|
||||
@@ -39,6 +42,9 @@ class InputFile : public api::InputFile {
|
||||
private:
|
||||
NSURL *nsURL_;
|
||||
NSInputStream *nsStream_;
|
||||
|
||||
std::string path_;
|
||||
size_t total_size_;
|
||||
};
|
||||
|
||||
} // namespace ios
|
||||
|
||||
@@ -30,6 +30,11 @@ InputFile::InputFile(NSURL *nsURL) : nsURL_(nsURL) {
|
||||
[nsStream_ open];
|
||||
}
|
||||
|
||||
InputFile::InputFile(absl::string_view file_path, std::int64_t size)
|
||||
: path_(file_path), total_size_(size) {
|
||||
// TODO(jfcarroll): This is not implemented for iOS yet.
|
||||
}
|
||||
|
||||
ExceptionOr<ByteArray> InputFile::Read(std::int64_t size) {
|
||||
uint8_t *bytes_read = new uint8_t[size];
|
||||
NSUInteger numberOfBytesToRead = [[NSNumber numberWithLongLong:size] unsignedIntegerValue];
|
||||
|
||||
Reference in New Issue
Block a user