7 #include "packager/file/file_util.h" 11 #include "packager/base/files/file_path.h" 12 #include "packager/base/files/file_util.h" 13 #include "packager/base/process/process_handle.h" 14 #include "packager/base/strings/stringprintf.h" 15 #include "packager/base/threading/platform_thread.h" 16 #include "packager/base/time/time.h" 21 std::string TempFileName() {
22 const int32_t process_id =
static_cast<int32_t
>(base::GetCurrentProcId());
23 const int32_t thread_id =
24 static_cast<int32_t
>(base::PlatformThread::CurrentId());
29 static thread_local int32_t instance_id = 0;
32 const int64_t current_time = base::Time::Now().ToInternalValue();
33 return base::StringPrintf(
"packager-tempfile-%x-%x-%x-%" PRIx64, process_id,
34 thread_id, instance_id, current_time);
38 bool TempFilePath(
const std::string& temp_dir, std::string* temp_file_path) {
39 if (temp_dir.empty()) {
40 base::FilePath file_path;
41 if (!base::CreateTemporaryFile(&file_path)) {
42 LOG(ERROR) <<
"Failed to create temporary file.";
45 *temp_file_path = file_path.AsUTF8Unsafe();
48 base::FilePath::FromUTF8Unsafe(temp_dir)
49 .Append(base::FilePath::FromUTF8Unsafe(TempFileName()))
bool TempFilePath(const std::string &temp_dir, std::string *temp_file_path)
All the methods that are virtual are virtual for mocking.