aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2018-04-11 23:28:35 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2018-04-11 23:28:35 +0000
commit048c95c20965e5ce59f486be54b3a082030c5aae (patch)
treeb3682fc53ddcbc609288c69c8522b265be1ea4d9
parent0371727a4782c43bbf96a7a579fa1d771083f3ea (diff)
parent871dde4cfa02530e1b8b0ba9cd7fe0c1ad8892df (diff)
downloadlibmojo-048c95c20965e5ce59f486be54b3a082030c5aae.tar.gz
Merge "Use the build_config.h in libchrome."
-rw-r--r--Android.bp23
-rw-r--r--base/android/content_uri_utils.cc48
-rw-r--r--base/android/content_uri_utils.h29
-rw-r--r--base/android/content_uri_utils_unittest.cc37
-rw-r--r--base/android/java/src/org/chromium/base/ContentUriUtils.java269
-rw-r--r--base/android/java/src/org/chromium/base/PathUtils.java224
-rw-r--r--base/android/java/src/org/chromium/base/SystemMessageHandler.java166
-rw-r--r--base/android/path_utils.cc78
-rw-r--r--base/android/path_utils.h54
-rw-r--r--base/android/path_utils_unittest.cc65
-rw-r--r--base/base_paths_android.cc63
-rw-r--r--base/base_paths_android.h25
-rw-r--r--base/base_paths_posix.cc123
-rw-r--r--base/files/file_util_android.cc16
-rw-r--r--base/message_loop/message_pump_android.cc196
-rw-r--r--base/message_loop/message_pump_android.h64
-rw-r--r--base/trace_event/java_heap_dump_provider_android.cc47
-rw-r--r--base/trace_event/java_heap_dump_provider_android.h36
-rw-r--r--base/trace_event/trace_event_android.cc216
-rw-r--r--build/build_config.h37
-rw-r--r--jni/java/lang/Runtime.classbin3209 -> 0 bytes
-rw-r--r--mojo/edk/embedder/platform_channel_pair_posix.cc6
-rw-r--r--mojo/edk/system/ports/node.cc2
23 files changed, 163 insertions, 1661 deletions
diff --git a/Android.bp b/Android.bp
index 85d31cb..33f4664 100644
--- a/Android.bp
+++ b/Android.bp
@@ -196,14 +196,7 @@ genrule {
srcs: [
"base/android/java/src/org/chromium/base/BuildInfo.java",
- "base/android/java/src/org/chromium/base/ContentUriUtils.java",
"base/android/java/src/org/chromium/base/ContextUtils.java",
- "base/android/java/src/org/chromium/base/PathUtils.java",
- "base/android/java/src/org/chromium/base/SystemMessageHandler.java",
- // Runtime.class is added (instead of Runtime.java that lives in
- // libcore) since the script that generates the JNI files does not
- // handle compiling it well.
- "jni/java/lang/Runtime.class",
"mojo/android/system/src/org/chromium/mojo/system/impl/BaseRunLoop.java",
"mojo/android/system/src/org/chromium/mojo/system/impl/CoreImpl.java",
"mojo/android/system/src/org/chromium/mojo/system/impl/WatcherImpl.java",
@@ -211,11 +204,7 @@ genrule {
out: [
"jni/BuildInfo_jni.h",
- "jni/ContentUriUtils_jni.h",
"jni/ContextUtils_jni.h",
- "jni/PathUtils_jni.h",
- "jni/SystemMessageHandler_jni.h",
- "jni/Runtime_jni.h",
"jni/BaseRunLoop_jni.h",
"jni/CoreImpl_jni.h",
"jni/WatcherImpl_jni.h",
@@ -241,20 +230,13 @@ cc_library_shared {
srcs: [
"base/android/build_info.cc",
- "base/android/content_uri_utils.cc",
"base/android/context_utils.cc",
- "base/android/java_runtime.cc",
"base/android/jni_android.cc",
"base/android/jni_string.cc",
- "base/android/path_utils.cc",
"base/android/scoped_java_ref.cc",
"base/base_paths.cc",
- "base/base_paths_android.cc",
- "base/files/file_util_android.cc",
- "base/message_loop/message_pump_android.cc",
+ "base/base_paths_posix.cc",
"base/path_service.cc",
- "base/trace_event/java_heap_dump_provider_android.cc",
- "base/trace_event/trace_event_android.cc",
"base/unguessable_token.cc",
"device/bluetooth/bluetooth_advertisement.cc",
"device/bluetooth/bluetooth_uuid.cc",
@@ -369,7 +351,6 @@ cc_library_shared {
"-DMOJO_EDK_LEGACY_PROTOCOL",
],
- // We use OS_POSIX since we need to communicate with Chrome.
// We also pass NO_ASHMEM to make base::SharedMemory avoid using it and prefer
// the POSIX versions.
cppflags: [
@@ -377,9 +358,7 @@ cc_library_shared {
"-Wno-non-virtual-dtor",
"-Wno-ignored-qualifiers",
"-Wno-extra",
- "-DOS_POSIX",
"-DNO_ASHMEM",
- "-DNO_TCMALLOC",
],
shared_libs: [
diff --git a/base/android/content_uri_utils.cc b/base/android/content_uri_utils.cc
deleted file mode 100644
index f7484cf..0000000
--- a/base/android/content_uri_utils.cc
+++ /dev/null
@@ -1,48 +0,0 @@
-// 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/context_utils.h"
-#include "base/android/jni_android.h"
-#include "base/android/jni_string.h"
-#include "jni/ContentUriUtils_jni.h"
-
-using base::android::ConvertUTF8ToJavaString;
-using base::android::ScopedJavaLocalRef;
-
-namespace base {
-
-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);
-}
-
-File 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);
- if (fd < 0)
- return File();
- return File(fd);
-}
-
-std::string GetContentUriMimeType(const FilePath& content_uri) {
- JNIEnv* env = base::android::AttachCurrentThread();
- ScopedJavaLocalRef<jstring> j_uri =
- ConvertUTF8ToJavaString(env, content_uri.value());
- ScopedJavaLocalRef<jstring> j_mime = Java_ContentUriUtils_getMimeType(
- env, base::android::GetApplicationContext(), j_uri);
- if (j_mime.is_null())
- return std::string();
-
- return base::android::ConvertJavaStringToUTF8(env, j_mime.obj());
-}
-
-} // namespace base
diff --git a/base/android/content_uri_utils.h b/base/android/content_uri_utils.h
deleted file mode 100644
index 6d817c0..0000000
--- a/base/android/content_uri_utils.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// 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.
-
-#ifndef BASE_ANDROID_CONTENT_URI_UTILS_H_
-#define BASE_ANDROID_CONTENT_URI_UTILS_H_
-
-#include <jni.h>
-
-#include "base/base_export.h"
-#include "base/files/file.h"
-#include "base/files/file_path.h"
-
-namespace base {
-
-// Opens a content URI for read and returns the file descriptor to the caller.
-// Returns -1 if the URI is invalid.
-BASE_EXPORT File OpenContentUriForRead(const FilePath& content_uri);
-
-// Check whether a content URI exists.
-BASE_EXPORT bool ContentUriExists(const FilePath& content_uri);
-
-// Gets MIME type from a content URI. Returns an empty string if the URI is
-// invalid.
-BASE_EXPORT std::string GetContentUriMimeType(const FilePath& content_uri);
-
-} // namespace base
-
-#endif // BASE_ANDROID_CONTENT_URI_UTILS_H_
diff --git a/base/android/content_uri_utils_unittest.cc b/base/android/content_uri_utils_unittest.cc
deleted file mode 100644
index c762035..0000000
--- a/base/android/content_uri_utils_unittest.cc
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2014 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/files/file_util.h"
-#include "base/path_service.h"
-#include "base/test/test_file_util.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace base {
-namespace android {
-
-TEST(ContentUriUtilsTest, ContentUriMimeTest) {
- // Get the test image path.
- FilePath data_dir;
- ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &data_dir));
- data_dir = data_dir.AppendASCII("file_util");
- ASSERT_TRUE(PathExists(data_dir));
- FilePath image_file = data_dir.Append(FILE_PATH_LITERAL("red.png"));
-
- // Insert the image into MediaStore. MediaStore will do some conversions, and
- // return the content URI.
- FilePath path = base::InsertImageIntoMediaStore(image_file);
- EXPECT_TRUE(path.IsContentUri());
- EXPECT_TRUE(PathExists(path));
-
- std::string mime = GetContentUriMimeType(path);
- EXPECT_EQ(mime, std::string("image/png"));
-
- FilePath invalid_path("content://foo.bar");
- mime = GetContentUriMimeType(invalid_path);
- EXPECT_TRUE(mime.empty());
-}
-
-} // namespace android
-} // namespace base
diff --git a/base/android/java/src/org/chromium/base/ContentUriUtils.java b/base/android/java/src/org/chromium/base/ContentUriUtils.java
deleted file mode 100644
index 9253f28..0000000
--- a/base/android/java/src/org/chromium/base/ContentUriUtils.java
+++ /dev/null
@@ -1,269 +0,0 @@
-// 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.
-
-package org.chromium.base;
-
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.res.AssetFileDescriptor;
-import android.database.Cursor;
-import android.net.Uri;
-import android.os.Build;
-import android.os.ParcelFileDescriptor;
-import android.provider.DocumentsContract;
-import android.util.Log;
-import android.webkit.MimeTypeMap;
-
-import org.chromium.base.annotations.CalledByNative;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-
-/**
- * This class provides methods to access content URI schemes.
- */
-public abstract class ContentUriUtils {
- private static final String TAG = "ContentUriUtils";
- private static FileProviderUtil sFileProviderUtil;
-
- // Guards access to sFileProviderUtil.
- private static final Object sLock = new Object();
-
- /**
- * Provides functionality to translate a file into a content URI for use
- * with a content provider.
- */
- public interface FileProviderUtil {
- /**
- * Generate a content URI from the given file.
- * @param context Application context.
- * @param file The file to be translated.
- */
- Uri getContentUriFromFile(Context context, File file);
- }
-
- // Prevent instantiation.
- private ContentUriUtils() {}
-
- public static void setFileProviderUtil(FileProviderUtil util) {
- synchronized (sLock) {
- sFileProviderUtil = util;
- }
- }
-
- public static Uri getContentUriFromFile(Context context, File file) {
- synchronized (sLock) {
- if (sFileProviderUtil != null) {
- return sFileProviderUtil.getContentUriFromFile(context, file);
- }
- }
- return null;
- }
-
- /**
- * Opens the content URI for reading, and returns the file descriptor to
- * the caller. The caller is responsible for closing the file desciptor.
- *
- * @param context {@link Context} in interest
- * @param uriString the content URI to open
- * @return file desciptor upon success, or -1 otherwise.
- */
- @CalledByNative
- public static int openContentUriForRead(Context context, String uriString) {
- AssetFileDescriptor afd = getAssetFileDescriptor(context, uriString);
- if (afd != null) {
- return afd.getParcelFileDescriptor().detachFd();
- }
- return -1;
- }
-
- /**
- * Check whether a content URI exists.
- *
- * @param context {@link Context} in interest.
- * @param uriString the content URI to query.
- * @return true if the URI exists, or false otherwise.
- */
- @CalledByNative
- public static boolean contentUriExists(Context context, String uriString) {
- AssetFileDescriptor asf = null;
- try {
- asf = getAssetFileDescriptor(context, uriString);
- return asf != null;
- } finally {
- // Do not use StreamUtil.closeQuietly here, as AssetFileDescriptor
- // does not implement Closeable until KitKat.
- if (asf != null) {
- try {
- asf.close();
- } catch (IOException e) {
- // Closing quietly.
- }
- }
- }
- }
-
- /**
- * Retrieve the MIME type for the content URI.
- *
- * @param context {@link Context} in interest.
- * @param uriString the content URI to look up.
- * @return MIME type or null if the input params are empty or invalid.
- */
- @CalledByNative
- public static String getMimeType(Context context, String uriString) {
- ContentResolver resolver = context.getContentResolver();
- Uri uri = Uri.parse(uriString);
- if (isVirtualDocument(uri, context)) {
- String[] streamTypes = resolver.getStreamTypes(uri, "*/*");
- return (streamTypes != null && streamTypes.length > 0) ? streamTypes[0] : null;
- }
- return resolver.getType(uri);
- }
-
- /**
- * Helper method to open a content URI and returns the ParcelFileDescriptor.
- *
- * @param context {@link Context} in interest.
- * @param uriString the content URI to open.
- * @return AssetFileDescriptor of the content URI, or NULL if the file does not exist.
- */
- private static AssetFileDescriptor getAssetFileDescriptor(Context context, String uriString) {
- ContentResolver resolver = context.getContentResolver();
- Uri uri = Uri.parse(uriString);
-
- try {
- if (isVirtualDocument(uri, context)) {
- String[] streamTypes = resolver.getStreamTypes(uri, "*/*");
- if (streamTypes != null && streamTypes.length > 0) {
- AssetFileDescriptor afd =
- resolver.openTypedAssetFileDescriptor(uri, streamTypes[0], null);
- if (afd.getStartOffset() != 0) {
- // Do not use StreamUtil.closeQuietly here, as AssetFileDescriptor
- // does not implement Closeable until KitKat.
- try {
- afd.close();
- } catch (IOException e) {
- // Closing quietly.
- }
- throw new SecurityException("Cannot open files with non-zero offset type.");
- }
- return afd;
- }
- } else {
- ParcelFileDescriptor pfd = resolver.openFileDescriptor(uri, "r");
- if (pfd != null) {
- return new AssetFileDescriptor(pfd, 0, AssetFileDescriptor.UNKNOWN_LENGTH);
- }
- }
- } catch (FileNotFoundException e) {
- Log.w(TAG, "Cannot find content uri: " + uriString, e);
- } catch (SecurityException e) {
- Log.w(TAG, "Cannot open content uri: " + uriString, e);
- } catch (IllegalArgumentException e) {
- Log.w(TAG, "Unknown content uri: " + uriString, e);
- } catch (IllegalStateException e) {
- Log.w(TAG, "Unknown content uri: " + uriString, e);
- }
-
- return null;
- }
-
- /**
- * Method to resolve the display name of a content URI.
- *
- * @param uri the content URI to be resolved.
- * @param context {@link Context} in interest.
- * @param columnField the column field to query.
- * @return the display name of the @code uri if present in the database
- * or an empty string otherwise.
- */
- public static String getDisplayName(Uri uri, Context context, String columnField) {
- if (uri == null) return "";
- ContentResolver contentResolver = context.getContentResolver();
- Cursor cursor = null;
- try {
- cursor = contentResolver.query(uri, null, null, null, null);
-
- if (cursor != null && cursor.getCount() >= 1) {
- cursor.moveToFirst();
- int displayNameIndex = cursor.getColumnIndex(columnField);
- if (displayNameIndex == -1) {
- return "";
- }
- String displayName = cursor.getString(displayNameIndex);
- // For Virtual documents, try to modify the file extension so it's compatible
- // with the alternative MIME type.
- if (hasVirtualFlag(cursor)) {
- String[] mimeTypes = contentResolver.getStreamTypes(uri, "*/*");
- if (mimeTypes != null && mimeTypes.length > 0) {
- String ext =
- MimeTypeMap.getSingleton().getExtensionFromMimeType(mimeTypes[0]);
- if (ext != null) {
- // Just append, it's simpler and more secure than altering an
- // existing extension.
- displayName += "." + ext;
- }
- }
- }
- return displayName;
- }
- } catch (NullPointerException e) {
- // Some android models don't handle the provider call correctly.
- // see crbug.com/345393
- return "";
- } finally {
- StreamUtil.closeQuietly(cursor);
- }
- return "";
- }
-
- /**
- * Checks whether the passed Uri represents a virtual document.
- *
- * @param uri the content URI to be resolved.
- * @param contentResolver the content resolver to query.
- * @return True for virtual file, false for any other file.
- */
- private static boolean isVirtualDocument(Uri uri, Context context) {
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return false;
- if (uri == null) return false;
- if (!DocumentsContract.isDocumentUri(context, uri)) return false;
- ContentResolver contentResolver = context.getContentResolver();
- Cursor cursor = null;
- try {
- cursor = contentResolver.query(uri, null, null, null, null);
-
- if (cursor != null && cursor.getCount() >= 1) {
- cursor.moveToFirst();
- return hasVirtualFlag(cursor);
- }
- } catch (NullPointerException e) {
- // Some android models don't handle the provider call correctly.
- // see crbug.com/345393
- return false;
- } finally {
- StreamUtil.closeQuietly(cursor);
- }
- return false;
- }
-
- /**
- * Checks whether the passed cursor for a document has a virtual document flag.
- *
- * The called must close the passed cursor.
- *
- * @param cursor Cursor with COLUMN_FLAGS.
- * @return True for virtual file, false for any other file.
- */
- private static boolean hasVirtualFlag(Cursor cursor) {
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return false;
- int index = cursor.getColumnIndex(DocumentsContract.Document.COLUMN_FLAGS);
- if (index > -1) {
- return (cursor.getLong(index) & DocumentsContract.Document.FLAG_VIRTUAL_DOCUMENT) != 0;
- }
- return false;
- }
-}
diff --git a/base/android/java/src/org/chromium/base/PathUtils.java b/base/android/java/src/org/chromium/base/PathUtils.java
deleted file mode 100644
index 00977d5..0000000
--- a/base/android/java/src/org/chromium/base/PathUtils.java
+++ /dev/null
@@ -1,224 +0,0 @@
-// Copyright 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.content.pm.ApplicationInfo;
-import android.os.AsyncTask;
-import android.os.Environment;
-import android.os.StrictMode;
-import android.os.SystemClock;
-
-import org.chromium.base.annotations.CalledByNative;
-import org.chromium.base.annotations.MainDex;
-import org.chromium.base.metrics.RecordHistogram;
-
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-/**
- * This class provides the path related methods for the native library.
- */
-@MainDex
-public abstract class PathUtils {
- private static final String THUMBNAIL_DIRECTORY_NAME = "textures";
-
- private static final int DATA_DIRECTORY = 0;
- private static final int THUMBNAIL_DIRECTORY = 1;
- private static final int DATABASE_DIRECTORY = 2;
- private static final int CACHE_DIRECTORY = 3;
- private static final int NUM_DIRECTORIES = 4;
- private static final AtomicBoolean sInitializationStarted = new AtomicBoolean();
- private static AsyncTask<Void, Void, String[]> sDirPathFetchTask;
-
- // If the AsyncTask started in setPrivateDataDirectorySuffix() fails to complete by the time we
- // need the values, we will need the suffix so that we can restart the task synchronously on
- // the UI thread.
- private static String sDataDirectorySuffix;
-
- // Prevent instantiation.
- private PathUtils() {}
-
- /**
- * Initialization-on-demand holder. This exists for thread-safe lazy initialization. It will
- * cause getOrComputeDirectoryPaths() to be called (safely) the first time DIRECTORY_PATHS is
- * accessed.
- *
- * <p>See https://en.wikipedia.org/wiki/Initialization-on-demand_holder_idiom.
- */
- private static class Holder {
- private static final String[] DIRECTORY_PATHS = getOrComputeDirectoryPaths();
- }
-
- /**
- * Get the directory paths from sDirPathFetchTask if available, or compute it synchronously
- * on the UI thread otherwise. This should only be called as part of Holder's initialization
- * above to guarantee thread-safety as part of the initialization-on-demand holder idiom.
- */
- private static String[] getOrComputeDirectoryPaths() {
- try {
- // We need to call sDirPathFetchTask.cancel() here to prevent races. If it returns
- // true, that means that the task got canceled successfully (and thus, it did not
- // finish running its task). Otherwise, it failed to cancel, meaning that it was
- // already finished.
- if (sDirPathFetchTask.cancel(false)) {
- // Allow disk access here because we have no other choice.
- StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
- StrictMode.allowThreadDiskWrites();
- try {
- // sDirPathFetchTask did not complete. We have to run the code it was supposed
- // to be responsible for synchronously on the UI thread.
- return PathUtils.setPrivateDataDirectorySuffixInternal();
- } finally {
- StrictMode.setThreadPolicy(oldPolicy);
- }
- } else {
- // sDirPathFetchTask succeeded, and the values we need should be ready to access
- // synchronously in its internal future.
- return sDirPathFetchTask.get();
- }
- } catch (InterruptedException e) {
- } catch (ExecutionException e) {
- }
-
- return null;
- }
-
- /**
- * Fetch the path of the directory where private data is to be stored by the application. This
- * is meant to be called in an AsyncTask in setPrivateDataDirectorySuffix(), but if we need the
- * result before the AsyncTask has had a chance to finish, then it's best to cancel the task
- * and run it on the UI thread instead, inside getOrComputeDirectoryPaths().
- *
- * @see Context#getDir(String, int)
- */
- private static String[] setPrivateDataDirectorySuffixInternal() {
- String[] paths = new String[NUM_DIRECTORIES];
- Context appContext = ContextUtils.getApplicationContext();
- paths[DATA_DIRECTORY] = appContext.getDir(
- sDataDirectorySuffix, Context.MODE_PRIVATE).getPath();
- paths[THUMBNAIL_DIRECTORY] = appContext.getDir(
- THUMBNAIL_DIRECTORY_NAME, Context.MODE_PRIVATE).getPath();
- paths[DATABASE_DIRECTORY] = appContext.getDatabasePath("foo").getParent();
- if (appContext.getCacheDir() != null) {
- paths[CACHE_DIRECTORY] = appContext.getCacheDir().getPath();
- }
- return paths;
- }
-
- /**
- * Starts an asynchronous task to fetch the path of the directory where private data is to be
- * stored by the application.
- *
- * <p>This task can run long (or more likely be delayed in a large task queue), in which case we
- * want to cancel it and run on the UI thread instead. Unfortunately, this means keeping a bit
- * of extra static state - we need to store the suffix and the application context in case we
- * need to try to re-execute later.
- *
- * @param suffix The private data directory suffix.
- * @see Context#getDir(String, int)
- */
- public static void setPrivateDataDirectorySuffix(String suffix) {
- // This method should only be called once, but many tests end up calling it multiple times,
- // so adding a guard here.
- if (!sInitializationStarted.getAndSet(true)) {
- assert ContextUtils.getApplicationContext() != null;
- sDataDirectorySuffix = suffix;
- sDirPathFetchTask = new AsyncTask<Void, Void, String[]>() {
- @Override
- protected String[] doInBackground(Void... unused) {
- return PathUtils.setPrivateDataDirectorySuffixInternal();
- }
- }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
- }
- }
-
- /**
- * @param index The index of the cached directory path.
- * @return The directory path requested.
- */
- private static String getDirectoryPath(int index) {
- return Holder.DIRECTORY_PATHS[index];
- }
-
- /**
- * @return the private directory that is used to store application data.
- */
- @CalledByNative
- public static String getDataDirectory() {
- assert sDirPathFetchTask != null : "setDataDirectorySuffix must be called first.";
- return getDirectoryPath(DATA_DIRECTORY);
- }
-
- /**
- * @return the private directory that is used to store application database.
- */
- @CalledByNative
- public static String getDatabaseDirectory() {
- assert sDirPathFetchTask != null : "setDataDirectorySuffix must be called first.";
- return getDirectoryPath(DATABASE_DIRECTORY);
- }
-
- /**
- * @return the cache directory.
- */
- @CalledByNative
- public static String getCacheDirectory() {
- assert sDirPathFetchTask != null : "setDataDirectorySuffix must be called first.";
- return getDirectoryPath(CACHE_DIRECTORY);
- }
-
- @CalledByNative
- public static String getThumbnailCacheDirectory() {
- assert sDirPathFetchTask != null : "setDataDirectorySuffix must be called first.";
- return getDirectoryPath(THUMBNAIL_DIRECTORY);
- }
-
- /**
- * @return the public downloads directory.
- */
- @SuppressWarnings("unused")
- @CalledByNative
- private static String getDownloadsDirectory() {
- // Temporarily allowing disk access while fixing. TODO: http://crbug.com/508615
- StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
- String downloadsPath;
- try {
- long time = SystemClock.elapsedRealtime();
- downloadsPath = Environment.getExternalStoragePublicDirectory(
- Environment.DIRECTORY_DOWNLOADS).getPath();
- RecordHistogram.recordTimesHistogram("Android.StrictMode.DownloadsDir",
- SystemClock.elapsedRealtime() - time, TimeUnit.MILLISECONDS);
- } finally {
- StrictMode.setThreadPolicy(oldPolicy);
- }
- return downloadsPath;
- }
-
- /**
- * @return the path to native libraries.
- */
- @SuppressWarnings("unused")
- @CalledByNative
- private static String getNativeLibraryDirectory() {
- ApplicationInfo ai = ContextUtils.getApplicationContext().getApplicationInfo();
- if ((ai.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0
- || (ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
- return ai.nativeLibraryDir;
- }
-
- return "/system/lib/";
- }
-
- /**
- * @return the external storage directory.
- */
- @SuppressWarnings("unused")
- @CalledByNative
- public static String getExternalStorageDirectory() {
- return Environment.getExternalStorageDirectory().getAbsolutePath();
- }
-}
diff --git a/base/android/java/src/org/chromium/base/SystemMessageHandler.java b/base/android/java/src/org/chromium/base/SystemMessageHandler.java
deleted file mode 100644
index abfa2d8..0000000
--- a/base/android/java/src/org/chromium/base/SystemMessageHandler.java
+++ /dev/null
@@ -1,166 +0,0 @@
-// Copyright 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.annotation.SuppressLint;
-import android.os.Build;
-import android.os.Handler;
-import android.os.Message;
-
-import org.chromium.base.annotations.CalledByNative;
-import org.chromium.base.annotations.MainDex;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-@MainDex
-class SystemMessageHandler extends Handler {
-
- private static final String TAG = "cr.SysMessageHandler";
-
- private static final int SCHEDULED_WORK = 1;
- private static final int DELAYED_SCHEDULED_WORK = 2;
-
- // Native class pointer set by the constructor of the SharedClient native class.
- private long mMessagePumpDelegateNative = 0;
- private long mMessagePumpNative = 0;
- private long mDelayedScheduledTimeTicks = 0;
-
- protected SystemMessageHandler(long messagePumpDelegateNative, long messagePumpNative) {
- mMessagePumpDelegateNative = messagePumpDelegateNative;
- mMessagePumpNative = messagePumpNative;
- }
-
- @Override
- public void handleMessage(Message msg) {
- if (msg.what == DELAYED_SCHEDULED_WORK) {
- mDelayedScheduledTimeTicks = 0;
- }
- nativeDoRunLoopOnce(
- mMessagePumpDelegateNative, mMessagePumpNative, mDelayedScheduledTimeTicks);
- }
-
- @SuppressWarnings("unused")
- @CalledByNative
- private void scheduleWork() {
- sendMessage(obtainAsyncMessage(SCHEDULED_WORK));
- }
-
- @SuppressWarnings("unused")
- @CalledByNative
- private void scheduleDelayedWork(long delayedTimeTicks, long millis) {
- if (mDelayedScheduledTimeTicks != 0) {
- removeMessages(DELAYED_SCHEDULED_WORK);
- }
- mDelayedScheduledTimeTicks = delayedTimeTicks;
- sendMessageDelayed(obtainAsyncMessage(DELAYED_SCHEDULED_WORK), millis);
- }
-
- @SuppressWarnings("unused")
- @CalledByNative
- private void removeAllPendingMessages() {
- removeMessages(SCHEDULED_WORK);
- removeMessages(DELAYED_SCHEDULED_WORK);
- }
-
- private Message obtainAsyncMessage(int what) {
- // Marking the message async provides fair Chromium task dispatch when
- // served by the Android UI thread's Looper, avoiding stalls when the
- // Looper has a sync barrier.
- Message msg = Message.obtain();
- msg.what = what;
- MessageCompat.setAsynchronous(msg, true);
- return msg;
- }
-
- /**
- * Abstraction utility class for marking a Message as asynchronous. Prior
- * to L MR1 the async Message API was hidden, and for such cases we fall
- * back to using reflection to obtain the necessary method.
- */
- private static class MessageCompat {
- /**
- * @See android.os.Message#setAsynchronous(boolean)
- */
- public static void setAsynchronous(Message message, boolean async) {
- IMPL.setAsynchronous(message, async);
- }
-
- interface MessageWrapperImpl {
- /**
- * @See android.os.Message#setAsynchronous(boolean)
- */
- public void setAsynchronous(Message message, boolean async);
- }
-
- static final MessageWrapperImpl IMPL;
- static {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
- IMPL = new LollipopMr1MessageWrapperImpl();
- } else {
- IMPL = new LegacyMessageWrapperImpl();
- }
- }
-
- static class LollipopMr1MessageWrapperImpl implements MessageWrapperImpl {
- @SuppressLint("NewApi")
- @Override
- public void setAsynchronous(Message msg, boolean async) {
- msg.setAsynchronous(async);
- }
- }
-
- static class LegacyMessageWrapperImpl implements MessageWrapperImpl {
- // Reflected API for marking a message as asynchronous.
- // Note: Use of this API is experimental and likely to evolve in the future.
- private Method mMessageMethodSetAsynchronous;
-
- LegacyMessageWrapperImpl() {
- try {
- Class<?> messageClass = Class.forName("android.os.Message");
- mMessageMethodSetAsynchronous =
- messageClass.getMethod("setAsynchronous", new Class[] {boolean.class});
- } catch (ClassNotFoundException e) {
- Log.e(TAG, "Failed to find android.os.Message class", e);
- } catch (NoSuchMethodException e) {
- Log.e(TAG, "Failed to load Message.setAsynchronous method", e);
- } catch (RuntimeException e) {
- Log.e(TAG, "Exception while loading Message.setAsynchronous method", e);
- }
- }
-
- @Override
- public void setAsynchronous(Message msg, boolean async) {
- if (mMessageMethodSetAsynchronous == null) return;
- // If invocation fails, assume this is indicative of future
- // failures, and avoid log spam by nulling the reflected method.
- try {
- mMessageMethodSetAsynchronous.invoke(msg, async);
- } catch (IllegalAccessException e) {
- Log.e(TAG, "Illegal access to async message creation, disabling.");
- mMessageMethodSetAsynchronous = null;
- } catch (IllegalArgumentException e) {
- Log.e(TAG, "Illegal argument for async message creation, disabling.");
- mMessageMethodSetAsynchronous = null;
- } catch (InvocationTargetException e) {
- Log.e(TAG, "Invocation exception during async message creation, disabling.");
- mMessageMethodSetAsynchronous = null;
- } catch (RuntimeException e) {
- Log.e(TAG, "Runtime exception during async message creation, disabling.");
- mMessageMethodSetAsynchronous = null;
- }
- }
- }
- }
-
- @CalledByNative
- private static SystemMessageHandler create(
- long messagePumpDelegateNative, long messagePumpNative) {
- return new SystemMessageHandler(messagePumpDelegateNative, messagePumpNative);
- }
-
- private native void nativeDoRunLoopOnce(
- long messagePumpDelegateNative, long messagePumpNative, long delayedScheduledTimeTicks);
-}
diff --git a/base/android/path_utils.cc b/base/android/path_utils.cc
deleted file mode 100644
index 89ab833..0000000
--- a/base/android/path_utils.cc
+++ /dev/null
@@ -1,78 +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.
-
-#include "base/android/path_utils.h"
-
-#include "base/android/context_utils.h"
-#include "base/android/jni_android.h"
-#include "base/android/jni_string.h"
-#include "base/android/scoped_java_ref.h"
-#include "base/files/file_path.h"
-
-#include "jni/PathUtils_jni.h"
-
-namespace base {
-namespace android {
-
-bool GetDataDirectory(FilePath* result) {
- JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jstring> path = Java_PathUtils_getDataDirectory(env);
- FilePath data_path(ConvertJavaStringToUTF8(path));
- *result = data_path;
- return true;
-}
-
-bool GetDatabaseDirectory(FilePath* result) {
- JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jstring> path = Java_PathUtils_getDatabaseDirectory(env);
- FilePath data_path(ConvertJavaStringToUTF8(path));
- *result = data_path;
- return true;
-}
-
-bool GetCacheDirectory(FilePath* result) {
- JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jstring> path = Java_PathUtils_getCacheDirectory(env);
- FilePath cache_path(ConvertJavaStringToUTF8(path));
- *result = cache_path;
- return true;
-}
-
-bool GetThumbnailCacheDirectory(FilePath* result) {
- JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jstring> path =
- Java_PathUtils_getThumbnailCacheDirectory(env);
- FilePath thumbnail_cache_path(ConvertJavaStringToUTF8(path));
- *result = thumbnail_cache_path;
- return true;
-}
-
-bool GetDownloadsDirectory(FilePath* result) {
- JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jstring> path = Java_PathUtils_getDownloadsDirectory(env);
- FilePath downloads_path(ConvertJavaStringToUTF8(path));
- *result = downloads_path;
- return true;
-}
-
-bool GetNativeLibraryDirectory(FilePath* result) {
- JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jstring> path =
- Java_PathUtils_getNativeLibraryDirectory(env);
- FilePath library_path(ConvertJavaStringToUTF8(path));
- *result = library_path;
- return true;
-}
-
-bool GetExternalStorageDirectory(FilePath* result) {
- JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jstring> path =
- Java_PathUtils_getExternalStorageDirectory(env);
- FilePath storage_path(ConvertJavaStringToUTF8(path));
- *result = storage_path;
- return true;
-}
-
-} // namespace android
-} // namespace base
diff --git a/base/android/path_utils.h b/base/android/path_utils.h
deleted file mode 100644
index 7402644..0000000
--- a/base/android/path_utils.h
+++ /dev/null
@@ -1,54 +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.
-
-#ifndef BASE_ANDROID_PATH_UTILS_H_
-#define BASE_ANDROID_PATH_UTILS_H_
-
-#include <jni.h>
-
-#include "base/base_export.h"
-
-namespace base {
-
-class FilePath;
-
-namespace android {
-
-// Retrieves the absolute path to the data directory of the current
-// 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.
-BASE_EXPORT bool GetDataDirectory(FilePath* result);
-
-// Retrieves the absolute path to the database directory that Android
-// framework's SQLiteDatabase class uses when creating database files.
-BASE_EXPORT bool GetDatabaseDirectory(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.
-BASE_EXPORT bool GetCacheDirectory(FilePath* result);
-
-// Retrieves the path to the thumbnail cache directory. The result is placed
-// in the FilePath pointed to by 'result'.
-BASE_EXPORT bool GetThumbnailCacheDirectory(FilePath* result);
-
-// Retrieves the path to the public downloads directory. The result is placed
-// in the FilePath pointed to by 'result'.
-BASE_EXPORT bool GetDownloadsDirectory(FilePath* result);
-
-// Retrieves the path to the native JNI libraries via
-// ApplicationInfo.nativeLibraryDir on the Java side. The result is placed in
-// the FilePath pointed to by 'result'.
-BASE_EXPORT bool GetNativeLibraryDirectory(FilePath* result);
-
-// Retrieves the absolute path to the external storage directory. The result
-// is placed in the FilePath pointed to by 'result'.
-BASE_EXPORT bool GetExternalStorageDirectory(FilePath* result);
-
-} // namespace android
-} // namespace base
-
-#endif // BASE_ANDROID_PATH_UTILS_H_
diff --git a/base/android/path_utils_unittest.cc b/base/android/path_utils_unittest.cc
deleted file mode 100644
index dca8ca1..0000000
--- a/base/android/path_utils_unittest.cc
+++ /dev/null
@@ -1,65 +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.
-
-#include "base/android/path_utils.h"
-#include "base/files/file_path.h"
-#include "base/files/file_util.h"
-#include "base/strings/string_util.h"
-
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace base {
-namespace android {
-
-typedef testing::Test PathUtilsTest;
-
-namespace {
-void ExpectEither(const std::string& expected1,
- const std::string& expected2,
- const std::string& actual) {
- EXPECT_TRUE(expected1 == actual || expected2 == actual)
- << "Value of: " << actual << std::endl
- << "Expected either: " << expected1 << std::endl
- << "or: " << expected2;
-}
-} // namespace
-
-TEST_F(PathUtilsTest, TestGetDataDirectory) {
- // The string comes from the Java side and depends on the APK
- // we are running in. Assumes that we are packaged in
- // org.chromium.native_test
- FilePath path;
- GetDataDirectory(&path);
-
- ExpectEither("/data/data/org.chromium.native_test/app_chrome",
- "/data/user/0/org.chromium.native_test/app_chrome",
- path.value());
-}
-
-TEST_F(PathUtilsTest, TestGetCacheDirectory) {
- // The string comes from the Java side and depends on the APK
- // we are running in. Assumes that we are packaged in
- // org.chromium.native_test
- FilePath path;
- GetCacheDirectory(&path);
- ExpectEither("/data/data/org.chromium.native_test/cache",
- "/data/user/0/org.chromium.native_test/cache",
- path.value());
-}
-
-TEST_F(PathUtilsTest, TestGetNativeLibraryDirectory) {
- // The string comes from the Java side and depends on the APK
- // we are running in. Assumes that the directory contains
- // the base tests shared object.
- FilePath path;
- GetNativeLibraryDirectory(&path);
- EXPECT_TRUE(
- base::PathExists(path.Append("libbase_unittests.so")) ||
- base::PathExists(path.Append("libbase_unittests.cr.so")) ||
- base::PathExists(path.Append("lib_base_unittests__library.so")) ||
- base::PathExists(path.Append("lib_base_unittests__library.cr.so")));
-}
-
-} // namespace android
-} // namespace base
diff --git a/base/base_paths_android.cc b/base/base_paths_android.cc
deleted file mode 100644
index 8a400e5..0000000
--- a/base/base_paths_android.cc
+++ /dev/null
@@ -1,63 +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.
-
-// Defines base::PathProviderAndroid which replaces base::PathProviderPosix for
-// Android in base/path_service.cc.
-
-#include <limits.h>
-#include <unistd.h>
-
-#include "base/android/jni_android.h"
-#include "base/android/path_utils.h"
-#include "base/base_paths.h"
-#include "base/files/file_path.h"
-#include "base/files/file_util.h"
-#include "base/logging.h"
-#include "base/process/process_metrics.h"
-
-namespace base {
-
-bool PathProviderAndroid(int key, FilePath* result) {
- switch (key) {
- case base::FILE_EXE: {
- char bin_dir[PATH_MAX + 1];
- int bin_dir_size = readlink(kProcSelfExe, bin_dir, PATH_MAX);
- if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) {
- NOTREACHED() << "Unable to resolve " << kProcSelfExe << ".";
- return false;
- }
- bin_dir[bin_dir_size] = 0;
- *result = FilePath(bin_dir);
- return true;
- }
- case base::FILE_MODULE:
- // dladdr didn't work in Android as only the file name was returned.
- NOTIMPLEMENTED();
- return false;
- case base::DIR_MODULE:
- return base::android::GetNativeLibraryDirectory(result);
- case base::DIR_SOURCE_ROOT:
- // Used only by tests.
- // In that context, hooked up via base/test/test_support_android.cc.
- NOTIMPLEMENTED();
- return false;
- case base::DIR_USER_DESKTOP:
- // Android doesn't support GetUserDesktop.
- NOTIMPLEMENTED();
- return false;
- case base::DIR_CACHE:
- return base::android::GetCacheDirectory(result);
- case base::DIR_ANDROID_APP_DATA:
- return base::android::GetDataDirectory(result);
- case base::DIR_ANDROID_EXTERNAL_STORAGE:
- return base::android::GetExternalStorageDirectory(result);
- default:
- // Note: the path system expects this function to override the default
- // behavior. So no need to log an error if we don't support a given
- // path. The system will just use the default.
- return false;
- }
-}
-
-} // namespace base
diff --git a/base/base_paths_android.h b/base/base_paths_android.h
deleted file mode 100644
index 7a9ac4a..0000000
--- a/base/base_paths_android.h
+++ /dev/null
@@ -1,25 +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.
-
-#ifndef BASE_BASE_PATHS_ANDROID_H_
-#define BASE_BASE_PATHS_ANDROID_H_
-
-// This file declares Android-specific path keys for the base module.
-// These can be used with the PathService to access various special
-// directories and files.
-
-namespace base {
-
-enum {
- PATH_ANDROID_START = 300,
-
- DIR_ANDROID_APP_DATA, // Directory where to put Android app's data.
- DIR_ANDROID_EXTERNAL_STORAGE, // Android external storage directory.
-
- PATH_ANDROID_END
-};
-
-} // namespace base
-
-#endif // BASE_BASE_PATHS_ANDROID_H_
diff --git a/base/base_paths_posix.cc b/base/base_paths_posix.cc
new file mode 100644
index 0000000..d291e71
--- /dev/null
+++ b/base/base_paths_posix.cc
@@ -0,0 +1,123 @@
+// 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.
+
+// Defines base::PathProviderPosix, default path provider on POSIX OSes that
+// don't have their own base_paths_OS.cc implementation (i.e. all but Mac and
+// Android).
+
+#include "base/base_paths.h"
+
+#include <limits.h>
+#include <stddef.h>
+
+#include <memory>
+#include <ostream>
+#include <string>
+
+#include "base/environment.h"
+#include "base/files/file_path.h"
+#include "base/files/file_util.h"
+#include "base/logging.h"
+// Unused. TODO(hidehiko): Introduce a stub file when merging into libchrome.
+// #include "base/nix/xdg_util.h"
+#include "base/path_service.h"
+#include "base/process/process_metrics.h"
+#include "build/build_config.h"
+
+#if defined(OS_FREEBSD)
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#elif defined(OS_SOLARIS)
+#include <stdlib.h>
+#endif
+
+namespace base {
+
+bool PathProviderPosix(int key, FilePath* result) {
+ FilePath path;
+ switch (key) {
+ case FILE_EXE:
+ case FILE_MODULE: { // TODO(evanm): is this correct?
+#if defined(OS_LINUX)
+ FilePath bin_dir;
+ if (!ReadSymbolicLink(FilePath(kProcSelfExe), &bin_dir)) {
+ NOTREACHED() << "Unable to resolve " << kProcSelfExe << ".";
+ return false;
+ }
+ *result = bin_dir;
+ return true;
+#elif defined(OS_FREEBSD)
+ int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
+ char bin_dir[PATH_MAX + 1];
+ size_t length = sizeof(bin_dir);
+ // Upon return, |length| is the number of bytes written to |bin_dir|
+ // including the string terminator.
+ int error = sysctl(name, 4, bin_dir, &length, NULL, 0);
+ if (error < 0 || length <= 1) {
+ NOTREACHED() << "Unable to resolve path.";
+ return false;
+ }
+ *result = FilePath(FilePath::StringType(bin_dir, length - 1));
+ return true;
+#elif defined(OS_SOLARIS)
+ char bin_dir[PATH_MAX + 1];
+ if (realpath(getexecname(), bin_dir) == NULL) {
+ NOTREACHED() << "Unable to resolve " << getexecname() << ".";
+ return false;
+ }
+ *result = FilePath(bin_dir);
+ return true;
+#elif defined(OS_OPENBSD)
+ // There is currently no way to get the executable path on OpenBSD
+ char* cpath;
+ if ((cpath = getenv("CHROME_EXE_PATH")) != NULL)
+ *result = FilePath(cpath);
+ else
+ *result = FilePath("/usr/local/chrome/chrome");
+ return true;
+#endif
+ }
+// Following paths are not supported in libchrome/libmojo.
+#if 0
+ case DIR_SOURCE_ROOT: {
+ // Allow passing this in the environment, for more flexibility in build
+ // tree configurations (sub-project builds, gyp --output_dir, etc.)
+ std::unique_ptr<Environment> env(Environment::Create());
+ std::string cr_source_root;
+ if (env->GetVar("CR_SOURCE_ROOT", &cr_source_root)) {
+ path = FilePath(cr_source_root);
+ if (PathExists(path)) {
+ *result = path;
+ return true;
+ }
+ DLOG(WARNING) << "CR_SOURCE_ROOT is set, but it appears to not "
+ << "point to a directory.";
+ }
+ // On POSIX, unit tests execute two levels deep from the source root.
+ // For example: out/{Debug|Release}/net_unittest
+ if (PathService::Get(DIR_EXE, &path)) {
+ *result = path.DirName().DirName();
+ return true;
+ }
+
+ DLOG(ERROR) << "Couldn't find your source root. "
+ << "Try running from your chromium/src directory.";
+ return false;
+ }
+ case DIR_USER_DESKTOP:
+ *result = nix::GetXDGUserDirectory("DESKTOP", "Desktop");
+ return true;
+ case DIR_CACHE: {
+ std::unique_ptr<Environment> env(Environment::Create());
+ FilePath cache_dir(
+ nix::GetXDGDirectory(env.get(), "XDG_CACHE_HOME", ".cache"));
+ *result = cache_dir;
+ return true;
+ }
+#endif
+ }
+ return false;
+}
+
+} // namespace base
diff --git a/base/files/file_util_android.cc b/base/files/file_util_android.cc
deleted file mode 100644
index b8b3b37..0000000
--- a/base/files/file_util_android.cc
+++ /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.
-
-#include "base/files/file_util.h"
-
-#include "base/files/file_path.h"
-#include "base/path_service.h"
-
-namespace base {
-
-bool GetShmemTempDir(bool executable, base::FilePath* path) {
- return PathService::Get(base::DIR_CACHE, path);
-}
-
-} // namespace base
diff --git a/base/message_loop/message_pump_android.cc b/base/message_loop/message_pump_android.cc
deleted file mode 100644
index bedb205..0000000
--- a/base/message_loop/message_pump_android.cc
+++ /dev/null
@@ -1,196 +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.
-
-#include "base/message_loop/message_pump_android.h"
-
-#include <jni.h>
-
-#include "base/android/java_message_handler_factory.h"
-#include "base/android/jni_android.h"
-#include "base/android/scoped_java_ref.h"
-#include "base/lazy_instance.h"
-#include "base/logging.h"
-#include "base/message_loop/message_loop.h"
-#include "base/run_loop.h"
-#include "base/time/time.h"
-#include "jni/SystemMessageHandler_jni.h"
-
-using base::android::JavaParamRef;
-using base::android::ScopedJavaLocalRef;
-
-// ----------------------------------------------------------------------------
-// Native JNI methods called by Java.
-// ----------------------------------------------------------------------------
-// This method can not move to anonymous namespace as it has been declared as
-// 'static' in system_message_handler_jni.h.
-static void DoRunLoopOnce(JNIEnv* env,
- const JavaParamRef<jobject>& obj,
- jlong native_delegate,
- jlong native_message_pump,
- jlong delayed_scheduled_time_ticks) {
- base::MessagePump::Delegate* delegate =
- reinterpret_cast<base::MessagePump::Delegate*>(native_delegate);
- DCHECK(delegate);
- base::MessagePumpForUI* pump =
- reinterpret_cast<base::MessagePumpForUI*>(native_message_pump);
- DCHECK(pump);
- // This is based on MessagePumpForUI::DoRunLoop() from desktop.
- // Note however that our system queue is handled in the java side.
- // In desktop we inspect and process a single system message and then
- // we call DoWork() / DoDelayedWork().
- // On Android, the java message queue may contain messages for other handlers
- // that will be processed before calling here again.
- bool did_work = delegate->DoWork();
- if (pump->ShouldAbort()) {
- // There is a pending JNI exception, return to Java so that the exception is
- // thrown correctly.
- return;
- }
-
- // In the java side, |SystemMessageHandler| keeps a single "delayed" message.
- // It's an expensive operation to |removeMessage| there, so this is optimized
- // to avoid those calls.
- //
- // At this stage, |next_delayed_work_time| can be:
- // 1) The same as previously scheduled: nothing to be done, move along. This
- // is the typical case, since this method is called for every single message.
- //
- // 2) Not previously scheduled: just post a new message in java.
- //
- // 3) Shorter than previously scheduled: far less common. In this case,
- // |removeMessage| and post a new one.
- //
- // 4) Longer than previously scheduled (or null): nothing to be done, move
- // along.
- //
- // Side note: base::TimeTicks is a C++ representation and can't be
- // compared in java. When calling |scheduleDelayedWork|, pass the
- // |InternalValue()| to java and then back to C++ so the comparisons can be
- // done here.
- // This roundtrip allows comparing TimeTicks directly (cheap) and
- // avoid comparisons with TimeDelta / Now() (expensive).
- base::TimeTicks next_delayed_work_time;
- did_work |= delegate->DoDelayedWork(&next_delayed_work_time);
- if (pump->ShouldAbort()) {
- // There is a pending JNI exception, return to Java so that the exception is
- // thrown correctly
- return;
- }
-
- if (!next_delayed_work_time.is_null()) {
- // Schedule a new message if there's nothing already scheduled or there's a
- // shorter delay than previously scheduled (see (2) and (3) above).
- if (delayed_scheduled_time_ticks == 0 ||
- next_delayed_work_time < base::TimeTicks::FromInternalValue(
- delayed_scheduled_time_ticks)) {
- Java_SystemMessageHandler_scheduleDelayedWork(env, obj,
- next_delayed_work_time.ToInternalValue(),
- (next_delayed_work_time -
- base::TimeTicks::Now()).InMillisecondsRoundedUp());
- }
- }
-
- // This is a major difference between android and other platforms: since we
- // can't inspect it and process just one single message, instead we'll yeld
- // the callstack.
- if (did_work)
- return;
-
- delegate->DoIdleWork();
- // Note that we do not check whether we should abort here since we are
- // returning to the JVM anyway. If, in the future, we add any more code after
- // the call to DoIdleWork() here, we should add an abort-check and return
- // immediately if the check passes.
-}
-
-namespace base {
-
-MessagePumpForUI::MessagePumpForUI()
- : run_loop_(nullptr), should_abort_(false) {}
-
-MessagePumpForUI::~MessagePumpForUI() {
-}
-
-void MessagePumpForUI::Run(Delegate* delegate) {
- NOTREACHED() << "UnitTests should rely on MessagePumpForUIStub in"
- " test_stub_android.h";
-}
-
-JNIEnv* MessagePumpForUI::StartInternal() {
- run_loop_ = new RunLoop();
- // Since the RunLoop was just created above, BeforeRun should be guaranteed to
- // return true (it only returns false if the RunLoop has been Quit already).
- if (!run_loop_->BeforeRun())
- NOTREACHED();
-
- DCHECK(system_message_handler_obj_.is_null());
-
- JNIEnv* env = base::android::AttachCurrentThread();
- DCHECK(env);
- return env;
-}
-
-void MessagePumpForUI::Start(Delegate* delegate) {
- JNIEnv* env = StartInternal();
- system_message_handler_obj_.Reset(Java_SystemMessageHandler_create(
- env, reinterpret_cast<intptr_t>(delegate),
- reinterpret_cast<intptr_t>(this)));
-}
-
-void MessagePumpForUI::StartForUnitTest(
- Delegate* delegate,
- base::android::JavaMessageHandlerFactory* factory,
- WaitableEvent* test_done_event) {
- JNIEnv* env = StartInternal();
- system_message_handler_obj_.Reset(
- factory->CreateMessageHandler(env, delegate, this, test_done_event));
-}
-
-void MessagePumpForUI::Quit() {
- if (!system_message_handler_obj_.is_null()) {
- JNIEnv* env = base::android::AttachCurrentThread();
- DCHECK(env);
-
- Java_SystemMessageHandler_removeAllPendingMessages(
- env, system_message_handler_obj_);
- system_message_handler_obj_.Reset();
- }
-
- if (run_loop_) {
- run_loop_->AfterRun();
- delete run_loop_;
- run_loop_ = NULL;
- }
-}
-
-void MessagePumpForUI::ScheduleWork() {
- DCHECK(!system_message_handler_obj_.is_null());
-
- JNIEnv* env = base::android::AttachCurrentThread();
- DCHECK(env);
-
- Java_SystemMessageHandler_scheduleWork(env, system_message_handler_obj_);
-}
-
-void MessagePumpForUI::ScheduleDelayedWork(const TimeTicks& delayed_work_time) {
- DCHECK(!system_message_handler_obj_.is_null());
-
- JNIEnv* env = base::android::AttachCurrentThread();
- DCHECK(env);
-
- jlong millis =
- (delayed_work_time - TimeTicks::Now()).InMillisecondsRoundedUp();
- // Note that we're truncating to milliseconds as required by the java side,
- // even though delayed_work_time is microseconds resolution.
- Java_SystemMessageHandler_scheduleDelayedWork(
- env, system_message_handler_obj_, delayed_work_time.ToInternalValue(),
- millis);
-}
-
-// static
-bool MessagePumpForUI::RegisterBindings(JNIEnv* env) {
- return RegisterNativesImpl(env);
-}
-
-} // namespace base
diff --git a/base/message_loop/message_pump_android.h b/base/message_loop/message_pump_android.h
deleted file mode 100644
index e4adaf6..0000000
--- a/base/message_loop/message_pump_android.h
+++ /dev/null
@@ -1,64 +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.
-
-#ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_ANDROID_H_
-#define BASE_MESSAGE_LOOP_MESSAGE_PUMP_ANDROID_H_
-
-#include <jni.h>
-
-#include "base/android/scoped_java_ref.h"
-#include "base/base_export.h"
-#include "base/compiler_specific.h"
-#include "base/macros.h"
-#include "base/message_loop/message_pump.h"
-
-namespace base {
-
-namespace android {
-class JavaMessageHandlerFactory;
-}
-
-class RunLoop;
-class TimeTicks;
-class WaitableEvent;
-
-// This class implements a MessagePump needed for TYPE_UI MessageLoops on
-// OS_ANDROID platform.
-class BASE_EXPORT MessagePumpForUI : public MessagePump {
- public:
- MessagePumpForUI();
- ~MessagePumpForUI() override;
-
- void Run(Delegate* delegate) override;
- void Quit() override;
- void ScheduleWork() override;
- void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override;
-
- virtual void Start(Delegate* delegate);
- void StartForUnitTest(Delegate* delegate,
- base::android::JavaMessageHandlerFactory* factory,
- WaitableEvent* test_done_event);
-
- // We call Abort when there is a pending JNI exception, meaning that the
- // current thread will crash when we return to Java.
- // We can't call any JNI-methods before returning to Java as we would then
- // cause a native crash (instead of the original Java crash).
- void Abort() { should_abort_ = true; }
- bool ShouldAbort() const { return should_abort_; }
-
- static bool RegisterBindings(JNIEnv* env);
-
- private:
- JNIEnv* StartInternal();
-
- RunLoop* run_loop_;
- base::android::ScopedJavaGlobalRef<jobject> system_message_handler_obj_;
- bool should_abort_;
-
- DISALLOW_COPY_AND_ASSIGN(MessagePumpForUI);
-};
-
-} // namespace base
-
-#endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_ANDROID_H_
diff --git a/base/trace_event/java_heap_dump_provider_android.cc b/base/trace_event/java_heap_dump_provider_android.cc
deleted file mode 100644
index 684f730..0000000
--- a/base/trace_event/java_heap_dump_provider_android.cc
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2015 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/trace_event/java_heap_dump_provider_android.h"
-
-#include "base/android/java_runtime.h"
-#include "base/trace_event/process_memory_dump.h"
-
-namespace base {
-namespace trace_event {
-
-// static
-JavaHeapDumpProvider* JavaHeapDumpProvider::GetInstance() {
- return Singleton<JavaHeapDumpProvider,
- LeakySingletonTraits<JavaHeapDumpProvider>>::get();
-}
-
-JavaHeapDumpProvider::JavaHeapDumpProvider() {
-}
-
-JavaHeapDumpProvider::~JavaHeapDumpProvider() {
-}
-
-// Called at trace dump point time. Creates a snapshot with the memory counters
-// for the current process.
-bool JavaHeapDumpProvider::OnMemoryDump(const MemoryDumpArgs& args,
- ProcessMemoryDump* pmd) {
- // These numbers come from java.lang.Runtime stats.
- long total_heap_size = 0;
- long free_heap_size = 0;
- android::JavaRuntime::GetMemoryUsage(&total_heap_size, &free_heap_size);
-
- MemoryAllocatorDump* outer_dump = pmd->CreateAllocatorDump("java_heap");
- outer_dump->AddScalar(MemoryAllocatorDump::kNameSize,
- MemoryAllocatorDump::kUnitsBytes, total_heap_size);
-
- MemoryAllocatorDump* inner_dump =
- pmd->CreateAllocatorDump("java_heap/allocated_objects");
- inner_dump->AddScalar(MemoryAllocatorDump::kNameSize,
- MemoryAllocatorDump::kUnitsBytes,
- total_heap_size - free_heap_size);
- return true;
-}
-
-} // namespace trace_event
-} // namespace base
diff --git a/base/trace_event/java_heap_dump_provider_android.h b/base/trace_event/java_heap_dump_provider_android.h
deleted file mode 100644
index b9f2333..0000000
--- a/base/trace_event/java_heap_dump_provider_android.h
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2015 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.
-
-#ifndef BASE_TRACE_EVENT_JAVA_HEAP_DUMP_PROVIDER_ANDROID_H_
-#define BASE_TRACE_EVENT_JAVA_HEAP_DUMP_PROVIDER_ANDROID_H_
-
-#include "base/macros.h"
-#include "base/memory/singleton.h"
-#include "base/trace_event/memory_dump_provider.h"
-
-namespace base {
-namespace trace_event {
-
-// Dump provider which collects process-wide memory stats.
-class BASE_EXPORT JavaHeapDumpProvider : public MemoryDumpProvider {
- public:
- static JavaHeapDumpProvider* GetInstance();
-
- // MemoryDumpProvider implementation.
- bool OnMemoryDump(const MemoryDumpArgs& args,
- ProcessMemoryDump* pmd) override;
-
- private:
- friend struct DefaultSingletonTraits<JavaHeapDumpProvider>;
-
- JavaHeapDumpProvider();
- ~JavaHeapDumpProvider() override;
-
- DISALLOW_COPY_AND_ASSIGN(JavaHeapDumpProvider);
-};
-
-} // namespace trace_event
-} // namespace base
-
-#endif // BASE_TRACE_EVENT_JAVA_HEAP_DUMP_PROVIDER_ANDROID_H_
diff --git a/base/trace_event/trace_event_android.cc b/base/trace_event/trace_event_android.cc
deleted file mode 100644
index 0a4e6ea..0000000
--- a/base/trace_event/trace_event_android.cc
+++ /dev/null
@@ -1,216 +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.
-
-#include "base/trace_event/trace_event_impl.h"
-
-#include <fcntl.h>
-#include <stddef.h>
-#include <stdint.h>
-
-#include "base/format_macros.h"
-#include "base/logging.h"
-#include "base/posix/eintr_wrapper.h"
-#include "base/strings/stringprintf.h"
-#include "base/synchronization/waitable_event.h"
-#include "base/threading/thread.h"
-#include "base/trace_event/trace_event.h"
-
-namespace base {
-namespace trace_event {
-
-namespace {
-
-int g_atrace_fd = -1;
-const char kATraceMarkerFile[] = "/sys/kernel/debug/tracing/trace_marker";
-
-void WriteToATrace(int fd, const char* buffer, size_t size) {
- size_t total_written = 0;
- while (total_written < size) {
- ssize_t written = HANDLE_EINTR(write(
- fd, buffer + total_written, size - total_written));
- if (written <= 0)
- break;
- total_written += written;
- }
- if (total_written < size) {
- PLOG(WARNING) << "Failed to write buffer '" << std::string(buffer, size)
- << "' to " << kATraceMarkerFile;
- }
-}
-
-void WriteEvent(
- char phase,
- const char* category_group,
- const char* name,
- unsigned long long id,
- const char** arg_names,
- const unsigned char* arg_types,
- const TraceEvent::TraceValue* arg_values,
- const std::unique_ptr<ConvertableToTraceFormat>* convertable_values,
- unsigned int flags) {
- std::string out = StringPrintf("%c|%d|%s", phase, getpid(), name);
- if (flags & TRACE_EVENT_FLAG_HAS_ID)
- StringAppendF(&out, "-%" PRIx64, static_cast<uint64_t>(id));
- out += '|';
-
- for (int i = 0; i < kTraceMaxNumArgs && arg_names[i];
- ++i) {
- if (i)
- out += ';';
- out += arg_names[i];
- out += '=';
- std::string::size_type value_start = out.length();
- if (arg_types[i] == TRACE_VALUE_TYPE_CONVERTABLE)
- convertable_values[i]->AppendAsTraceFormat(&out);
- else
- TraceEvent::AppendValueAsJSON(arg_types[i], arg_values[i], &out);
-
- // Remove the quotes which may confuse the atrace script.
- ReplaceSubstringsAfterOffset(&out, value_start, "\\\"", "'");
- ReplaceSubstringsAfterOffset(&out, value_start, "\"", "");
- // Replace chars used for separators with similar chars in the value.
- std::replace(out.begin() + value_start, out.end(), ';', ',');
- std::replace(out.begin() + value_start, out.end(), '|', '!');
- }
-
- out += '|';
- out += category_group;
- WriteToATrace(g_atrace_fd, out.c_str(), out.size());
-}
-
-void NoOpOutputCallback(WaitableEvent* complete_event,
- const scoped_refptr<RefCountedString>&,
- bool has_more_events) {
- if (!has_more_events)
- complete_event->Signal();
-}
-
-void EndChromeTracing(TraceLog* trace_log,
- WaitableEvent* complete_event) {
- trace_log->SetDisabled();
- // Delete the buffered trace events as they have been sent to atrace.
- trace_log->Flush(Bind(&NoOpOutputCallback, complete_event));
-}
-
-} // namespace
-
-// These functions support Android systrace.py when 'webview' category is
-// traced. With the new adb_profile_chrome, we may have two phases:
-// - before WebView is ready for combined tracing, we can use adb_profile_chrome
-// to trace android categories other than 'webview' and chromium categories.
-// In this way we can avoid the conflict between StartATrace/StopATrace and
-// the intents.
-// - TODO(wangxianzhu): after WebView is ready for combined tracing, remove
-// StartATrace, StopATrace and SendToATrace, and perhaps send Java traces
-// directly to atrace in trace_event_binding.cc.
-
-void TraceLog::StartATrace() {
- if (g_atrace_fd != -1)
- return;
-
- g_atrace_fd = HANDLE_EINTR(open(kATraceMarkerFile, O_WRONLY));
- if (g_atrace_fd == -1) {
- PLOG(WARNING) << "Couldn't open " << kATraceMarkerFile;
- return;
- }
- TraceConfig trace_config;
- trace_config.SetTraceRecordMode(RECORD_CONTINUOUSLY);
- SetEnabled(trace_config, TraceLog::RECORDING_MODE);
-}
-
-void TraceLog::StopATrace() {
- if (g_atrace_fd == -1)
- return;
-
- close(g_atrace_fd);
- g_atrace_fd = -1;
-
- // TraceLog::Flush() requires the current thread to have a message loop, but
- // this thread called from Java may not have one, so flush in another thread.
- Thread end_chrome_tracing_thread("end_chrome_tracing");
- WaitableEvent complete_event(WaitableEvent::ResetPolicy::AUTOMATIC,
- WaitableEvent::InitialState::NOT_SIGNALED);
- end_chrome_tracing_thread.Start();
- end_chrome_tracing_thread.task_runner()->PostTask(
- FROM_HERE, base::Bind(&EndChromeTracing, Unretained(this),
- Unretained(&complete_event)));
- complete_event.Wait();
-}
-
-void TraceEvent::SendToATrace() {
- if (g_atrace_fd == -1)
- return;
-
- const char* category_group =
- TraceLog::GetCategoryGroupName(category_group_enabled_);
-
- switch (phase_) {
- case TRACE_EVENT_PHASE_BEGIN:
- WriteEvent('B', category_group, name_, id_,
- arg_names_, arg_types_, arg_values_, convertable_values_,
- flags_);
- break;
-
- case TRACE_EVENT_PHASE_COMPLETE:
- WriteEvent(duration_.ToInternalValue() == -1 ? 'B' : 'E',
- category_group, name_, id_,
- arg_names_, arg_types_, arg_values_, convertable_values_,
- flags_);
- break;
-
- case TRACE_EVENT_PHASE_END:
- // Though a single 'E' is enough, here append pid, name and
- // category_group etc. So that unpaired events can be found easily.
- WriteEvent('E', category_group, name_, id_,
- arg_names_, arg_types_, arg_values_, convertable_values_,
- flags_);
- break;
-
- case TRACE_EVENT_PHASE_INSTANT:
- // Simulate an instance event with a pair of begin/end events.
- WriteEvent('B', category_group, name_, id_,
- arg_names_, arg_types_, arg_values_, convertable_values_,
- flags_);
- WriteToATrace(g_atrace_fd, "E", 1);
- break;
-
- case TRACE_EVENT_PHASE_COUNTER:
- for (int i = 0; i < kTraceMaxNumArgs && arg_names_[i]; ++i) {
- DCHECK(arg_types_[i] == TRACE_VALUE_TYPE_INT);
- std::string out = base::StringPrintf(
- "C|%d|%s-%s", getpid(), name_, arg_names_[i]);
- if (flags_ & TRACE_EVENT_FLAG_HAS_ID)
- StringAppendF(&out, "-%" PRIx64, static_cast<uint64_t>(id_));
- StringAppendF(&out, "|%d|%s",
- static_cast<int>(arg_values_[i].as_int), category_group);
- WriteToATrace(g_atrace_fd, out.c_str(), out.size());
- }
- break;
-
- default:
- // Do nothing.
- break;
- }
-}
-
-void TraceLog::AddClockSyncMetadataEvent() {
- int atrace_fd = HANDLE_EINTR(open(kATraceMarkerFile, O_WRONLY | O_APPEND));
- if (atrace_fd == -1) {
- PLOG(WARNING) << "Couldn't open " << kATraceMarkerFile;
- return;
- }
-
- // Android's kernel trace system has a trace_marker feature: this is a file on
- // debugfs that takes the written data and pushes it onto the trace
- // buffer. So, to establish clock sync, we write our monotonic clock into that
- // trace buffer.
- double now_in_seconds = (TimeTicks::Now() - TimeTicks()).InSecondsF();
- std::string marker = StringPrintf(
- "trace_event_clock_sync: parent_ts=%f\n", now_in_seconds);
- WriteToATrace(atrace_fd, marker.c_str(), marker.size());
- close(atrace_fd);
-}
-
-} // namespace trace_event
-} // namespace base
diff --git a/build/build_config.h b/build/build_config.h
index fd5489f..5ee96b1 100644
--- a/build/build_config.h
+++ b/build/build_config.h
@@ -16,6 +16,40 @@
#ifndef BUILD_BUILD_CONFIG_H_
#define BUILD_BUILD_CONFIG_H_
+// A brief primer on #defines:
+//
+// - __ANDROID__ is automatically defined by the Android toolchain (see
+// https://goo.gl/v61lXa). It's not defined when building host code.
+// - __ANDROID_HOST__ is defined via -D by Android.mk when building host code
+// within an Android checkout.
+// - ANDROID is defined via -D when building code for either Android targets or
+// hosts. Use __ANDROID__ and __ANDROID_HOST__ instead.
+// - OS_ANDROID is a Chrome-specific define used to build Chrome for Android
+// within the NDK.
+
+// Android targets and hosts don't use tcmalloc.
+#if defined(__ANDROID__) || defined(__ANDROID_HOST__)
+#define NO_TCMALLOC
+#endif // defined(__ANDROID__) || defined(__ANDROID_HOST__)
+
+// Use the Chrome OS version of the code for both Android targets and Chrome OS builds.
+#if !defined(__ANDROID_HOST__)
+#define OS_CHROMEOS 1
+#endif // !defined(__ANDROID_HOST__)
+
+#if defined(__ANDROID__) // Android targets
+
+#define __linux__ 1
+
+#elif !defined(__ANDROID_HOST__) // Chrome OS
+
+// TODO: Remove these once the GLib MessageLoopForUI isn't being used:
+// https://crbug.com/361635
+#define USE_GLIB 1
+#define USE_OZONE 1
+
+#endif // defined(__ANDROID__)
+
// A set of macros to use for platform detection.
#if defined(__native_client__)
// __native_client__ must be first, so that other OS_ defines are not set.
@@ -28,8 +62,7 @@
#else
#define OS_NACL_SFI
#endif
-#elif defined(ANDROID)
-#define OS_ANDROID 1
+// Don't set OS_ANDROID; it's only used when building Chrome for Android.
#elif defined(__APPLE__)
// only include TargetConditions after testing ANDROID as some android builds
// on mac don't have this header available and it's not needed unless the target
diff --git a/jni/java/lang/Runtime.class b/jni/java/lang/Runtime.class
deleted file mode 100644
index 8ca9ea0..0000000
--- a/jni/java/lang/Runtime.class
+++ /dev/null
Binary files differ
diff --git a/mojo/edk/embedder/platform_channel_pair_posix.cc b/mojo/edk/embedder/platform_channel_pair_posix.cc
index 4760e95..fe9f8f5 100644
--- a/mojo/edk/embedder/platform_channel_pair_posix.cc
+++ b/mojo/edk/embedder/platform_channel_pair_posix.cc
@@ -35,7 +35,7 @@ namespace edk {
namespace {
-#if defined(OS_ANDROID)
+#if defined(OS_ANDROID) || defined(__ANDROID__)
enum {
// Leave room for any other descriptors defined in content for example.
// TODO(jcivelli): consider changing base::GlobalDescriptors to generate a
@@ -102,7 +102,7 @@ ScopedPlatformHandle
PlatformChannelPair::PassClientHandleFromParentProcessFromString(
const std::string& value) {
int client_fd = -1;
-#if defined(OS_ANDROID)
+#if defined(OS_ANDROID) || defined(__ANDROID__)
base::GlobalDescriptors::Key key = -1;
if (value.empty() || !base::StringToUint(value, &key)) {
LOG(ERROR) << "Missing or invalid --" << kMojoPlatformChannelHandleSwitch;
@@ -142,7 +142,7 @@ void PlatformChannelPair::PrepareToPassClientHandleToChildProcess(
std::string
PlatformChannelPair::PrepareToPassClientHandleToChildProcessAsString(
HandlePassingInformation* handle_passing_info) const {
-#if defined(OS_ANDROID)
+#if defined(OS_ANDROID) || defined(__ANDROID__)
int fd = client_handle_.get().handle;
handle_passing_info->push_back(
std::pair<int, int>(fd, kAndroidClientHandleDescriptor));
diff --git a/mojo/edk/system/ports/node.cc b/mojo/edk/system/ports/node.cc
index 9c6f1fd..f9a3feb 100644
--- a/mojo/edk/system/ports/node.cc
+++ b/mojo/edk/system/ports/node.cc
@@ -803,7 +803,7 @@ scoped_refptr<Port> Node::GetPort_Locked(const PortName& port_name) {
if (iter == ports_.end())
return nullptr;
-#if defined(OS_ANDROID) && defined(ARCH_CPU_ARM64)
+#if (defined(OS_ANDROID) || defined(__ANDROID__)) && defined(ARCH_CPU_ARM64)
// Workaround for https://crbug.com/665869.
base::subtle::MemoryBarrier();
#endif