Skip to content

Commit

Permalink
First step towards component build for Android.
Browse files Browse the repository at this point in the history
Add symbol exports needed to build content shell.

BUG=158821

Review URL: https://codereview.chromium.org/11368031

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165420 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
yfriedman@chromium.org committed Nov 1, 2012
1 parent 42af17e commit be363b2
Show file tree
Hide file tree
Showing 33 changed files with 137 additions and 96 deletions.
4 changes: 3 additions & 1 deletion base/android/base_jni_registrar.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

#include <jni.h>

#include "base/base_export.h"

namespace base {
namespace android {

// Register all JNI bindings necessary for base.
bool RegisterJni(JNIEnv* env);
BASE_EXPORT bool RegisterJni(JNIEnv* env);

} // namespace android
} // namespace base
Expand Down
59 changes: 31 additions & 28 deletions base/android/jni_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "base/android/scoped_java_ref.h"
#include "base/atomicops.h"
#include "base/base_export.h"
#include "base/compiler_specific.h"

namespace base {
Expand All @@ -25,41 +26,43 @@ struct RegistrationMethod {
};

// Attach the current thread to the VM (if necessary) and return the JNIEnv*.
JNIEnv* AttachCurrentThread();
BASE_EXPORT JNIEnv* AttachCurrentThread();

// Detach the current thread from VM if it is attached.
void DetachFromVM();
BASE_EXPORT void DetachFromVM();

// Initializes the global JVM. It is not necessarily called before
// InitApplicationContext().
void InitVM(JavaVM* vm);
BASE_EXPORT void InitVM(JavaVM* vm);

// Initializes the global application context object. The |context| can be any
// valid reference to the application context. Internally holds a global ref to
// the context. InitVM and InitApplicationContext maybe called in either order.
void InitApplicationContext(const JavaRef<jobject>& context);
BASE_EXPORT void InitApplicationContext(const JavaRef<jobject>& context);

// Gets a global ref to the application context set with
// InitApplicationContext(). Ownership is retained by the function - the caller
// must NOT release it.
const jobject GetApplicationContext();
const BASE_EXPORT jobject GetApplicationContext();

// Finds the class named |class_name| and returns it.
// Use this method instead of invoking directly the JNI FindClass method (to
// prevent leaking local references).
// This method triggers a fatal assertion if the class could not be found.
// Use HasClass if you need to check whether the class exists.
ScopedJavaLocalRef<jclass> GetClass(JNIEnv* env, const char* class_name);
BASE_EXPORT ScopedJavaLocalRef<jclass> GetClass(JNIEnv* env,
const char* class_name);

// Similar to the above, but the caller is responsible to manage the jclass
// lifetime.
jclass GetUnscopedClass(JNIEnv* env, const char* class_name) WARN_UNUSED_RESULT;
BASE_EXPORT jclass GetUnscopedClass(JNIEnv* env,
const char* class_name) WARN_UNUSED_RESULT;

// Returns true iff the class |class_name| could be found.
bool HasClass(JNIEnv* env, const char* class_name);
BASE_EXPORT bool HasClass(JNIEnv* env, const char* class_name);

// This class is a wrapper for JNIEnv Get(Static)MethodID.
class MethodID {
class BASE_EXPORT MethodID {
public:
enum Type {
TYPE_STATIC,
Expand Down Expand Up @@ -92,41 +95,41 @@ class MethodID {
// beyond the duration of all future calls to this function, across all
// threads. In practice, this means that the function should only be used with
// string constants.
jmethodID GetMethodIDFromClassName(JNIEnv* env,
const char* class_name,
const char* method,
const char* jni_signature);
BASE_EXPORT jmethodID GetMethodIDFromClassName(JNIEnv* env,
const char* class_name,
const char* method,
const char* jni_signature);

// Gets the field ID for a class field.
// This method triggers a fatal assertion if the field could not be found.
jfieldID GetFieldID(JNIEnv* env,
const JavaRef<jclass>& clazz,
const char* field_name,
const char* jni_signature);
BASE_EXPORT jfieldID GetFieldID(JNIEnv* env,
const JavaRef<jclass>& clazz,
const char* field_name,
const char* jni_signature);

// Returns true if |clazz| as a field with the given name and signature.
// TODO(jcivelli): Determine whether we explicitly have to pass the environment.
bool HasField(JNIEnv* env,
const JavaRef<jclass>& clazz,
const char* field_name,
const char* jni_signature);

// Gets the field ID for a static class field.
// This method triggers a fatal assertion if the field could not be found.
jfieldID GetStaticFieldID(JNIEnv* env,
BASE_EXPORT bool HasField(JNIEnv* env,
const JavaRef<jclass>& clazz,
const char* field_name,
const char* jni_signature);

// Gets the field ID for a static class field.
// This method triggers a fatal assertion if the field could not be found.
BASE_EXPORT jfieldID GetStaticFieldID(JNIEnv* env,
const JavaRef<jclass>& clazz,
const char* field_name,
const char* jni_signature);

// Returns true if an exception is pending in the provided JNIEnv*.
bool HasException(JNIEnv* env);
BASE_EXPORT bool HasException(JNIEnv* env);

// If an exception is pending in the provided JNIEnv*, this function clears it
// and returns true.
bool ClearException(JNIEnv* env);
BASE_EXPORT bool ClearException(JNIEnv* env);

// This function will call CHECK() macro if there's any pending exception.
void CheckException(JNIEnv* env);
BASE_EXPORT void CheckException(JNIEnv* env);

} // namespace android
} // namespace base
Expand Down
43 changes: 24 additions & 19 deletions base/android/jni_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,47 @@ namespace base {
namespace android {

// Returns a new Java byte array converted from the given bytes array.
ScopedJavaLocalRef<jbyteArray> ToJavaByteArray(
BASE_EXPORT ScopedJavaLocalRef<jbyteArray> ToJavaByteArray(
JNIEnv* env, const uint8* bytes, size_t len);

// Returns a array of Java byte array converted from |v|.
ScopedJavaLocalRef<jobjectArray> ToJavaArrayOfByteArray(
BASE_EXPORT ScopedJavaLocalRef<jobjectArray> ToJavaArrayOfByteArray(
JNIEnv* env, const std::vector<std::string>& v);

ScopedJavaLocalRef<jobjectArray> ToJavaArrayOfStrings(
BASE_EXPORT ScopedJavaLocalRef<jobjectArray> ToJavaArrayOfStrings(
JNIEnv* env, const std::vector<std::string>& v);

ScopedJavaLocalRef<jobjectArray> ToJavaArrayOfStrings(
BASE_EXPORT ScopedJavaLocalRef<jobjectArray> ToJavaArrayOfStrings(
JNIEnv* env, const std::vector<string16>& v);

// Converts a Java string array to a native array.
void AppendJavaStringArrayToStringVector(JNIEnv* env,
jobjectArray array,
std::vector<string16>* out);
BASE_EXPORT void AppendJavaStringArrayToStringVector(
JNIEnv* env,
jobjectArray array,
std::vector<string16>* out);

void AppendJavaStringArrayToStringVector(JNIEnv* env,
jobjectArray array,
std::vector<std::string>* out);
BASE_EXPORT void AppendJavaStringArrayToStringVector(
JNIEnv* env,
jobjectArray array,
std::vector<std::string>* out);

// Appends the Java bytes in |bytes_array| onto the end of |out|.
void AppendJavaByteArrayToByteVector(JNIEnv* env,
jbyteArray byte_array,
std::vector<uint8>* out);
BASE_EXPORT void AppendJavaByteArrayToByteVector(
JNIEnv* env,
jbyteArray byte_array,
std::vector<uint8>* out);

// Replaces the content of |out| with the Java bytes in |bytes_array|.
void JavaByteArrayToByteVector(JNIEnv* env,
jbyteArray byte_array,
std::vector<uint8>* out);
BASE_EXPORT void JavaByteArrayToByteVector(
JNIEnv* env,
jbyteArray byte_array,
std::vector<uint8>* out);

// Replaces the content of |out| with the Java ints in |int_array|.
void JavaIntArrayToIntVector(JNIEnv* env,
jintArray int_array,
std::vector<int>* out);
BASE_EXPORT void JavaIntArrayToIntVector(
JNIEnv* env,
jintArray int_array,
std::vector<int>* out);

} // namespace android
} // namespace base
Expand Down
5 changes: 3 additions & 2 deletions base/android/jni_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

#include <jni.h>

#include "base/base_export.h"
#include "base/android/scoped_java_ref.h"

// Manages WeakGlobalRef lifecycle.
// This class is not thread-safe w.r.t. get() and reset(). Multiple threads may
// safely use get() concurrently, but if the user calls reset() (or of course,
// calls the destructor) they'll need to provide their own synchronization.
class JavaObjectWeakGlobalRef {
class BASE_EXPORT JavaObjectWeakGlobalRef {
public:
JavaObjectWeakGlobalRef();
JavaObjectWeakGlobalRef(const JavaObjectWeakGlobalRef& orig);
Expand All @@ -34,7 +35,7 @@ class JavaObjectWeakGlobalRef {

// Get the real object stored in the weak reference returned as a
// ScopedJavaLocalRef.
base::android::ScopedJavaLocalRef<jobject> GetRealObject(
BASE_EXPORT base::android::ScopedJavaLocalRef<jobject> GetRealObject(
JNIEnv* env, jweak obj);

#endif // BASE_ANDROID_JNI_HELPER_H_
7 changes: 4 additions & 3 deletions base/android/jni_registrar.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define BASE_ANDROID_JNI_REGISTRAR_H_

#include <jni.h>
#include "base/base_export.h"
#include "base/basictypes.h"

namespace base {
Expand All @@ -16,9 +17,9 @@ struct RegistrationMethod;
// Registers the JNI bindings for the specified |method| definition containing
// |count| elements. Returns whether the registration of the given methods
// succeeded.
bool RegisterNativeMethods(JNIEnv* env,
const RegistrationMethod* method,
size_t count);
BASE_EXPORT bool RegisterNativeMethods(JNIEnv* env,
const RegistrationMethod* method,
size_t count);

} // namespace android
} // namespace base
Expand Down
13 changes: 7 additions & 6 deletions base/android/jni_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,27 @@
#include <string>

#include "base/android/scoped_java_ref.h"
#include "base/base_export.h"
#include "base/string_piece.h"

namespace base {
namespace android {

// Convert a Java string to UTF8. Returns a std string.
std::string ConvertJavaStringToUTF8(JNIEnv* env, jstring str);
std::string ConvertJavaStringToUTF8(const JavaRef<jstring>& str);
BASE_EXPORT std::string ConvertJavaStringToUTF8(JNIEnv* env, jstring str);
BASE_EXPORT std::string ConvertJavaStringToUTF8(const JavaRef<jstring>& str);

// Convert a std string to Java string.
ScopedJavaLocalRef<jstring> ConvertUTF8ToJavaString(
BASE_EXPORT ScopedJavaLocalRef<jstring> ConvertUTF8ToJavaString(
JNIEnv* env,
const base::StringPiece& str);

// Convert a Java string to UTF16. Returns a string16.
string16 ConvertJavaStringToUTF16(JNIEnv* env, jstring str);
string16 ConvertJavaStringToUTF16(const JavaRef<jstring>& str);
BASE_EXPORT string16 ConvertJavaStringToUTF16(JNIEnv* env, jstring str);
BASE_EXPORT string16 ConvertJavaStringToUTF16(const JavaRef<jstring>& str);

// Convert a string16 to a Java string.
ScopedJavaLocalRef<jstring> ConvertUTF16ToJavaString(
BASE_EXPORT ScopedJavaLocalRef<jstring> ConvertUTF16ToJavaString(
JNIEnv* env,
const base::StringPiece16& str);

Expand Down
5 changes: 3 additions & 2 deletions base/android/locale_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@

#include <string>

#include "base/base_export.h"
#include "base/string16.h"

namespace base {
namespace android {

// Return the current default locale of the device.
std::string GetDefaultLocale();
BASE_EXPORT std::string GetDefaultLocale();

string16 GetDisplayNameForLocale(const std::string& locale,
BASE_EXPORT string16 GetDisplayNameForLocale(const std::string& locale,
const std::string& display_locale);

bool RegisterLocaleUtils(JNIEnv* env);
Expand Down
8 changes: 5 additions & 3 deletions base/android/path_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include <jni.h>

#include "base/base_export.h"

class FilePath;

namespace base {
Expand All @@ -16,13 +18,13 @@ namespace android {
// application. The result is placed in the FilePath pointed to by 'result'.
// This method is dedicated for base_paths_android.c, Using
// PathService::Get(base::DIR_ANDROID_APP_DATA, ...) gets the data dir.
bool GetDataDirectory(FilePath* result);
BASE_EXPORT bool GetDataDirectory(FilePath* result);

// Retrieves the absolute path to the cache directory. The result is placed in
// the FilePath pointed to by 'result'. This method is dedicated for
// base_paths_android.c, Using PathService::Get(base::DIR_CACHE, ...) gets the
// cache dir.
bool GetCacheDirectory(FilePath* result);
BASE_EXPORT bool GetCacheDirectory(FilePath* result);

// Retrieves the path to the public downloads directory. The result is placed
// in the FilePath pointed to by 'result'.
Expand All @@ -35,7 +37,7 @@ bool GetNativeLibraryDirectory(FilePath* result);

// Retrieves the absolute path to the external storage directory. The result
// is placed in the FilePath pointed to by 'result'.
bool GetExternalStorageDirectory(FilePath* result);
BASE_EXPORT bool GetExternalStorageDirectory(FilePath* result);

bool RegisterPathUtils(JNIEnv* env);

Expand Down
3 changes: 2 additions & 1 deletion base/android/scoped_java_ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <jni.h>
#include <stddef.h>

#include "base/base_export.h"
#include "base/basictypes.h"

namespace base {
Expand All @@ -20,7 +21,7 @@ template<typename T> class JavaRef;
// other JavaRef<> template types. This allows you to e.g. pass
// ScopedJavaLocalRef<jstring> into a function taking const JavaRef<jobject>&
template<>
class JavaRef<jobject> {
class BASE_EXPORT JavaRef<jobject> {
public:
jobject obj() const { return obj_; }

Expand Down
3 changes: 2 additions & 1 deletion base/message_pump_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <jni.h>

#include "base/base_export.h"
#include "base/compiler_specific.h"
#include "base/message_pump.h"

Expand All @@ -17,7 +18,7 @@ class TimeTicks;

// This class implements a MessagePump needed for TYPE_UI MessageLoops on
// OS_ANDROID platform.
class MessagePumpForUI : public MessagePump {
class BASE_EXPORT MessagePumpForUI : public MessagePump {
public:
MessagePumpForUI();

Expand Down
10 changes: 6 additions & 4 deletions base/test/test_support_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
#ifndef BASE_TEST_TEST_SUPPORT_ANDROID_H_
#define BASE_TEST_TEST_SUPPORT_ANDROID_H_

#include "base/base_export.h"

namespace base {

// Init logging for tests on Android. Logs will be output into Android's logcat.
void InitAndroidTestLogging();
BASE_EXPORT void InitAndroidTestLogging();

// Init path providers for tests on Android.
void InitAndroidTestPaths();
BASE_EXPORT void InitAndroidTestPaths();

// Init the message loop for tests on Android.
void InitAndroidTestMessageLoop();
BASE_EXPORT void InitAndroidTestMessageLoop();

// Do all of the initializations above.
void InitAndroidTest();
BASE_EXPORT void InitAndroidTest();

} // namespace base

Expand Down
Loading

0 comments on commit be363b2

Please sign in to comment.