Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: chrome/browser/renderer_host/browser_render_process_host.h

Issue 397031: Launch processes asynchronously so as not to block the UI thread. For now, re... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: return 0 instead of -1 if zygote couldn't launch renderer Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_H_ 5 #ifndef CHROME_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_H_
6 #define CHROME_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_H_ 6 #define CHROME_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_H_
7 7
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 9
10 #include <map> 10 #include <map>
11 #include <queue>
11 #include <string> 12 #include <string>
12 13
13 #include "base/process.h" 14 #include "base/process.h"
14 #include "base/ref_counted.h" 15 #include "base/ref_counted.h"
15 #include "base/scoped_ptr.h" 16 #include "base/scoped_ptr.h"
16 #include "base/shared_memory.h" 17 #include "base/shared_memory.h"
17 #include "base/string16.h" 18 #include "base/string16.h"
18 #include "base/timer.h" 19 #include "base/timer.h"
19 #include "chrome/common/transport_dib.h" 20 #include "chrome/common/transport_dib.h"
21 #include "chrome/browser/child_process_launcher.h"
20 #include "chrome/browser/renderer_host/render_process_host.h" 22 #include "chrome/browser/renderer_host/render_process_host.h"
21 #include "chrome/common/notification_registrar.h" 23 #include "chrome/common/notification_registrar.h"
22 #include "third_party/WebKit/WebKit/chromium/public/WebCache.h" 24 #include "third_party/WebKit/WebKit/chromium/public/WebCache.h"
23 25
24 class AudioRendererHost; 26 class AudioRendererHost;
25 class CommandLine; 27 class CommandLine;
26 class GURL; 28 class GURL;
27 class RendererMainThread; 29 class RendererMainThread;
28 class RenderWidgetHelper; 30 class RenderWidgetHelper;
29 class TabContents; 31 class TabContents;
(...skipping 12 matching lines...) Expand all
42 // 44 //
43 // This object is refcounted so that it can release its resources when all 45 // This object is refcounted so that it can release its resources when all
44 // hosts using it go away. 46 // hosts using it go away.
45 // 47 //
46 // This object communicates back and forth with the RenderProcess object 48 // This object communicates back and forth with the RenderProcess object
47 // running in the renderer process. Each RenderProcessHost and RenderProcess 49 // running in the renderer process. Each RenderProcessHost and RenderProcess
48 // keeps a list of RenderView (renderer) and TabContents (browser) which 50 // keeps a list of RenderView (renderer) and TabContents (browser) which
49 // are correlated with IDs. This way, the Views and the corresponding ViewHosts 51 // are correlated with IDs. This way, the Views and the corresponding ViewHosts
50 // communicate through the two process objects. 52 // communicate through the two process objects.
51 class BrowserRenderProcessHost : public RenderProcessHost, 53 class BrowserRenderProcessHost : public RenderProcessHost,
52 public NotificationObserver { 54 public NotificationObserver,
55 public ChildProcessLauncher::Client {
53 public: 56 public:
54 explicit BrowserRenderProcessHost(Profile* profile); 57 explicit BrowserRenderProcessHost(Profile* profile);
55 ~BrowserRenderProcessHost(); 58 ~BrowserRenderProcessHost();
56 59
57 // RenderProcessHost implementation (public portion). 60 // RenderProcessHost implementation (public portion).
58 virtual bool Init(bool is_extensions_process, 61 virtual bool Init(bool is_extensions_process,
59 URLRequestContextGetter* request_context); 62 URLRequestContextGetter* request_context);
60 virtual int GetNextRoutingID(); 63 virtual int GetNextRoutingID();
61 virtual void CancelResourceRequests(int render_widget_id); 64 virtual void CancelResourceRequests(int render_widget_id);
62 virtual void CrossSiteClosePageACK(const ViewMsg_ClosePage_Params& params); 65 virtual void CrossSiteClosePageACK(const ViewMsg_ClosePage_Params& params);
63 virtual bool WaitForPaintMsg(int render_widget_id, 66 virtual bool WaitForPaintMsg(int render_widget_id,
64 const base::TimeDelta& max_delay, 67 const base::TimeDelta& max_delay,
65 IPC::Message* msg); 68 IPC::Message* msg);
66 virtual void ReceivedBadMessage(uint16 msg_type); 69 virtual void ReceivedBadMessage(uint16 msg_type);
67 virtual void WidgetRestored(); 70 virtual void WidgetRestored();
68 virtual void WidgetHidden(); 71 virtual void WidgetHidden();
69 virtual void ViewCreated(); 72 virtual void ViewCreated();
70 virtual void AddWord(const string16& word); 73 virtual void AddWord(const string16& word);
74 virtual void SendVisitedLinkTable(base::SharedMemory* table_memory);
71 virtual void AddVisitedLinks(const VisitedLinkCommon::Fingerprints& links); 75 virtual void AddVisitedLinks(const VisitedLinkCommon::Fingerprints& links);
72 virtual void ResetVisitedLinks(); 76 virtual void ResetVisitedLinks();
73 virtual bool FastShutdownIfPossible(); 77 virtual bool FastShutdownIfPossible();
74 virtual bool SendWithTimeout(IPC::Message* msg, int timeout_ms); 78 virtual bool SendWithTimeout(IPC::Message* msg, int timeout_ms);
75 virtual base::ProcessHandle GetHandle(); 79 virtual base::ProcessHandle GetHandle();
76 virtual TransportDIB* GetTransportDIB(TransportDIB::Id dib_id); 80 virtual TransportDIB* GetTransportDIB(TransportDIB::Id dib_id);
77 81
78 // IPC::Channel::Sender via RenderProcessHost. 82 // IPC::Channel::Sender via RenderProcessHost.
79 virtual bool Send(IPC::Message* msg); 83 virtual bool Send(IPC::Message* msg);
80 84
81 // IPC::Channel::Listener via RenderProcessHost. 85 // IPC::Channel::Listener via RenderProcessHost.
82 virtual void OnMessageReceived(const IPC::Message& msg); 86 virtual void OnMessageReceived(const IPC::Message& msg);
83 virtual void OnChannelConnected(int32 peer_pid); 87 virtual void OnChannelConnected(int32 peer_pid);
84 virtual void OnChannelError(); 88 virtual void OnChannelError();
85 89
86 // If the a process has sent a message that cannot be decoded, it is deemed 90 // If the a process has sent a message that cannot be decoded, it is deemed
87 // corrupted and thus needs to be terminated using this call. This function 91 // corrupted and thus needs to be terminated using this call. This function
88 // can be safely called from any thread. 92 // can be safely called from any thread.
89 static void BadMessageTerminateProcess(uint16 msg_type, 93 static void BadMessageTerminateProcess(uint16 msg_type,
90 base::ProcessHandle renderer); 94 base::ProcessHandle renderer);
91 95
92 // NotificationObserver implementation. 96 // NotificationObserver implementation.
93 virtual void Observe(NotificationType type, 97 virtual void Observe(NotificationType type,
94 const NotificationSource& source, 98 const NotificationSource& source,
95 const NotificationDetails& details); 99 const NotificationDetails& details);
96 100
101 // ChildProcessLauncher::Client implementation.
102 virtual void OnProcessLaunched();
103
97 private: 104 private:
98 friend class VisitRelayingRenderProcessHost; 105 friend class VisitRelayingRenderProcessHost;
99 106
100 // Control message handlers. 107 // Control message handlers.
101 void OnPageContents(const GURL& url, int32 page_id, 108 void OnPageContents(const GURL& url, int32 page_id,
102 const std::wstring& contents); 109 const std::wstring& contents);
103 void OnUpdatedCacheStats(const WebKit::WebCache::UsageStats& stats); 110 void OnUpdatedCacheStats(const WebKit::WebCache::UsageStats& stats);
104 void SuddenTerminationChanged(bool enabled); 111 void SuddenTerminationChanged(bool enabled);
105 void OnExtensionAddListener(const std::string& event_name); 112 void OnExtensionAddListener(const std::string& event_name);
106 void OnExtensionRemoveListener(const std::string& event_name); 113 void OnExtensionRemoveListener(const std::string& event_name);
107 void OnExtensionCloseChannel(int port_id); 114 void OnExtensionCloseChannel(int port_id);
108 115
109 // Initialize support for visited links. Send the renderer process its initial 116 // Initialize support for visited links. Send the renderer process its initial
110 // set of visited links. 117 // set of visited links.
111 void InitVisitedLinks(); 118 void InitVisitedLinks();
112 119
113 // Initialize support for user scripts. Send the renderer process its initial 120 // Initialize support for user scripts. Send the renderer process its initial
114 // set of scripts and listen for updates to scripts. 121 // set of scripts and listen for updates to scripts.
115 void InitUserScripts(); 122 void InitUserScripts();
116 123
117 // Initialize support for extension APIs. Send the list of registered API 124 // Initialize support for extension APIs. Send the list of registered API
118 // functions to thre renderer process. 125 // functions to thre renderer process.
119 void InitExtensions(); 126 void InitExtensions();
120 127
121 // Sends the renderer process a new set of user scripts. 128 // Sends the renderer process a new set of user scripts.
122 void SendUserScriptsUpdate(base::SharedMemory* shared_memory); 129 void SendUserScriptsUpdate(base::SharedMemory* shared_memory);
123 130
124 // Generates a command line to be used to spawn a renderer and appends the 131 // Generates a command line to be used to spawn a renderer and appends the
125 // results to |*command_line|. |*has_cmd_prefix| will be set if the renderer 132 // results to |*command_line|.
126 // command line specifies a prefix which is another program that will actually 133 void AppendRendererCommandLine(CommandLine* command_line) const;
127 // execute the renderer (like gdb).
128 void AppendRendererCommandLine(CommandLine* command_line,
129 bool* has_cmd_prefix) const;
130 134
131 // Copies applicable command line switches from the given |browser_cmd| line 135 // Copies applicable command line switches from the given |browser_cmd| line
132 // flags to the output |renderer_cmd| line flags. Not all switches will be 136 // flags to the output |renderer_cmd| line flags. Not all switches will be
133 // copied over. 137 // copied over.
134 void PropogateBrowserCommandLineToRenderer(const CommandLine& browser_cmd, 138 void PropogateBrowserCommandLineToRenderer(const CommandLine& browser_cmd,
135 CommandLine* renderer_cmd) const; 139 CommandLine* renderer_cmd) const;
136 140
137 // Spawns the renderer process, returning the new handle on success, or 0 on
138 // failure. The renderer command line is given in the first argument, and
139 // whether a command prefix was used when generating the command line is
140 // speficied in the second.
141 base::ProcessHandle ExecuteRenderer(CommandLine* cmd_line,
142 bool has_cmd_prefix);
143
144 // Callers can reduce the RenderProcess' priority. 141 // Callers can reduce the RenderProcess' priority.
145 // Returns true if the priority is backgrounded; false otherwise. 142 // Returns true if the priority is backgrounded; false otherwise.
146 void SetBackgrounded(bool boost); 143 void SetBackgrounded(bool boost);
147 144
148 #if defined(SPELLCHECKER_IN_RENDERER) 145 #if defined(SPELLCHECKER_IN_RENDERER)
149 // The renderer has requested that we initialize its spellchecker. This should 146 // The renderer has requested that we initialize its spellchecker. This should
150 // generally only be called once per session, as after the first call, all 147 // generally only be called once per session, as after the first call, all
151 // future renderers will be passed the initialization information on startup 148 // future renderers will be passed the initialization information on startup
152 // (or when the dictionary changes in some way). 149 // (or when the dictionary changes in some way).
153 void OnSpellCheckerRequestDictionary(); 150 void OnSpellCheckerRequestDictionary();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 void ClearTransportDIBCache(); 191 void ClearTransportDIBCache();
195 // This is used to clear our cache five seconds after the last use. 192 // This is used to clear our cache five seconds after the last use.
196 base::DelayTimer<BrowserRenderProcessHost> cached_dibs_cleaner_; 193 base::DelayTimer<BrowserRenderProcessHost> cached_dibs_cleaner_;
197 194
198 // Used in single-process mode. 195 // Used in single-process mode.
199 scoped_ptr<RendererMainThread> in_process_renderer_; 196 scoped_ptr<RendererMainThread> in_process_renderer_;
200 197
201 // Buffer visited links and send them to to renderer. 198 // Buffer visited links and send them to to renderer.
202 scoped_ptr<VisitedLinkUpdater> visited_link_updater_; 199 scoped_ptr<VisitedLinkUpdater> visited_link_updater_;
203 200
204 // True iff the renderer is a child of a zygote process.
205 bool zygote_child_;
206
207 // True iff this process is being used as an extension process. Not valid 201 // True iff this process is being used as an extension process. Not valid
208 // when running in single-process mode. 202 // when running in single-process mode.
209 bool extension_process_; 203 bool extension_process_;
210 204
211 base::Process process_; 205 // Usedt to launch and terminate the process without blocking the UI thread.
206 scoped_ptr<ChildProcessLauncher> child_process_;
212 207
208 // Messages we queue while waiting for the process handle. We queue them here
209 // instead of in the channel so that we ensure they're sent after init related
210 // messages that are sent once the process handle is available. This is
211 // because the queued messages may have dependencies on the init messages.
212 std::queue<IPC::Message*> queued_messages_;
213 213
214 DISALLOW_COPY_AND_ASSIGN(BrowserRenderProcessHost); 214 DISALLOW_COPY_AND_ASSIGN(BrowserRenderProcessHost);
215 }; 215 };
216 216
217 #endif // CHROME_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_H_ 217 #endif // CHROME_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_host.cc ('k') | chrome/browser/renderer_host/browser_render_process_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698