render_thread.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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/memory/shared_memory.h" 11#include "base/metrics/user_metrics_action.h" 12#include "content/common/content_export.h" 13#include "ipc/ipc_channel_proxy.h" 14#include "ipc/ipc_sender.h" 15 16#if defined(OS_WIN) 17#include <windows.h> 18#endif 19 20class GURL; 21 22namespace base { 23class MessageLoop; 24class MessageLoopProxy; 25class WaitableEvent; 26} 27 28namespace IPC { 29class SyncChannel; 30class SyncMessageFilter; 31} 32 33namespace v8 { 34class Extension; 35} 36 37namespace content { 38 39class RenderProcessObserver; 40class ResourceDispatcherDelegate; 41 42class CONTENT_EXPORT RenderThread : public IPC::Sender { 43 public: 44 // Returns the one render thread for this process. Note that this can only 45 // be accessed when running on the render thread itself. 46 static RenderThread* Get(); 47 48 RenderThread(); 49 virtual ~RenderThread(); 50 51 virtual base::MessageLoop* GetMessageLoop() = 0; 52 virtual IPC::SyncChannel* GetChannel() = 0; 53 virtual std::string GetLocale() = 0; 54 virtual IPC::SyncMessageFilter* GetSyncMessageFilter() = 0; 55 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() = 0; 56 57 // Called to add or remove a listener for a particular message routing ID. 58 // These methods normally get delegated to a MessageRouter. 59 virtual void AddRoute(int32 routing_id, IPC::Listener* listener) = 0; 60 virtual void RemoveRoute(int32 routing_id) = 0; 61 virtual int GenerateRoutingID() = 0; 62 63 // These map to IPC::ChannelProxy methods. 64 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) = 0; 65 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* 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 // We initialize WebKit as late as possible. Call this to force 76 // initialization. 77 virtual void EnsureWebKitInitialized() = 0; 78 79 // Sends over a base::UserMetricsAction to be recorded by user metrics as 80 // an action. Once a new user metric is added, run 81 // tools/metrics/actions/extract_actions.py --hash 82 // to generate a new mapping of [action hashes -> metric names] and send it 83 // out for review to be updated. 84 // WARNING: When using base::UserMetricsAction, base::UserMetricsAction 85 // and a string literal parameter must be on the same line, e.g. 86 // RenderThread::Get()->RecordAction( 87 // base::UserMetricsAction("my extremely long action name")); 88 // because otherwise our processing scripts won't pick up on new actions. 89 virtual void RecordAction(const base::UserMetricsAction& action) = 0; 90 91 // Sends over a string to be recorded by user metrics as a computed action. 92 // When you use this you need to also update the rules for extracting known 93 // actions in chrome/tools/extract_actions.py. 94 virtual void RecordComputedAction(const std::string& action) = 0; 95 96 // Asks the host to create a block of shared memory for the renderer. 97 // The shared memory allocated by the host is returned back. 98 virtual scoped_ptr<base::SharedMemory> HostAllocateSharedMemoryBuffer( 99 size_t buffer_size) = 0; 100 101 // Registers the given V8 extension with WebKit. 102 virtual void RegisterExtension(v8::Extension* extension) = 0; 103 104 // Schedule a call to IdleHandler with the given initial delay. 105 virtual void ScheduleIdleHandler(int64 initial_delay_ms) = 0; 106 107 // A task we invoke periodically to assist with idle cleanup. 108 virtual void IdleHandler() = 0; 109 110 // Get/Set the delay for how often the idle handler is called. 111 virtual int64 GetIdleNotificationDelayInMs() const = 0; 112 virtual void SetIdleNotificationDelayInMs( 113 int64 idle_notification_delay_in_ms) = 0; 114 115 virtual void UpdateHistograms(int sequence_number) = 0; 116 117 // Post task to all worker threads. Returns number of workers. 118 virtual int PostTaskToAllWebWorkers(const base::Closure& closure) = 0; 119 120 // Resolve the proxy servers to use for a given url. On success true is 121 // returned and |proxy_list| is set to a PAC string containing a list of 122 // proxy servers. 123 virtual bool ResolveProxy(const GURL& url, std::string* proxy_list) = 0; 124 125 // Gets the shutdown event for the process. 126 virtual base::WaitableEvent* GetShutdownEvent() = 0; 127 128#if defined(OS_WIN) 129 // Request that the given font be loaded by the browser so it's cached by the 130 // OS. Please see ChildProcessHost::PreCacheFont for details. 131 virtual void PreCacheFont(const LOGFONT& log_font) = 0; 132 133 // Release cached font. 134 virtual void ReleaseCachedFonts() = 0; 135#endif 136}; 137 138} // namespace content 139 140#endif // CONTENT_PUBLIC_RENDERER_RENDER_THREAD_H_ 141