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

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

Issue 2967943002: Update AuraInit to handle failed initialization (Closed)
Patch Set: Switch to a Create method for AuraInit 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(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 std::unique_ptr<AuraInit> AuraInit::Create(
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
69 if (mode == Mode::AURA_MUS) { 98 if (mode == Mode::AURA_MUS) {
70 mus_client_ = 99 mus_client_ =
71 base::WrapUnique(new MusClient(connector, identity, io_task_runner)); 100 base::WrapUnique(new MusClient(connector, identity, io_task_runner));
72 } 101 }
73 ui::MaterialDesignController::Initialize(); 102 ui::MaterialDesignController::Initialize();
74 if (!InitializeResources(connector)) 103 if (!InitializeResources(connector, resource_file, resource_file_200))
75 return; 104 return false;
76 105
77 // Initialize the skia font code to go ask fontconfig underneath. 106 // Initialize the skia font code to go ask fontconfig underneath.
78 #if defined(OS_LINUX) 107 #if defined(OS_LINUX)
79 font_loader_ = sk_make_sp<font_service::FontLoader>(connector); 108 font_loader_ = sk_make_sp<font_service::FontLoader>(connector);
80 SkFontConfigInterface::SetGlobal(font_loader_.get()); 109 SkFontConfigInterface::SetGlobal(font_loader_.get());
81 #endif 110 #endif
82 111
83 // There is a bunch of static state in gfx::Font, by running this now, 112 // 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. 113 // before any other apps load, we ensure all the state is set up.
85 gfx::Font(); 114 gfx::Font();
86 115
87 ui::InitializeInputMethodForTesting(); 116 ui::InitializeInputMethodForTesting();
88 initialized_ = true; 117 return true;
89 } 118 }
90 119
91 AuraInit::~AuraInit() { 120 bool AuraInit::InitializeResources(service_manager::Connector* connector,
92 #if defined(OS_LINUX) 121 const std::string& resource_file,
93 if (font_loader_.get()) { 122 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 123 // Resources may have already been initialized (e.g. when 'chrome --mash' is
105 // used to launch the current app). 124 // used to launch the current app).
106 if (ui::ResourceBundle::HasSharedInstance()) 125 if (ui::ResourceBundle::HasSharedInstance())
107 return false; 126 return false;
108 127
109 std::set<std::string> resource_paths({resource_file_}); 128 std::set<std::string> resource_paths({resource_file});
110 if (!resource_file_200_.empty()) 129 if (!resource_file_200.empty())
111 resource_paths.insert(resource_file_200_); 130 resource_paths.insert(resource_file_200);
112 131
113 catalog::ResourceLoader loader; 132 catalog::ResourceLoader loader;
114 filesystem::mojom::DirectoryPtr directory; 133 filesystem::mojom::DirectoryPtr directory;
115 connector->BindInterface(catalog::mojom::kServiceName, &directory); 134 connector->BindInterface(catalog::mojom::kServiceName, &directory);
116 // TODO(jonross): if this proves useful in resolving the crash of 135 // TODO(jonross): if this proves useful in resolving the crash of
117 // mash_unittests then switch AuraInit to have an Init method, returning a 136 // 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 137 // bool for success. Then update all callsites to use this to determine the
119 // shutdown of their ServiceContext. 138 // shutdown of their ServiceContext.
120 // One cause of failure is that the peer has closed, but we have not been 139 // 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. 140 // notified yet. It is not possible to complete initialization, so exit now.
122 // Calling services will shutdown ServiceContext as appropriate. 141 // Calling services will shutdown ServiceContext as appropriate.
123 if (!loader.OpenFiles(std::move(directory), resource_paths)) 142 if (!loader.OpenFiles(std::move(directory), resource_paths))
124 return false; 143 return false;
125 ui::RegisterPathProvider(); 144 ui::RegisterPathProvider();
126 base::File pak_file = loader.TakeFile(resource_file_); 145 base::File pak_file = loader.TakeFile(resource_file);
127 base::File pak_file_2 = pak_file.Duplicate(); 146 base::File pak_file_2 = pak_file.Duplicate();
128 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( 147 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion(
129 std::move(pak_file), base::MemoryMappedFile::Region::kWholeFile); 148 std::move(pak_file), base::MemoryMappedFile::Region::kWholeFile);
130 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( 149 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile(
131 std::move(pak_file_2), ui::SCALE_FACTOR_100P); 150 std::move(pak_file_2), ui::SCALE_FACTOR_100P);
132 if (!resource_file_200_.empty()) 151 if (!resource_file_200.empty())
133 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( 152 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile(
134 loader.TakeFile(resource_file_200_), ui::SCALE_FACTOR_200P); 153 loader.TakeFile(resource_file_200), ui::SCALE_FACTOR_200P);
135 return true; 154 return true;
136 } 155 }
137 156
138 } // namespace views 157 } // 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