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

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

Issue 6691044: Encourage reliability of code using browser thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Turn off fatal as it caused problem in tests Created 9 years, 8 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 | no next file » | 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) 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
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
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_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698