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