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

Side by Side Diff: ui/aura/mus/window_tree_client.cc

Issue 2741063002: Setup DiscardableMemory in the ash process (Closed)
Patch Set: Fix issues. Created 3 years, 9 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/aura/mus/window_tree_client.h" 5 #include "ui/aura/mus/window_tree_client.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/auto_reset.h" 13 #include "base/auto_reset.h"
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/threading/thread.h"
17 #include "components/discardable_memory/client/client_discardable_shared_memory_ manager.h"
16 #include "mojo/public/cpp/bindings/map.h" 18 #include "mojo/public/cpp/bindings/map.h"
17 #include "services/service_manager/public/cpp/connector.h" 19 #include "services/service_manager/public/cpp/connector.h"
18 #include "services/ui/common/accelerator_util.h" 20 #include "services/ui/common/accelerator_util.h"
19 #include "services/ui/public/cpp/gpu/gpu.h" 21 #include "services/ui/public/cpp/gpu/gpu.h"
20 #include "services/ui/public/cpp/property_type_converters.h" 22 #include "services/ui/public/cpp/property_type_converters.h"
21 #include "services/ui/public/interfaces/constants.mojom.h" 23 #include "services/ui/public/interfaces/constants.mojom.h"
22 #include "services/ui/public/interfaces/window_manager.mojom.h" 24 #include "services/ui/public/interfaces/window_manager.mojom.h"
23 #include "services/ui/public/interfaces/window_manager_window_tree_factory.mojom .h" 25 #include "services/ui/public/interfaces/window_manager_window_tree_factory.mojom .h"
24 #include "ui/aura/client/aura_constants.h" 26 #include "ui/aura/client/aura_constants.h"
25 #include "ui/aura/client/drag_drop_client.h" 27 #include "ui/aura/client/drag_drop_client.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 GetWindowTreeHostMus(target)->SendEventToProcessor(event); 170 GetWindowTreeHostMus(target)->SendEventToProcessor(event);
169 } 171 }
170 172
171 } // namespace 173 } // namespace
172 174
173 WindowTreeClient::WindowTreeClient( 175 WindowTreeClient::WindowTreeClient(
174 service_manager::Connector* connector, 176 service_manager::Connector* connector,
175 WindowTreeClientDelegate* delegate, 177 WindowTreeClientDelegate* delegate,
176 WindowManagerDelegate* window_manager_delegate, 178 WindowManagerDelegate* window_manager_delegate,
177 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request, 179 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request,
178 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) 180 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
181 bool create_discardable_memory)
179 : connector_(connector), 182 : connector_(connector),
180 client_id_(0), 183 client_id_(0),
181 next_window_id_(1), 184 next_window_id_(1),
182 next_change_id_(1), 185 next_change_id_(1),
183 delegate_(delegate), 186 delegate_(delegate),
184 window_manager_delegate_(window_manager_delegate), 187 window_manager_delegate_(window_manager_delegate),
185 binding_(this), 188 binding_(this),
186 tree_(nullptr), 189 tree_(nullptr),
187 in_destructor_(false), 190 in_destructor_(false),
188 weak_factory_(this) { 191 weak_factory_(this) {
189 DCHECK(delegate_); 192 DCHECK(delegate_);
190 // Allow for a null request in tests. 193 // Allow for a null request in tests.
191 if (request.is_pending()) 194 if (request.is_pending())
192 binding_.Bind(std::move(request)); 195 binding_.Bind(std::move(request));
193 client::GetTransientWindowClient()->AddObserver(this); 196 client::GetTransientWindowClient()->AddObserver(this);
194 if (window_manager_delegate) 197 if (window_manager_delegate)
195 window_manager_delegate->SetWindowManagerClient(this); 198 window_manager_delegate->SetWindowManagerClient(this);
196 if (connector) { // |connector| can be null in tests. 199 if (connector) { // |connector| can be null in tests.
197 gpu_ = ui::Gpu::Create(connector, std::move(io_task_runner)); 200 if (!io_task_runner) {
201 // |io_task_runner| is null in most case. But for the browser process,
202 // the |io_task_runner| is the browser's IO thread.
203 io_thread_ = base::MakeUnique<base::Thread>("IOThread");
204 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0);
205 thread_options.priority = base::ThreadPriority::NORMAL;
206 CHECK(io_thread_->StartWithOptions(thread_options));
207 io_task_runner = io_thread_->task_runner();
208 }
209
210 gpu_ = ui::Gpu::Create(connector, io_task_runner);
198 compositor_context_factory_ = 211 compositor_context_factory_ =
199 base::MakeUnique<MusContextFactory>(gpu_.get()); 212 base::MakeUnique<MusContextFactory>(gpu_.get());
200 initial_context_factory_ = Env::GetInstance()->context_factory(); 213 initial_context_factory_ = Env::GetInstance()->context_factory();
201 Env::GetInstance()->set_context_factory(compositor_context_factory_.get()); 214 Env::GetInstance()->set_context_factory(compositor_context_factory_.get());
215
216 // WindowServerTest will create more than one WindowTreeClient. We will not
217 // create the discardable memory manager for those tests.
218 if (create_discardable_memory) {
219 discardable_memory::mojom::DiscardableSharedMemoryManagerPtr manager_ptr;
220 connector->BindInterface(ui::mojom::kServiceName, &manager_ptr);
221 discardable_shared_memory_manager_ = base::MakeUnique<
222 discardable_memory::ClientDiscardableSharedMemoryManager>(
223 std::move(manager_ptr), std::move(io_task_runner));
224 base::DiscardableMemoryAllocator::SetInstance(
225 discardable_shared_memory_manager_.get());
226 }
202 } 227 }
203 } 228 }
204 229
205 WindowTreeClient::~WindowTreeClient() { 230 WindowTreeClient::~WindowTreeClient() {
206 in_destructor_ = true; 231 in_destructor_ = true;
207 232
233 if (discardable_shared_memory_manager_)
sky 2017/03/14 03:15:34 Should this be null'd out after the thread is shut
Peng 2017/03/14 15:03:14 SetInstance(nullptr) will prevent the manager bein
234 base::DiscardableMemoryAllocator::SetInstance(nullptr);
235
208 for (WindowTreeClientObserver& observer : observers_) 236 for (WindowTreeClientObserver& observer : observers_)
209 observer.OnWillDestroyClient(this); 237 observer.OnWillDestroyClient(this);
210 238
211 // Clients should properly delete all of their windows before shutdown. 239 // Clients should properly delete all of their windows before shutdown.
212 CHECK(windows_.empty()); 240 CHECK(windows_.empty());
213 241
214 capture_synchronizer_.reset(); 242 capture_synchronizer_.reset();
215 243
216 client::GetTransientWindowClient()->RemoveObserver(this); 244 client::GetTransientWindowClient()->RemoveObserver(this);
217 245
(...skipping 1605 matching lines...) Expand 10 before | Expand all | Expand 10 after
1823 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( 1851 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>(
1824 this, capture_synchronizer_.get(), window)); 1852 this, capture_synchronizer_.get(), window));
1825 } 1853 }
1826 1854
1827 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { 1855 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) {
1828 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( 1856 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>(
1829 this, focus_synchronizer_.get(), window)); 1857 this, focus_synchronizer_.get(), window));
1830 } 1858 }
1831 1859
1832 } // namespace aura 1860 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698