OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 IOS_WEB_PUBLIC_WEB_THREAD_H_ | 5 #ifndef IOS_WEB_PUBLIC_WEB_THREAD_H_ |
6 #define IOS_WEB_PUBLIC_WEB_THREAD_H_ | 6 #define IOS_WEB_PUBLIC_WEB_THREAD_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/task_runner_util.h" | 14 #include "base/task_runner_util.h" |
15 | 15 |
16 namespace base { | 16 namespace base { |
17 class MessageLoop; | 17 class MessageLoop; |
18 class SequencedWorkerPool; | 18 class SequencedWorkerPool; |
19 } | 19 } |
20 | 20 |
21 namespace tracked_objects { | 21 namespace tracked_objects { |
22 class Location; | 22 class Location; |
23 } | 23 } |
24 | 24 |
25 namespace web { | 25 namespace web { |
26 | 26 |
| 27 class WebThreadDelegate; |
| 28 |
27 // Use DCHECK_CURRENTLY_ON_WEB_THREAD(WebThread::ID) to assert that a function | 29 // Use DCHECK_CURRENTLY_ON_WEB_THREAD(WebThread::ID) to assert that a function |
28 // can only be called on the named WebThread. | 30 // can only be called on the named WebThread. |
29 // TODO(ios): rename to DCHECK_CURRENTLY_ON once iOS is independent from | 31 // TODO(ios): rename to DCHECK_CURRENTLY_ON once iOS is independent from |
30 // content/ so it won't collide with the macro DCHECK_CURRENTLY_ON in content/. | 32 // content/ so it won't collide with the macro DCHECK_CURRENTLY_ON in content/. |
31 // http://crbug.com/438202 | 33 // http://crbug.com/438202 |
32 #define DCHECK_CURRENTLY_ON_WEB_THREAD(thread_identifier) \ | 34 #define DCHECK_CURRENTLY_ON_WEB_THREAD(thread_identifier) \ |
33 (DCHECK(::web::WebThread::CurrentlyOn(thread_identifier)) \ | 35 (DCHECK(::web::WebThread::CurrentlyOn(thread_identifier)) \ |
34 << ::web::WebThread::GetDCheckCurrentlyOnErrorMessage(thread_identifier)) | 36 << ::web::WebThread::GetDCheckCurrentlyOnErrorMessage(thread_identifier)) |
35 | 37 |
36 /////////////////////////////////////////////////////////////////////////////// | 38 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 200 |
199 // If the current message loop is one of the known threads, returns true and | 201 // If the current message loop is one of the known threads, returns true and |
200 // sets identifier to its ID. | 202 // sets identifier to its ID. |
201 static bool GetCurrentThreadIdentifier(ID* identifier) WARN_UNUSED_RESULT; | 203 static bool GetCurrentThreadIdentifier(ID* identifier) WARN_UNUSED_RESULT; |
202 | 204 |
203 // Callers can hold on to a refcounted SingleThreadTaskRunner beyond the | 205 // Callers can hold on to a refcounted SingleThreadTaskRunner beyond the |
204 // lifetime of the thread. | 206 // lifetime of the thread. |
205 static scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunnerForThread( | 207 static scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunnerForThread( |
206 ID identifier); | 208 ID identifier); |
207 | 209 |
| 210 // Sets the delegate for the specified WebThread. |
| 211 // |
| 212 // Only one delegate may be registered at a time. Delegates may be |
| 213 // unregistered by providing a nullptr pointer. |
| 214 // |
| 215 // If the caller unregisters a delegate before CleanUp has been |
| 216 // called, it must perform its own locking to ensure the delegate is |
| 217 // not deleted while unregistering. |
| 218 static void SetDelegate(ID identifier, WebThreadDelegate* delegate); |
| 219 |
208 // Returns an appropriate error message for when | 220 // Returns an appropriate error message for when |
209 // DCHECK_CURRENTLY_ON_WEB_THREAD() fails. | 221 // DCHECK_CURRENTLY_ON_WEB_THREAD() fails. |
210 static std::string GetDCheckCurrentlyOnErrorMessage(ID expected); | 222 static std::string GetDCheckCurrentlyOnErrorMessage(ID expected); |
211 | 223 |
212 private: | 224 private: |
213 friend class WebThreadImpl; | 225 friend class WebThreadImpl; |
214 | 226 |
215 WebThread() {} | 227 WebThread() {} |
216 DISALLOW_COPY_AND_ASSIGN(WebThread); | 228 DISALLOW_COPY_AND_ASSIGN(WebThread); |
217 }; | 229 }; |
218 | 230 |
219 } // namespace web | 231 } // namespace web |
220 | 232 |
221 #endif // IOS_WEB_PUBLIC_WEB_THREAD_H_ | 233 #endif // IOS_WEB_PUBLIC_WEB_THREAD_H_ |
OLD | NEW |