render_thread.h revision 7dbb3d5cf0c15f500944d211057644d6a2f37371
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 3// found in the LICENSE file. 4 5#ifndef CONTENT_PUBLIC_RENDERER_RENDER_THREAD_H_ 6#define CONTENT_PUBLIC_RENDERER_RENDER_THREAD_H_ 7 8#include "base/basictypes.h" 9#include "base/callback.h" 10#include "base/shared_memory.h" 11#include "content/common/content_export.h" 12#include "ipc/ipc_channel_proxy.h" 13#include "ipc/ipc_sender.h" 14 15#if defined(OS_WIN) 16#include <windows.h> 17#endif 18 19class GURL; 20 21namespace base { 22class MessageLoop; 23class MessageLoopProxy; 24} 25 26namespace IPC { 27class SyncChannel; 28class SyncMessageFilter; 29} 30 31namespace v8 { 32class Extension; 33} 34 35namespace content { 36 37class RenderProcessObserver; 38class ResourceDispatcherDelegate; 39 40class CONTENT_EXPORT RenderThread : public IPC::Sender { 41 public: 42 // Returns the one render thread for this process. Note that this can only 43 // be accessed when running on the render thread itself. 44 static RenderThread* Get(); 45 46 RenderThread(); 47 virtual ~RenderThread(); 48 49 virtual base::MessageLoop* GetMessageLoop() = 0; 50 virtual IPC::SyncChannel* GetChannel() = 0; 51 virtual std::string GetLocale() = 0; 52 virtual IPC::SyncMessageFilter* GetSyncMessageFilter() = 0; 53 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() = 0; 54 55 // Called to add or remove a listener for a particular message routing ID. 56 // These methods normally get delegated to a MessageRouter. 57 virtual void AddRoute(int32 routing_id, IPC::Listener* listener) = 0; 58 virtual void RemoveRoute(int32 routing_id) = 0; 59 virtual int GenerateRoutingID() = 0; 60 61 // These map to IPC::ChannelProxy methods. 62 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) = 0; 63 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) = 0; 64 virtual void SetOutgoingMessageFilter( 65 IPC::ChannelProxy::OutgoingMessageFilter* filter) = 0; 66 67 // Add/remove observers for the process. 68 virtual void AddObserver(RenderProcessObserver* observer) = 0; 69 virtual void RemoveObserver(RenderProcessObserver* observer) = 0; 70 71 // Set the ResourceDispatcher delegate object for this process. 72 virtual void SetResourceDispatcherDelegate( 73 ResourceDispatcherDelegate* delegate) = 0; 74 75 // Called by a RenderWidget when it is hidden or restored. 76 virtual void WidgetHidden() = 0; 77 virtual void WidgetRestored() = 0; 78 79 // We initialize WebKit as late as possible. Call this to force 80 // initialization. 81 virtual void EnsureWebKitInitialized() = 0; 82 83 // Helper function to send over a string to be recorded by user metrics 84 virtual void RecordUserMetrics(const std::string& action) = 0; 85 86 // Asks the host to create a block of shared memory for the renderer. 87 // The shared memory allocated by the host is returned back. 88 virtual scoped_ptr<base::SharedMemory> HostAllocateSharedMemoryBuffer( 89 size_t buffer_size) = 0; 90 91 // Registers the given V8 extension with WebKit. 92 virtual void RegisterExtension(v8::Extension* extension) = 0; 93 94 // Schedule a call to IdleHandler with the given initial delay. 95 virtual void ScheduleIdleHandler(int64 initial_delay_ms) = 0; 96 97 // A task we invoke periodically to assist with idle cleanup. 98 virtual void IdleHandler() = 0; 99 100 // Get/Set the delay for how often the idle handler is called. 101 virtual int64 GetIdleNotificationDelayInMs() const = 0; 102 virtual void SetIdleNotificationDelayInMs( 103 int64 idle_notification_delay_in_ms) = 0; 104 105 // Suspend/resume the webkit timer for this renderer. 106 virtual void ToggleWebKitSharedTimer(bool suspend) = 0; 107 108 virtual void UpdateHistograms(int sequence_number) = 0; 109 110 // Post task to all worker threads. Returns number of workers. 111 virtual int PostTaskToAllWebWorkers(const base::Closure& closure) = 0; 112 113 // Resolve the proxy servers to use for a given url. On success true is 114 // returned and |proxy_list| is set to a PAC string containing a list of 115 // proxy servers. 116 virtual bool ResolveProxy(const GURL& url, std::string* proxy_list) = 0; 117 118#if defined(OS_WIN) 119 // Request that the given font be loaded by the browser so it's cached by the 120 // OS. Please see ChildProcessHost::PreCacheFont for details. 121 virtual void PreCacheFont(const LOGFONT& log_font) = 0; 122 123 // Release cached font. 124 virtual void ReleaseCachedFonts() = 0; 125#endif 126}; 127 128} // namespace content 129 130#endif // CONTENT_PUBLIC_RENDERER_RENDER_THREAD_H_ 131