OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "shell/android/android_handler.h" | 5 #include "shell/android/android_handler.h" |
6 | 6 |
| 7 #include <fcntl.h> |
| 8 |
7 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
9 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
10 #include "base/logging.h" | 12 #include "base/logging.h" |
11 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/rand_util.h" |
12 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
13 #include "base/scoped_native_library.h" | 16 #include "base/scoped_native_library.h" |
| 17 #include "base/strings/string_number_conversions.h" |
14 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
15 #include "jni/AndroidHandler_jni.h" | 19 #include "jni/AndroidHandler_jni.h" |
16 #include "mojo/common/data_pipe_utils.h" | 20 #include "mojo/common/data_pipe_utils.h" |
17 #include "mojo/public/c/system/main.h" | 21 #include "mojo/public/c/system/main.h" |
18 #include "mojo/public/cpp/application/application_impl.h" | 22 #include "mojo/public/cpp/application/application_impl.h" |
19 #include "shell/android/run_android_application_function.h" | 23 #include "shell/android/run_android_application_function.h" |
20 #include "shell/native_application_support.h" | 24 #include "shell/native_application_support.h" |
21 | 25 |
22 using base::android::AttachCurrentThread; | 26 using base::android::AttachCurrentThread; |
23 using base::android::ScopedJavaLocalRef; | 27 using base::android::ScopedJavaLocalRef; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 *extracted_dir = base::FilePath( | 151 *extracted_dir = base::FilePath( |
148 std::string(reinterpret_cast<char*>(&extracted_path.front()), | 152 std::string(reinterpret_cast<char*>(&extracted_path.front()), |
149 extracted_path.size())); | 153 extracted_path.size())); |
150 *cache_dir = base::FilePath(std::string( | 154 *cache_dir = base::FilePath(std::string( |
151 reinterpret_cast<char*>(&cache_path.front()), cache_path.size())); | 155 reinterpret_cast<char*>(&cache_path.front()), cache_path.size())); |
152 } | 156 } |
153 callback.Run(); | 157 callback.Run(); |
154 }); | 158 }); |
155 } | 159 } |
156 | 160 |
| 161 jstring CreateTemporaryFile(JNIEnv* env, |
| 162 jclass jcaller, |
| 163 jstring j_directory, |
| 164 jstring j_basename, |
| 165 jstring j_extension) { |
| 166 std::string basename(ConvertJavaStringToUTF8(env, j_basename)); |
| 167 std::string extension(ConvertJavaStringToUTF8(env, j_extension)); |
| 168 base::FilePath directory(ConvertJavaStringToUTF8(env, j_directory)); |
| 169 |
| 170 for (;;) { |
| 171 std::string random = base::RandBytesAsString(16); |
| 172 std::string filename = |
| 173 basename + base::HexEncode(random.data(), random.size()) + extension; |
| 174 base::FilePath temporary_file = directory.Append(filename); |
| 175 int fd = open(temporary_file.value().c_str(), O_CREAT | O_EXCL, 0600); |
| 176 if (fd != -1) { |
| 177 close(fd); |
| 178 return ConvertUTF8ToJavaString(env, temporary_file.value()).Release(); |
| 179 } |
| 180 } |
| 181 } |
| 182 |
157 bool RegisterAndroidHandlerJni(JNIEnv* env) { | 183 bool RegisterAndroidHandlerJni(JNIEnv* env) { |
158 return RegisterNativesImpl(env); | 184 return RegisterNativesImpl(env); |
159 } | 185 } |
160 | 186 |
161 } // namespace shell | 187 } // namespace shell |
OLD | NEW |