| 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" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 env_(aura::Env::CreateInstance( | 63 env_(aura::Env::CreateInstance( |
| 64 (mode == Mode::AURA_MUS || mode == Mode::AURA_MUS_WINDOW_MANAGER) | 64 (mode == Mode::AURA_MUS || mode == Mode::AURA_MUS_WINDOW_MANAGER) |
| 65 ? aura::Env::Mode::MUS | 65 ? aura::Env::Mode::MUS |
| 66 : aura::Env::Mode::LOCAL)), | 66 : aura::Env::Mode::LOCAL)), |
| 67 views_delegate_(new MusViewsDelegate) { | 67 views_delegate_(new MusViewsDelegate) { |
| 68 if (mode == Mode::AURA_MUS) { | 68 if (mode == Mode::AURA_MUS) { |
| 69 mus_client_ = | 69 mus_client_ = |
| 70 base::WrapUnique(new MusClient(connector, identity, io_task_runner)); | 70 base::WrapUnique(new MusClient(connector, identity, io_task_runner)); |
| 71 } | 71 } |
| 72 ui::MaterialDesignController::Initialize(); | 72 ui::MaterialDesignController::Initialize(); |
| 73 InitializeResources(connector); | 73 if (!InitializeResources(connector)) |
| 74 return; |
| 74 | 75 |
| 75 // Initialize the skia font code to go ask fontconfig underneath. | 76 // Initialize the skia font code to go ask fontconfig underneath. |
| 76 #if defined(OS_LINUX) | 77 #if defined(OS_LINUX) |
| 77 font_loader_ = sk_make_sp<font_service::FontLoader>(connector); | 78 font_loader_ = sk_make_sp<font_service::FontLoader>(connector); |
| 78 SkFontConfigInterface::SetGlobal(font_loader_.get()); | 79 SkFontConfigInterface::SetGlobal(font_loader_.get()); |
| 79 #endif | 80 #endif |
| 80 | 81 |
| 81 // There is a bunch of static state in gfx::Font, by running this now, | 82 // There is a bunch of static state in gfx::Font, by running this now, |
| 82 // before any other apps load, we ensure all the state is set up. | 83 // before any other apps load, we ensure all the state is set up. |
| 83 gfx::Font(); | 84 gfx::Font(); |
| 84 | 85 |
| 85 ui::InitializeInputMethodForTesting(); | 86 ui::InitializeInputMethodForTesting(); |
| 87 initialized_ = true; |
| 86 } | 88 } |
| 87 | 89 |
| 88 AuraInit::~AuraInit() { | 90 AuraInit::~AuraInit() { |
| 89 #if defined(OS_LINUX) | 91 #if defined(OS_LINUX) |
| 90 if (font_loader_.get()) { | 92 if (font_loader_.get()) { |
| 91 SkFontConfigInterface::SetGlobal(nullptr); | 93 SkFontConfigInterface::SetGlobal(nullptr); |
| 92 // FontLoader is ref counted. We need to explicitly shutdown the background | 94 // FontLoader is ref counted. We need to explicitly shutdown the background |
| 93 // thread, otherwise the background thread may be shutdown after the app is | 95 // thread, otherwise the background thread may be shutdown after the app is |
| 94 // torn down, when we're in a bad state. | 96 // torn down, when we're in a bad state. |
| 95 font_loader_->Shutdown(); | 97 font_loader_->Shutdown(); |
| 96 } | 98 } |
| 97 #endif | 99 #endif |
| 98 } | 100 } |
| 99 | 101 |
| 100 void AuraInit::InitializeResources(service_manager::Connector* connector) { | 102 bool AuraInit::InitializeResources(service_manager::Connector* connector) { |
| 101 // Resources may have already been initialized (e.g. when 'chrome --mash' is | 103 // Resources may have already been initialized (e.g. when 'chrome --mash' is |
| 102 // used to launch the current app). | 104 // used to launch the current app). |
| 103 if (ui::ResourceBundle::HasSharedInstance()) | 105 if (ui::ResourceBundle::HasSharedInstance()) |
| 104 return; | 106 return false; |
| 105 | 107 |
| 106 std::set<std::string> resource_paths({resource_file_}); | 108 std::set<std::string> resource_paths({resource_file_}); |
| 107 if (!resource_file_200_.empty()) | 109 if (!resource_file_200_.empty()) |
| 108 resource_paths.insert(resource_file_200_); | 110 resource_paths.insert(resource_file_200_); |
| 109 | 111 |
| 110 catalog::ResourceLoader loader; | 112 catalog::ResourceLoader loader; |
| 111 filesystem::mojom::DirectoryPtr directory; | 113 filesystem::mojom::DirectoryPtr directory; |
| 112 connector->BindInterface(catalog::mojom::kServiceName, &directory); | 114 connector->BindInterface(catalog::mojom::kServiceName, &directory); |
| 113 CHECK(loader.OpenFiles(std::move(directory), resource_paths)); | 115 // TODO(jonross): if this proves useful in resolving the crash of |
| 116 // mash_unittests then switch AuraInit to have an Init method, returning a |
| 117 // bool for success. Then update all callsites to use this to determine the |
| 118 // shutdown of their ServiceContext. |
| 119 // One cause of failure is that the peer has closed, but we have not been |
| 120 // notified yet. It is not possible to complete initialization, so exit now. |
| 121 // Calling services will shutdown ServiceContext as appropriate. |
| 122 if (!loader.OpenFiles(std::move(directory), resource_paths)) |
| 123 return false; |
| 114 ui::RegisterPathProvider(); | 124 ui::RegisterPathProvider(); |
| 115 base::File pak_file = loader.TakeFile(resource_file_); | 125 base::File pak_file = loader.TakeFile(resource_file_); |
| 116 base::File pak_file_2 = pak_file.Duplicate(); | 126 base::File pak_file_2 = pak_file.Duplicate(); |
| 117 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( | 127 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( |
| 118 std::move(pak_file), base::MemoryMappedFile::Region::kWholeFile); | 128 std::move(pak_file), base::MemoryMappedFile::Region::kWholeFile); |
| 119 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( | 129 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( |
| 120 std::move(pak_file_2), ui::SCALE_FACTOR_100P); | 130 std::move(pak_file_2), ui::SCALE_FACTOR_100P); |
| 121 if (!resource_file_200_.empty()) | 131 if (!resource_file_200_.empty()) |
| 122 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( | 132 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( |
| 123 loader.TakeFile(resource_file_200_), ui::SCALE_FACTOR_200P); | 133 loader.TakeFile(resource_file_200_), ui::SCALE_FACTOR_200P); |
| 134 return true; |
| 124 } | 135 } |
| 125 | 136 |
| 126 } // namespace views | 137 } // namespace views |
| OLD | NEW |