Chromium Code Reviews| Index: android_webview/browser/aw_browser_main_parts.cc |
| diff --git a/android_webview/browser/aw_browser_main_parts.cc b/android_webview/browser/aw_browser_main_parts.cc |
| index 29e9003755682f2aa04e2e21031bf2aace38b876..70771ca7e4f0a07373a0146833225ac4ebb8d48e 100644 |
| --- a/android_webview/browser/aw_browser_main_parts.cc |
| +++ b/android_webview/browser/aw_browser_main_parts.cc |
| @@ -6,6 +6,7 @@ |
| #include "android_webview/browser/aw_browser_context.h" |
| #include "android_webview/browser/aw_result_codes.h" |
| +#include "android_webview/native/aw_assets.h" |
| #include "base/android/build_info.h" |
| #include "base/android/memory_pressure_listener_android.h" |
| #include "base/command_line.h" |
| @@ -19,6 +20,7 @@ |
| #include "gpu/command_buffer/service/mailbox_synchronizer.h" |
| #include "net/android/network_change_notifier_factory_android.h" |
| #include "net/base/network_change_notifier.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| #include "ui/base/l10n/l10n_util_android.h" |
| #include "ui/base/layout.h" |
| #include "ui/base/resource/resource_bundle.h" |
| @@ -45,15 +47,42 @@ void AwBrowserMainParts::PreEarlyInitialization() { |
| } |
| int AwBrowserMainParts::PreCreateThreads() { |
| - ui::ResourceBundle::InitSharedInstanceLocaleOnly( |
| - l10n_util::GetDefaultLocale(), NULL); |
| - |
| - base::FilePath pak_path; |
| - PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &pak_path); |
| + int pak_fd = 0; |
| + int64 pak_off = 0; |
| + int64 pak_len = 0; |
| + |
| + // Try to load the locale pak file directly from the apk, falling back to |
| + // the default ResourceBundle behavior, which uses PATH_SERVICE to locate the |
| + // files on the storage, in case of failure. |
| + std::string locale_pak_file = l10n_util::GetApplicationLocale(l10n_util::GetDefaultLocale()) + ".pak"; |
| + if (AwAssets::OpenAsset(locale_pak_file, &pak_fd, &pak_off, &pak_len)) { |
| + VLOG(0) << "Loading " << locale_pak_file << " from FD: " << pak_fd << " OFF: " << pak_off << " LEN: " << pak_len; |
|
mkosiba (inactive)
2014/07/21 14:20:58
aren't these lines a bit tooo loooonnnggg?
Primiano Tucci (use gerrit)
2014/07/21 17:20:02
Yeah, that's why the patchset was entitled "WIP" ;
|
| + ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( |
| + base::File(pak_fd), |
| + base::File::Region(pak_off, pak_len), |
| + /*should_load_common_resources=*/false); |
|
mkosiba (inactive)
2014/07/21 14:20:58
nit: I _think_ it should be like: /*should_load_c
Primiano Tucci (use gerrit)
2014/07/21 17:20:03
A search in code search seems to suggest the contr
|
| + } else { |
|
mkosiba (inactive)
2014/07/21 14:20:58
does this make sense? If it's not there in the apk
benm (inactive)
2014/07/21 14:38:55
Long term, yes we should remove this. But for now
Primiano Tucci (use gerrit)
2014/07/21 17:20:02
Quoting Torne's previous comment in this CL:
"Yeah
|
| + LOG(WARNING) << "Cannot load " << locale_pak_file << " assets from the apk." |
| + " Falling back loading it using PATH_SERVICE."; |
| + ui::ResourceBundle::InitSharedInstanceLocaleOnly( |
| + l10n_util::GetDefaultLocale(), NULL); |
| + } |
| - ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( |
| - pak_path.AppendASCII("webviewchromium.pak"), |
| - ui::SCALE_FACTOR_NONE); |
| + // Same logic as above for the webviewchromium.pak. |
| + if (AwAssets::OpenAsset("webviewchromium.pak", &pak_fd, &pak_off, &pak_len)) { |
| + VLOG(0) << "Loading pak from FD: " << pak_fd << " OFF: " << pak_off |
| + << " LEN: " << pak_len; |
| + ui::ResourceBundle::GetSharedInstance().AddDataPackFromFileRegion( |
| + base::File(pak_fd), base::File::Region(pak_off, pak_len), ui::SCALE_FACTOR_NONE); |
| + } else { |
| + base::FilePath pak_path; |
| + PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &pak_path); |
| + LOG(WARNING) << "Cannot load webviewchromium.pak assets from the apk. " |
| + "Falling back loading it from " << pak_path.MaybeAsASCII(); |
| + ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( |
| + pak_path.AppendASCII("webviewchromium.pak"), |
| + ui::SCALE_FACTOR_NONE); |
| + } |
| base::android::MemoryPressureListenerAndroid::RegisterSystemCallback( |
| base::android::AttachCurrentThread()); |