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