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_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_BROWSER_THREAD_IMPL_H_ |
6 #define CONTENT_BROWSER_BROWSER_THREAD_IMPL_H_ | 6 #define CONTENT_BROWSER_BROWSER_THREAD_IMPL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
| 9 #include "base/synchronization/lock.h" |
| 10 #include "base/threading/thread.h" |
9 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
10 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
11 | 13 |
12 namespace content { | 14 namespace content { |
13 | 15 |
14 class CONTENT_EXPORT BrowserThreadImpl : public BrowserThread { | 16 class CONTENT_EXPORT BrowserThreadImpl |
| 17 : public BrowserThread, public base::Thread { |
15 public: | 18 public: |
| 19 // Construct a BrowserThreadImpl with the supplied identifier. It is an error |
| 20 // to construct a BrowserThreadImpl that already exists. |
16 explicit BrowserThreadImpl(BrowserThread::ID identifier); | 21 explicit BrowserThreadImpl(BrowserThread::ID identifier); |
| 22 |
| 23 // Special constructor for the main (UI) thread and unittests. We use a dummy |
| 24 // thread here since the main thread already exists. |
17 BrowserThreadImpl(BrowserThread::ID identifier, MessageLoop* message_loop); | 25 BrowserThreadImpl(BrowserThread::ID identifier, MessageLoop* message_loop); |
18 virtual ~BrowserThreadImpl(); | 26 virtual ~BrowserThreadImpl(); |
19 | 27 |
| 28 protected: |
| 29 virtual void Init() OVERRIDE; |
| 30 virtual void CleanUp() OVERRIDE; |
| 31 |
20 private: | 32 private: |
21 // We implement most functionality on the public set of | 33 // We implement all the functionality of the public BrowserThread |
22 // BrowserThread functions, but state is stored in the | 34 // functions, but state is stored in the BrowserThreadImpl to keep |
23 // BrowserThreadImpl to keep the public API cleaner. Therefore make | 35 // the API cleaner. Therefore make BrowserThread a friend class. |
24 // BrowserThread a friend class. | |
25 friend class BrowserThread; | 36 friend class BrowserThread; |
26 | 37 |
27 // TODO(brettw) remove this variant when Task->Closure migration is complete. | 38 // TODO(brettw) remove this variant when Task->Closure migration is complete. |
28 static bool PostTaskHelper( | 39 static bool PostTaskHelper( |
29 BrowserThread::ID identifier, | 40 BrowserThread::ID identifier, |
30 const tracked_objects::Location& from_here, | 41 const tracked_objects::Location& from_here, |
31 Task* task, | 42 Task* task, |
32 int64 delay_ms, | 43 int64 delay_ms, |
33 bool nestable); | 44 bool nestable); |
34 static bool PostTaskHelper( | 45 static bool PostTaskHelper( |
35 BrowserThread::ID identifier, | 46 BrowserThread::ID identifier, |
36 const tracked_objects::Location& from_here, | 47 const tracked_objects::Location& from_here, |
37 const base::Closure& task, | 48 const base::Closure& task, |
38 int64 delay_ms, | 49 int64 delay_ms, |
39 bool nestable); | 50 bool nestable); |
| 51 |
| 52 // Common initialization code for the constructors. |
| 53 void Initialize(); |
| 54 |
| 55 // The identifier of this thread. Only one thread can exist with a given |
| 56 // identifier at a given time. |
| 57 ID identifier_; |
40 }; | 58 }; |
41 | 59 |
42 } // namespace content | 60 } // namespace content |
43 | 61 |
44 #endif // CONTENT_BROWSER_BROWSER_THREAD_IMPL_H_ | 62 #endif // CONTENT_BROWSER_BROWSER_THREAD_IMPL_H_ |
OLD | NEW |