summaryrefslogtreecommitdiffstats
path: root/chromium/base/android/content_uri_utils.cc
blob: 64d6ad24226e3c72a7a6a945c221dec12f9bdfe1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/android/content_uri_utils.h"

#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "base/platform_file.h"
#include "jni/ContentUriUtils_jni.h"

using base::android::ConvertUTF8ToJavaString;

namespace base {

bool RegisterContentUriUtils(JNIEnv* env) {
  return RegisterNativesImpl(env);
}

bool ContentUriExists(const FilePath& content_uri) {
  JNIEnv* env = base::android::AttachCurrentThread();
  ScopedJavaLocalRef<jstring> j_uri =
      ConvertUTF8ToJavaString(env, content_uri.value());
  return Java_ContentUriUtils_contentUriExists(
      env, base::android::GetApplicationContext(), j_uri.obj());
}

int OpenContentUriForRead(const FilePath& content_uri) {
  JNIEnv* env = base::android::AttachCurrentThread();
  ScopedJavaLocalRef<jstring> j_uri =
      ConvertUTF8ToJavaString(env, content_uri.value());
  jint fd = Java_ContentUriUtils_openContentUriForRead(
      env, base::android::GetApplicationContext(), j_uri.obj());
  if (fd < 0)
    return base::kInvalidPlatformFileValue;
  return fd;
}

}  // namespace base