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

Side by Side Diff: webkit/glue/worker_task_runner.cc

Issue 8785013: Track webcore worker message loops in chromium. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove debug code Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « webkit/glue/worker_task_runner.h ('k') | webkit/glue/worker_task_runner_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/callback.h"
6 #include "base/lazy_instance.h"
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "webkit/glue/worker_task_runner.h"
10
11 using WebKit::WebWorkerRunLoop;
12
13 namespace {
14
15 class RunClosureTask : public WebKit::WebWorkerRunLoop::Task {
16 public:
17 RunClosureTask(const base::Closure& task) : task_(task) { }
18 virtual ~RunClosureTask() { }
19 virtual void Run() {
20 task_.Run();
21 }
22 private:
23 base::Closure task_;
24 };
25
26 }
27
28 namespace webkit_glue {
29
30 WorkerTaskRunner::WorkerTaskRunner() : id_sequence_(0) {
31 }
32
33 void WorkerTaskRunner::PostTask(
34 int id, const base::Closure& closure) {
35 DCHECK(id > 0);
36 base::AutoLock locker_(lock_);
37 IDToLoopMap::iterator found = loop_map_.find(id);
38 if (found != loop_map_.end())
39 found->second.postTask(new RunClosureTask(closure));
40 }
41
42 int WorkerTaskRunner::CurrentWorkerId() {
43 if (!current_tls_.Get())
44 return 0;
45 return current_tls_.Get()->first;
46 }
47
48 WorkerTaskRunner* WorkerTaskRunner::Instance() {
49 static base::LazyInstance<WorkerTaskRunner,
50 base::LeakyLazyInstanceTraits<WorkerTaskRunner> >
51 worker_task_runner_ = LAZY_INSTANCE_INITIALIZER;
52 return worker_task_runner_.Pointer();
53 }
54
55 void WorkerTaskRunner::AddObserver(Observer* obs) {
56 base::AutoLock locker(observer_lock_);
57 observer_list_.insert(obs);
58 }
59
60 int WorkerTaskRunner::RemoveObserver(Observer* obs) {
61 base::AutoLock locker(observer_lock_);
62 return observer_list_.erase(obs);
63 }
64
65 WorkerTaskRunner::~WorkerTaskRunner() {
66 }
67
68 void WorkerTaskRunner::OnWorkerRunLoopStarted(const WebWorkerRunLoop& loop) {
69 DCHECK(!current_tls_.Get());
70 {
71 base::AutoLock locker_(lock_);
72 int id = ++id_sequence_;
73 current_tls_.Set(new std::pair<int, WebWorkerRunLoop>(id, loop));
74 loop_map_[id] = loop;
75 }
76 observer_lock_.Acquire();
77 ObserverList observers_snapshot(observer_list_);
78 observer_lock_.Release();
79 for(ObserverList::iterator iter = observers_snapshot.begin();
80 iter != observers_snapshot.end(); iter++) {
81 (*iter)->OnWorkerRunLoopStarted();
82 }
83 }
84
85 void WorkerTaskRunner::OnWorkerRunLoopStopped(
86 const WebWorkerRunLoop& loop) {
87 DCHECK(CurrentWorkerId() > 0);
88 DCHECK(current_tls_.Get());
89 observer_lock_.Acquire();
90 ObserverList observers_snapshot(observer_list_);
michaeln 2011/12/09 20:45:34 This still doesn't work. As coded it's more amenab
91 observer_lock_.Release();
92 for(ObserverList::iterator iter = observers_snapshot.begin();
93 iter != observers_snapshot.end(); iter++) {
94 (*iter)->OnWorkerRunLoopStopped();
95 }
96 base::AutoLock locker_(lock_);
97 DCHECK(loop_map_[CurrentWorkerId()] == loop);
98 loop_map_.erase(CurrentWorkerId());
99 delete current_tls_.Get();
100 current_tls_.Set(NULL);
101 }
102
103 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « webkit/glue/worker_task_runner.h ('k') | webkit/glue/worker_task_runner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698