diff options
author | peter@chromium.org <peter@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-14 11:24:04 +0000 |
---|---|---|
committer | peter@chromium.org <peter@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-14 11:24:04 +0000 |
commit | 6fa1e7ef83628e4eac8db9cc824a2b8b471477c3 (patch) | |
tree | 7afb1d8a6ae92aa07ebe706486fc6d9e4db28f7e /base | |
parent | 192bd691ed6eedb3e08b5b619019cb7cb4300b84 (diff) | |
download | chromium_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')
-rw-r--r-- | base/android/java/base.xml | 13 | ||||
-rw-r--r-- | base/android/java/org/chromium/base/CalledByNative.java | 19 | ||||
-rw-r--r-- | base/android/java/org/chromium/base/DeleteStaging.java | 16 | ||||
-rw-r--r-- | base/android/java/org/chromium/base/PathUtils.java | 44 | ||||
-rw-r--r-- | base/android/path_utils.cc | 21 | ||||
-rw-r--r-- | base/base.gyp | 23 | ||||
-rw-r--r-- | base/base.gypi | 6 | ||||
-rw-r--r-- | base/test/test_stub_android.cc | 7 |
8 files changed, 114 insertions, 35 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) { diff --git a/base/base.gyp b/base/base.gyp index 0b20027..e3ccc34 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -115,6 +115,29 @@ ], }, { + 'target_name': 'base_jni_headers', + 'type': 'none', + 'actions': [ + { + 'action_name': 'generate_jni_headers', + 'inputs': [ + 'android/jni_generator/jni_generator.py', + 'android/java/org/chromium/base/PathUtils.java', + ], + 'outputs': [ + '<(SHARED_INTERMEDIATE_DIR)/base/jni/path_utils_jni.h', + ], + 'action': [ + 'python', + 'android/jni_generator/jni_generator.py', + '-o', + '<@(_inputs)', + '<@(_outputs)', + ], + } + ], + }, + { 'target_name': 'base_unittests', 'type': 'executable', 'sources': [ diff --git a/base/base.gypi b/base/base.gypi index c82011e..f5bf4a9 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -487,8 +487,6 @@ ['include', '^worker_pool_linux\\.cc$'], # TODO(michaelbai): The below files are excluded because of the # missing JNI, add them back when JNI is ready. - ['exclude', '^android/path_utils\\.cc$'], - ['exclude', '^base_paths_android\\.cc$'], ['exclude', '^message_pump_android\\.cc$'], ], }], @@ -666,6 +664,10 @@ 'dependencies': [ 'symbolize', '../third_party/ashmem/ashmem.gyp:ashmem', + 'base_jni_headers', + ], + 'include_dirs': [ + '<(SHARED_INTERMEDIATE_DIR)/base', ], 'link_settings': { 'libraries': [ diff --git a/base/test/test_stub_android.cc b/base/test/test_stub_android.cc index bcc241d..c806e22 100644 --- a/base/test/test_stub_android.cc +++ b/base/test/test_stub_android.cc @@ -201,11 +201,4 @@ void MessagePumpForUI::ScheduleWork() {} void MessagePumpForUI::ScheduleDelayedWork(const TimeTicks& delayed_work_time) { } -// TODO(michaelbai): The below PathProviderAndroid was added because we -// excluded base_paths_android.cc which requires JNI to compile. Remove them -// when this file added. -bool PathProviderAndroid(int key, FilePath* result) { - return false; -} - } // namespace base |