Fix emulator build error
[platform/framework/web/chromium-efl.git] / base / android / important_file_writer_android.cc
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.
4
5 #include <string>
6
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"
12
13 namespace base {
14 namespace android {
15
16 class ScopedAllowBlockingForImportantFileWriter
17     : public base::ScopedAllowBlocking {};
18
19 static jboolean JNI_ImportantFileWriterAndroid_WriteFileAtomically(
20     JNIEnv* env,
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);
33   return result;
34 }
35
36 }  // namespace android
37 }  // namespace base