OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/gpu/gpu_process_host_ui_shim.h" | 5 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 #if defined(USE_OZONE) | 37 #if defined(USE_OZONE) |
38 #include "ui/ozone/public/gpu_platform_support_host.h" | 38 #include "ui/ozone/public/gpu_platform_support_host.h" |
39 #include "ui/ozone/public/ozone_platform.h" | 39 #include "ui/ozone/public/ozone_platform.h" |
40 #endif | 40 #endif |
41 | 41 |
42 namespace content { | 42 namespace content { |
43 | 43 |
44 namespace { | 44 namespace { |
45 | 45 |
46 // One of the linux specific headers defines this as a macro. | 46 base::LazyInstance<IDMap<GpuProcessHostUIShim*>>::Leaky g_hosts_by_id = |
47 #ifdef DestroyAll | 47 LAZY_INSTANCE_INITIALIZER; |
48 #undef DestroyAll | |
49 #endif | |
50 | |
51 base::LazyInstance<IDMap<GpuProcessHostUIShim*>>::DestructorAtExit | |
52 g_hosts_by_id = LAZY_INSTANCE_INITIALIZER; | |
53 | 48 |
54 #if defined(OS_ANDROID) | 49 #if defined(OS_ANDROID) |
55 template <typename Interface> | 50 template <typename Interface> |
56 void BindJavaInterface(mojo::InterfaceRequest<Interface> request) { | 51 void BindJavaInterface(mojo::InterfaceRequest<Interface> request) { |
57 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 52 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
58 content::GetGlobalJavaInterfaces()->GetInterface(std::move(request)); | 53 content::GetGlobalJavaInterfaces()->GetInterface(std::move(request)); |
59 } | 54 } |
60 #endif | 55 #endif |
61 | 56 |
62 } // namespace | 57 } // namespace |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 #if defined(USE_OZONE) | 89 #if defined(USE_OZONE) |
95 ui::OzonePlatform::GetInstance() | 90 ui::OzonePlatform::GetInstance() |
96 ->GetGpuPlatformSupportHost() | 91 ->GetGpuPlatformSupportHost() |
97 ->OnChannelDestroyed(host_id); | 92 ->OnChannelDestroyed(host_id); |
98 #endif | 93 #endif |
99 | 94 |
100 delete FromID(host_id); | 95 delete FromID(host_id); |
101 } | 96 } |
102 | 97 |
103 // static | 98 // static |
104 void GpuProcessHostUIShim::DestroyAll() { | |
105 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
106 while (!g_hosts_by_id.Pointer()->IsEmpty()) { | |
107 IDMap<GpuProcessHostUIShim*>::iterator it(g_hosts_by_id.Pointer()); | |
108 delete it.GetCurrentValue(); | |
109 } | |
110 } | |
111 | |
112 // static | |
113 GpuProcessHostUIShim* GpuProcessHostUIShim::FromID(int host_id) { | 99 GpuProcessHostUIShim* GpuProcessHostUIShim::FromID(int host_id) { |
114 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 100 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
115 return g_hosts_by_id.Pointer()->Lookup(host_id); | 101 return g_hosts_by_id.Pointer()->Lookup(host_id); |
116 } | 102 } |
117 | 103 |
118 bool GpuProcessHostUIShim::OnMessageReceived(const IPC::Message& message) { | 104 void GpuProcessHostUIShim::OnMessageReceived(const IPC::Message& message) { |
119 DCHECK(CalledOnValidThread()); | 105 DCHECK(CalledOnValidThread()); |
120 | 106 |
121 #if defined(USE_OZONE) | 107 #if defined(USE_OZONE) |
122 if (ui::OzonePlatform::GetInstance() | 108 if (ui::OzonePlatform::GetInstance() |
123 ->GetGpuPlatformSupportHost() | 109 ->GetGpuPlatformSupportHost() |
124 ->OnMessageReceived(message)) | 110 ->OnMessageReceived(message)) |
125 return true; | 111 return; |
126 #endif | 112 #endif |
127 | 113 |
128 if (message.routing_id() != MSG_ROUTING_CONTROL) | 114 if (message.routing_id() == MSG_ROUTING_CONTROL) { |
129 return false; | 115 NOTREACHED() << "Invalid message with type = " << message.type(); |
130 | 116 } |
131 NOTREACHED() << "Invalid message with type = " << message.type(); | |
132 return true; | |
133 } | 117 } |
134 | 118 |
135 GpuProcessHostUIShim::~GpuProcessHostUIShim() { | 119 GpuProcessHostUIShim::~GpuProcessHostUIShim() { |
136 DCHECK(CalledOnValidThread()); | 120 DCHECK(CalledOnValidThread()); |
137 g_hosts_by_id.Pointer()->Remove(host_id_); | 121 g_hosts_by_id.Pointer()->Remove(host_id_); |
138 } | 122 } |
139 | 123 |
140 // static | 124 // static |
141 void GpuProcessHostUIShim::RegisterUIThreadMojoInterfaces( | 125 void GpuProcessHostUIShim::RegisterUIThreadMojoInterfaces( |
142 service_manager::BinderRegistry* registry) { | 126 service_manager::BinderRegistry* registry) { |
143 auto task_runner = BrowserThread::GetTaskRunnerForThread(BrowserThread::UI); | 127 auto task_runner = BrowserThread::GetTaskRunnerForThread(BrowserThread::UI); |
144 | 128 |
145 registry->AddInterface(base::Bind(&FieldTrialRecorder::Create), task_runner); | 129 registry->AddInterface(base::Bind(&FieldTrialRecorder::Create), task_runner); |
146 registry->AddInterface( | 130 registry->AddInterface( |
147 base::Bind( | 131 base::Bind( |
148 &memory_instrumentation::CoordinatorImpl::BindCoordinatorRequest, | 132 &memory_instrumentation::CoordinatorImpl::BindCoordinatorRequest, |
149 base::Unretained( | 133 base::Unretained( |
150 memory_instrumentation::CoordinatorImpl::GetInstance())), | 134 memory_instrumentation::CoordinatorImpl::GetInstance())), |
151 task_runner); | 135 task_runner); |
152 #if defined(OS_ANDROID) | 136 #if defined(OS_ANDROID) |
153 registry->AddInterface( | 137 registry->AddInterface( |
154 base::Bind(&BindJavaInterface<media::mojom::AndroidOverlayProvider>), | 138 base::Bind(&BindJavaInterface<media::mojom::AndroidOverlayProvider>), |
155 task_runner); | 139 task_runner); |
156 #endif | 140 #endif |
157 } | 141 } |
158 | 142 |
159 } // namespace content | 143 } // namespace content |
OLD | NEW |