Commit 67101cd0 authored by agrieve's avatar agrieve Committed by Commit bot

Reland of Move language pak files to assets.

Reverted by:
https://codereview.chromium.org/2369683002/

Reason for reland:
I've reworked it so that:
1. The list of pak files to extract are not set on start-up, but rather lazy initialized
2. This is done by putting the list of locale assets right in base's BuildConfig.java
3. Downstream parts have been upstreams so that this won't require a 2-sided patch

Language pak files were moved to res/raw when split apks was being implemented.
Moving them to assets with a java constant keeping track of pak file locations
will improve lookup time and save some space (no more xml files and
resources.arsc).

Other notables:
- .pak filenames no longer mangled. No more .lpak. no more hyphens to _s
- Ensures that monochrome doesn't extract files by extracting only when
files are compressed.

BUG=529604

Review-Url: https://codereview.chromium.org/2371843002
Cr-Commit-Position: refs/heads/master@{#422836}
parent 0bd9f1a1
...@@ -53,7 +53,8 @@ webview_repack_locales("repack_locales") { ...@@ -53,7 +53,8 @@ webview_repack_locales("repack_locales") {
} }
} }
locale_pak_resources("locale_paks") { android_assets("locale_pak_assets") {
disable_compression = true
sources = [] sources = []
foreach(_locale, locales) { foreach(_locale, locales) {
sources += [ "$root_out_dir/android_webview/locales/$_locale.pak" ] sources += [ "$root_out_dir/android_webview/locales/$_locale.pak" ]
...@@ -135,6 +136,7 @@ android_assets("monochrome_webview_assets") { ...@@ -135,6 +136,7 @@ android_assets("monochrome_webview_assets") {
android_assets("assets") { android_assets("assets") {
deps = [ deps = [
":locale_pak_assets",
":monochrome_webview_assets", ":monochrome_webview_assets",
":pak_file_assets", ":pak_file_assets",
] ]
...@@ -164,7 +166,6 @@ android_resources("resources") { ...@@ -164,7 +166,6 @@ android_resources("resources") {
resource_dirs = [ "java/res" ] resource_dirs = [ "java/res" ]
custom_package = "org.chromium.android_webview" custom_package = "org.chromium.android_webview"
deps = [ deps = [
":locale_paks",
":strings_grd", ":strings_grd",
] ]
} }
......
...@@ -48,7 +48,6 @@ import org.chromium.android_webview.AwResource; ...@@ -48,7 +48,6 @@ import org.chromium.android_webview.AwResource;
import org.chromium.android_webview.AwServiceWorkerController; import org.chromium.android_webview.AwServiceWorkerController;
import org.chromium.android_webview.AwSettings; import org.chromium.android_webview.AwSettings;
import org.chromium.android_webview.HttpAuthDatabase; import org.chromium.android_webview.HttpAuthDatabase;
import org.chromium.android_webview.R;
import org.chromium.android_webview.ResourcesContextWrapperFactory; import org.chromium.android_webview.ResourcesContextWrapperFactory;
import org.chromium.base.BuildConfig; import org.chromium.base.BuildConfig;
import org.chromium.base.CommandLine; import org.chromium.base.CommandLine;
...@@ -64,7 +63,6 @@ import org.chromium.base.library_loader.LibraryProcessType; ...@@ -64,7 +63,6 @@ import org.chromium.base.library_loader.LibraryProcessType;
import org.chromium.base.library_loader.ProcessInitException; import org.chromium.base.library_loader.ProcessInitException;
import org.chromium.content.browser.ContentViewStatics; import org.chromium.content.browser.ContentViewStatics;
import org.chromium.net.NetworkChangeNotifier; import org.chromium.net.NetworkChangeNotifier;
import org.chromium.ui.base.ResourceBundle;
import java.io.File; import java.io.File;
import java.util.Queue; import java.util.Queue;
...@@ -393,7 +391,6 @@ public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider { ...@@ -393,7 +391,6 @@ public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider {
final String webViewPackageName = WebViewFactory.getLoadedPackageInfo().packageName; final String webViewPackageName = WebViewFactory.getLoadedPackageInfo().packageName;
Context context = ContextUtils.getApplicationContext(); Context context = ContextUtils.getApplicationContext();
setUpResources(webViewPackageName, context); setUpResources(webViewPackageName, context);
ResourceBundle.initializeLocalePaks(context, R.array.locale_paks);
initPlatSupportLibrary(); initPlatSupportLibrary();
initNetworkChangeNotifier(context); initNetworkChangeNotifier(context);
final int extraBindFlags = Context.BIND_EXTERNAL_SERVICE; final int extraBindFlags = Context.BIND_EXTERNAL_SERVICE;
......
...@@ -24,7 +24,6 @@ template("system_webview_apk_tmpl") { ...@@ -24,7 +24,6 @@ template("system_webview_apk_tmpl") {
_native_lib_file = _native_lib_file =
rebase_path("$root_gen_dir/CHROME_VERSION.json", root_out_dir) rebase_path("$root_gen_dir/CHROME_VERSION.json", root_out_dir)
native_lib_version_arg = "@FileArg($_native_lib_file:full-quoted)" native_lib_version_arg = "@FileArg($_native_lib_file:full-quoted)"
extensions_to_not_compress = ".lpak,.pak,.bin,.dat"
if (build_apk_secondary_abi && android_64bit_target_cpu) { if (build_apk_secondary_abi && android_64bit_target_cpu) {
secondary_abi_shared_libraries = [ "//android_webview:libwebviewchromium($android_secondary_abi_toolchain)" ] secondary_abi_shared_libraries = [ "//android_webview:libwebviewchromium($android_secondary_abi_toolchain)" ]
} }
......
...@@ -20,6 +20,7 @@ android_apk("android_webview_apk") { ...@@ -20,6 +20,7 @@ android_apk("android_webview_apk") {
":android_webview_apk_assets", ":android_webview_apk_assets",
":android_webview_apk_resources", ":android_webview_apk_resources",
"//android_webview:android_webview_java", "//android_webview:android_webview_java",
"//android_webview:locale_pak_assets",
"//base:base_java", "//base:base_java",
"//base:base_java_test_support", "//base:base_java_test_support",
"//components/policy/android:policy_java_test_support", "//components/policy/android:policy_java_test_support",
...@@ -51,8 +52,6 @@ android_apk("android_webview_apk") { ...@@ -51,8 +52,6 @@ android_apk("android_webview_apk") {
_native_lib_file = _native_lib_file =
rebase_path("$root_gen_dir/CHROME_VERSION.json", root_build_dir) rebase_path("$root_gen_dir/CHROME_VERSION.json", root_build_dir)
native_lib_version_arg = "@FileArg($_native_lib_file:full-quoted)" native_lib_version_arg = "@FileArg($_native_lib_file:full-quoted)"
extensions_to_not_compress = ".dat,.bin,.pak,.lpak"
} }
android_resources("android_webview_apk_resources") { android_resources("android_webview_apk_resources") {
......
...@@ -4,11 +4,9 @@ ...@@ -4,11 +4,9 @@
package org.chromium.android_webview.shell; package org.chromium.android_webview.shell;
import org.chromium.android_webview.R;
import org.chromium.base.CommandLine; import org.chromium.base.CommandLine;
import org.chromium.base.annotations.SuppressFBWarnings; import org.chromium.base.annotations.SuppressFBWarnings;
import org.chromium.content.app.ContentApplication; import org.chromium.content.app.ContentApplication;
import org.chromium.ui.base.ResourceBundle;
/** /**
* The android_webview shell Application subclass. * The android_webview shell Application subclass.
...@@ -18,16 +16,6 @@ public class AwShellApplication extends ContentApplication { ...@@ -18,16 +16,6 @@ public class AwShellApplication extends ContentApplication {
super(false /* mShouldInitializeApplicationStatusTracking */); super(false /* mShouldInitializeApplicationStatusTracking */);
} }
@Override
public void onCreate() {
super.onCreate();
}
@Override
protected void initializeLibraryDependencies() {
ResourceBundle.initializeLocalePaks(this, R.array.locale_paks);
}
@SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME") @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
@Override @Override
public void initCommandLine() { public void initCommandLine() {
......
...@@ -19,14 +19,23 @@ public class LocaleUtils { ...@@ -19,14 +19,23 @@ public class LocaleUtils {
} }
/** /**
* @return the string for the given locale, translating * @return The string for the given locale, translating Android deprecated language codes
* Android deprecated language codes into the modern ones * into the modern ones used by Chromium.
* used by Chromium.
*/ */
public static String getLocale(Locale locale) { public static String getLocale(Locale locale) {
String language = locale.getLanguage(); String language = getLanguage(locale);
String country = locale.getCountry(); String country = locale.getCountry();
return country.isEmpty() ? language : language + "-" + country;
}
/**
* @return The language for the given locale, translating Android deprecated languages codes
* into modern ones used by Chromium.
*/
public static String getLanguage(Locale locale) {
String language = locale.getLanguage();
// Android uses deprecated lanuages codes for Hebrew and Indonesian but Chromium uses the // Android uses deprecated lanuages codes for Hebrew and Indonesian but Chromium uses the
// updated codes. Also, Android uses "tl" while Chromium uses "fil" for Tagalog/Filipino. // updated codes. Also, Android uses "tl" while Chromium uses "fil" for Tagalog/Filipino.
// So apply a mapping. // So apply a mapping.
...@@ -38,12 +47,12 @@ public class LocaleUtils { ...@@ -38,12 +47,12 @@ public class LocaleUtils {
} else if ("tl".equals(language)) { } else if ("tl".equals(language)) {
language = "fil"; language = "fil";
} }
return country.isEmpty() ? language : language + "-" + country; return language;
} }
/** /**
* @return the default locale, translating Android deprecated * @return The default locale, translating Android deprecated language codes into the modern
* language codes into the modern ones used by Chromium. * ones used by Chromium.
*/ */
@CalledByNative @CalledByNative
public static String getDefaultLocale() { public static String getDefaultLocale() {
...@@ -51,8 +60,7 @@ public class LocaleUtils { ...@@ -51,8 +60,7 @@ public class LocaleUtils {
} }
/** /**
* Get the default country code set during install. * @return The default country code set during install.
* @return country code.
*/ */
@CalledByNative @CalledByNative
private static String getDefaultCountryCode() { private static String getDefaultCountryCode() {
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
package org.chromium.base; package org.chromium.base;
import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
...@@ -12,8 +11,6 @@ import android.os.AsyncTask; ...@@ -12,8 +11,6 @@ import android.os.AsyncTask;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import org.chromium.base.annotations.SuppressFBWarnings;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
...@@ -21,6 +18,7 @@ import java.io.InputStream; ...@@ -21,6 +18,7 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
...@@ -35,23 +33,7 @@ public class ResourceExtractor { ...@@ -35,23 +33,7 @@ public class ResourceExtractor {
private static final String V8_NATIVES_DATA_FILENAME = "natives_blob.bin"; private static final String V8_NATIVES_DATA_FILENAME = "natives_blob.bin";
private static final String V8_SNAPSHOT_DATA_FILENAME = "snapshot_blob.bin"; private static final String V8_SNAPSHOT_DATA_FILENAME = "snapshot_blob.bin";
private static final String APP_VERSION_PREF = "org.chromium.base.ResourceExtractor.Version"; private static final String APP_VERSION_PREF = "org.chromium.base.ResourceExtractor.Version";
private static final String FALLBACK_LOCALE = "en-US";
private static ResourceEntry[] sResourcesToExtract = new ResourceEntry[0];
/**
* Holds information about a res/raw file (e.g. locale .pak files).
*/
public static final class ResourceEntry {
public final int resourceId;
public final String pathWithinApk;
public final String extractedFileName;
public ResourceEntry(int resourceId, String pathWithinApk, String extractedFileName) {
this.resourceId = resourceId;
this.pathWithinApk = pathWithinApk;
this.extractedFileName = extractedFileName;
}
}
private class ExtractTask extends AsyncTask<Void, Void, Void> { private class ExtractTask extends AsyncTask<Void, Void, Void> {
private static final int BUFFER_SIZE = 16 * 1024; private static final int BUFFER_SIZE = 16 * 1024;
...@@ -107,16 +89,16 @@ public class ResourceExtractor { ...@@ -107,16 +89,16 @@ public class ResourceExtractor {
TraceEvent.begin("WalkAssets"); TraceEvent.begin("WalkAssets");
byte[] buffer = new byte[BUFFER_SIZE]; byte[] buffer = new byte[BUFFER_SIZE];
try { try {
for (ResourceEntry entry : sResourcesToExtract) { for (String assetName : mAssetsToExtract) {
File output = new File(outputDir, entry.extractedFileName); File output = new File(outputDir, assetName);
// TODO(agrieve): It would be better to check that .length == expectedLength. // TODO(agrieve): It would be better to check that .length == expectedLength.
// http://crbug.com/606413 // http://crbug.com/606413
if (output.length() != 0) { if (output.length() != 0) {
continue; continue;
} }
TraceEvent.begin("ExtractResource"); TraceEvent.begin("ExtractResource");
InputStream inputStream = mContext.getResources().openRawResource( InputStream inputStream =
entry.resourceId); ContextUtils.getApplicationContext().getAssets().open(assetName);
try { try {
extractResourceHelper(inputStream, output, buffer); extractResourceHelper(inputStream, output, buffer);
} finally { } finally {
...@@ -128,7 +110,7 @@ public class ResourceExtractor { ...@@ -128,7 +110,7 @@ public class ResourceExtractor {
// Try to recover here, can we try again after deleting files instead of // Try to recover here, can we try again after deleting files instead of
// returning null? It might be useful to gather UMA here too to track if // returning null? It might be useful to gather UMA here too to track if
// this happens with regularity. // this happens with regularity.
Log.w(TAG, "Exception unpacking required pak resources: %s", e.getMessage()); Log.w(TAG, "Exception unpacking required pak asset: %s", e.getMessage());
deleteFiles(); deleteFiles();
return; return;
} finally { } finally {
...@@ -166,10 +148,11 @@ public class ResourceExtractor { ...@@ -166,10 +148,11 @@ public class ResourceExtractor {
/** Returns a number that is different each time the apk changes. */ /** Returns a number that is different each time the apk changes. */
private long getApkVersion() { private long getApkVersion() {
PackageManager pm = mContext.getPackageManager(); PackageManager pm = ContextUtils.getApplicationContext().getPackageManager();
try { try {
// More appropriate would be versionCode, but it doesn't change while developing. // More appropriate would be versionCode, but it doesn't change while developing.
PackageInfo pi = pm.getPackageInfo(mContext.getPackageName(), 0); PackageInfo pi =
pm.getPackageInfo(ContextUtils.getApplicationContext().getPackageName(), 0);
return pi.lastUpdateTime; return pi.lastUpdateTime;
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
...@@ -177,31 +160,38 @@ public class ResourceExtractor { ...@@ -177,31 +160,38 @@ public class ResourceExtractor {
} }
} }
private final Context mContext;
private ExtractTask mExtractTask; private ExtractTask mExtractTask;
private final String[] mAssetsToExtract = detectFilesToExtract();
private static ResourceExtractor sInstance; private static ResourceExtractor sInstance;
public static ResourceExtractor get(Context context) { public static ResourceExtractor get() {
if (sInstance == null) { if (sInstance == null) {
sInstance = new ResourceExtractor(context); sInstance = new ResourceExtractor();
} }
return sInstance; return sInstance;
} }
/** private static boolean isPakFileForLanguage(String pakFileName, String language) {
* Specifies the files that should be extracted from the APK. if (pakFileName.length() <= language.length() || !pakFileName.startsWith(language)) {
* and moved to {@link #getOutputDir()}. return false;
*/ }
@SuppressFBWarnings("EI_EXPOSE_STATIC_REP2") char c = pakFileName.charAt(language.length());
public static void setResourcesToExtract(ResourceEntry[] entries) { return c == '.' || c == '-';
assert (sInstance == null || sInstance.mExtractTask == null)
: "Must be called before startExtractingResources is called";
sResourcesToExtract = entries;
} }
private ResourceExtractor(Context context) { private static String[] detectFilesToExtract() {
mContext = context.getApplicationContext(); String language = LocaleUtils.getLanguage(Locale.getDefault());
// Currenty (Oct 2016), this array can be as big as 4 entries, so using a capacity
// that allows a bit of growth, but is still in the right ballpark..
ArrayList<String> activeLocalePakFiles = new ArrayList<String>(6);
for (String pakFileName : BuildConfig.COMPRESSED_ASSETS) {
if (isPakFileForLanguage(pakFileName, language)
|| isPakFileForLanguage(pakFileName, FALLBACK_LOCALE)) {
activeLocalePakFiles.add(pakFileName);
}
}
return activeLocalePakFiles.toArray(new String[activeLocalePakFiles.size()]);
} }
/** /**
...@@ -329,6 +319,6 @@ public class ResourceExtractor { ...@@ -329,6 +319,6 @@ public class ResourceExtractor {
* Pak extraction not necessarily required by the embedder. * Pak extraction not necessarily required by the embedder.
*/ */
private static boolean shouldSkipPakExtraction() { private static boolean shouldSkipPakExtraction() {
return sResourcesToExtract.length == 0; return get().mAssetsToExtract.length == 0;
} }
} }
...@@ -29,4 +29,19 @@ public class BuildConfig { ...@@ -29,4 +29,19 @@ public class BuildConfig {
public static final boolean DCHECK_IS_ON = false; public static final boolean DCHECK_IS_ON = false;
#endif #endif
// Sorted list of compressed assets contained in the apk (AssetManager.list() is slow).
public static final String[] COMPRESSED_ASSETS =
#if defined(COMPRESSED_ASSETS_LIST)
COMPRESSED_ASSETS_LIST;
#else
{};
#endif
// Sorted list of uncompressed assets contained in the apk (AssetManager.list() is slow).
public static final String[] UNCOMPRESSED_ASSETS =
#if defined(UNCOMPRESSED_ASSETS_LIST)
UNCOMPRESSED_ASSETS_LIST;
#else
{};
#endif
} }
...@@ -10,7 +10,6 @@ import org.chromium.base.BaseChromiumApplication; ...@@ -10,7 +10,6 @@ import org.chromium.base.BaseChromiumApplication;
import org.chromium.base.CommandLineInitUtil; import org.chromium.base.CommandLineInitUtil;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.PathUtils; import org.chromium.base.PathUtils;
import org.chromium.base.ResourceExtractor;
/** /**
* The {@link Application} for the Blimp client. * The {@link Application} for the Blimp client.
...@@ -27,7 +26,6 @@ public class BlimpApplication extends BaseChromiumApplication { ...@@ -27,7 +26,6 @@ public class BlimpApplication extends BaseChromiumApplication {
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
ResourceExtractor.setResourcesToExtract(new ResourceExtractor.ResourceEntry[0]);
PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX, this); PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX, this);
initCommandLine(); initCommandLine();
} }
......
...@@ -6,7 +6,6 @@ package org.chromium.blimp; ...@@ -6,7 +6,6 @@ package org.chromium.blimp;
import android.os.Handler; import android.os.Handler;
import org.chromium.base.ContextUtils;
import org.chromium.base.ObserverList; import org.chromium.base.ObserverList;
import org.chromium.base.ResourceExtractor; import org.chromium.base.ResourceExtractor;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
...@@ -81,7 +80,7 @@ public final class BlimpLibraryLoader { ...@@ -81,7 +80,7 @@ public final class BlimpLibraryLoader {
if (sLoadAttempted) return; if (sLoadAttempted) return;
sLoadAttempted = true; sLoadAttempted = true;
ResourceExtractor extractor = ResourceExtractor.get(ContextUtils.getApplicationContext()); ResourceExtractor extractor = ResourceExtractor.get();
extractor.startExtractingResources(); extractor.startExtractingResources();
LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized(); LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized();
......
#!/usr/bin/env python
#
# 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.
"""Creates a resources.zip for locale .pak files.
Places the locale.pak files into appropriate resource configs
(e.g. en-GB.pak -> res/raw-en/en_gb.lpak). Also generates a locale_paks
TypedArray so that resource files can be enumerated at runtime.
"""
import collections
import optparse
import os
import sys
import zipfile
from util import build_utils
# This should stay in sync with:
# base/android/java/src/org/chromium/base/LocaleUtils.java
_CHROME_TO_ANDROID_LOCALE_MAP = {
'he': 'iw',
'id': 'in',
'fil': 'tl',
}
def ToResourceFileName(name):
"""Returns the resource-compatible file name for the given file."""
# Resources file names must consist of [a-z0-9_.].
# Changes extension to .lpak so that compression can be toggled separately for
# locale pak files vs other pak files.
return name.replace('-', '_').replace('.pak', '.lpak').lower()
def CreateLocalePaksXml(names):
"""Creates the contents for the locale-paks.xml files."""
VALUES_FILE_TEMPLATE = '''<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="locale_paks">%s
</array>
</resources>
'''
VALUES_ITEM_TEMPLATE = '''
<item>@raw/%s</item>'''
res_names = (os.path.splitext(name)[0] for name in names)
items = ''.join((VALUES_ITEM_TEMPLATE % name for name in res_names))
return VALUES_FILE_TEMPLATE % items
def ComputeMappings(sources):
"""Computes the mappings of sources -> resources.
Returns a tuple of:
- mappings: List of (src, dest) paths
- lang_to_locale_map: Map of language -> list of resource names
e.g. "en" -> ["en_gb.lpak"]
"""
lang_to_locale_map = collections.defaultdict(list)
mappings = []
for src_path in sources:
basename = os.path.basename(src_path)
name = os.path.splitext(basename)[0]
res_name = ToResourceFileName(basename)
if name == 'en-US':
dest_dir = 'raw'
else:
# Chrome's uses different region mapping logic from Android, so include
# all regions for each language.
android_locale = _CHROME_TO_ANDROID_LOCALE_MAP.get(name, name)
lang = android_locale[0:2]
dest_dir = 'raw-' + lang
lang_to_locale_map[lang].append(res_name)
mappings.append((src_path, os.path.join(dest_dir, res_name)))
return mappings, lang_to_locale_map
def main():
parser = optparse.OptionParser()
build_utils.AddDepfileOption(parser)
parser.add_option('--locale-paks', help='List of files for res/raw-LOCALE')
parser.add_option('--resources-zip', help='Path to output resources.zip')
parser.add_option('--print-languages',
action='store_true',
help='Print out the list of languages that cover the given locale paks '
'(using Android\'s language codes)')
options, _ = parser.parse_args()
build_utils.CheckOptions(options, parser,
required=['locale_paks'])
sources = build_utils.ParseGnList(options.locale_paks)
if options.depfile:
assert options.resources_zip
build_utils.WriteDepfile(options.depfile, options.resources_zip, sources)
mappings, lang_to_locale_map = ComputeMappings(sources)
if options.print_languages:
print '\n'.join(sorted(lang_to_locale_map))
if options.resources_zip:
with zipfile.ZipFile(options.resources_zip, 'w', zipfile.ZIP_STORED) as out:
for mapping in mappings:
out.write(mapping[0], mapping[1])
# Create TypedArray resources so ResourceExtractor can enumerate files.
def WriteValuesFile(lang, names):
dest_dir = 'values'
if lang:
dest_dir += '-' + lang
# Always extract en-US.lpak since it's the fallback.
xml = CreateLocalePaksXml(names + ['en_us.lpak'])
out.writestr(os.path.join(dest_dir, 'locale-paks.xml'), xml)
for lang, names in lang_to_locale_map.iteritems():
WriteValuesFile(lang, names)
WriteValuesFile(None, [])
if __name__ == '__main__':
sys.exit(main())
...@@ -209,12 +209,19 @@ def _ExtractSharedLibsFromRuntimeDeps(runtime_deps_files): ...@@ -209,12 +209,19 @@ def _ExtractSharedLibsFromRuntimeDeps(runtime_deps_files):
ret.reverse() ret.reverse()
return ret return ret
def _CreateJavaLibrariesList(library_paths): def _CreateJavaLibrariesList(library_paths):
""" Create a java literal array with the "base" library names: """Returns a java literal array with the "base" library names:
e.g. libfoo.so -> foo e.g. libfoo.so -> foo
""" """
return ('{%s}' % ','.join(['"%s"' % s[3:-3] for s in library_paths])) return ('{%s}' % ','.join(['"%s"' % s[3:-3] for s in library_paths]))
def _CreateJavaAssetList(assets):
"""Returns a java literal array from a list of assets in the form src:dst."""
return '{%s}' % ','.join(sorted(['"%s"' % a.split(':')[1] for a in assets]))
def main(argv): def main(argv):
parser = optparse.OptionParser() parser = optparse.OptionParser()
build_utils.AddDepfileOption(parser) build_utils.AddDepfileOption(parser)
...@@ -233,8 +240,6 @@ def main(argv): ...@@ -233,8 +240,6 @@ def main(argv):
parser.add_option('--package-name', parser.add_option('--package-name',
help='Java package name for these resources.') help='Java package name for these resources.')
parser.add_option('--android-manifest', help='Path to android manifest.') parser.add_option('--android-manifest', help='Path to android manifest.')
parser.add_option('--is-locale-resource', action='store_true',
help='Whether it is locale resource.')
parser.add_option('--resource-dirs', action='append', default=[], parser.add_option('--resource-dirs', action='append', default=[],
help='GYP-list of resource dirs') help='GYP-list of resource dirs')
...@@ -290,8 +295,6 @@ def main(argv): ...@@ -290,8 +295,6 @@ def main(argv):
help='GYP-list of proguard flag files to use in final apk.') help='GYP-list of proguard flag files to use in final apk.')
parser.add_option('--proguard-info', parser.add_option('--proguard-info',
help='Path to the proguard .info output for this apk.') help='Path to the proguard .info output for this apk.')
parser.add_option('--has-alternative-locale-resource', action='store_true',
help='Whether there is alternative-locale-resource in direct deps')
parser.add_option('--fail', parser.add_option('--fail',
help='GYP-list of error message lines to fail with.') help='GYP-list of error message lines to fail with.')
...@@ -339,21 +342,6 @@ def main(argv): ...@@ -339,21 +342,6 @@ def main(argv):
deps = Deps(direct_deps_config_paths) deps = Deps(direct_deps_config_paths)
all_inputs = deps.AllConfigPaths() all_inputs = deps.AllConfigPaths()
# Remove other locale resources if there is alternative_locale_resource in
# direct deps.
if options.has_alternative_locale_resource:
alternative = [r['path'] for r in deps.Direct('android_resources')
if r.get('is_locale_resource')]
# We can only have one locale resources in direct deps.
if len(alternative) != 1:
raise Exception('The number of locale resource in direct deps is wrong %d'
% len(alternative))
unwanted = [r['path'] for r in deps.All('android_resources')
if r.get('is_locale_resource') and r['path'] not in alternative]
for p in unwanted:
deps.RemoveNonDirectDep(p)
direct_library_deps = deps.Direct('java_library') direct_library_deps = deps.Direct('java_library')
all_library_deps = deps.All('java_library') all_library_deps = deps.All('java_library')
...@@ -485,8 +473,6 @@ def main(argv): ...@@ -485,8 +473,6 @@ def main(argv):
deps_info['package_name'] = options.package_name deps_info['package_name'] = options.package_name
if options.r_text: if options.r_text:
deps_info['r_text'] = options.r_text deps_info['r_text'] = options.r_text
if options.is_locale_resource:
deps_info['is_locale_resource'] = True
deps_info['resources_dirs'] = [] deps_info['resources_dirs'] = []
if options.resource_dirs: if options.resource_dirs:
...@@ -658,6 +644,10 @@ def main(argv): ...@@ -658,6 +644,10 @@ def main(argv):
} }
config['assets'], config['uncompressed_assets'] = ( config['assets'], config['uncompressed_assets'] = (
_MergeAssets(deps.All('android_assets'))) _MergeAssets(deps.All('android_assets')))
config['compressed_assets_java_list'] = (
_CreateJavaAssetList(config['assets']))
config['uncompressed_assets_java_list'] = (
_CreateJavaAssetList(config['uncompressed_assets']))
build_utils.WriteJson(config, options.build_config, only_if_changed=True) build_utils.WriteJson(config, options.build_config, only_if_changed=True)
......
...@@ -184,12 +184,16 @@ def PrintApkAnalysis(apk_filename, chartjson=None): ...@@ -184,12 +184,16 @@ def PrintApkAnalysis(apk_filename, chartjson=None):
NO = lambda _: False NO = lambda _: False
FILE_GROUPS = ( FILE_GROUPS = (
FileGroup('Native code', r'\.so$', lambda f: 'crazy' not in f), FileGroup('Native code', r'\.so$', lambda f: 'crazy' not in f),
FileGroup('Java code', r'\.dex$', YES), FileGroup('Java code', r'^classes.*\.dex$', YES),
FileGroup('Native resources (no l10n)', r'\.pak$', NO), FileGroup('Native resources (no l10n)',
r'^assets/.*(resources|percent)\.pak$', NO),
# For locale paks, assume only english paks are extracted. # For locale paks, assume only english paks are extracted.
FileGroup('Native resources (l10n)', r'\.lpak$', lambda f: 'en_' in f), # Handles locale paks as bother resources or assets (.lpak or .pak).
FileGroup('ICU (i18n library) data', r'assets/icudtl\.dat$', NO), FileGroup('Native resources (l10n)',
FileGroup('V8 Snapshots', r'\.bin$', NO), r'\.lpak$|^assets/.*(?!resources|percent)\.pak$',
lambda f: 'en_' in f or 'en-' in f),
FileGroup('ICU (i18n library) data', r'^assets/icudtl\.dat$', NO),
FileGroup('V8 Snapshots', r'^assets/.*\.bin$', NO),
FileGroup('PNG drawables', r'\.png$', NO), FileGroup('PNG drawables', r'\.png$', NO),
FileGroup('Non-compiled Android resources', r'^res/', NO), FileGroup('Non-compiled Android resources', r'^res/', NO),
FileGroup('Compiled Android resources', r'\.arsc$', NO), FileGroup('Compiled Android resources', r'\.arsc$', NO),
...@@ -221,13 +225,18 @@ def PrintApkAnalysis(apk_filename, chartjson=None): ...@@ -221,13 +225,18 @@ def PrintApkAnalysis(apk_filename, chartjson=None):
total_install_size = total_apk_size total_install_size = total_apk_size
for group in FILE_GROUPS: for group in FILE_GROUPS:
uncompressed_size = sum(member.file_size for member in found_files[group]) uncompressed_size = 0
packed_size = sum(member.compress_size for member in found_files[group]) packed_size = 0
install_size = packed_size extracted_size = 0
install_bytes = sum(member.file_size for member in found_files[group] for member in found_files[group]:
if group.extracted(member.filename)) uncompressed_size += member.file_size
install_size += install_bytes packed_size += member.compress_size
total_install_size += install_bytes # Assume that if a file is not compressed, then it is not extracted.
is_compressed = member.compress_type != zipfile.ZIP_STORED
if is_compressed and group.extracted(member.filename):
extracted_size += member.file_size
install_size = packed_size + extracted_size
total_install_size += extracted_size
ReportPerfResult(chartjson, apk_basename + '_Breakdown', ReportPerfResult(chartjson, apk_basename + '_Breakdown',
group.name + ' size', packed_size, 'bytes') group.name + ' size', packed_size, 'bytes')
......
...@@ -275,13 +275,6 @@ template("write_build_config") { ...@@ -275,13 +275,6 @@ template("write_build_config") {
rebase_path(invoker.r_text, root_build_dir), rebase_path(invoker.r_text, root_build_dir),
] ]
} }
if (defined(invoker.is_locale_resource) && invoker.is_locale_resource) {
args += [ "--is-locale-resource" ]
}
if (defined(invoker.has_alternative_locale_resource) &&
invoker.has_alternative_locale_resource) {
args += [ "--has-alternative-locale-resource" ]
}
} }
if (is_android_resources && defined(invoker.resource_dirs)) { if (is_android_resources && defined(invoker.resource_dirs)) {
......
...@@ -607,69 +607,6 @@ if (enable_java_templates) { ...@@ -607,69 +607,6 @@ if (enable_java_templates) {
} }
} }
# Creates a resources.zip with locale.pak files placed into appropriate
# resource configs (e.g. en-GB.pak -> res/raw-en/en_gb.pak). Also generates
# a locale_paks TypedArray so that resource files can be enumerated at runtime.
#
# If this target is included in the deps of an android resources/library/apk,
# the resources will be included with that target.
#
# Variables:
# sources: List of .pak files. Names must be of the form "en.pak" or
# "en-US.pak".
# deps: (optional) List of dependencies that might be needed to generate
# the .pak files.
#
# Example
# locale_pak_resources("locale_paks") {
# sources = [ "path/en-US.pak", "path/fr.pak", ... ]
# }
template("locale_pak_resources") {
set_sources_assignment_filter([])
assert(defined(invoker.sources))
_base_path = "$target_gen_dir/$target_name"
_resources_zip = _base_path + ".resources.zip"
_build_config = _base_path + ".build_config"
write_build_config("${target_name}__build_config") {
build_config = _build_config
resources_zip = _resources_zip
type = "android_resources"
is_locale_resource = true
}
action("${target_name}__create_resources_zip") {
forward_variables_from(invoker,
[
"deps",
"sources",
])
script = "//build/android/gyp/locale_pak_resources.py"
depfile = "$target_gen_dir/$target_name.d"
outputs = [
_resources_zip,
]
_rebased_sources = rebase_path(sources, root_build_dir)
args = [
"--locale-paks=${_rebased_sources}",
"--resources-zip",
rebase_path(_resources_zip, root_build_dir),
"--depfile",
rebase_path(depfile, root_build_dir),
]
}
group(target_name) {
public_deps = [
":${target_name}__build_config",
":${target_name}__create_resources_zip",
]
}
}
# Declare an Android resources target # Declare an Android resources target
# #
# This creates a resources zip file that will be used when building an Android # This creates a resources zip file that will be used when building an Android
...@@ -1431,8 +1368,6 @@ if (enable_java_templates) { ...@@ -1431,8 +1368,6 @@ if (enable_java_templates) {
# testonly: Marks this target as "test-only". # testonly: Marks this target as "test-only".
# write_asset_list: Adds an extra file to the assets, which contains a list of # write_asset_list: Adds an extra file to the assets, which contains a list of
# all other asset files. # all other asset files.
# alternative_locale_resource_dep: The locale resource target which overrides
# any exsting locale resources in dep graph.
# requires_sdk_api_level_23: If defined and true, the apk is intended for # requires_sdk_api_level_23: If defined and true, the apk is intended for
# installation only on Android M or later. In these releases the system # installation only on Android M or later. In these releases the system
# linker does relocation unpacking, so we can enable it unconditionally. # linker does relocation unpacking, so we can enable it unconditionally.
...@@ -1665,11 +1600,6 @@ if (enable_java_templates) { ...@@ -1665,11 +1600,6 @@ if (enable_java_templates) {
possible_config_deps = invoker.deps possible_config_deps = invoker.deps
} }
if (defined(invoker.alternative_locale_resource_dep)) {
possible_config_deps += [ invoker.alternative_locale_resource_dep ]
has_alternative_locale_resource = true
}
# Added emma to the target's classpath via its .build_config. # Added emma to the target's classpath via its .build_config.
if (emma_coverage && !_emma_never_instrument) { if (emma_coverage && !_emma_never_instrument) {
possible_config_deps += [ "//third_party/android_tools:emma_device" ] possible_config_deps += [ "//third_party/android_tools:emma_device" ]
...@@ -1720,9 +1650,6 @@ if (enable_java_templates) { ...@@ -1720,9 +1650,6 @@ if (enable_java_templates) {
if (defined(invoker.deps)) { if (defined(invoker.deps)) {
deps += invoker.deps deps += invoker.deps
} }
if (defined(invoker.alternative_locale_resource_dep)) {
deps += [ invoker.alternative_locale_resource_dep ]
}
} }
_srcjar_deps += [ ":$process_resources_target" ] _srcjar_deps += [ ":$process_resources_target" ]
...@@ -1793,6 +1720,9 @@ if (enable_java_templates) { ...@@ -1793,6 +1720,9 @@ if (enable_java_templates) {
sources = [ sources = [
"//base/android/java/templates/BuildConfig.template", "//base/android/java/templates/BuildConfig.template",
] ]
deps = [
":$build_config_target",
]
defines = [] defines = []
if (enable_multidex) { if (enable_multidex) {
...@@ -1801,6 +1731,12 @@ if (enable_java_templates) { ...@@ -1801,6 +1731,12 @@ if (enable_java_templates) {
if (is_java_debug || dcheck_always_on) { if (is_java_debug || dcheck_always_on) {
defines += [ "_DCHECK_IS_ON" ] defines += [ "_DCHECK_IS_ON" ]
} }
defines += [
"COMPRESSED_ASSETS_LIST=" +
"@FileArg($_rebased_build_config:compressed_assets_java_list)",
"UNCOMPRESSED_ASSETS_LIST=" +
"@FileArg($_rebased_build_config:uncompressed_assets_java_list)",
]
} }
_srcjar_deps += [ ":${_template_name}__build_config_java" ] _srcjar_deps += [ ":${_template_name}__build_config_java" ]
} }
......
...@@ -67,24 +67,12 @@ jinja_template("chrome_sync_shell_android_manifest") { ...@@ -67,24 +67,12 @@ jinja_template("chrome_sync_shell_android_manifest") {
] ]
} }
locale_pak_resources("chrome_locale_paks") {
sources = []
foreach(_locale, locales - android_chrome_omitted_locales) {
sources += [ "$root_out_dir/locales/$_locale.pak" ]
}
deps = [
"//chrome:packed_resources",
]
}
android_resources("chrome_java_resources") { android_resources("chrome_java_resources") {
resource_dirs = [ resource_dirs = [
"java/res", "java/res",
"//chrome/android/java/res_chromium", "//chrome/android/java/res_chromium",
] ]
deps = [ deps = [
":chrome_locale_paks",
":chrome_strings_grd", ":chrome_strings_grd",
"//chrome/app:java_strings_grd", "//chrome/app:java_strings_grd",
"//components/policy:app_restrictions_resources", "//components/policy:app_restrictions_resources",
...@@ -457,14 +445,6 @@ android_resources("chrome_public_apk_resources") { ...@@ -457,14 +445,6 @@ android_resources("chrome_public_apk_resources") {
] ]
} }
# TODO(agrieve): Delete once downstream no longer references this target.
java_group("chrome_public_apk_assets") {
deps = [
":chrome_public_non_pak_assets",
":chrome_public_pak_assets",
]
}
java_group("chrome_public_non_pak_assets") { java_group("chrome_public_non_pak_assets") {
deps = [ deps = [
"//chrome/android/webapk/libs/runtime_library:runtime_library_assets", "//chrome/android/webapk/libs/runtime_library:runtime_library_assets",
...@@ -481,6 +461,7 @@ android_assets("chrome_public_pak_assets") { ...@@ -481,6 +461,7 @@ android_assets("chrome_public_pak_assets") {
disable_compression = true disable_compression = true
deps = [ deps = [
":chrome_public_locale_pak_assets",
"//chrome:packed_resources", "//chrome:packed_resources",
"//chrome/android/webapk/libs/runtime_library:runtime_library_assets", "//chrome/android/webapk/libs/runtime_library:runtime_library_assets",
"//third_party/icu:icu_assets", "//third_party/icu:icu_assets",
...@@ -488,6 +469,19 @@ android_assets("chrome_public_pak_assets") { ...@@ -488,6 +469,19 @@ android_assets("chrome_public_pak_assets") {
] ]
} }
# This target is separate from chrome_public_pak_assets because it does not
# disable compression.
android_assets("chrome_public_locale_pak_assets") {
sources = []
foreach(_locale, locales - android_chrome_omitted_locales) {
sources += [ "$root_out_dir/locales/$_locale.pak" ]
}
deps = [
"//chrome:packed_resources",
]
}
jinja_template_resources("chrome_public_apk_template_resources") { jinja_template_resources("chrome_public_apk_template_resources") {
resources = [ resources = [
"java/res_template/xml/chromebackupscheme.xml", "java/res_template/xml/chromebackupscheme.xml",
...@@ -564,11 +558,15 @@ if (current_toolchain == default_toolchain) { ...@@ -564,11 +558,15 @@ if (current_toolchain == default_toolchain) {
} }
} }
locale_pak_resources("monochrome_locale_paks") { android_assets("monochrome_pak_assets") {
sources = [] sources = [
"$target_gen_dir/monochrome_paks/chrome_100_percent.pak",
"$target_gen_dir/monochrome_paks/resources.pak",
]
foreach(_locale, locales) { foreach(_locale, locales) {
sources += [ "$target_gen_dir/monochrome_paks/locales/$_locale.pak" ] sources += [ "$target_gen_dir/monochrome_paks/locales/$_locale.pak" ]
} }
disable_compression = true
deps = [ deps = [
":monochrome_paks", ":monochrome_paks",
...@@ -576,17 +574,6 @@ if (current_toolchain == default_toolchain) { ...@@ -576,17 +574,6 @@ if (current_toolchain == default_toolchain) {
} }
} # current_toolchain == host_toolchain } # current_toolchain == host_toolchain
android_assets("monochrome_pak_assets") {
sources = [
"$target_gen_dir/monochrome_paks/chrome_100_percent.pak",
"$target_gen_dir/monochrome_paks/resources.pak",
]
deps = [
":monochrome_paks",
]
disable_compression = true
}
# #
# Only 32-bit //chrome/android/monochrome is needed, beside # Only 32-bit //chrome/android/monochrome is needed, beside
# being built with 32-bit default toolchain, it is also built # being built with 32-bit default toolchain, it is also built
...@@ -642,11 +629,11 @@ template("chrome_public_apk_tmpl_shared") { ...@@ -642,11 +629,11 @@ template("chrome_public_apk_tmpl_shared") {
forward_variables_from(invoker, "*") forward_variables_from(invoker, "*")
native_lib_version_rule = "//build/util:chrome_version_json" native_lib_version_rule = "//build/util:chrome_version_json"
deps += [ deps += [
":chrome_java", ":chrome_java",
":chrome_public_apk_assets",
":chrome_public_apk_resources", ":chrome_public_apk_resources",
":chrome_public_non_pak_assets",
":chrome_public_pak_assets",
"//base:base_java", "//base:base_java",
] ]
} }
......
...@@ -92,8 +92,6 @@ template("monochrome_public_apk_tmpl") { ...@@ -92,8 +92,6 @@ template("monochrome_public_apk_tmpl") {
[ "//chrome/android:monochrome_secondary_abi_lib" ] [ "//chrome/android:monochrome_secondary_abi_lib" ]
} }
alternative_locale_resource_dep = "//chrome/android:monochrome_locale_paks"
alternative_android_sdk_jar = webview_framework_jar alternative_android_sdk_jar = webview_framework_jar
app_as_shared_lib = true app_as_shared_lib = true
use_chromium_linker = false use_chromium_linker = false
......
...@@ -17,13 +17,11 @@ import org.chromium.base.ApiCompatibilityUtils; ...@@ -17,13 +17,11 @@ import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ApplicationStatus; import org.chromium.base.ApplicationStatus;
import org.chromium.base.CommandLineInitUtil; import org.chromium.base.CommandLineInitUtil;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.ResourceExtractor;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.TraceEvent; import org.chromium.base.TraceEvent;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.SuppressFBWarnings; import org.chromium.base.annotations.SuppressFBWarnings;
import org.chromium.base.library_loader.ProcessInitException; import org.chromium.base.library_loader.ProcessInitException;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.banners.AppDetailsDelegate; import org.chromium.chrome.browser.banners.AppDetailsDelegate;
import org.chromium.chrome.browser.customtabs.CustomTabsConnection; import org.chromium.chrome.browser.customtabs.CustomTabsConnection;
import org.chromium.chrome.browser.datausage.ExternalDataUseObserver; import org.chromium.chrome.browser.datausage.ExternalDataUseObserver;
...@@ -69,7 +67,6 @@ import org.chromium.content.browser.ChildProcessCreationParams; ...@@ -69,7 +67,6 @@ import org.chromium.content.browser.ChildProcessCreationParams;
import org.chromium.policy.AppRestrictionsProvider; import org.chromium.policy.AppRestrictionsProvider;
import org.chromium.policy.CombinedPolicyProvider; import org.chromium.policy.CombinedPolicyProvider;
import org.chromium.printing.PrintingController; import org.chromium.printing.PrintingController;
import org.chromium.ui.base.ResourceBundle;
/** /**
* Basic application functionality that should be shared among all browser applications that use * Basic application functionality that should be shared among all browser applications that use
...@@ -158,14 +155,6 @@ public class ChromeApplication extends ContentApplication { ...@@ -158,14 +155,6 @@ public class ChromeApplication extends ContentApplication {
SavePasswordsPreferences.class.getName()); SavePasswordsPreferences.class.getName());
} }
@Override
protected void initializeLibraryDependencies() {
// The ResourceExtractor is only needed by the browser process, but this will have no
// impact on the renderer process construction.
ResourceBundle.initializeLocalePaks(this, R.array.locale_paks);
ResourceExtractor.setResourcesToExtract(ResourceBundle.getActiveLocaleResources());
}
@Override @Override
public void initCommandLine() { public void initCommandLine() {
CommandLineInitUtil.initCommandLine(this, COMMAND_LINE_FILE); CommandLineInitUtil.initCommandLine(this, COMMAND_LINE_FILE);
......
...@@ -208,7 +208,7 @@ public class ChromeBrowserInitializer { ...@@ -208,7 +208,7 @@ public class ChromeBrowserInitializer {
// Check to see if we need to extract any new resources from the APK. This could // Check to see if we need to extract any new resources from the APK. This could
// be on first run when we need to extract all the .pak files we need, or after // be on first run when we need to extract all the .pak files we need, or after
// the user has switched locale, in which case we want new locale resources. // the user has switched locale, in which case we want new locale resources.
ResourceExtractor.get(mApplication).startExtractingResources(); ResourceExtractor.get().startExtractingResources();
mPostInflationStartupComplete = true; mPostInflationStartupComplete = true;
} }
......
...@@ -56,17 +56,9 @@ public abstract class ContentApplication extends BaseChromiumApplication { ...@@ -56,17 +56,9 @@ public abstract class ContentApplication extends BaseChromiumApplication {
} }
}); });
initializeLibraryDependencies();
mLibraryDependenciesInitialized = true; mLibraryDependenciesInitialized = true;
} }
/**
* Initialize all the dependencies that need to be setup before library loading can be
* kicked off.
*/
protected void initializeLibraryDependencies() {
}
/** /**
* @return Whether the library dependencies have been initialized and it is safe to issue * @return Whether the library dependencies have been initialized and it is safe to issue
* requests to load the native library. * requests to load the native library.
......
...@@ -290,7 +290,7 @@ public class BrowserStartupController { ...@@ -290,7 +290,7 @@ public class BrowserStartupController {
// Normally Main.java will have kicked this off asynchronously for Chrome. But other // Normally Main.java will have kicked this off asynchronously for Chrome. But other
// ContentView apps like tests also need them so we make sure we've extracted resources // ContentView apps like tests also need them so we make sure we've extracted resources
// here. We can still make it a little async (wait until the library is loaded). // here. We can still make it a little async (wait until the library is loaded).
ResourceExtractor resourceExtractor = ResourceExtractor.get(mContext); ResourceExtractor resourceExtractor = ResourceExtractor.get();
resourceExtractor.startExtractingResources(); resourceExtractor.startExtractingResources();
// This strictmode exception is to cover the case where the browser process is being started // This strictmode exception is to cover the case where the browser process is being started
...@@ -336,7 +336,7 @@ public class BrowserStartupController { ...@@ -336,7 +336,7 @@ public class BrowserStartupController {
* Initialization needed for tests. Mainly used by content browsertests. * Initialization needed for tests. Mainly used by content browsertests.
*/ */
public void initChromiumBrowserProcessForTests() { public void initChromiumBrowserProcessForTests() {
ResourceExtractor resourceExtractor = ResourceExtractor.get(mContext); ResourceExtractor resourceExtractor = ResourceExtractor.get();
resourceExtractor.startExtractingResources(); resourceExtractor.startExtractingResources();
resourceExtractor.waitForCompletion(); resourceExtractor.waitForCompletion();
nativeSetCommandLineFlags(false, null); nativeSetCommandLineFlags(false, null);
......
...@@ -27,10 +27,6 @@ public class ContentShellApplication extends ContentApplication { ...@@ -27,10 +27,6 @@ public class ContentShellApplication extends ContentApplication {
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
}
@Override
protected void initializeLibraryDependencies() {
PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX, this); PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX, this);
} }
......
...@@ -4,18 +4,12 @@ ...@@ -4,18 +4,12 @@
package org.chromium.ui.base; package org.chromium.ui.base;
import android.content.Context; import org.chromium.base.BuildConfig;
import android.content.res.Resources;
import android.content.res.TypedArray;
import org.chromium.base.ResourceExtractor;
import org.chromium.base.ThreadUtils;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.SuppressFBWarnings;
import java.io.File; import java.io.File;
import java.util.Locale; import java.util.Arrays;
/** /**
* This class provides the resource bundle related methods for the native * This class provides the resource bundle related methods for the native
...@@ -23,67 +17,13 @@ import java.util.Locale; ...@@ -23,67 +17,13 @@ import java.util.Locale;
*/ */
@JNINamespace("ui") @JNINamespace("ui")
public class ResourceBundle { public class ResourceBundle {
private static ResourceExtractor.ResourceEntry[] sActiveLocaleResources; private static final String ASSET_DIR = "assets";
/**
* Applies the reverse mapping done by locale_pak_resources.py.
*/
private static String toChromeLocaleName(String srcFileName) {
srcFileName = srcFileName.replace(".lpak", ".pak");
String[] parts = srcFileName.split("_");
if (parts.length > 1) {
int dotIdx = parts[1].indexOf('.');
return parts[0] + "-" + parts[1].substring(0, dotIdx).toUpperCase(Locale.ENGLISH)
+ parts[1].substring(dotIdx);
}
return srcFileName;
}
/**
* Initializes the list of locale packs for the active locale that are
* present within the apk.
*
* @param context Any context
* @param localePaksResId Resource ID locale_paks (generated by
* locale_pak_resources.py)
*/
@SuppressFBWarnings("LI_LAZY_INIT_UPDATE_STATIC") // Not thread-safe.
public static void initializeLocalePaks(Context context, int localePaksResId) {
ThreadUtils.assertOnUiThread();
assert sActiveLocaleResources == null;
Resources resources = context.getResources();
TypedArray resIds = resources.obtainTypedArray(localePaksResId);
try {
int len = resIds.length();
sActiveLocaleResources = new ResourceExtractor.ResourceEntry[len];
for (int i = 0; i < len; ++i) {
int resId = resIds.getResourceId(i, 0);
String resPath = resources.getString(resId);
String srcBaseName = new File(resPath).getName();
String dstBaseName = toChromeLocaleName(srcBaseName);
sActiveLocaleResources[i] = new ResourceExtractor.ResourceEntry(resId, resPath,
dstBaseName);
}
} finally {
resIds.recycle();
}
}
@SuppressFBWarnings("MS_EXPOSE_REP") // Don't modify the array.
public static ResourceExtractor.ResourceEntry[] getActiveLocaleResources() {
return sActiveLocaleResources;
}
@CalledByNative @CalledByNative
private static String getLocalePakResourcePath(String locale) { private static String getLocalePakResourcePath(String locale) {
if (sActiveLocaleResources == null) {
return null;
}
String fileName = locale + ".pak"; String fileName = locale + ".pak";
for (ResourceExtractor.ResourceEntry entry : sActiveLocaleResources) { if (Arrays.binarySearch(BuildConfig.UNCOMPRESSED_ASSETS, fileName) >= 0) {
if (fileName.equals(entry.extractedFileName)) { return new File(ASSET_DIR, fileName).toString();
return entry.pathWithinApk;
}
} }
return null; return null;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment