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

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

Issue 155876: Revert r21117 as it caused reliability failures.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: 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
« no previous file with comments | « chrome/common/child_process.cc ('k') | chrome/common/child_thread.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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_THREAD_H_ 5 #ifndef CHROME_COMMON_CHILD_THREAD_H_
6 #define CHROME_COMMON_CHILD_THREAD_H_ 6 #define CHROME_COMMON_CHILD_THREAD_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 "chrome/common/ipc_sync_channel.h" 11 #include "chrome/common/ipc_sync_channel.h"
11 #include "chrome/common/message_router.h" 12 #include "chrome/common/message_router.h"
12 #include "chrome/common/resource_dispatcher.h" 13 #include "chrome/common/resource_dispatcher.h"
13 14
14 class NotificationService; 15 // Child processes's background thread should derive from this class.
15
16 // The main thread of a child process derives from this class.
17 class ChildThread : public IPC::Channel::Listener, 16 class ChildThread : public IPC::Channel::Listener,
18 public IPC::Message::Sender { 17 public IPC::Message::Sender,
18 public base::Thread {
19 public: 19 public:
20 // Creates the thread. 20 // Creates the thread.
21 ChildThread(); 21 ChildThread(Thread::Options options);
22 // Used for single-process mode.
23 ChildThread(const std::string channel_name);
24 virtual ~ChildThread(); 22 virtual ~ChildThread();
25 23
26 // IPC::Message::Sender implementation: 24 // IPC::Message::Sender implementation:
27 virtual bool Send(IPC::Message* msg); 25 virtual bool Send(IPC::Message* msg);
28 26
29 // See documentation on MessageRouter for AddRoute and RemoveRoute 27 // See documentation on MessageRouter for AddRoute and RemoveRoute
30 void AddRoute(int32 routing_id, IPC::Channel::Listener* listener); 28 void AddRoute(int32 routing_id, IPC::Channel::Listener* listener);
31 void RemoveRoute(int32 routing_id); 29 void RemoveRoute(int32 routing_id);
32 30
31 MessageLoop* owner_loop() { return owner_loop_; }
32
33 ResourceDispatcher* resource_dispatcher() { 33 ResourceDispatcher* resource_dispatcher() {
34 return resource_dispatcher_.get(); 34 return resource_dispatcher_.get();
35 } 35 }
36 36
37 MessageLoop* message_loop() { return message_loop_; }
38
39 // Returns the one child thread. 37 // Returns the one child thread.
40 static ChildThread* current(); 38 static ChildThread* current();
41 39
42 protected: 40 protected:
43 friend class ChildProcess; 41 friend class ChildProcess;
44 42
43 // Starts the thread.
44 bool Run();
45
46 // Overrides the channel name. Used for --single-process mode.
47 void SetChannelName(const std::string& name) { channel_name_ = name; }
48
45 // Called when the process refcount is 0. 49 // Called when the process refcount is 0.
46 void OnProcessFinalRelease(); 50 void OnProcessFinalRelease();
47 51
52 protected:
53 // The required stack size if V8 runs on a thread.
54 static const size_t kV8StackSize;
55
48 virtual void OnControlMessageReceived(const IPC::Message& msg) { } 56 virtual void OnControlMessageReceived(const IPC::Message& msg) { }
49 57
50 IPC::SyncChannel* channel() { return channel_.get(); } 58 IPC::SyncChannel* channel() { return channel_.get(); }
51 59
60 // Thread implementation.
61 virtual void Init();
62 virtual void CleanUp();
63
52 private: 64 private:
53 void Init();
54
55 // IPC::Channel::Listener implementation: 65 // IPC::Channel::Listener implementation:
56 virtual void OnMessageReceived(const IPC::Message& msg); 66 virtual void OnMessageReceived(const IPC::Message& msg);
57 virtual void OnChannelError(); 67 virtual void OnChannelError();
58 68
69 // The message loop used to run tasks on the thread that started this thread.
70 MessageLoop* owner_loop_;
71
59 std::string channel_name_; 72 std::string channel_name_;
60 scoped_ptr<IPC::SyncChannel> channel_; 73 scoped_ptr<IPC::SyncChannel> channel_;
61 74
62 // Implements message routing functionality to the consumers of ChildThread. 75 // Used only on the background render thread to implement message routing
76 // functionality to the consumers of the ChildThread.
63 MessageRouter router_; 77 MessageRouter router_;
64 78
79 Thread::Options options_;
80
65 // Handles resource loads for this process. 81 // Handles resource loads for this process.
82 // NOTE: this object lives on the owner thread.
66 scoped_ptr<ResourceDispatcher> resource_dispatcher_; 83 scoped_ptr<ResourceDispatcher> resource_dispatcher_;
67 84
68 // If true, checks with the browser process before shutdown. This avoids race 85 // If true, checks with the browser process before shutdown. This avoids race
69 // conditions if the process refcount is 0 but there's an IPC message inflight 86 // conditions if the process refcount is 0 but there's an IPC message inflight
70 // that would addref it. 87 // that would addref it.
71 bool check_with_browser_before_shutdown_; 88 bool check_with_browser_before_shutdown_;
72 89
73 MessageLoop* message_loop_;
74
75 scoped_ptr<NotificationService> notification_service_;
76
77 DISALLOW_COPY_AND_ASSIGN(ChildThread); 90 DISALLOW_COPY_AND_ASSIGN(ChildThread);
78 }; 91 };
79 92
80 #endif // CHROME_COMMON_CHILD_THREAD_H_ 93 #endif // CHROME_COMMON_CHILD_THREAD_H_
OLDNEW
« no previous file with comments | « chrome/common/child_process.cc ('k') | chrome/common/child_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698