1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/android/important_file_writer_android.h"
9 #include "base/android/jni_string.h"
10 #include "base/files/important_file_writer.h"
11 #include "base/threading/thread_restrictions.h"
12 #include "jni/ImportantFileWriterAndroid_jni.h"
17 static jboolean
WriteFileAtomically(JNIEnv
* env
,
21 // This is called on the UI thread during shutdown to save tab data, so
22 // needs to enable IO.
23 base::ThreadRestrictions::ScopedAllowIO allow_io
;
24 std::string native_file_name
;
25 base::android::ConvertJavaStringToUTF8(env
, file_name
, &native_file_name
);
26 base::FilePath
path(native_file_name
);
27 int data_length
= env
->GetArrayLength(data
);
28 jbyte
* native_data
= env
->GetByteArrayElements(data
, NULL
);
29 std::string
native_data_string(reinterpret_cast<char *>(native_data
),
31 bool result
= base::ImportantFileWriter::WriteFileAtomically(
32 path
, native_data_string
);
33 env
->ReleaseByteArrayElements(data
, native_data
, JNI_ABORT
);
37 bool RegisterImportantFileWriterAndroid(JNIEnv
* env
) {
38 return RegisterNativesImpl(env
);
41 } // namespace android