Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: ui/views/mus/aura_init.cc

Issue 2973103002: Revert of Update AuraInit to handle failed initialization (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/mus/aura_init.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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() { 55 AuraInit::AuraInit(service_manager::Connector* connector,
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)) {
56 if (!ViewsDelegate::GetInstance()) 67 if (!ViewsDelegate::GetInstance())
57 views_delegate_ = base::MakeUnique<MusViewsDelegate>(); 68 views_delegate_ = base::MakeUnique<MusViewsDelegate>();
69 if (mode == Mode::AURA_MUS) {
70 mus_client_ =
71 base::WrapUnique(new MusClient(connector, identity, io_task_runner));
72 }
73 ui::MaterialDesignController::Initialize();
74 if (!InitializeResources(connector))
75 return;
76
77 // Initialize the skia font code to go ask fontconfig underneath.
78 #if defined(OS_LINUX)
79 font_loader_ = sk_make_sp<font_service::FontLoader>(connector);
80 SkFontConfigInterface::SetGlobal(font_loader_.get());
81 #endif
82
83 // 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.
85 gfx::Font();
86
87 ui::InitializeInputMethodForTesting();
88 initialized_ = true;
58 } 89 }
59 90
60 AuraInit::~AuraInit() { 91 AuraInit::~AuraInit() {
61 #if defined(OS_LINUX) 92 #if defined(OS_LINUX)
62 if (font_loader_.get()) { 93 if (font_loader_.get()) {
63 SkFontConfigInterface::SetGlobal(nullptr); 94 SkFontConfigInterface::SetGlobal(nullptr);
64 // FontLoader is ref counted. We need to explicitly shutdown the background 95 // FontLoader is ref counted. We need to explicitly shutdown the background
65 // thread, otherwise the background thread may be shutdown after the app is 96 // thread, otherwise the background thread may be shutdown after the app is
66 // torn down, when we're in a bad state. 97 // torn down, when we're in a bad state.
67 font_loader_->Shutdown(); 98 font_loader_->Shutdown();
68 } 99 }
69 #endif 100 #endif
70 } 101 }
71 102
72 std::unique_ptr<AuraInit> AuraInit::Create( 103 bool AuraInit::InitializeResources(service_manager::Connector* connector) {
73 service_manager::Connector* connector,
74 const service_manager::Identity& identity,
75 const std::string& resource_file,
76 const std::string& resource_file_200,
77 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
78 Mode mode) {
79 std::unique_ptr<AuraInit> aura_init = base::WrapUnique(new AuraInit());
80 if (!aura_init->Init(connector, identity, resource_file, resource_file_200,
81 io_task_runner, mode)) {
82 aura_init.reset();
83 }
84 return aura_init;
85 }
86
87 bool AuraInit::Init(service_manager::Connector* connector,
88 const service_manager::Identity& identity,
89 const std::string& resource_file,
90 const std::string& resource_file_200,
91 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
92 Mode mode) {
93 env_ = aura::Env::CreateInstance(
94 (mode == Mode::AURA_MUS || mode == Mode::AURA_MUS_WINDOW_MANAGER)
95 ? aura::Env::Mode::MUS
96 : aura::Env::Mode::LOCAL);
97
98 if (mode == Mode::AURA_MUS) {
99 mus_client_ =
100 base::WrapUnique(new MusClient(connector, identity, io_task_runner));
101 }
102 ui::MaterialDesignController::Initialize();
103 if (!InitializeResources(connector, resource_file, resource_file_200))
104 return false;
105
106 // Initialize the skia font code to go ask fontconfig underneath.
107 #if defined(OS_LINUX)
108 font_loader_ = sk_make_sp<font_service::FontLoader>(connector);
109 SkFontConfigInterface::SetGlobal(font_loader_.get());
110 #endif
111
112 // There is a bunch of static state in gfx::Font, by running this now,
113 // before any other apps load, we ensure all the state is set up.
114 gfx::Font();
115
116 ui::InitializeInputMethodForTesting();
117 return true;
118 }
119
120 bool AuraInit::InitializeResources(service_manager::Connector* connector,
121 const std::string& resource_file,
122 const std::string& resource_file_200) {
123 // Resources may have already been initialized (e.g. when 'chrome --mash' is 104 // Resources may have already been initialized (e.g. when 'chrome --mash' is
124 // used to launch the current app). 105 // used to launch the current app).
125 if (ui::ResourceBundle::HasSharedInstance()) 106 if (ui::ResourceBundle::HasSharedInstance())
126 return false; 107 return false;
127 108
128 std::set<std::string> resource_paths({resource_file}); 109 std::set<std::string> resource_paths({resource_file_});
129 if (!resource_file_200.empty()) 110 if (!resource_file_200_.empty())
130 resource_paths.insert(resource_file_200); 111 resource_paths.insert(resource_file_200_);
131 112
132 catalog::ResourceLoader loader; 113 catalog::ResourceLoader loader;
133 filesystem::mojom::DirectoryPtr directory; 114 filesystem::mojom::DirectoryPtr directory;
134 connector->BindInterface(catalog::mojom::kServiceName, &directory); 115 connector->BindInterface(catalog::mojom::kServiceName, &directory);
135 // TODO(jonross): if this proves useful in resolving the crash of 116 // TODO(jonross): if this proves useful in resolving the crash of
136 // mash_unittests then switch AuraInit to have an Init method, returning a 117 // mash_unittests then switch AuraInit to have an Init method, returning a
137 // bool for success. Then update all callsites to use this to determine the 118 // bool for success. Then update all callsites to use this to determine the
138 // shutdown of their ServiceContext. 119 // shutdown of their ServiceContext.
139 // One cause of failure is that the peer has closed, but we have not been 120 // One cause of failure is that the peer has closed, but we have not been
140 // notified yet. It is not possible to complete initialization, so exit now. 121 // notified yet. It is not possible to complete initialization, so exit now.
141 // Calling services will shutdown ServiceContext as appropriate. 122 // Calling services will shutdown ServiceContext as appropriate.
142 if (!loader.OpenFiles(std::move(directory), resource_paths)) 123 if (!loader.OpenFiles(std::move(directory), resource_paths))
143 return false; 124 return false;
144 ui::RegisterPathProvider(); 125 ui::RegisterPathProvider();
145 base::File pak_file = loader.TakeFile(resource_file); 126 base::File pak_file = loader.TakeFile(resource_file_);
146 base::File pak_file_2 = pak_file.Duplicate(); 127 base::File pak_file_2 = pak_file.Duplicate();
147 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( 128 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion(
148 std::move(pak_file), base::MemoryMappedFile::Region::kWholeFile); 129 std::move(pak_file), base::MemoryMappedFile::Region::kWholeFile);
149 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( 130 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile(
150 std::move(pak_file_2), ui::SCALE_FACTOR_100P); 131 std::move(pak_file_2), ui::SCALE_FACTOR_100P);
151 if (!resource_file_200.empty()) 132 if (!resource_file_200_.empty())
152 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( 133 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile(
153 loader.TakeFile(resource_file_200), ui::SCALE_FACTOR_200P); 134 loader.TakeFile(resource_file_200_), ui::SCALE_FACTOR_200P);
154 return true; 135 return true;
155 } 136 }
156 137
157 } // namespace views 138 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/aura_init.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698