summaryrefslogtreecommitdiffstats
path: root/base/android
diff options
context:
space:
mode:
authorpeter@chromium.org <peter@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-14 11:24:04 +0000
committerpeter@chromium.org <peter@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-14 11:24:04 +0000
commit6fa1e7ef83628e4eac8db9cc824a2b8b471477c3 (patch)
tree7afb1d8a6ae92aa07ebe706486fc6d9e4db28f7e /base/android
parent192bd691ed6eedb3e08b5b619019cb7cb4300b84 (diff)
downloadchromium_src-6fa1e7ef83628e4eac8db9cc824a2b8b471477c3.zip
chromium_src-6fa1e7ef83628e4eac8db9cc824a2b8b471477c3.tar.gz
chromium_src-6fa1e7ef83628e4eac8db9cc824a2b8b471477c3.tar.bz2
Upstream Android's PathUtils implementation.
BUG= TEST= Review URL: http://codereview.chromium.org/9443018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126624 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/android')
-rw-r--r--base/android/java/base.xml13
-rw-r--r--base/android/java/org/chromium/base/CalledByNative.java19
-rw-r--r--base/android/java/org/chromium/base/DeleteStaging.java16
-rw-r--r--base/android/java/org/chromium/base/PathUtils.java44
-rw-r--r--base/android/path_utils.cc21
5 files changed, 87 insertions, 26 deletions
diff --git a/base/android/java/base.xml b/base/android/java/base.xml
index a688eab..87cd72b 100644
--- a/base/android/java/base.xml
+++ b/base/android/java/base.xml
@@ -2,10 +2,13 @@
<description>
building base java source code with ant
</description>
- <!-- set global properties for this build -->
+ <!-- Set global properties for this build -->
+ <property environment="env"/>
+ <property name="sdk.dir" location="${env.ANDROID_SDK_ROOT}"/>
+ <property name="sdk.version" value="${env.ANDROID_SDK_VERSION}"/>
<property name="src" location="."/>
<property name="build" location="build"/>
- <property name="dist" location="dist"/>
+ <property name="dist" location="dist"/>
<target name="init">
<!-- Create the time stamp -->
@@ -17,7 +20,11 @@
<target name="compile" depends="init"
description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
- <javac srcdir="${src}" destdir="${build}"/>
+ <javac srcdir="${src}" destdir="${build}">
+ <classpath>
+ <path location="${sdk.dir}/platforms/android-${sdk.version}/android.jar"/>
+ </classpath>
+ </javac>
</target>
<target name="dist" depends="compile"
diff --git a/base/android/java/org/chromium/base/CalledByNative.java b/base/android/java/org/chromium/base/CalledByNative.java
new file mode 100644
index 0000000..086be32
--- /dev/null
+++ b/base/android/java/org/chromium/base/CalledByNative.java
@@ -0,0 +1,19 @@
+// Copyright (c) 2012 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.
+
+package org.chromium.base;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+// This annotation is used by the JNI generator to create the necessary JNI
+// bindings and expose this method to native code.
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface CalledByNative {
+ // If present, tells which inner class the method belongs to.
+ public String value() default "";
+}
diff --git a/base/android/java/org/chromium/base/DeleteStaging.java b/base/android/java/org/chromium/base/DeleteStaging.java
deleted file mode 100644
index 5f0718c..0000000
--- a/base/android/java/org/chromium/base/DeleteStaging.java
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright (c) 2012 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.
-
-package org.chromium.base;
-
-// This class serves as arbitrary Java code that can be compiled as part of
-// base_java, which builds base Java code that will be upstreamed. Please
-// delete this file and replace with actual base Java source files (e.g.
-// CallByNative.java and PathUtils.java).
-
-public class DeleteStaging {
- public static void main(String[] args) {
- return;
- }
-}
diff --git a/base/android/java/org/chromium/base/PathUtils.java b/base/android/java/org/chromium/base/PathUtils.java
new file mode 100644
index 0000000..94403d4
--- /dev/null
+++ b/base/android/java/org/chromium/base/PathUtils.java
@@ -0,0 +1,44 @@
+// Copyright (c) 2012 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.
+
+package org.chromium.base;
+
+import android.content.Context;
+import android.os.Environment;
+
+import org.chromium.base.CalledByNative;
+
+import java.io.File;
+
+/**
+ * This class provides the path related methods for the native library.
+ */
+class PathUtils {
+
+ /**
+ * @return the private directory that used to store application data.
+ */
+ @CalledByNative
+ public static String getDataDirectory(Context appContext) {
+ // TODO(beverloo) base/ should not know about "chrome": http://b/6057342
+ return appContext.getDir("chrome", Context.MODE_PRIVATE).getPath();
+ }
+
+ /**
+ * @return the cache directory.
+ */
+ @CalledByNative
+ public static String getCacheDirectory(Context appContext) {
+ return appContext.getCacheDir().getPath();
+ }
+
+ /**
+ * @return the public downloads directory.
+ */
+ @CalledByNative
+ public static String getDownloadsDirectory(Context appContext) {
+ return Environment.getExternalStoragePublicDirectory(
+ Environment.DIRECTORY_DOWNLOADS).getPath();
+ }
+}
diff --git a/base/android/path_utils.cc b/base/android/path_utils.cc
index dc45c28..c46e669 100644
--- a/base/android/path_utils.cc
+++ b/base/android/path_utils.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -15,16 +15,23 @@ namespace android {
std::string GetDataDirectory() {
JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jstring> path(env, Java_PathUtils_getDataDirectory(
- env, base::android::GetApplicationContext()));
- return base::android::ConvertJavaStringToUTF8(env, path.obj());
+ ScopedJavaLocalRef<jstring> path =
+ Java_PathUtils_getDataDirectory(env, GetApplicationContext());
+ return ConvertJavaStringToUTF8(path);
}
std::string GetCacheDirectory() {
JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jstring> path(env, Java_PathUtils_getCacheDirectory(
- env, base::android::GetApplicationContext()));
- return base::android::ConvertJavaStringToUTF8(env, path.obj());
+ ScopedJavaLocalRef<jstring> path =
+ Java_PathUtils_getCacheDirectory(env, GetApplicationContext());
+ return ConvertJavaStringToUTF8(path);
+}
+
+std::string GetDownloadsDirectory() {
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jstring> path =
+ Java_PathUtils_getDownloadsDirectory(env, GetApplicationContext());
+ return ConvertJavaStringToUTF8(path);
}
bool RegisterPathUtils(JNIEnv* env) {