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

Side by Side Diff: chrome/browser/chrome_thread.h

Issue 1800008: Created a MessageLoopProxy interface. This provides a thread-safe refcounted ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 8 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 | « base/message_loop_proxy.h ('k') | chrome/browser/chrome_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_BROWSER_CHROME_THREAD_H_ 5 #ifndef CHROME_BROWSER_CHROME_THREAD_H_
6 #define CHROME_BROWSER_CHROME_THREAD_H_ 6 #define CHROME_BROWSER_CHROME_THREAD_H_
7 7
8 #include "base/lock.h" 8 #include "base/lock.h"
9 #include "base/task.h" 9 #include "base/task.h"
10 #include "base/thread.h" 10 #include "base/thread.h"
11 11
12 class MessageLoopProxy;
13
12 /////////////////////////////////////////////////////////////////////////////// 14 ///////////////////////////////////////////////////////////////////////////////
13 // ChromeThread 15 // ChromeThread
14 // 16 //
15 // This class represents a thread that is known by a browser-wide name. For 17 // This class represents a thread that is known by a browser-wide name. For
16 // example, there is one IO thread for the entire browser process, and various 18 // example, there is one IO thread for the entire browser process, and various
17 // pieces of code find it useful to retrieve a pointer to the IO thread's 19 // pieces of code find it useful to retrieve a pointer to the IO thread's
18 // Invoke a task by thread ID: 20 // Invoke a task by thread ID:
19 // 21 //
20 // ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, task); 22 // ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, task);
21 // 23 //
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 static bool IsWellKnownThread(ID identifier); 121 static bool IsWellKnownThread(ID identifier);
120 122
121 // Callable on any thread. Returns whether you're currently on a particular 123 // Callable on any thread. Returns whether you're currently on a particular
122 // thread. 124 // thread.
123 static bool CurrentlyOn(ID identifier); 125 static bool CurrentlyOn(ID identifier);
124 126
125 // If the current message loop is one of the known threads, returns true and 127 // If the current message loop is one of the known threads, returns true and
126 // sets identifier to its ID. Otherwise returns false. 128 // sets identifier to its ID. Otherwise returns false.
127 static bool GetCurrentThreadIdentifier(ID* identifier); 129 static bool GetCurrentThreadIdentifier(ID* identifier);
128 130
131 // Callers can hold on to a refcounted MessageLoopProxy beyond the lifetime
132 // of the thread.
133 static scoped_refptr<MessageLoopProxy> GetMessageLoopProxyForThread(
134 ID identifier);
135
129 // Use these templates in conjuction with RefCountedThreadSafe when you want 136 // Use these templates in conjuction with RefCountedThreadSafe when you want
130 // to ensure that an object is deleted on a specific thread. This is needed 137 // to ensure that an object is deleted on a specific thread. This is needed
131 // when an object can hop between threads (i.e. IO -> FILE -> IO), and thread 138 // when an object can hop between threads (i.e. IO -> FILE -> IO), and thread
132 // switching delays can mean that the final IO tasks executes before the FILE 139 // switching delays can mean that the final IO tasks executes before the FILE
133 // task's stack unwinds. This would lead to the object destructing on the 140 // task's stack unwinds. This would lead to the object destructing on the
134 // FILE thread, which often is not what you want (i.e. to unregister from 141 // FILE thread, which often is not what you want (i.e. to unregister from
135 // NotificationService, to notify other objects on the creating thread etc). 142 // NotificationService, to notify other objects on the creating thread etc).
136 template<ID thread> 143 template<ID thread>
137 struct DeleteOnThread { 144 struct DeleteOnThread {
138 template<typename T> 145 template<typename T>
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 static Lock lock_; 189 static Lock lock_;
183 190
184 // An array of the ChromeThread objects. This array is protected by |lock_|. 191 // An array of the ChromeThread objects. This array is protected by |lock_|.
185 // The threads are not owned by this array. Typically, the threads are owned 192 // The threads are not owned by this array. Typically, the threads are owned
186 // on the UI thread by the g_browser_process object. ChromeThreads remove 193 // on the UI thread by the g_browser_process object. ChromeThreads remove
187 // themselves from this array upon destruction. 194 // themselves from this array upon destruction.
188 static ChromeThread* chrome_threads_[ID_COUNT]; 195 static ChromeThread* chrome_threads_[ID_COUNT];
189 }; 196 };
190 197
191 #endif // CHROME_BROWSER_CHROME_THREAD_H_ 198 #endif // CHROME_BROWSER_CHROME_THREAD_H_
OLDNEW
« no previous file with comments | « base/message_loop_proxy.h ('k') | chrome/browser/chrome_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698