| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/mus/aura_init.h" | 5 #include "ui/views/mus/aura_init.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "services/catalog/public/cpp/resource_loader.h" | 13 #include "services/catalog/public/cpp/resource_loader.h" |
| 14 #include "services/shell/public/cpp/connector.h" | 14 #include "services/shell/public/cpp/connector.h" |
| 15 #include "ui/aura/env.h" | 15 #include "ui/aura/env.h" |
| 16 #include "ui/base/ime/input_method_initializer.h" | 16 #include "ui/base/ime/input_method_initializer.h" |
| 17 #include "ui/base/material_design/material_design_controller.h" | 17 #include "ui/base/material_design/material_design_controller.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 19 #include "ui/base/ui_base_paths.h" | 19 #include "ui/base/ui_base_paths.h" |
| 20 #include "ui/views/views_delegate.h" | 20 #include "ui/views/views_delegate.h" |
| 21 | 21 |
| 22 #if defined(OS_LINUX) && !defined(OS_ANDROID) | 22 #if defined(OS_LINUX) |
| 23 #include "components/font_service/public/cpp/font_loader.h" | 23 #include "components/font_service/public/cpp/font_loader.h" |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 namespace views { | 26 namespace views { |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 std::set<std::string> GetResourcePaths(const std::string& resource_file) { | 30 std::set<std::string> GetResourcePaths(const std::string& resource_file) { |
| 31 std::set<std::string> paths; | 31 std::set<std::string> paths; |
| 32 paths.insert(resource_file); | 32 paths.insert(resource_file); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 56 : resource_file_(resource_file), | 56 : resource_file_(resource_file), |
| 57 env_(aura::Env::CreateInstance()), | 57 env_(aura::Env::CreateInstance()), |
| 58 views_delegate_(new MusViewsDelegate) { | 58 views_delegate_(new MusViewsDelegate) { |
| 59 ui::MaterialDesignController::Initialize(); | 59 ui::MaterialDesignController::Initialize(); |
| 60 InitializeResources(connector); | 60 InitializeResources(connector); |
| 61 | 61 |
| 62 ui::InitializeInputMethodForTesting(); | 62 ui::InitializeInputMethodForTesting(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 AuraInit::~AuraInit() { | 65 AuraInit::~AuraInit() { |
| 66 #if defined(OS_LINUX) && !defined(OS_ANDROID) | 66 #if defined(OS_LINUX) |
| 67 if (font_loader_.get()) { | 67 if (font_loader_.get()) { |
| 68 SkFontConfigInterface::SetGlobal(nullptr); | 68 SkFontConfigInterface::SetGlobal(nullptr); |
| 69 // FontLoader is ref counted. We need to explicitly shutdown the background | 69 // FontLoader is ref counted. We need to explicitly shutdown the background |
| 70 // thread, otherwise the background thread may be shutdown after the app is | 70 // thread, otherwise the background thread may be shutdown after the app is |
| 71 // torn down, when we're in a bad state. | 71 // torn down, when we're in a bad state. |
| 72 font_loader_->Shutdown(); | 72 font_loader_->Shutdown(); |
| 73 } | 73 } |
| 74 #endif | 74 #endif |
| 75 } | 75 } |
| 76 | 76 |
| 77 void AuraInit::InitializeResources(shell::Connector* connector) { | 77 void AuraInit::InitializeResources(shell::Connector* connector) { |
| 78 if (ui::ResourceBundle::HasSharedInstance()) | 78 if (ui::ResourceBundle::HasSharedInstance()) |
| 79 return; | 79 return; |
| 80 catalog::ResourceLoader loader; | 80 catalog::ResourceLoader loader; |
| 81 filesystem::mojom::DirectoryPtr directory; | 81 filesystem::mojom::DirectoryPtr directory; |
| 82 connector->ConnectToInterface("mojo:catalog", &directory); | 82 connector->ConnectToInterface("mojo:catalog", &directory); |
| 83 CHECK(loader.OpenFiles(std::move(directory), | 83 CHECK(loader.OpenFiles(std::move(directory), |
| 84 GetResourcePaths(resource_file_))); | 84 GetResourcePaths(resource_file_))); |
| 85 ui::RegisterPathProvider(); | 85 ui::RegisterPathProvider(); |
| 86 base::File pak_file = loader.TakeFile(resource_file_); | 86 base::File pak_file = loader.TakeFile(resource_file_); |
| 87 base::File pak_file_2 = pak_file.Duplicate(); | 87 base::File pak_file_2 = pak_file.Duplicate(); |
| 88 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( | 88 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( |
| 89 std::move(pak_file), base::MemoryMappedFile::Region::kWholeFile); | 89 std::move(pak_file), base::MemoryMappedFile::Region::kWholeFile); |
| 90 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( | 90 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( |
| 91 std::move(pak_file_2), ui::SCALE_FACTOR_100P); | 91 std::move(pak_file_2), ui::SCALE_FACTOR_100P); |
| 92 | 92 |
| 93 // Initialize the skia font code to go ask fontconfig underneath. | 93 // Initialize the skia font code to go ask fontconfig underneath. |
| 94 #if defined(OS_LINUX) && !defined(OS_ANDROID) | 94 #if defined(OS_LINUX) |
| 95 font_loader_ = sk_make_sp<font_service::FontLoader>(connector); | 95 font_loader_ = sk_make_sp<font_service::FontLoader>(connector); |
| 96 SkFontConfigInterface::SetGlobal(font_loader_.get()); | 96 SkFontConfigInterface::SetGlobal(font_loader_.get()); |
| 97 #endif | 97 #endif |
| 98 | 98 |
| 99 // There is a bunch of static state in gfx::Font, by running this now, | 99 // There is a bunch of static state in gfx::Font, by running this now, |
| 100 // before any other apps load, we ensure all the state is set up. | 100 // before any other apps load, we ensure all the state is set up. |
| 101 gfx::Font(); | 101 gfx::Font(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 } // namespace views | 104 } // namespace views |
| OLD | NEW |