gpu_process_host_ui_shim.cc revision 731df977c0511bca2206b5f333555b1205ff1f43
1// Copyright (c) 2010 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/browser/gpu_process_host_ui_shim.h" 6 7#include "chrome/browser/browser_thread.h" 8#include "chrome/browser/gpu_process_host.h" 9#include "chrome/common/gpu_messages.h" 10 11// Tasks used by this file 12namespace { 13 14class SendOnIOThreadTask : public Task { 15 public: 16 explicit SendOnIOThreadTask(IPC::Message* msg) : msg_(msg) { 17 } 18 19 private: 20 void Run() { 21 GpuProcessHost::Get()->Send(msg_); 22 } 23 IPC::Message* msg_; 24}; 25 26} // namespace 27 28GpuProcessHostUIShim::GpuProcessHostUIShim() : last_routing_id_(1) { 29} 30 31GpuProcessHostUIShim::~GpuProcessHostUIShim() { 32} 33 34// static 35GpuProcessHostUIShim* GpuProcessHostUIShim::Get() { 36 return Singleton<GpuProcessHostUIShim>::get(); 37} 38 39int32 GpuProcessHostUIShim::NewRenderWidgetHostView( 40 GpuNativeWindowHandle parent) { 41 int32 routing_id = GetNextRoutingId(); 42 Send(new GpuMsg_NewRenderWidgetHostView(parent, routing_id)); 43 return routing_id; 44} 45 46bool GpuProcessHostUIShim::Send(IPC::Message* msg) { 47 BrowserThread::PostTask(BrowserThread::IO, 48 FROM_HERE, 49 new SendOnIOThreadTask(msg)); 50 return true; 51} 52 53int32 GpuProcessHostUIShim::GetNextRoutingId() { 54 return ++last_routing_id_; 55} 56 57void GpuProcessHostUIShim::AddRoute(int32 routing_id, 58 IPC::Channel::Listener* listener) { 59 router_.AddRoute(routing_id, listener); 60} 61 62void GpuProcessHostUIShim::RemoveRoute(int32 routing_id) { 63 router_.RemoveRoute(routing_id); 64} 65 66void GpuProcessHostUIShim::OnMessageReceived(const IPC::Message& message) { 67 router_.RouteMessage(message); 68} 69 70void GpuProcessHostUIShim::CollectGraphicsInfoAsynchronously() { 71 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); 72 BrowserThread::PostTask( 73 BrowserThread::IO, 74 FROM_HERE, 75 new SendOnIOThreadTask(new GpuMsg_CollectGraphicsInfo())); 76} 77