Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(494)

Unified Diff: ui/base/resource/resource_bundle_android.cc

Issue 1181953002: Load non-locale .pak files directly from the .apk on Android (rather than extracting on start-up). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@raw-paks
Patch Set: yfriedman review comments Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..386819abbc69058d38c9e0819dc3704e2de89a00 100644
--- a/ui/base/resource/resource_bundle_android.cc
+++ b/ui/base/resource/resource_bundle_android.cc
@@ -2,28 +2,33 @@
// 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/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;
sadrul 2015/06/22 20:35:03 Does this add a couple of new static initializers?
agrieve 2015/06/22 23:53:33 It would have a couple of weeks ago, but after get
+}
namespace ui {
void ResourceBundle::LoadCommonResources() {
- base::FilePath path;
- PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &path);
- 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);
+ 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 +37,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(
« ui/base/resource/resource_bundle_android.h ('K') | « ui/base/resource/resource_bundle_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698