blob: 36ecdd6ebdc3caf89f51b7c382c15d803635ea86 [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2013 The Chromium Authors
[email protected]b144fe82013-03-01 19:32:272// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Andrew Grievef46caa512024-05-23 16:59:365#include "base/files/important_file_writer.h"
6
[email protected]b144fe82013-03-01 19:32:277#include <string>
8
9#include "base/android/jni_string.h"
[email protected]4ecbb8f82013-03-06 09:33:5310#include "base/threading/thread_restrictions.h"
[email protected]b144fe82013-03-01 19:32:2711
Andrew Grievef46caa512024-05-23 16:59:3612// Must come after all headers that specialize FromJniType() / ToJniType().
13#include "base/base_jni/ImportantFileWriterAndroid_jni.h"
14
[email protected]b144fe82013-03-01 19:32:2715namespace base {
16namespace android {
17
Etienne Pierre-doray89272912022-11-07 22:35:3818class ScopedAllowBlockingForImportantFileWriter
19 : public base::ScopedAllowBlocking {};
20
Daniel Bratell7aacf952017-11-21 17:51:2521static jboolean JNI_ImportantFileWriterAndroid_WriteFileAtomically(
22 JNIEnv* env,
Andrew Grievea74c30d2024-03-26 17:57:2523 std::string& native_file_name,
24 jni_zero::ByteArrayView& data) {
[email protected]4ecbb8f82013-03-06 09:33:5325 // This is called on the UI thread during shutdown to save tab data, so
26 // needs to enable IO.
Etienne Pierre-doray89272912022-11-07 22:35:3827 ScopedAllowBlockingForImportantFileWriter allow_blocking;
[email protected]b144fe82013-03-01 19:32:2728 base::FilePath path(native_file_name);
Andrew Grievea74c30d2024-03-26 17:57:2529 bool result =
30 base::ImportantFileWriter::WriteFileAtomically(path, data.string_view());
[email protected]b144fe82013-03-01 19:32:2731 return result;
32}
33
[email protected]b144fe82013-03-01 19:32:2734} // namespace android
35} // namespace base