Chromium Code Reviews| Index: ui/base/resource/resource_bundle_android.cc |
| diff --git a/ui/base/resource/resource_bundle_android.cc b/ui/base/resource/resource_bundle_android.cc |
| index 9dc036eeded50c7ce4431733c5d5949e9d766463..50dfc2223636107d80e1d74b923524e6d4be8e4e 100644 |
| --- a/ui/base/resource/resource_bundle_android.cc |
| +++ b/ui/base/resource/resource_bundle_android.cc |
| @@ -2,28 +2,34 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "ui/base/resource/resource_bundle.h" |
| - |
| -#include <string> |
| +#include "ui/base/resource/resource_bundle_android.h" |
| +#include "base/android/apk_assets.h" |
| #include "base/android/jni_android.h" |
| #include "base/android/jni_string.h" |
| -#include "base/files/file_path.h" |
| -#include "base/files/file_util.h" |
| +//#include "base/files/file_util.h" |
|
Yaron
2015/06/17 14:12:28
remove
agrieve
2015/06/17 14:35:40
Done.
|
| #include "base/logging.h" |
| -#include "base/path_service.h" |
| -#include "base/strings/stringprintf.h" |
| #include "jni/ResourceBundle_jni.h" |
| -#include "ui/base/resource/resource_handle.h" |
| -#include "ui/base/ui_base_paths.h" |
| +#include "ui/base/resource/resource_bundle.h" |
| + |
| +namespace { |
| +// It is okay to cache and share these file descriptors since the |
| +// ResourceBundle singleton never closes the handles. |
| +int g_chrome_100_percent_fd = -1; |
| +int g_resources_pack_fd = -1; |
| +base::MemoryMappedFile::Region g_chrome_100_percent_region; |
| +base::MemoryMappedFile::Region g_resources_pack_region; |
| +} |
| namespace ui { |
| void ResourceBundle::LoadCommonResources() { |
| - base::FilePath path; |
| - PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &path); |
|
Yaron
2015/06/17 14:12:28
Will this constant only be removed when language p
agrieve
2015/06/17 14:35:40
Only for ChromeModern, and we can't remove it unle
|
| - AddDataPackFromPath(path.AppendASCII("chrome_100_percent.pak"), |
| - SCALE_FACTOR_100P); |
| + DCHECK_EQ(g_chrome_100_percent_fd, -1); |
| + g_chrome_100_percent_fd = base::android::OpenApkAsset( |
| + "assets/chrome_100_percent.pak", &g_chrome_100_percent_region); |
|
Yaron
2015/06/17 14:12:28
That's odd. I'm surprised that ui/ is dealing with
agrieve
2015/06/17 14:35:40
That caught me too. I think the original intention
|
| + DCHECK_GE(g_chrome_100_percent_fd, 0); |
| + AddDataPackFromFileRegion(base::File(g_chrome_100_percent_fd), |
| + g_chrome_100_percent_region, SCALE_FACTOR_100P); |
| } |
| gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { |
| @@ -32,6 +38,28 @@ gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { |
| return GetImageNamed(resource_id); |
| } |
| +void LoadMainAndroidPackFile() { |
| + DCHECK_EQ(g_resources_pack_fd, -1); |
| + g_resources_pack_fd = base::android::OpenApkAsset("assets/resources.pak", |
| + &g_resources_pack_region); |
| + DCHECK_GE(g_resources_pack_fd, 0); |
| + ResourceBundle::GetSharedInstance().AddDataPackFromFileRegion( |
| + base::File(g_resources_pack_fd), g_resources_pack_region, |
| + SCALE_FACTOR_NONE); |
| +} |
| + |
| +int GetMainAndroidPackFd(base::MemoryMappedFile::Region* out_region) { |
| + DCHECK_GE(g_resources_pack_fd, 0); |
| + *out_region = g_resources_pack_region; |
| + return g_resources_pack_fd; |
| +} |
| + |
| +int GetCommonResourcesPackFd(base::MemoryMappedFile::Region* out_region) { |
| + DCHECK_GE(g_chrome_100_percent_fd, 0); |
| + *out_region = g_chrome_100_percent_region; |
| + return g_chrome_100_percent_fd; |
| +} |
| + |
| bool AssetContainedInApk(const std::string& filename) { |
| JNIEnv* env = base::android::AttachCurrentThread(); |
| return Java_ResourceBundle_assetContainedInApk( |