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 #include "content/child/worker_thread_registry.h" | 5 #include "content/child/worker_thread_registry.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/threading/thread_local.h" | 16 #include "base/threading/thread_local.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
18 #include "content/public/child/worker_thread.h" | 18 #include "content/public/child/worker_thread.h" |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 using WorkerThreadObservers = base::ObserverList<WorkerThread::Observer>; | 24 using WorkerThreadObservers = base::ObserverList<WorkerThread::Observer>; |
25 using ThreadLocalWorkerThreadObservers = | 25 using ThreadLocalWorkerThreadObservers = |
26 base::ThreadLocalPointer<WorkerThreadObservers>; | 26 base::ThreadLocalPointer<WorkerThreadObservers>; |
27 | 27 |
28 // Stores a WorkerThreadObservers instance per thread. | 28 // Stores a WorkerThreadObservers instance per thread. |
29 base::LazyInstance<ThreadLocalWorkerThreadObservers> g_observers_tls = | 29 base::LazyInstance<ThreadLocalWorkerThreadObservers>::DestructorAtExit |
30 LAZY_INSTANCE_INITIALIZER; | 30 g_observers_tls = LAZY_INSTANCE_INITIALIZER; |
31 | 31 |
32 // A task-runner that refuses to run any tasks. | 32 // A task-runner that refuses to run any tasks. |
33 class DoNothingTaskRunner : public base::TaskRunner { | 33 class DoNothingTaskRunner : public base::TaskRunner { |
34 public: | 34 public: |
35 DoNothingTaskRunner() {} | 35 DoNothingTaskRunner() {} |
36 | 36 |
37 private: | 37 private: |
38 ~DoNothingTaskRunner() override {} | 38 ~DoNothingTaskRunner() override {} |
39 | 39 |
40 bool PostDelayedTask(const tracked_objects::Location& from_here, | 40 bool PostDelayedTask(const tracked_objects::Location& from_here, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 bool WorkerThreadRegistry::PostTask(int id, const base::Closure& closure) { | 128 bool WorkerThreadRegistry::PostTask(int id, const base::Closure& closure) { |
129 DCHECK(id > 0); | 129 DCHECK(id > 0); |
130 base::AutoLock locker(task_runner_map_lock_); | 130 base::AutoLock locker(task_runner_map_lock_); |
131 IDToTaskRunnerMap::iterator found = task_runner_map_.find(id); | 131 IDToTaskRunnerMap::iterator found = task_runner_map_.find(id); |
132 if (found == task_runner_map_.end()) | 132 if (found == task_runner_map_.end()) |
133 return false; | 133 return false; |
134 return found->second->PostTask(FROM_HERE, closure); | 134 return found->second->PostTask(FROM_HERE, closure); |
135 } | 135 } |
136 | 136 |
137 } // namespace content | 137 } // namespace content |
OLD | NEW |