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

Side by Side Diff: content/browser/browser_thread_impl.h

Issue 8477004: Have content/ create and destroy its own threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More IWYU, missing link-time dependency for Chrome Frame. Created 9 years, 1 month 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) 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
20 private: 28 private:
21 // We implement most functionality on the public set of 29 // We implement all the functionality of the public BrowserThread
22 // BrowserThread functions, but state is stored in the 30 // functions, but state is stored in the BrowserThreadImpl to keep
23 // BrowserThreadImpl to keep the public API cleaner. Therefore make 31 // the API cleaner. Therefore make BrowserThread a friend class.
24 // BrowserThread a friend class.
25 friend class BrowserThread; 32 friend class BrowserThread;
26 33
27 // TODO(brettw) remove this variant when Task->Closure migration is complete. 34 // TODO(brettw) remove this variant when Task->Closure migration is complete.
28 static bool PostTaskHelper( 35 static bool PostTaskHelper(
29 BrowserThread::ID identifier, 36 BrowserThread::ID identifier,
30 const tracked_objects::Location& from_here, 37 const tracked_objects::Location& from_here,
31 Task* task, 38 Task* task,
32 int64 delay_ms, 39 int64 delay_ms,
33 bool nestable); 40 bool nestable);
34 static bool PostTaskHelper( 41 static bool PostTaskHelper(
35 BrowserThread::ID identifier, 42 BrowserThread::ID identifier,
36 const tracked_objects::Location& from_here, 43 const tracked_objects::Location& from_here,
37 const base::Closure& task, 44 const base::Closure& task,
38 int64 delay_ms, 45 int64 delay_ms,
39 bool nestable); 46 bool nestable);
40 47
41 // This lock protects |browser_threads_|. Do not read or modify that array 48 // This lock protects |browser_threads_|. Do not read or modify that array
42 // without holding this lock. Do not block while holding this lock. 49 // without holding this lock. Do not block while holding this lock.
43 static base::Lock lock_; 50 static base::Lock lock_;
44 51
45 // An array of the BrowserThread objects. This array is protected by |lock_|. 52 // An array of the BrowserThreadImpl objects. This array is
46 // The threads are not owned by this array. Typically, the threads are owned 53 // protected by |lock_|. The threads are not owned by this array.
47 // on the UI thread by the g_browser_process object. BrowserThreads remove 54 // Typically, the threads are owned on the UI thread by the
48 // themselves from this array upon destruction. 55 // g_browser_process object. BrowserThreadImpls remove themselves
49 static BrowserThread* browser_threads_[ID_COUNT]; 56 // from this array upon destruction.
57 static BrowserThreadImpl* browser_threads_[ID_COUNT];
58
59 // Common initialization code for the constructors.
60 void Initialize();
61
62 // The identifier of this thread. Only one thread can exist with a given
63 // identifier at a given time.
64 ID identifier_;
50 }; 65 };
51 66
52 } // namespace content 67 } // namespace content
53 68
54 #endif // CONTENT_BROWSER_BROWSER_THREAD_IMPL_H_ 69 #endif // CONTENT_BROWSER_BROWSER_THREAD_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698