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

Side by Side Diff: content/child/worker_thread_registry.cc

Issue 2422933002: Reduce usage of FOR_EACH_OBSERVER macro in content/ (Closed)
Patch Set: Created 4 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
« no previous file with comments | « no previous file | content/public/test/mock_download_item.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 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"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 g_observers_tls.Pointer()->Set(new WorkerThreadObservers()); 100 g_observers_tls.Pointer()->Set(new WorkerThreadObservers());
101 int id = base::PlatformThread::CurrentId(); 101 int id = base::PlatformThread::CurrentId();
102 base::AutoLock locker_(task_runner_map_lock_); 102 base::AutoLock locker_(task_runner_map_lock_);
103 task_runner_map_[id] = base::ThreadTaskRunnerHandle::Get().get(); 103 task_runner_map_[id] = base::ThreadTaskRunnerHandle::Get().get();
104 CHECK(task_runner_map_[id]); 104 CHECK(task_runner_map_[id]);
105 } 105 }
106 106
107 void WorkerThreadRegistry::WillStopCurrentWorkerThread() { 107 void WorkerThreadRegistry::WillStopCurrentWorkerThread() {
108 WorkerThreadObservers* observers = g_observers_tls.Pointer()->Get(); 108 WorkerThreadObservers* observers = g_observers_tls.Pointer()->Get();
109 DCHECK(observers); 109 DCHECK(observers);
110 FOR_EACH_OBSERVER(WorkerThread::Observer, *observers, 110 for (auto& observer : *observers)
111 WillStopCurrentWorkerThread()); 111 observer.WillStopCurrentWorkerThread();
112
112 { 113 {
113 base::AutoLock locker(task_runner_map_lock_); 114 base::AutoLock locker(task_runner_map_lock_);
114 task_runner_map_.erase(WorkerThread::GetCurrentId()); 115 task_runner_map_.erase(WorkerThread::GetCurrentId());
115 } 116 }
116 delete observers; 117 delete observers;
117 g_observers_tls.Pointer()->Set(nullptr); 118 g_observers_tls.Pointer()->Set(nullptr);
118 } 119 }
119 120
120 base::TaskRunner* WorkerThreadRegistry::GetTaskRunnerFor(int worker_id) { 121 base::TaskRunner* WorkerThreadRegistry::GetTaskRunnerFor(int worker_id) {
121 base::AutoLock locker(task_runner_map_lock_); 122 base::AutoLock locker(task_runner_map_lock_);
122 return base::ContainsKey(task_runner_map_, worker_id) 123 return base::ContainsKey(task_runner_map_, worker_id)
123 ? task_runner_map_[worker_id] 124 ? task_runner_map_[worker_id]
124 : task_runner_for_dead_worker_.get(); 125 : task_runner_for_dead_worker_.get();
125 } 126 }
126 127
127 bool WorkerThreadRegistry::PostTask(int id, const base::Closure& closure) { 128 bool WorkerThreadRegistry::PostTask(int id, const base::Closure& closure) {
128 DCHECK(id > 0); 129 DCHECK(id > 0);
129 base::AutoLock locker(task_runner_map_lock_); 130 base::AutoLock locker(task_runner_map_lock_);
130 IDToTaskRunnerMap::iterator found = task_runner_map_.find(id); 131 IDToTaskRunnerMap::iterator found = task_runner_map_.find(id);
131 if (found == task_runner_map_.end()) 132 if (found == task_runner_map_.end())
132 return false; 133 return false;
133 return found->second->PostTask(FROM_HERE, closure); 134 return found->second->PostTask(FROM_HERE, closure);
134 } 135 }
135 136
136 } // namespace content 137 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/public/test/mock_download_item.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698