Upstreaming chrome/common/chrome_* diff.

Upstreaming chrome/common/chrome_* diff for Android.

BUG=152827


Review URL: https://chromiumcodereview.appspot.com/11031008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@159777 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: 18011cb7cb6e6f5e39e8eca7a546e61c8f4af721
diff --git a/base/android/path_utils.cc b/base/android/path_utils.cc
index 1e8d1e8..3d86177 100644
--- a/base/android/path_utils.cc
+++ b/base/android/path_utils.cc
@@ -7,45 +7,56 @@
 #include "base/android/jni_android.h"
 #include "base/android/jni_string.h"
 #include "base/android/scoped_java_ref.h"
+#include "base/file_path.h"
 
 #include "jni/PathUtils_jni.h"
 
 namespace base {
 namespace android {
 
-std::string GetDataDirectory() {
+bool GetDataDirectory(FilePath* result) {
   JNIEnv* env = AttachCurrentThread();
   ScopedJavaLocalRef<jstring> path =
       Java_PathUtils_getDataDirectory(env, GetApplicationContext());
-  return ConvertJavaStringToUTF8(path);
+  FilePath data_path(ConvertJavaStringToUTF8(path));
+  *result = data_path;
+  return true;
 }
 
-std::string GetCacheDirectory() {
+bool GetCacheDirectory(FilePath* result) {
   JNIEnv* env = AttachCurrentThread();
   ScopedJavaLocalRef<jstring> path =
       Java_PathUtils_getCacheDirectory(env, GetApplicationContext());
-  return ConvertJavaStringToUTF8(path);
+  FilePath cache_path(ConvertJavaStringToUTF8(path));
+  *result = cache_path;
+  return true;
 }
 
-std::string GetDownloadsDirectory() {
+bool GetDownloadsDirectory(FilePath* result) {
   JNIEnv* env = AttachCurrentThread();
   ScopedJavaLocalRef<jstring> path =
       Java_PathUtils_getDownloadsDirectory(env, GetApplicationContext());
-  return ConvertJavaStringToUTF8(path);
+  FilePath downloads_path(ConvertJavaStringToUTF8(path));
+  *result = downloads_path;
+  return true;
 }
 
-std::string GetNativeLibraryDirectory() {
+bool GetNativeLibraryDirectory(FilePath* result) {
   JNIEnv* env = AttachCurrentThread();
   ScopedJavaLocalRef<jstring> path =
       Java_PathUtils_getNativeLibraryDirectory(env, GetApplicationContext());
-  return ConvertJavaStringToUTF8(path);
+  FilePath library_path(ConvertJavaStringToUTF8(path));
+  *result = library_path;
+  return true;
 }
 
-std::string GetExternalStorageDirectory() {
+bool GetExternalStorageDirectory(FilePath* result) {
   JNIEnv* env = AttachCurrentThread();
   ScopedJavaLocalRef<jstring> path =
       Java_PathUtils_getExternalStorageDirectory(env);
-  return ConvertJavaStringToUTF8(path);
+  FilePath storage_path(ConvertJavaStringToUTF8(path));
+  *result = storage_path;
+  return true;
 }
 
 bool RegisterPathUtils(JNIEnv* env) {
diff --git a/base/android/path_utils.h b/base/android/path_utils.h
index 29c94d6..37349d3 100644
--- a/base/android/path_utils.h
+++ b/base/android/path_utils.h
@@ -6,30 +6,36 @@
 #define BASE_ANDROID_PATH_UTILS_H_
 
 #include <jni.h>
-#include <string>
+
+class FilePath;
 
 namespace base {
 namespace android {
 
-// Return the absolute path to the data directory of the current application.
+// 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.
-std::string GetDataDirectory();
+bool GetDataDirectory(FilePath* result);
 
-// Return the absolute path to the cache directory. This method is dedicated for
+// 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.
-std::string GetCacheDirectory();
+bool GetCacheDirectory(FilePath* result);
 
-// Returns the path to the public downloads directory.
-std::string GetDownloadsDirectory();
+// Retrieves the path to the public downloads directory. The result is placed
+// in the FilePath pointed to by 'result'.
+bool GetDownloadsDirectory(FilePath* result);
 
-// Returns the path to the native JNI libraries via
-// ApplicationInfo.nativeLibraryDir on the Java side.
-std::string GetNativeLibraryDirectory();
+// 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'.
+bool GetNativeLibraryDirectory(FilePath* result);
 
-// Returns the absolute path to the external storage directory.
-std::string GetExternalStorageDirectory();
+// Retrieves the absolute path to the external storage directory. The result
+// is placed in the FilePath pointed to by 'result'.
+bool GetExternalStorageDirectory(FilePath* result);
 
 bool RegisterPathUtils(JNIEnv* env);
 
diff --git a/base/android/path_utils_unittest.cc b/base/android/path_utils_unittest.cc
index faa00b5..92728b5 100644
--- a/base/android/path_utils_unittest.cc
+++ b/base/android/path_utils_unittest.cc
@@ -3,6 +3,7 @@
 // found in the LICENSE file.
 
 #include "base/android/path_utils.h"
+#include "base/file_path.h"
 
 #include "testing/gtest/include/gtest/gtest.h"
 
@@ -15,24 +16,30 @@
   // 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);
   EXPECT_STREQ("/data/data/org.chromium.native_test/app_chrome",
-               GetDataDirectory().c_str());
+               path.value().c_str());
 }
 
 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);
   EXPECT_STREQ("/data/data/org.chromium.native_test/cache",
-               GetCacheDirectory().c_str());
+               path.value().c_str());
 }
 
 TEST_F(PathUtilsTest, TestGetNativeLibraryDirectory) {
   // 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;
+  GetNativeLibraryDirectory(&path);
   EXPECT_STREQ("/data/data/org.chromium.native_test/lib",
-               GetNativeLibraryDirectory().c_str());
+               path.value().c_str());
 }
 
 }  // namespace android