diff options
author | jam <jam@chromium.org> | 2015-07-15 15:20:06 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-15 22:21:10 +0000 |
commit | 94a5ec036c072c9f2d3ef6a4f54b6a191cc8f1b5 (patch) | |
tree | bd8736bc0edce931f293d5585cea9eeebd32bc1c | |
parent | 0314e59cdf11cc3a4e0799a2082940a452578e54 (diff) | |
download | chromium_src-94a5ec036c072c9f2d3ef6a4f54b6a191cc8f1b5.zip chromium_src-94a5ec036c072c9f2d3ef6a4f54b6a191cc8f1b5.tar.gz chromium_src-94a5ec036c072c9f2d3ef6a4f54b6a191cc8f1b5.tar.bz2 |
Share ICU data file among multiple Mandoline apps through the ResourceProvider.
This brings the stripped release Linux binary size from 81.2MB to 71.4MB. For comparison, content shell is 75.2MB.
BUG=477435
Review URL: https://codereview.chromium.org/1240493003
Cr-Commit-Position: refs/heads/master@{#338926}
-rw-r--r-- | components/html_viewer/BUILD.gn | 4 | ||||
-rw-r--r-- | components/html_viewer/global_state.cc | 4 | ||||
-rw-r--r-- | components/resource_provider/BUILD.gn | 6 | ||||
-rw-r--r-- | components/resource_provider/public/cpp/resource_loader.cc | 38 | ||||
-rw-r--r-- | components/resource_provider/public/cpp/resource_loader.h | 6 | ||||
-rw-r--r-- | components/resource_provider/public/interfaces/resource_provider.mojom | 3 | ||||
-rw-r--r-- | components/resource_provider/resource_provider_impl.cc | 11 | ||||
-rw-r--r-- | components/resource_provider/resource_provider_impl.h | 1 | ||||
-rw-r--r-- | mandoline/ui/aura/aura_init.cc | 4 | ||||
-rw-r--r-- | mandoline/ui/browser/BUILD.gn | 6 | ||||
-rw-r--r-- | mandoline/ui/omnibox/BUILD.gn | 6 | ||||
-rw-r--r-- | mojo/public/mojo_application.gni | 25 |
12 files changed, 81 insertions, 33 deletions
diff --git a/components/html_viewer/BUILD.gn b/components/html_viewer/BUILD.gn index 9cea081..ee770c5 100644 --- a/components/html_viewer/BUILD.gn +++ b/components/html_viewer/BUILD.gn @@ -198,12 +198,10 @@ mojo_native_application("html_viewer") { deps = [ ":html_viewer_resources_grit", ":lib", - "//third_party/icu:icudata", "//third_party/mojo/src/mojo/public/c/system:for_shared_library", "//ui/resources:ui_test_pak", ] resources = [ - "$root_out_dir/icudtl.dat", "$root_out_dir/ui_test.pak", "$target_gen_dir/html_viewer_resources.pak", ] @@ -234,13 +232,11 @@ mojo_native_application("layout_test_html_viewer") { "//components/test_runner", "//third_party/WebKit/public:blink", "//third_party/WebKit/public:test_support", - "//third_party/icu:icudata", "//third_party/mojo/src/mojo/public/c/system:for_shared_library", "//ui/resources:ui_test_pak", "//url", ] resources = [ - "$root_out_dir/icudtl.dat", "$root_out_dir/ui_test.pak", "$target_gen_dir/html_viewer_resources.pak", ] diff --git a/components/html_viewer/global_state.cc b/components/html_viewer/global_state.cc index 67ef469..03872de 100644 --- a/components/html_viewer/global_state.cc +++ b/components/html_viewer/global_state.cc @@ -38,7 +38,6 @@ const char kJavaScriptFlags[] = "js-flags"; size_t kDesiredMaxMemory = 20 * 1024 * 1024; // Paths resources are loaded from. -const char kResourceIcudtl[] = "icudtl.dat"; const char kResourceResourcesPak[] = "html_viewer_resources.pak"; const char kResourceUIPak[] = "ui_test.pak"; #if defined(V8_USE_EXTERNAL_STARTUP_DATA) @@ -49,7 +48,6 @@ const char kResourceSnapshotBlob[] = "snapshot_blob.bin"; std::set<std::string> GetResourcePaths() { std::set<std::string> paths; paths.insert(kResourceResourcesPak); - paths.insert(kResourceIcudtl); paths.insert(kResourceUIPak); #if defined(V8_USE_EXTERNAL_STARTUP_DATA) paths.insert(kResourceNativesBlob); @@ -113,7 +111,7 @@ void GlobalState::InitIfNecessary(const gfx::Size& screen_size_in_pixels, #endif blink::initialize(blink_platform_.get()); base::i18n::InitializeICUWithFileDescriptor( - resource_loader_.ReleaseFile(kResourceIcudtl).TakePlatformFile(), + resource_loader_.GetICUFile().TakePlatformFile(), base::MemoryMappedFile::Region::kWholeFile); ui::RegisterPathProvider(); diff --git a/components/resource_provider/BUILD.gn b/components/resource_provider/BUILD.gn index 0a8363f..0eea37b 100644 --- a/components/resource_provider/BUILD.gn +++ b/components/resource_provider/BUILD.gn @@ -16,7 +16,10 @@ if (is_android) { deps = [ ":java_library", ":resource_provider_lib", + "//third_party/icu:icudata", ] + + resources = [ "$root_out_dir/icudtl.dat" ] } shared_library("resource_provider_lib") { @@ -69,8 +72,11 @@ if (is_android) { "//base", "//components/resource_provider/public/interfaces", "//mojo/environment:chromium", + "//third_party/icu:icudata", "//url", ] + + resources = [ "$root_out_dir/icudtl.dat" ] } } diff --git a/components/resource_provider/public/cpp/resource_loader.cc b/components/resource_provider/public/cpp/resource_loader.cc index ba31461..13937b5 100644 --- a/components/resource_provider/public/cpp/resource_loader.cc +++ b/components/resource_provider/public/cpp/resource_loader.cc @@ -7,21 +7,32 @@ #include "base/bind.h" #include "base/files/file.h" #include "mojo/application/public/cpp/connect.h" +#include "mojo/application/public/interfaces/service_provider.mojom.h" #include "mojo/application/public/interfaces/shell.mojom.h" #include "mojo/common/common_type_converters.h" #include "mojo/platform_handle/platform_handle_functions.h" namespace resource_provider { +namespace { +base::File GetFileFromHandle(mojo::ScopedHandle handle) { + CHECK(handle.is_valid()); + MojoPlatformHandle platform_handle; + CHECK(MojoExtractPlatformHandle(handle.release().value(), + &platform_handle) == MOJO_RESULT_OK); + return base::File(platform_handle).Pass(); +} +} ResourceLoader::ResourceLoader(mojo::Shell* shell, const std::set<std::string>& paths) : loaded_(false), did_block_(false) { mojo::URLRequestPtr request(mojo::URLRequest::New()); request->url = mojo::String::From("mojo:resource_provider"); + mojo::ServiceProviderPtr resource_provider_service_provider; shell->ConnectToApplication(request.Pass(), - GetProxy(&resource_provider_service_provider_), + GetProxy(&resource_provider_service_provider), nullptr); - mojo::ConnectToService(resource_provider_service_provider_.get(), + mojo::ConnectToService(resource_provider_service_provider.get(), &resource_provider_); std::vector<std::string> paths_vector(paths.begin(), paths.end()); resource_provider_->GetResources( @@ -49,22 +60,29 @@ base::File ResourceLoader::ReleaseFile(const std::string& path) { return file_wrapper->Pass(); } +base::File ResourceLoader::GetICUFile() { + base::File rv; + resource_provider_->GetICUHandle( + base::Bind(&ResourceLoader::OnGotICU, base::Unretained(this), &rv)); + resource_provider_.WaitForIncomingResponse(); + CHECK(rv.IsValid()); + return rv.Pass(); +} + void ResourceLoader::OnGotResources(const std::vector<std::string>& paths, mojo::Array<mojo::ScopedHandle> resources) { - // We no longer need the connection to ResourceProvider. - resource_provider_.reset(); - resource_provider_service_provider_.reset(); CHECK(!resources.is_null()); CHECK_EQ(resources.size(), paths.size()); for (size_t i = 0; i < resources.size(); ++i) { - CHECK(resources[i].is_valid()); - MojoPlatformHandle platform_handle; - CHECK(MojoExtractPlatformHandle(resources[i].release().value(), - &platform_handle) == MOJO_RESULT_OK); - resource_map_[paths[i]].reset(new base::File(platform_handle)); + resource_map_[paths[i]].reset( + new base::File(GetFileFromHandle(resources[i].Pass()))); } loaded_ = true; } +void ResourceLoader::OnGotICU(base::File* file, mojo::ScopedHandle handle) { + *file = GetFileFromHandle(handle.Pass()); +} + } // namespace resource_provider diff --git a/components/resource_provider/public/cpp/resource_loader.h b/components/resource_provider/public/cpp/resource_loader.h index 97f2b2ae..fae6655 100644 --- a/components/resource_provider/public/cpp/resource_loader.h +++ b/components/resource_provider/public/cpp/resource_loader.h @@ -13,7 +13,6 @@ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "components/resource_provider/public/interfaces/resource_provider.mojom.h" -#include "mojo/application/public/interfaces/service_provider.mojom.h" #include "mojo/platform_handle/platform_handle.h" #include "third_party/mojo/src/mojo/public/cpp/bindings/array.h" #include "third_party/mojo/src/mojo/public/cpp/system/handle.h" @@ -46,6 +45,8 @@ class ResourceLoader { // Releases and returns the file wrapping the handle. base::File ReleaseFile(const std::string& path); + base::File GetICUFile(); + bool loaded() const { return loaded_; } private: @@ -54,8 +55,7 @@ class ResourceLoader { // Callback when resources have loaded. void OnGotResources(const std::vector<std::string>& paths, mojo::Array<mojo::ScopedHandle> resources); - - mojo::ServiceProviderPtr resource_provider_service_provider_; + void OnGotICU(base::File* file, mojo::ScopedHandle handle); ResourceProviderPtr resource_provider_; diff --git a/components/resource_provider/public/interfaces/resource_provider.mojom b/components/resource_provider/public/interfaces/resource_provider.mojom index 15af0d1..01c6b99 100644 --- a/components/resource_provider/public/interfaces/resource_provider.mojom +++ b/components/resource_provider/public/interfaces/resource_provider.mojom @@ -15,4 +15,7 @@ interface ResourceProvider { // The result is an array of platform handles for each of the requested paths. // TODO(sky): this should really be map<string,handle>, but that doesn't work. GetResources(array<string> paths) => (array<handle> resource_handles); + + // Fetch a handle to the shared version of ICU table. + GetICUHandle() => (handle resource_handle); }; diff --git a/components/resource_provider/resource_provider_impl.cc b/components/resource_provider/resource_provider_impl.cc index 405338e..53dd9a0 100644 --- a/components/resource_provider/resource_provider_impl.cc +++ b/components/resource_provider/resource_provider_impl.cc @@ -10,12 +10,15 @@ #include "base/logging.h" #include "components/resource_provider/file_utils.h" #include "mojo/platform_handle/platform_handle_functions.h" +#include "url/gurl.h" using mojo::ScopedHandle; namespace resource_provider { namespace { +const char kResourceIcudtl[] = "icudtl.dat"; + ScopedHandle GetHandleForPath(const base::FilePath& path) { if (path.empty()) return ScopedHandle(); @@ -63,4 +66,12 @@ void ResourceProviderImpl::GetResources(mojo::Array<mojo::String> paths, callback.Run(handles.Pass()); } +void ResourceProviderImpl::GetICUHandle(const GetICUHandleCallback& callback) { + const base::FilePath resource_app_path( + GetPathForApplicationUrl(GURL("mojo:resource_provider"))); + mojo::ScopedHandle handle = GetHandleForPath( + GetPathForResourceNamed(resource_app_path, kResourceIcudtl)); + callback.Run(handle.Pass()); +} + } // namespace resource_provider diff --git a/components/resource_provider/resource_provider_impl.h b/components/resource_provider/resource_provider_impl.h index eb2e22b..3cb43a6 100644 --- a/components/resource_provider/resource_provider_impl.h +++ b/components/resource_provider/resource_provider_impl.h @@ -20,6 +20,7 @@ class ResourceProviderImpl : public resource_provider::ResourceProvider { // ResourceProvider: void GetResources(mojo::Array<mojo::String> paths, const GetResourcesCallback& callback) override; + void GetICUHandle(const GetICUHandleCallback& callback) override; const base::FilePath application_path_; diff --git a/mandoline/ui/aura/aura_init.cc b/mandoline/ui/aura/aura_init.cc index 7f684b7..9873aa0 100644 --- a/mandoline/ui/aura/aura_init.cc +++ b/mandoline/ui/aura/aura_init.cc @@ -20,12 +20,10 @@ namespace mandoline { namespace { // Paths resources are loaded from. -const char kResourceIcudtl[] = "icudtl.dat"; const char kResourceUIPak[] = "mandoline_ui.pak"; std::set<std::string> GetResourcePaths() { std::set<std::string> paths; - paths.insert(kResourceIcudtl); paths.insert(kResourceUIPak); return paths; } @@ -55,7 +53,7 @@ void AuraInit::InitializeResources(mojo::Shell* shell) { return; CHECK(resource_loader.loaded()); base::i18n::InitializeICUWithFileDescriptor( - resource_loader.ReleaseFile(kResourceIcudtl).TakePlatformFile(), + resource_loader.GetICUFile().TakePlatformFile(), base::MemoryMappedFile::Region::kWholeFile); ui::RegisterPathProvider(); ui::ResourceBundle::InitSharedInstanceWithPakPath(base::FilePath()); diff --git a/mandoline/ui/browser/BUILD.gn b/mandoline/ui/browser/BUILD.gn index 586eae8..844e950 100644 --- a/mandoline/ui/browser/BUILD.gn +++ b/mandoline/ui/browser/BUILD.gn @@ -16,13 +16,9 @@ mojo_native_application("browser") { "//mandoline/services/navigation/public/interfaces", "//mandoline/ui/common/resources", "//mojo/application/public/cpp", - "//third_party/icu:icudata", ] - resources = [ - "$root_out_dir/icudtl.dat", - "$root_out_dir/mandoline_ui.pak", - ] + resources = [ "$root_out_dir/mandoline_ui.pak" ] } source_set("lib") { diff --git a/mandoline/ui/omnibox/BUILD.gn b/mandoline/ui/omnibox/BUILD.gn index afe45fa..309d009 100644 --- a/mandoline/ui/omnibox/BUILD.gn +++ b/mandoline/ui/omnibox/BUILD.gn @@ -14,13 +14,9 @@ mojo_native_application("omnibox") { "//mandoline/services/navigation/public/interfaces", "//mandoline/ui/common/resources", "//mojo/application/public/cpp", - "//third_party/icu:icudata", ] - resources = [ - "$root_out_dir/icudtl.dat", - "$root_out_dir/mandoline_ui.pak", - ] + resources = [ "$root_out_dir/mandoline_ui.pak" ] } source_set("lib") { diff --git a/mojo/public/mojo_application.gni b/mojo/public/mojo_application.gni index c5cac19..ce18576 100644 --- a/mojo/public/mojo_application.gni +++ b/mojo/public/mojo_application.gni @@ -322,6 +322,29 @@ if (is_android) { assert(defined(invoker.input_so)) assert(defined(invoker.input_dex_jar)) + mojo_deps = [] + if (defined(invoker.resources)) { + base_target_name = target_name + if (defined(invoker.output_name)) { + base_target_name = invoker.output_name + } + + copy_step_name = "${base_target_name}__copy_resources" + copy(copy_step_name) { + sources = invoker.resources + outputs = [ + "${root_out_dir}/${base_target_name}/resources/{{source_file_part}}", + ] + if (defined(invoker.testonly)) { + testonly = invoker.testonly + } + if (defined(invoker.deps)) { + deps = invoker.deps + } + } + mojo_deps += [ ":$copy_step_name" ] + } + zip_action_name = "${target_name}_zip" zip_action_output = "$target_gen_dir/${target_name}.zip" prepend_action_name = target_name @@ -383,6 +406,8 @@ if (is_android) { "--line=#!mojo mojo:android_handler", ] + deps = mojo_deps + public_deps = [ ":$zip_action_name", ] |