| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_GPU_PROCESS_HOST_H_ | 5 #ifndef CHROME_BROWSER_GPU_PROCESS_HOST_H_ |
| 6 #define CHROME_BROWSER_GPU_PROCESS_HOST_H_ | 6 #define CHROME_BROWSER_GPU_PROCESS_HOST_H_ |
| 7 | 7 |
| 8 #include <queue> | 8 #include <queue> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
| 12 #include "base/singleton.h" | 12 #include "chrome/browser/child_process_host.h" |
| 13 #include "chrome/browser/child_process_launcher.h" | 13 #include "chrome/browser/renderer_host/resource_message_filter.h" |
| 14 #include "chrome/common/gpu_native_window_handle.h" | |
| 15 #include "chrome/common/message_router.h" | |
| 16 #include "gfx/native_widget_types.h" | |
| 17 #include "ipc/ipc_channel_handle.h" | |
| 18 #include "ipc/ipc_channel_proxy.h" | |
| 19 | 14 |
| 20 class ChildProcessLauncher; | 15 class ChildProcessLauncher; |
| 21 class CommandBufferProxy; | 16 class CommandBufferProxy; |
| 22 | 17 |
| 23 class GpuProcessHost : public IPC::Channel::Sender, | 18 class GpuProcessHost : public ChildProcessHost { |
| 24 public IPC::Channel::Listener, | |
| 25 public ChildProcessLauncher::Client { | |
| 26 public: | 19 public: |
| 27 // Getter for the singleton. This will return NULL on failure. | 20 // Getter for the singleton. This will return NULL on failure. |
| 28 static GpuProcessHost* Get(); | 21 static GpuProcessHost* Get(); |
| 29 | 22 |
| 30 int32 GetNextRoutingId(); | 23 // Shutdown routine, which should only be called upon process |
| 24 // termination. |
| 25 static void Shutdown(); |
| 31 | 26 |
| 32 // Creates the new remote view and returns the routing ID for the view, or 0 | |
| 33 // on failure. | |
| 34 int32 NewRenderWidgetHostView(GpuNativeWindowHandle parent); | |
| 35 | |
| 36 // IPC::Channel::Sender implementation. | |
| 37 virtual bool Send(IPC::Message* msg); | 27 virtual bool Send(IPC::Message* msg); |
| 38 | 28 |
| 39 // IPC::Channel::Listener implementation. | 29 // IPC::Channel::Listener implementation. |
| 40 virtual void OnMessageReceived(const IPC::Message& message); | 30 virtual void OnMessageReceived(const IPC::Message& message); |
| 41 virtual void OnChannelConnected(int32 peer_pid); | |
| 42 virtual void OnChannelError(); | |
| 43 | |
| 44 // ChildProcessLauncher::Client implementation. | |
| 45 virtual void OnProcessLaunched(); | |
| 46 | |
| 47 // See documentation on MessageRouter for AddRoute and RemoveRoute | |
| 48 void AddRoute(int32 routing_id, IPC::Channel::Listener* listener); | |
| 49 void RemoveRoute(int32 routing_id); | |
| 50 | 31 |
| 51 // Tells the GPU process to create a new channel for communication with a | 32 // Tells the GPU process to create a new channel for communication with a |
| 52 // renderer. Will asynchronously send message to object with given routing id | 33 // renderer. Will asynchronously send message to object with given routing id |
| 53 // on completion. | 34 // on completion. |
| 54 void EstablishGpuChannel(int renderer_id); | 35 void EstablishGpuChannel(int renderer_id, |
| 36 ResourceMessageFilter* filter); |
| 55 | 37 |
| 56 // Sends a reply message later when the next GpuHostMsg_SynchronizeReply comes | 38 // Sends a reply message later when the next GpuHostMsg_SynchronizeReply comes |
| 57 // in. | 39 // in. |
| 58 void Synchronize(int renderer_id, IPC::Message* reply); | 40 void Synchronize(IPC::Message* reply, |
| 41 ResourceMessageFilter* filter); |
| 59 | 42 |
| 60 private: | 43 private: |
| 61 friend struct DefaultSingletonTraits<GpuProcessHost>; | |
| 62 | |
| 63 // Used to queue pending channel requests. | 44 // Used to queue pending channel requests. |
| 64 struct ChannelRequest { | 45 struct ChannelRequest { |
| 65 explicit ChannelRequest(int renderer_id) : renderer_id(renderer_id) {} | 46 explicit ChannelRequest(ResourceMessageFilter* filter) |
| 66 // Used to identify the renderer. The ID is used instead of a pointer to | 47 : filter(filter) {} |
| 67 // the RenderProcessHost in case it is destroyed while the request is | 48 // Used to send the reply message back to the renderer. |
| 68 // pending. | 49 scoped_refptr<ResourceMessageFilter> filter; |
| 69 // TODO(apatrick): investigate whether these IDs are used for future | 50 }; |
| 70 // render processes. | 51 |
| 71 int renderer_id; | 52 // Used to queue pending synchronization requests. |
| 53 struct SynchronizationRequest { |
| 54 SynchronizationRequest(IPC::Message* reply, |
| 55 ResourceMessageFilter* filter) |
| 56 : reply(reply), |
| 57 filter(filter) {} |
| 58 // The delayed reply message which needs to be sent to the |
| 59 // renderer. |
| 60 IPC::Message* reply; |
| 61 |
| 62 // Used to send the reply message back to the renderer. |
| 63 scoped_refptr<ResourceMessageFilter> filter; |
| 72 }; | 64 }; |
| 73 | 65 |
| 74 GpuProcessHost(); | 66 GpuProcessHost(); |
| 75 virtual ~GpuProcessHost(); | 67 virtual ~GpuProcessHost(); |
| 76 | 68 |
| 69 bool EnsureInitialized(); |
| 70 bool Init(); |
| 71 |
| 77 void OnControlMessageReceived(const IPC::Message& message); | 72 void OnControlMessageReceived(const IPC::Message& message); |
| 78 | 73 |
| 79 // Message handlers. | 74 // Message handlers. |
| 80 void OnChannelEstablished(const IPC::ChannelHandle& channel_handle); | 75 void OnChannelEstablished(const IPC::ChannelHandle& channel_handle); |
| 81 void OnSynchronizeReply(int renderer_id); | 76 void OnSynchronizeReply(); |
| 82 | 77 |
| 83 void ReplyToRenderer(int renderer_id, | 78 void ReplyToRenderer(const IPC::ChannelHandle& channel, |
| 84 const IPC::ChannelHandle& channel); | 79 ResourceMessageFilter* filter); |
| 85 | |
| 86 // These are the channel requests that we have already sent to | |
| 87 // the GPU process, but haven't heard back about yet. | |
| 88 std::queue<ChannelRequest> sent_requests_; | |
| 89 | 80 |
| 90 // Copies applicable command line switches from the given |browser_cmd| line | 81 // Copies applicable command line switches from the given |browser_cmd| line |
| 91 // flags to the output |gpu_cmd| line flags. Not all switches will be | 82 // flags to the output |gpu_cmd| line flags. Not all switches will be |
| 92 // copied over. | 83 // copied over. |
| 93 void PropagateBrowserCommandLineToGpu(const CommandLine& browser_cmd, | 84 void PropagateBrowserCommandLineToGpu(const CommandLine& browser_cmd, |
| 94 CommandLine* gpu_cmd) const; | 85 CommandLine* gpu_cmd) const; |
| 95 | 86 |
| 96 scoped_ptr<ChildProcessLauncher> child_process_; | 87 // ResourceDispatcherHost::Receiver implementation: |
| 88 virtual URLRequestContext* GetRequestContext( |
| 89 uint32 request_id, |
| 90 const ViewHostMsg_Resource_Request& request_data); |
| 97 | 91 |
| 98 // A proxy for our IPC::Channel that lives on the IO thread (see | 92 virtual bool CanShutdown(); |
| 99 // browser_process.h). This will be NULL if the class failed to connect. | |
| 100 scoped_ptr<IPC::ChannelProxy> channel_; | |
| 101 | 93 |
| 102 int last_routing_id_; | 94 bool initialized_; |
| 95 bool initialized_successfully_; |
| 103 | 96 |
| 104 MessageRouter router_; | 97 // These are the channel requests that we have already sent to |
| 105 | 98 // the GPU process, but haven't heard back about yet. |
| 106 // Messages we queue while waiting for the process handle. We queue them here | 99 std::queue<ChannelRequest> sent_requests_; |
| 107 // instead of in the channel so that we ensure they're sent after init related | |
| 108 // messages that are sent once the process handle is available. This is | |
| 109 // because the queued messages may have dependencies on the init messages. | |
| 110 std::queue<IPC::Message*> queued_messages_; | |
| 111 | 100 |
| 112 // The pending synchronization requests we need to reply to. | 101 // The pending synchronization requests we need to reply to. |
| 113 std::queue<IPC::Message*> queued_synchronization_replies_; | 102 std::queue<SynchronizationRequest> queued_synchronization_replies_; |
| 114 | 103 |
| 115 DISALLOW_COPY_AND_ASSIGN(GpuProcessHost); | 104 DISALLOW_COPY_AND_ASSIGN(GpuProcessHost); |
| 116 }; | 105 }; |
| 117 | 106 |
| 118 #endif // CHROME_BROWSER_GPU_PROCESS_HOST_H_ | 107 #endif // CHROME_BROWSER_GPU_PROCESS_HOST_H_ |
| OLD | NEW |