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 CONTENT_CHILD_WORKER_THREAD_REGISTRY_H_ | 5 #ifndef CONTENT_CHILD_WORKER_THREAD_REGISTRY_H_ |
6 #define CONTENT_CHILD_WORKER_THREAD_REGISTRY_H_ | 6 #define CONTENT_CHILD_WORKER_THREAD_REGISTRY_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 // Always returns a non-null task runner regardless of whether the | 33 // Always returns a non-null task runner regardless of whether the |
34 // corresponding worker thread is gone or not. If the thread is already gone | 34 // corresponding worker thread is gone or not. If the thread is already gone |
35 // the tasks posted onto the task runner will be silently discarded. | 35 // the tasks posted onto the task runner will be silently discarded. |
36 base::TaskRunner* GetTaskRunnerFor(int worker_id); | 36 base::TaskRunner* GetTaskRunnerFor(int worker_id); |
37 | 37 |
38 private: | 38 private: |
39 friend class WorkerThread; | 39 friend class WorkerThread; |
40 friend class WorkerThreadRegistryTest; | 40 friend class WorkerThreadRegistryTest; |
41 | 41 |
42 bool PostTask(int id, base::Closure task); | 42 bool PostTask(int id, base::OnceClosure task); |
43 | 43 |
44 using IDToTaskRunnerMap = std::map<base::PlatformThreadId, base::TaskRunner*>; | 44 using IDToTaskRunnerMap = std::map<base::PlatformThreadId, base::TaskRunner*>; |
45 | 45 |
46 ~WorkerThreadRegistry(); | 46 ~WorkerThreadRegistry(); |
47 | 47 |
48 // It is possible for an IPC message to arrive for a worker thread that has | 48 // It is possible for an IPC message to arrive for a worker thread that has |
49 // already gone away. In such cases, it is still necessary to provide a | 49 // already gone away. In such cases, it is still necessary to provide a |
50 // task-runner for that particular thread, because otherwise the message will | 50 // task-runner for that particular thread, because otherwise the message will |
51 // end up being handled as per usual in the main-thread, causing incorrect | 51 // end up being handled as per usual in the main-thread, causing incorrect |
52 // results. |task_runner_for_dead_worker_| is used to handle such messages, | 52 // results. |task_runner_for_dead_worker_| is used to handle such messages, |
53 // which silently discards all the tasks it receives. | 53 // which silently discards all the tasks it receives. |
54 scoped_refptr<base::TaskRunner> task_runner_for_dead_worker_; | 54 scoped_refptr<base::TaskRunner> task_runner_for_dead_worker_; |
55 | 55 |
56 IDToTaskRunnerMap task_runner_map_; | 56 IDToTaskRunnerMap task_runner_map_; |
57 base::Lock task_runner_map_lock_; | 57 base::Lock task_runner_map_lock_; |
58 }; | 58 }; |
59 | 59 |
60 } // namespace content | 60 } // namespace content |
61 | 61 |
62 #endif // CONTENT_CHILD_WORKER_THREAD_REGISTRY_H_ | 62 #endif // CONTENT_CHILD_WORKER_THREAD_REGISTRY_H_ |
OLD | NEW |