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 #if defined(UNIT_TEST) |
| 10 #include "base/logging.h" |
| 11 #endif // UNIT_TEST |
9 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
10 #include "base/task.h" | 13 #include "base/task.h" |
11 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
12 | 15 |
13 namespace base { | 16 namespace base { |
14 class MessageLoopProxy; | 17 class MessageLoopProxy; |
15 } | 18 } |
16 | 19 |
17 /////////////////////////////////////////////////////////////////////////////// | 20 /////////////////////////////////////////////////////////////////////////////// |
18 // BrowserThread | 21 // BrowserThread |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 // task's stack unwinds. This would lead to the object destructing on the | 157 // task's stack unwinds. This would lead to the object destructing on the |
155 // FILE thread, which often is not what you want (i.e. to unregister from | 158 // FILE thread, which often is not what you want (i.e. to unregister from |
156 // NotificationService, to notify other objects on the creating thread etc). | 159 // NotificationService, to notify other objects on the creating thread etc). |
157 template<ID thread> | 160 template<ID thread> |
158 struct DeleteOnThread { | 161 struct DeleteOnThread { |
159 template<typename T> | 162 template<typename T> |
160 static void Destruct(const T* x) { | 163 static void Destruct(const T* x) { |
161 if (CurrentlyOn(thread)) { | 164 if (CurrentlyOn(thread)) { |
162 delete x; | 165 delete x; |
163 } else { | 166 } else { |
164 DeleteSoon(thread, FROM_HERE, x); | 167 if (!DeleteSoon(thread, FROM_HERE, x)) { |
| 168 #if defined(UNIT_TEST) |
| 169 // Only logged under unit testing because leaks at shutdown |
| 170 // are acceptable under normal circumstances. |
| 171 LOG(ERROR) << "DeleteSoon failed on thread " << thread; |
| 172 #endif // UNIT_TEST |
| 173 } |
165 } | 174 } |
166 } | 175 } |
167 }; | 176 }; |
168 | 177 |
169 // Sample usage: | 178 // Sample usage: |
170 // class Foo | 179 // class Foo |
171 // : public base::RefCountedThreadSafe< | 180 // : public base::RefCountedThreadSafe< |
172 // Foo, BrowserThread::DeleteOnIOThread> { | 181 // Foo, BrowserThread::DeleteOnIOThread> { |
173 // | 182 // |
174 // ... | 183 // ... |
(...skipping 28 matching lines...) Expand all Loading... |
203 static base::Lock lock_; | 212 static base::Lock lock_; |
204 | 213 |
205 // An array of the BrowserThread objects. This array is protected by |lock_|. | 214 // An array of the BrowserThread objects. This array is protected by |lock_|. |
206 // The threads are not owned by this array. Typically, the threads are owned | 215 // The threads are not owned by this array. Typically, the threads are owned |
207 // on the UI thread by the g_browser_process object. BrowserThreads remove | 216 // on the UI thread by the g_browser_process object. BrowserThreads remove |
208 // themselves from this array upon destruction. | 217 // themselves from this array upon destruction. |
209 static BrowserThread* browser_threads_[ID_COUNT]; | 218 static BrowserThread* browser_threads_[ID_COUNT]; |
210 }; | 219 }; |
211 | 220 |
212 #endif // CONTENT_BROWSER_BROWSER_THREAD_H_ | 221 #endif // CONTENT_BROWSER_BROWSER_THREAD_H_ |
OLD | NEW |