OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CONTENT_BROWSER_BROWSER_THREAD_H_ | 5 #ifndef CONTENT_BROWSER_BROWSER_THREAD_H_ |
6 #define CONTENT_BROWSER_BROWSER_THREAD_H_ | 6 #define CONTENT_BROWSER_BROWSER_THREAD_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
11 #include "base/task.h" | 11 #include "base/task.h" |
12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
13 | 13 |
14 #if defined(UNIT_TEST) | 14 #if defined(UNIT_TEST) |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #endif // UNIT_TEST | 16 #endif // UNIT_TEST |
17 | 17 |
18 #include "content/common/content_export.h" | |
darin (slow to review)
2011/09/04 15:41:04
move up to main block of includes. it is normal f
Dirk Pranke
2011/09/07 01:46:07
Done.
| |
19 | |
18 namespace base { | 20 namespace base { |
19 class MessageLoopProxy; | 21 class MessageLoopProxy; |
20 } | 22 } |
21 | 23 |
22 /////////////////////////////////////////////////////////////////////////////// | 24 /////////////////////////////////////////////////////////////////////////////// |
23 // BrowserThread | 25 // BrowserThread |
24 // | 26 // |
25 // This class represents a thread that is known by a browser-wide name. For | 27 // This class represents a thread that is known by a browser-wide name. For |
26 // example, there is one IO thread for the entire browser process, and various | 28 // example, there is one IO thread for the entire browser process, and various |
27 // pieces of code find it useful to retrieve a pointer to the IO thread's | 29 // pieces of code find it useful to retrieve a pointer to the IO thread's |
28 // Invoke a task by thread ID: | 30 // Invoke a task by thread ID: |
29 // | 31 // |
30 // BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task); | 32 // BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task); |
31 // | 33 // |
32 // The return value is false if the task couldn't be posted because the target | 34 // The return value is false if the task couldn't be posted because the target |
33 // thread doesn't exist. If this could lead to data loss, you need to check the | 35 // thread doesn't exist. If this could lead to data loss, you need to check the |
34 // result and restructure the code to ensure it doesn't occur. | 36 // result and restructure the code to ensure it doesn't occur. |
35 // | 37 // |
36 // This class automatically handles the lifetime of different threads. | 38 // This class automatically handles the lifetime of different threads. |
37 // It's always safe to call PostTask on any thread. If it's not yet created, | 39 // It's always safe to call PostTask on any thread. If it's not yet created, |
38 // the task is deleted. There are no race conditions. If the thread that the | 40 // the task is deleted. There are no race conditions. If the thread that the |
39 // task is posted to is guaranteed to outlive the current thread, then no locks | 41 // task is posted to is guaranteed to outlive the current thread, then no locks |
40 // are used. You should never need to cache pointers to MessageLoops, since | 42 // are used. You should never need to cache pointers to MessageLoops, since |
41 // they're not thread safe. | 43 // they're not thread safe. |
42 class BrowserThread : public base::Thread { | 44 class CONTENT_EXPORT BrowserThread : public base::Thread { |
43 public: | 45 public: |
44 // An enumeration of the well-known threads. | 46 // An enumeration of the well-known threads. |
45 // NOTE: threads must be listed in the order of their life-time, with each | 47 // NOTE: threads must be listed in the order of their life-time, with each |
46 // thread outliving every other thread below it. | 48 // thread outliving every other thread below it. |
47 enum ID { | 49 enum ID { |
48 // The main thread in the browser. | 50 // The main thread in the browser. |
49 UI, | 51 UI, |
50 | 52 |
51 // This is the thread that interacts with the database. | 53 // This is the thread that interacts with the database. |
52 DB, | 54 DB, |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 static base::Lock lock_; | 243 static base::Lock lock_; |
242 | 244 |
243 // An array of the BrowserThread objects. This array is protected by |lock_|. | 245 // An array of the BrowserThread objects. This array is protected by |lock_|. |
244 // The threads are not owned by this array. Typically, the threads are owned | 246 // The threads are not owned by this array. Typically, the threads are owned |
245 // on the UI thread by the g_browser_process object. BrowserThreads remove | 247 // on the UI thread by the g_browser_process object. BrowserThreads remove |
246 // themselves from this array upon destruction. | 248 // themselves from this array upon destruction. |
247 static BrowserThread* browser_threads_[ID_COUNT]; | 249 static BrowserThread* browser_threads_[ID_COUNT]; |
248 }; | 250 }; |
249 | 251 |
250 #endif // CONTENT_BROWSER_BROWSER_THREAD_H_ | 252 #endif // CONTENT_BROWSER_BROWSER_THREAD_H_ |
OLD | NEW |