| 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> | 7 #include <fcntl.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 *extracted_dir = base::FilePath( | 150 *extracted_dir = base::FilePath( |
| 151 std::string(reinterpret_cast<char*>(&extracted_path.front()), | 151 std::string(reinterpret_cast<char*>(&extracted_path.front()), |
| 152 extracted_path.size())); | 152 extracted_path.size())); |
| 153 *cache_dir = base::FilePath(std::string( | 153 *cache_dir = base::FilePath(std::string( |
| 154 reinterpret_cast<char*>(&cache_path.front()), cache_path.size())); | 154 reinterpret_cast<char*>(&cache_path.front()), cache_path.size())); |
| 155 } | 155 } |
| 156 callback.Run(); | 156 callback.Run(); |
| 157 }); | 157 }); |
| 158 } | 158 } |
| 159 | 159 |
| 160 jstring CreateTemporaryFile(JNIEnv* env, | 160 ScopedJavaLocalRef<jstring> CreateTemporaryFile(JNIEnv* env, |
| 161 jclass jcaller, | 161 jclass jcaller, |
| 162 jstring j_directory, | 162 jstring j_directory, |
| 163 jstring j_basename, | 163 jstring j_basename, |
| 164 jstring j_extension) { | 164 jstring j_extension) { |
| 165 std::string basename(ConvertJavaStringToUTF8(env, j_basename)); | 165 std::string basename(ConvertJavaStringToUTF8(env, j_basename)); |
| 166 std::string extension(ConvertJavaStringToUTF8(env, j_extension)); | 166 std::string extension(ConvertJavaStringToUTF8(env, j_extension)); |
| 167 base::FilePath directory(ConvertJavaStringToUTF8(env, j_directory)); | 167 base::FilePath directory(ConvertJavaStringToUTF8(env, j_directory)); |
| 168 | 168 |
| 169 for (;;) { | 169 for (;;) { |
| 170 std::string random = base::RandBytesAsString(16); | 170 std::string random = base::RandBytesAsString(16); |
| 171 std::string filename = | 171 std::string filename = |
| 172 basename + base::HexEncode(random.data(), random.size()) + extension; | 172 basename + base::HexEncode(random.data(), random.size()) + extension; |
| 173 base::FilePath temporary_file = directory.Append(filename); | 173 base::FilePath temporary_file = directory.Append(filename); |
| 174 int fd = open(temporary_file.value().c_str(), O_CREAT | O_EXCL, 0600); | 174 int fd = open(temporary_file.value().c_str(), O_CREAT | O_EXCL, 0600); |
| 175 if (fd != -1) { | 175 if (fd != -1) { |
| 176 close(fd); | 176 close(fd); |
| 177 return ConvertUTF8ToJavaString(env, temporary_file.value()).Release(); | 177 return ConvertUTF8ToJavaString(env, temporary_file.value()); |
| 178 } | 178 } |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 | 181 |
| 182 bool RegisterAndroidHandlerJni(JNIEnv* env) { | 182 bool RegisterAndroidHandlerJni(JNIEnv* env) { |
| 183 return RegisterNativesImpl(env); | 183 return RegisterNativesImpl(env); |
| 184 } | 184 } |
| 185 | 185 |
| 186 } // namespace shell | 186 } // namespace shell |
| OLD | NEW |