1 // Copyright 2013 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include "base/android/jni_array.h"
8 #include "base/android/jni_string.h"
9 #include "base/base_jni/ImportantFileWriterAndroid_jni.h"
10 #include "base/files/important_file_writer.h"
11 #include "base/threading/thread_restrictions.h"
16 class ScopedAllowBlockingForImportantFileWriter
17 : public base::ScopedAllowBlocking {};
19 static jboolean JNI_ImportantFileWriterAndroid_WriteFileAtomically(
21 const JavaParamRef<jstring>& file_name,
22 const JavaParamRef<jbyteArray>& data) {
23 // This is called on the UI thread during shutdown to save tab data, so
24 // needs to enable IO.
25 ScopedAllowBlockingForImportantFileWriter allow_blocking;
26 std::string native_file_name;
27 base::android::ConvertJavaStringToUTF8(env, file_name, &native_file_name);
28 base::FilePath path(native_file_name);
29 std::string native_data_string;
30 JavaByteArrayToString(env, data, &native_data_string);
31 bool result = base::ImportantFileWriter::WriteFileAtomically(
32 path, native_data_string);
36 } // namespace android