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

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

Issue 3971004: Revert "Revert "Const-ify RefCountedThreadSafe::AddRef and Release."" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 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 | « base/task.h ('k') | chrome/browser/browser_thread_unittest.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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 CHROME_BROWSER_BROWSER_THREAD_H_ 5 #ifndef CHROME_BROWSER_BROWSER_THREAD_H_
6 #define CHROME_BROWSER_BROWSER_THREAD_H_ 6 #define CHROME_BROWSER_BROWSER_THREAD_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/lock.h" 9 #include "base/lock.h"
10 #include "base/task.h" 10 #include "base/task.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 Task* task); 102 Task* task);
103 static bool PostNonNestableDelayedTask( 103 static bool PostNonNestableDelayedTask(
104 ID identifier, 104 ID identifier,
105 const tracked_objects::Location& from_here, 105 const tracked_objects::Location& from_here,
106 Task* task, 106 Task* task,
107 int64 delay_ms); 107 int64 delay_ms);
108 108
109 template <class T> 109 template <class T>
110 static bool DeleteSoon(ID identifier, 110 static bool DeleteSoon(ID identifier,
111 const tracked_objects::Location& from_here, 111 const tracked_objects::Location& from_here,
112 T* object) { 112 const T* object) {
113 return PostNonNestableTask( 113 return PostNonNestableTask(
114 identifier, from_here, new DeleteTask<T>(object)); 114 identifier, from_here, new DeleteTask<T>(object));
115 } 115 }
116 116
117 template <class T> 117 template <class T>
118 static bool ReleaseSoon(ID identifier, 118 static bool ReleaseSoon(ID identifier,
119 const tracked_objects::Location& from_here, 119 const tracked_objects::Location& from_here,
120 T* object) { 120 const T* object) {
121 return PostNonNestableTask( 121 return PostNonNestableTask(
122 identifier, from_here, new ReleaseTask<T>(object)); 122 identifier, from_here, new ReleaseTask<T>(object));
123 } 123 }
124 124
125 // Callable on any thread. Returns whether the given ID corresponds to a well 125 // Callable on any thread. Returns whether the given ID corresponds to a well
126 // known thread. 126 // known thread.
127 static bool IsWellKnownThread(ID identifier); 127 static bool IsWellKnownThread(ID identifier);
128 128
129 // Callable on any thread. Returns whether you're currently on a particular 129 // Callable on any thread. Returns whether you're currently on a particular
130 // thread. 130 // thread.
(...skipping 16 matching lines...) Expand all
147 // Use these templates in conjuction with RefCountedThreadSafe when you want 147 // Use these templates in conjuction with RefCountedThreadSafe when you want
148 // to ensure that an object is deleted on a specific thread. This is needed 148 // to ensure that an object is deleted on a specific thread. This is needed
149 // when an object can hop between threads (i.e. IO -> FILE -> IO), and thread 149 // when an object can hop between threads (i.e. IO -> FILE -> IO), and thread
150 // switching delays can mean that the final IO tasks executes before the FILE 150 // switching delays can mean that the final IO tasks executes before the FILE
151 // task's stack unwinds. This would lead to the object destructing on the 151 // task's stack unwinds. This would lead to the object destructing on the
152 // FILE thread, which often is not what you want (i.e. to unregister from 152 // FILE thread, which often is not what you want (i.e. to unregister from
153 // NotificationService, to notify other objects on the creating thread etc). 153 // NotificationService, to notify other objects on the creating thread etc).
154 template<ID thread> 154 template<ID thread>
155 struct DeleteOnThread { 155 struct DeleteOnThread {
156 template<typename T> 156 template<typename T>
157 static void Destruct(T* x) { 157 static void Destruct(const T* x) {
158 if (CurrentlyOn(thread)) { 158 if (CurrentlyOn(thread)) {
159 delete x; 159 delete x;
160 } else { 160 } else {
161 DeleteSoon(thread, FROM_HERE, x); 161 DeleteSoon(thread, FROM_HERE, x);
162 } 162 }
163 } 163 }
164 }; 164 };
165 165
166 // Sample usage: 166 // Sample usage:
167 // class Foo 167 // class Foo
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 static Lock lock_; 200 static Lock lock_;
201 201
202 // An array of the BrowserThread objects. This array is protected by |lock_|. 202 // An array of the BrowserThread objects. This array is protected by |lock_|.
203 // The threads are not owned by this array. Typically, the threads are owned 203 // The threads are not owned by this array. Typically, the threads are owned
204 // on the UI thread by the g_browser_process object. BrowserThreads remove 204 // on the UI thread by the g_browser_process object. BrowserThreads remove
205 // themselves from this array upon destruction. 205 // themselves from this array upon destruction.
206 static BrowserThread* browser_threads_[ID_COUNT]; 206 static BrowserThread* browser_threads_[ID_COUNT];
207 }; 207 };
208 208
209 #endif // CHROME_BROWSER_BROWSER_THREAD_H_ 209 #endif // CHROME_BROWSER_BROWSER_THREAD_H_
OLDNEW
« no previous file with comments | « base/task.h ('k') | chrome/browser/browser_thread_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698