Chromium Code Reviews| Index: ui/aura/mus/window_tree_client.cc |
| diff --git a/ui/aura/mus/window_tree_client.cc b/ui/aura/mus/window_tree_client.cc |
| index 82f54f0d6d4d97dc79c56cebfb063cc8c2b5661e..07b3a510051feb21f7ff049d94c0cacd19af1cd3 100644 |
| --- a/ui/aura/mus/window_tree_client.cc |
| +++ b/ui/aura/mus/window_tree_client.cc |
| @@ -13,6 +13,8 @@ |
| #include "base/auto_reset.h" |
| #include "base/bind.h" |
| #include "base/memory/ptr_util.h" |
| +#include "base/threading/thread.h" |
| +#include "components/discardable_memory/client/client_discardable_shared_memory_manager.h" |
| #include "mojo/public/cpp/bindings/map.h" |
| #include "services/service_manager/public/cpp/connector.h" |
| #include "services/ui/common/accelerator_util.h" |
| @@ -175,7 +177,8 @@ WindowTreeClient::WindowTreeClient( |
| WindowTreeClientDelegate* delegate, |
| WindowManagerDelegate* window_manager_delegate, |
| mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request, |
| - scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) |
| + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| + bool create_discardable_memory) |
| : connector_(connector), |
| client_id_(0), |
| next_window_id_(1), |
| @@ -194,17 +197,42 @@ WindowTreeClient::WindowTreeClient( |
| if (window_manager_delegate) |
| window_manager_delegate->SetWindowManagerClient(this); |
| if (connector) { // |connector| can be null in tests. |
| - gpu_ = ui::Gpu::Create(connector, std::move(io_task_runner)); |
| + if (!io_task_runner) { |
| + // |io_task_runner| is null in most case. But for the browser process, |
| + // the |io_task_runner| is the browser's IO thread. |
| + io_thread_ = base::MakeUnique<base::Thread>("IOThread"); |
| + base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); |
| + thread_options.priority = base::ThreadPriority::NORMAL; |
| + CHECK(io_thread_->StartWithOptions(thread_options)); |
| + io_task_runner = io_thread_->task_runner(); |
| + } |
| + |
| + gpu_ = ui::Gpu::Create(connector, io_task_runner); |
| compositor_context_factory_ = |
| base::MakeUnique<MusContextFactory>(gpu_.get()); |
| initial_context_factory_ = Env::GetInstance()->context_factory(); |
| Env::GetInstance()->set_context_factory(compositor_context_factory_.get()); |
| + |
| + // WindowServerTest will create more than one WindowTreeClient. We will not |
| + // create the discardable memory manager for those tests. |
| + if (create_discardable_memory) { |
| + discardable_memory::mojom::DiscardableSharedMemoryManagerPtr manager_ptr; |
| + connector->BindInterface(ui::mojom::kServiceName, &manager_ptr); |
| + discardable_shared_memory_manager_ = base::MakeUnique< |
| + discardable_memory::ClientDiscardableSharedMemoryManager>( |
| + std::move(manager_ptr), std::move(io_task_runner)); |
| + base::DiscardableMemoryAllocator::SetInstance( |
| + discardable_shared_memory_manager_.get()); |
| + } |
| } |
| } |
| WindowTreeClient::~WindowTreeClient() { |
| in_destructor_ = true; |
| + 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
|
| + base::DiscardableMemoryAllocator::SetInstance(nullptr); |
| + |
| for (WindowTreeClientObserver& observer : observers_) |
| observer.OnWillDestroyClient(this); |