| 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_task_runner.h" | 5 #include "content/child/worker_task_runner.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
| 16 | 16 |
| 17 using blink::WebWorkerRunLoop; | |
| 18 | |
| 19 namespace content { | 17 namespace content { |
| 20 | 18 |
| 21 namespace { | 19 namespace { |
| 22 | 20 |
| 23 // A task-runner that refuses to run any tasks. | 21 // A task-runner that refuses to run any tasks. |
| 24 class DoNothingTaskRunner : public base::TaskRunner { | 22 class DoNothingTaskRunner : public base::TaskRunner { |
| 25 public: | 23 public: |
| 26 DoNothingTaskRunner() {} | 24 DoNothingTaskRunner() {} |
| 27 | 25 |
| 28 private: | 26 private: |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 } | 81 } |
| 84 | 82 |
| 85 void WorkerTaskRunner::RemoveStopObserver(Observer* obs) { | 83 void WorkerTaskRunner::RemoveStopObserver(Observer* obs) { |
| 86 DCHECK(CurrentWorkerId() > 0); | 84 DCHECK(CurrentWorkerId() > 0); |
| 87 current_tls_.Get()->stop_observers_.RemoveObserver(obs); | 85 current_tls_.Get()->stop_observers_.RemoveObserver(obs); |
| 88 } | 86 } |
| 89 | 87 |
| 90 WorkerTaskRunner::~WorkerTaskRunner() { | 88 WorkerTaskRunner::~WorkerTaskRunner() { |
| 91 } | 89 } |
| 92 | 90 |
| 93 void WorkerTaskRunner::OnWorkerRunLoopStarted(const WebWorkerRunLoop& loop) { | 91 void WorkerTaskRunner::OnWorkerRunLoopStarted() { |
| 94 DCHECK(!current_tls_.Get()); | 92 DCHECK(!current_tls_.Get()); |
| 95 DCHECK(!base::PlatformThread::CurrentRef().is_null()); | 93 DCHECK(!base::PlatformThread::CurrentRef().is_null()); |
| 96 current_tls_.Set(new ThreadLocalState()); | 94 current_tls_.Set(new ThreadLocalState()); |
| 97 | 95 |
| 98 int id = base::PlatformThread::CurrentId(); | 96 int id = base::PlatformThread::CurrentId(); |
| 99 base::AutoLock locker_(task_runner_map_lock_); | 97 base::AutoLock locker_(task_runner_map_lock_); |
| 100 task_runner_map_[id] = base::ThreadTaskRunnerHandle::Get().get(); | 98 task_runner_map_[id] = base::ThreadTaskRunnerHandle::Get().get(); |
| 101 CHECK(task_runner_map_[id]); | 99 CHECK(task_runner_map_[id]); |
| 102 } | 100 } |
| 103 | 101 |
| 104 void WorkerTaskRunner::OnWorkerRunLoopStopped(const WebWorkerRunLoop& loop) { | 102 void WorkerTaskRunner::OnWorkerRunLoopStopped() { |
| 105 DCHECK(current_tls_.Get()); | 103 DCHECK(current_tls_.Get()); |
| 106 FOR_EACH_OBSERVER(Observer, current_tls_.Get()->stop_observers_, | 104 FOR_EACH_OBSERVER(Observer, current_tls_.Get()->stop_observers_, |
| 107 OnWorkerRunLoopStopped()); | 105 OnWorkerRunLoopStopped()); |
| 108 { | 106 { |
| 109 base::AutoLock locker(task_runner_map_lock_); | 107 base::AutoLock locker(task_runner_map_lock_); |
| 110 task_runner_map_.erase(CurrentWorkerId()); | 108 task_runner_map_.erase(CurrentWorkerId()); |
| 111 } | 109 } |
| 112 delete current_tls_.Get(); | 110 delete current_tls_.Get(); |
| 113 current_tls_.Set(NULL); | 111 current_tls_.Set(NULL); |
| 114 } | 112 } |
| 115 | 113 |
| 116 base::TaskRunner* WorkerTaskRunner::GetTaskRunnerFor(int worker_id) { | 114 base::TaskRunner* WorkerTaskRunner::GetTaskRunnerFor(int worker_id) { |
| 117 base::AutoLock locker(task_runner_map_lock_); | 115 base::AutoLock locker(task_runner_map_lock_); |
| 118 return ContainsKey(task_runner_map_, worker_id) ? task_runner_map_[worker_id] | 116 return ContainsKey(task_runner_map_, worker_id) ? task_runner_map_[worker_id] |
| 119 : task_runner_for_dead_worker_.get(); | 117 : task_runner_for_dead_worker_.get(); |
| 120 } | 118 } |
| 121 | 119 |
| 122 } // namespace content | 120 } // namespace content |
| OLD | NEW |