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

Side by Side Diff: chrome/common/child_process.h

Issue 155944: Switch the first thread in a child process to be the main thread... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync Created 11 years, 5 months 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_COMMON_CHILD_PROCESS_H__ 5 #ifndef CHROME_COMMON_CHILD_PROCESS_H__
6 #define CHROME_COMMON_CHILD_PROCESS_H__ 6 #define CHROME_COMMON_CHILD_PROCESS_H__
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/scoped_ptr.h" 9 #include "base/scoped_ptr.h"
10 #include "base/thread.h"
10 #include "base/waitable_event.h" 11 #include "base/waitable_event.h"
11 12 #include "chrome/common/child_thread.h"
12 class ChildThread;
13 13
14 // Base class for child processes of the browser process (i.e. renderer and 14 // Base class for child processes of the browser process (i.e. renderer and
15 // plugin host). This is a singleton object for each child process. 15 // plugin host). This is a singleton object for each child process.
16 class ChildProcess { 16 class ChildProcess {
17 public: 17 public:
18 // Child processes should have an object that derives from this class. The 18 // Child processes should have an object that derives from this class.
19 // constructor will return once ChildThread has started. 19 ChildProcess();
20 ChildProcess(ChildThread* child_thread);
21 virtual ~ChildProcess(); 20 virtual ~ChildProcess();
22 21
23 // Getter for this process' main thread. 22 // Getter for the child process' main thread.
24 ChildThread* child_thread() { return child_thread_.get(); } 23 ChildThread* main_thread() { return main_thread_.get(); }
24 void set_main_thread(ChildThread* thread) { main_thread_.reset(thread); }
25
26 MessageLoop* io_message_loop() { return io_thread_.message_loop(); }
25 27
26 // A global event object that is signalled when the main thread's message 28 // A global event object that is signalled when the main thread's message
27 // loop exits. This gives background threads a way to observe the main 29 // loop exits. This gives background threads a way to observe the main
28 // thread shutting down. This can be useful when a background thread is 30 // thread shutting down. This can be useful when a background thread is
29 // waiting for some information from the browser process. If the browser 31 // waiting for some information from the browser process. If the browser
30 // process goes away prematurely, the background thread can at least notice 32 // process goes away prematurely, the background thread can at least notice
31 // the child processes's main thread exiting to determine that it should give 33 // the child processes's main thread exiting to determine that it should give
32 // up waiting. 34 // up waiting.
33 // For example, see the renderer code used to implement 35 // For example, see the renderer code used to implement
34 // webkit_glue::GetCookies. 36 // webkit_glue::GetCookies.
35 base::WaitableEvent* GetShutDownEvent(); 37 base::WaitableEvent* GetShutDownEvent();
36 38
37 // These are used for ref-counting the child process. The process shuts 39 // These are used for ref-counting the child process. The process shuts
38 // itself down when the ref count reaches 0. 40 // itself down when the ref count reaches 0.
39 // For example, in the renderer process, generally each tab managed by this 41 // For example, in the renderer process, generally each tab managed by this
40 // process will hold a reference to the process, and release when closed. 42 // process will hold a reference to the process, and release when closed.
41 void AddRefProcess(); 43 void AddRefProcess();
42 void ReleaseProcess(); 44 void ReleaseProcess();
43 45
44 // Getter for the one ChildProcess object for this process. 46 // Getter for the one ChildProcess object for this process.
45 static ChildProcess* current() { return child_process_; } 47 static ChildProcess* current() { return child_process_; }
46 48
47 private: 49 private:
48 // NOTE: make sure that child_thread_ is listed before shutdown_event_, since
49 // it depends on it (indirectly through IPC::SyncChannel).
50 scoped_ptr<ChildThread> child_thread_;
51
52 int ref_count_; 50 int ref_count_;
53 51
54 // An event that will be signalled when we shutdown. 52 // An event that will be signalled when we shutdown.
55 base::WaitableEvent shutdown_event_; 53 base::WaitableEvent shutdown_event_;
56 54
55 // The thread that handles IO events.
56 base::Thread io_thread_;
57
58 // NOTE: make sure that main_thread_ is listed after shutdown_event_, since
59 // it depends on it (indirectly through IPC::SyncChannel). Same for
60 // io_thread_.
61 scoped_ptr<ChildThread> main_thread_;
62
57 // The singleton instance for this process. 63 // The singleton instance for this process.
58 static ChildProcess* child_process_; 64 static ChildProcess* child_process_;
59 65
60 DISALLOW_EVIL_CONSTRUCTORS(ChildProcess); 66 DISALLOW_EVIL_CONSTRUCTORS(ChildProcess);
61 }; 67 };
62 68
63 #endif // CHROME_COMMON_CHILD_PROCESS_H__ 69 #endif // CHROME_COMMON_CHILD_PROCESS_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698