Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
[email protected] | b144fe8 | 2013-03-01 19:32:27 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
Andrew Grieve | f46caa51 | 2024-05-23 16:59:36 | [diff] [blame] | 5 | #include "base/files/important_file_writer.h" |
6 | |||||
[email protected] | b144fe8 | 2013-03-01 19:32:27 | [diff] [blame] | 7 | #include <string> |
8 | |||||
9 | #include "base/android/jni_string.h" | ||||
[email protected] | 4ecbb8f8 | 2013-03-06 09:33:53 | [diff] [blame] | 10 | #include "base/threading/thread_restrictions.h" |
[email protected] | b144fe8 | 2013-03-01 19:32:27 | [diff] [blame] | 11 | |
Andrew Grieve | f46caa51 | 2024-05-23 16:59:36 | [diff] [blame] | 12 | // Must come after all headers that specialize FromJniType() / ToJniType(). |
13 | #include "base/base_jni/ImportantFileWriterAndroid_jni.h" | ||||
14 | |||||
[email protected] | b144fe8 | 2013-03-01 19:32:27 | [diff] [blame] | 15 | namespace base { |
16 | namespace android { | ||||
17 | |||||
Etienne Pierre-doray | 8927291 | 2022-11-07 22:35:38 | [diff] [blame] | 18 | class ScopedAllowBlockingForImportantFileWriter |
19 | : public base::ScopedAllowBlocking {}; | ||||
20 | |||||
Daniel Bratell | 7aacf95 | 2017-11-21 17:51:25 | [diff] [blame] | 21 | static jboolean JNI_ImportantFileWriterAndroid_WriteFileAtomically( |
22 | JNIEnv* env, | ||||
Andrew Grieve | a74c30d | 2024-03-26 17:57:25 | [diff] [blame] | 23 | std::string& native_file_name, |
24 | jni_zero::ByteArrayView& data) { | ||||
[email protected] | 4ecbb8f8 | 2013-03-06 09:33:53 | [diff] [blame] | 25 | // This is called on the UI thread during shutdown to save tab data, so |
26 | // needs to enable IO. | ||||
Etienne Pierre-doray | 8927291 | 2022-11-07 22:35:38 | [diff] [blame] | 27 | ScopedAllowBlockingForImportantFileWriter allow_blocking; |
[email protected] | b144fe8 | 2013-03-01 19:32:27 | [diff] [blame] | 28 | base::FilePath path(native_file_name); |
Andrew Grieve | a74c30d | 2024-03-26 17:57:25 | [diff] [blame] | 29 | bool result = |
30 | base::ImportantFileWriter::WriteFileAtomically(path, data.string_view()); | ||||
[email protected] | b144fe8 | 2013-03-01 19:32:27 | [diff] [blame] | 31 | return result; |
32 | } | ||||
33 | |||||
[email protected] | b144fe8 | 2013-03-01 19:32:27 | [diff] [blame] | 34 | } // namespace android |
35 | } // namespace base |