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