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 resources are unavailable do not complete start-up. |
74 if (!InitializeResources(connector)) | |
75 return; | |
74 | 76 |
75 // Initialize the skia font code to go ask fontconfig underneath. | 77 // Initialize the skia font code to go ask fontconfig underneath. |
76 #if defined(OS_LINUX) | 78 #if defined(OS_LINUX) |
77 font_loader_ = sk_make_sp<font_service::FontLoader>(connector); | 79 font_loader_ = sk_make_sp<font_service::FontLoader>(connector); |
78 SkFontConfigInterface::SetGlobal(font_loader_.get()); | 80 SkFontConfigInterface::SetGlobal(font_loader_.get()); |
79 #endif | 81 #endif |
80 | 82 |
81 // There is a bunch of static state in gfx::Font, by running this now, | 83 // 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. | 84 // before any other apps load, we ensure all the state is set up. |
83 gfx::Font(); | 85 gfx::Font(); |
84 | 86 |
85 ui::InitializeInputMethodForTesting(); | 87 ui::InitializeInputMethodForTesting(); |
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 true; |
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 if (!loader.OpenFiles(std::move(directory), resource_paths)) { |
116 LOG(ERROR) << "AuraInit failed to open resource files.\n"; | |
sky
2017/05/18 20:30:28
no \n here either.
jonross
2017/05/18 20:40:24
reverted.
| |
117 return false; | |
118 } | |
119 | |
114 ui::RegisterPathProvider(); | 120 ui::RegisterPathProvider(); |
115 base::File pak_file = loader.TakeFile(resource_file_); | 121 base::File pak_file = loader.TakeFile(resource_file_); |
116 base::File pak_file_2 = pak_file.Duplicate(); | 122 base::File pak_file_2 = pak_file.Duplicate(); |
117 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( | 123 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( |
118 std::move(pak_file), base::MemoryMappedFile::Region::kWholeFile); | 124 std::move(pak_file), base::MemoryMappedFile::Region::kWholeFile); |
119 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( | 125 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( |
120 std::move(pak_file_2), ui::SCALE_FACTOR_100P); | 126 std::move(pak_file_2), ui::SCALE_FACTOR_100P); |
121 if (!resource_file_200_.empty()) | 127 if (!resource_file_200_.empty()) |
122 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( | 128 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( |
123 loader.TakeFile(resource_file_200_), ui::SCALE_FACTOR_200P); | 129 loader.TakeFile(resource_file_200_), ui::SCALE_FACTOR_200P); |
130 return true; | |
124 } | 131 } |
125 | 132 |
126 } // namespace views | 133 } // namespace views |
OLD | NEW |