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

Side by Side Diff: base/threading/thread.h

Issue 11048029: Allow Thread to initialize COM for Windows consumers who need it (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 2 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 | « no previous file | base/threading/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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 BASE_THREAD_H_ 5 #ifndef BASE_THREADING_THREAD_H_
6 #define BASE_THREAD_H_ 6 #define BASE_THREADING_THREAD_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/base_export.h" 10 #include "base/base_export.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/message_loop_proxy.h" 12 #include "base/message_loop_proxy.h"
13 #include "base/threading/platform_thread.h" 13 #include "base/threading/platform_thread.h"
14 14
15 namespace base { 15 namespace base {
16 16
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 // Destroys the thread, stopping it if necessary. 50 // Destroys the thread, stopping it if necessary.
51 // 51 //
52 // NOTE: ALL SUBCLASSES OF Thread MUST CALL Stop() IN THEIR DESTRUCTORS (or 52 // NOTE: ALL SUBCLASSES OF Thread MUST CALL Stop() IN THEIR DESTRUCTORS (or
53 // guarantee Stop() is explicitly called before the subclass is destroyed). 53 // guarantee Stop() is explicitly called before the subclass is destroyed).
54 // This is required to avoid a data race between the destructor modifying the 54 // This is required to avoid a data race between the destructor modifying the
55 // vtable, and the thread's ThreadMain calling the virtual method Run(). It 55 // vtable, and the thread's ThreadMain calling the virtual method Run(). It
56 // also ensures that the CleanUp() virtual method is called on the subclass 56 // also ensures that the CleanUp() virtual method is called on the subclass
57 // before it is destructed. 57 // before it is destructed.
58 virtual ~Thread(); 58 virtual ~Thread();
59 59
60 #if defined(OS_WIN)
61 // Causes the thread to initialize COM. This must be called before calling
62 // Start() or StartWithOptions(). If |use_mta| is false, the thread is also
63 // started with a TYPE_UI message loop. It is an error to call
64 // init_com_with_mta(false) and then StartWithOptions() with any message loop
65 // type other than TYPE_UI.
66 void init_com_with_mta(bool use_mta) {
67 DCHECK(!started_);
68 com_status_ = use_mta ? MTA : STA;
69 }
70 #endif
71
60 // Starts the thread. Returns true if the thread was successfully started; 72 // Starts the thread. Returns true if the thread was successfully started;
61 // otherwise, returns false. Upon successful return, the message_loop() 73 // otherwise, returns false. Upon successful return, the message_loop()
62 // getter will return non-null. 74 // getter will return non-null.
63 // 75 //
64 // Note: This function can't be called on Windows with the loader lock held; 76 // Note: This function can't be called on Windows with the loader lock held;
65 // i.e. during a DllMain, global object construction or destruction, atexit() 77 // i.e. during a DllMain, global object construction or destruction, atexit()
66 // callback. 78 // callback.
67 bool Start(); 79 bool Start();
68 80
69 // Starts the thread. Behaves exactly like Start in addition to allow to 81 // Starts the thread. Behaves exactly like Start in addition to allow to
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 virtual void CleanUp() {} 153 virtual void CleanUp() {}
142 154
143 static void SetThreadWasQuitProperly(bool flag); 155 static void SetThreadWasQuitProperly(bool flag);
144 static bool GetThreadWasQuitProperly(); 156 static bool GetThreadWasQuitProperly();
145 157
146 void set_message_loop(MessageLoop* message_loop) { 158 void set_message_loop(MessageLoop* message_loop) {
147 message_loop_ = message_loop; 159 message_loop_ = message_loop;
148 } 160 }
149 161
150 private: 162 private:
151 bool thread_was_started() const { return started_; } 163 #if defined(OS_WIN)
164 enum ComStatus {
165 NONE,
166 STA,
167 MTA,
168 };
169 #endif
152 170
153 // PlatformThread::Delegate methods: 171 // PlatformThread::Delegate methods:
154 virtual void ThreadMain() OVERRIDE; 172 virtual void ThreadMain() OVERRIDE;
155 173
174 #if defined(OS_WIN)
175 // Whether this thread needs to initialize COM, and if so, in what mode.
176 ComStatus com_status_;
177 #endif
178
156 // Whether we successfully started the thread. 179 // Whether we successfully started the thread.
157 bool started_; 180 bool started_;
158 181
159 // If true, we're in the middle of stopping, and shouldn't access 182 // If true, we're in the middle of stopping, and shouldn't access
160 // |message_loop_|. It may non-NULL and invalid. 183 // |message_loop_|. It may non-NULL and invalid.
161 bool stopping_; 184 bool stopping_;
162 185
163 // True while inside of Run(). 186 // True while inside of Run().
164 bool running_; 187 bool running_;
165 188
(...skipping 14 matching lines...) Expand all
180 // The name of the thread. Used for debugging purposes. 203 // The name of the thread. Used for debugging purposes.
181 std::string name_; 204 std::string name_;
182 205
183 friend void ThreadQuitHelper(); 206 friend void ThreadQuitHelper();
184 207
185 DISALLOW_COPY_AND_ASSIGN(Thread); 208 DISALLOW_COPY_AND_ASSIGN(Thread);
186 }; 209 };
187 210
188 } // namespace base 211 } // namespace base
189 212
190 #endif // BASE_THREAD_H_ 213 #endif // BASE_THREADING_THREAD_H_
OLDNEW
« no previous file with comments | « no previous file | base/threading/thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698