OLD | NEW |
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/content_uri_utils.h" | 5 #include "base/android/content_uri_utils.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/platform_file.h" | |
10 #include "jni/ContentUriUtils_jni.h" | 9 #include "jni/ContentUriUtils_jni.h" |
11 | 10 |
12 using base::android::ConvertUTF8ToJavaString; | 11 using base::android::ConvertUTF8ToJavaString; |
13 | 12 |
14 namespace base { | 13 namespace base { |
15 | 14 |
16 bool RegisterContentUriUtils(JNIEnv* env) { | 15 bool RegisterContentUriUtils(JNIEnv* env) { |
17 return RegisterNativesImpl(env); | 16 return RegisterNativesImpl(env); |
18 } | 17 } |
19 | 18 |
20 bool ContentUriExists(const FilePath& content_uri) { | 19 bool ContentUriExists(const FilePath& content_uri) { |
21 JNIEnv* env = base::android::AttachCurrentThread(); | 20 JNIEnv* env = base::android::AttachCurrentThread(); |
22 ScopedJavaLocalRef<jstring> j_uri = | 21 ScopedJavaLocalRef<jstring> j_uri = |
23 ConvertUTF8ToJavaString(env, content_uri.value()); | 22 ConvertUTF8ToJavaString(env, content_uri.value()); |
24 return Java_ContentUriUtils_contentUriExists( | 23 return Java_ContentUriUtils_contentUriExists( |
25 env, base::android::GetApplicationContext(), j_uri.obj()); | 24 env, base::android::GetApplicationContext(), j_uri.obj()); |
26 } | 25 } |
27 | 26 |
28 int OpenContentUriForRead(const FilePath& content_uri) { | 27 File OpenContentUriForRead(const FilePath& content_uri) { |
29 JNIEnv* env = base::android::AttachCurrentThread(); | 28 JNIEnv* env = base::android::AttachCurrentThread(); |
30 ScopedJavaLocalRef<jstring> j_uri = | 29 ScopedJavaLocalRef<jstring> j_uri = |
31 ConvertUTF8ToJavaString(env, content_uri.value()); | 30 ConvertUTF8ToJavaString(env, content_uri.value()); |
32 jint fd = Java_ContentUriUtils_openContentUriForRead( | 31 jint fd = Java_ContentUriUtils_openContentUriForRead( |
33 env, base::android::GetApplicationContext(), j_uri.obj()); | 32 env, base::android::GetApplicationContext(), j_uri.obj()); |
34 if (fd < 0) | 33 if (fd < 0) |
35 return base::kInvalidPlatformFileValue; | 34 return File(); |
36 return fd; | 35 return File(fd); |
37 } | 36 } |
38 | 37 |
39 } // namespace base | 38 } // namespace base |
OLD | NEW |