Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: base/android/important_file_writer_android.cc

Issue 1312153003: jni_generator: Pass object parameters as JavaParamRef. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/android/important_file_writer_android.h" 5 #include "base/android/important_file_writer_android.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
10 #include "base/files/important_file_writer.h" 10 #include "base/files/important_file_writer.h"
11 #include "base/threading/thread_restrictions.h" 11 #include "base/threading/thread_restrictions.h"
12 #include "jni/ImportantFileWriterAndroid_jni.h" 12 #include "jni/ImportantFileWriterAndroid_jni.h"
13 13
14 namespace base { 14 namespace base {
15 namespace android { 15 namespace android {
16 16
17 static jboolean WriteFileAtomically(JNIEnv* env, 17 static jboolean WriteFileAtomically(JNIEnv* env,
18 jclass /* clazz */, 18 const JavaParamRef<jclass>& /* clazz */,
19 jstring file_name, 19 const JavaParamRef<jstring>& file_name,
20 jbyteArray data) { 20 const JavaParamRef<jbyteArray>& data) {
21 // This is called on the UI thread during shutdown to save tab data, so 21 // This is called on the UI thread during shutdown to save tab data, so
22 // needs to enable IO. 22 // needs to enable IO.
23 base::ThreadRestrictions::ScopedAllowIO allow_io; 23 base::ThreadRestrictions::ScopedAllowIO allow_io;
24 std::string native_file_name; 24 std::string native_file_name;
25 base::android::ConvertJavaStringToUTF8(env, file_name, &native_file_name); 25 base::android::ConvertJavaStringToUTF8(env, file_name, &native_file_name);
26 base::FilePath path(native_file_name); 26 base::FilePath path(native_file_name);
27 int data_length = env->GetArrayLength(data); 27 int data_length = env->GetArrayLength(data);
28 jbyte* native_data = env->GetByteArrayElements(data, NULL); 28 jbyte* native_data = env->GetByteArrayElements(data, NULL);
29 std::string native_data_string(reinterpret_cast<char *>(native_data), 29 std::string native_data_string(reinterpret_cast<char *>(native_data),
30 data_length); 30 data_length);
31 bool result = base::ImportantFileWriter::WriteFileAtomically( 31 bool result = base::ImportantFileWriter::WriteFileAtomically(
32 path, native_data_string); 32 path, native_data_string);
33 env->ReleaseByteArrayElements(data, native_data, JNI_ABORT); 33 env->ReleaseByteArrayElements(data, native_data, JNI_ABORT);
34 return result; 34 return result;
35 } 35 }
36 36
37 bool RegisterImportantFileWriterAndroid(JNIEnv* env) { 37 bool RegisterImportantFileWriterAndroid(JNIEnv* env) {
38 return RegisterNativesImpl(env); 38 return RegisterNativesImpl(env);
39 } 39 }
40 40
41 } // namespace android 41 } // namespace android
42 } // namespace base 42 } // namespace base
OLDNEW
« no previous file with comments | « base/android/field_trial_list.cc ('k') | base/android/jni_generator/golden_sample_for_tests_jni.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698