Chromium Code Reviews| Index: shell/android/android_handler.cc |
| diff --git a/shell/android/android_handler.cc b/shell/android/android_handler.cc |
| index 9d3181bbd999c3e5abf143283e06d466e5480e82..555efa80db2835f6cecadd78154e5a72af05cfe6 100644 |
| --- a/shell/android/android_handler.cc |
| +++ b/shell/android/android_handler.cc |
| @@ -4,13 +4,17 @@ |
| #include "shell/android/android_handler.h" |
| +#include <fcntl.h> |
| + |
| #include "base/android/jni_android.h" |
| #include "base/android/jni_string.h" |
| #include "base/files/file_path.h" |
| #include "base/logging.h" |
| #include "base/message_loop/message_loop.h" |
| +#include "base/rand_util.h" |
| #include "base/run_loop.h" |
| #include "base/scoped_native_library.h" |
| +#include "base/strings/string_number_conversions.h" |
| #include "base/trace_event/trace_event.h" |
| #include "jni/AndroidHandler_jni.h" |
| #include "mojo/common/data_pipe_utils.h" |
| @@ -154,6 +158,28 @@ void AndroidHandler::ExtractApplication(base::FilePath* extracted_dir, |
| }); |
| } |
| +jstring CreateTemporaryFile(JNIEnv* env, |
| + jclass jcaller, |
| + jstring j_directory, |
| + jstring j_basename, |
| + jstring j_extension) { |
| + std::string basename(ConvertJavaStringToUTF8(env, j_basename)); |
| + std::string extension(ConvertJavaStringToUTF8(env, j_extension)); |
| + base::FilePath directory(ConvertJavaStringToUTF8(env, j_directory)); |
| + |
| + for (;;) { |
| + std::string random = base::RandBytesAsString(16); |
| + std::string filename = |
| + basename + base::HexEncode(random.data(), random.size()) + extension; |
| + base::FilePath temporary_file = directory.Append(filename); |
| + int fd = open(temporary_file.value().c_str(), O_CREAT | O_EXCL, 0600); |
|
blundell
2015/05/13 09:16:43
Are you doing this construction in C++ rather than
qsr
2015/05/13 09:32:05
Nope, I do this in C++ because:
1) I now do not tr
|
| + if (fd != -1) { |
| + close(fd); |
| + return ConvertUTF8ToJavaString(env, temporary_file.value()).Release(); |
| + } |
| + } |
| +} |
| + |
| bool RegisterAndroidHandlerJni(JNIEnv* env) { |
| return RegisterNativesImpl(env); |
| } |