• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "base/files/important_file_writer.h"
6 
7 #include <string>
8 
9 #include "base/android/jni_string.h"
10 #include "base/threading/thread_restrictions.h"
11 
12 // Must come after all headers that specialize FromJniType() / ToJniType().
13 #include "base/base_jni/ImportantFileWriterAndroid_jni.h"
14 
15 namespace base {
16 namespace android {
17 
18 class ScopedAllowBlockingForImportantFileWriter
19     : public base::ScopedAllowBlocking {};
20 
JNI_ImportantFileWriterAndroid_WriteFileAtomically(JNIEnv * env,std::string & native_file_name,jni_zero::ByteArrayView & data)21 static jboolean JNI_ImportantFileWriterAndroid_WriteFileAtomically(
22     JNIEnv* env,
23     std::string& native_file_name,
24     jni_zero::ByteArrayView& data) {
25   // This is called on the UI thread during shutdown to save tab data, so
26   // needs to enable IO.
27   ScopedAllowBlockingForImportantFileWriter allow_blocking;
28   base::FilePath path(native_file_name);
29   bool result =
30       base::ImportantFileWriter::WriteFileAtomically(path, data.string_view());
31   return result;
32 }
33 
34 }  // namespace android
35 }  // namespace base
36