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

Unified Diff: webkit/glue/worker_task_runner.cc

Issue 8907009: Revert 114157 - Track webcore worker message loops in chromium. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/glue/worker_task_runner.cc
===================================================================
--- webkit/glue/worker_task_runner.cc (revision 114164)
+++ webkit/glue/worker_task_runner.cc (working copy)
@@ -1,103 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/callback.h"
-#include "base/lazy_instance.h"
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/observer_list.h"
-#include "webkit/glue/worker_task_runner.h"
-
-using WebKit::WebWorkerRunLoop;
-
-namespace {
-
-class RunClosureTask : public WebWorkerRunLoop::Task {
- public:
- RunClosureTask(const base::Closure& task) : task_(task) {}
- virtual ~RunClosureTask() {}
- virtual void Run() {
- task_.Run();
- }
- private:
- base::Closure task_;
-};
-
-} // unnamed namespace
-
-namespace webkit_glue {
-
-struct WorkerTaskRunner::ThreadLocalState {
- ThreadLocalState(int id, const WebWorkerRunLoop& loop)
- : id_(id), run_loop_(loop) {
- }
- int id_;
- WebWorkerRunLoop run_loop_;
- ObserverList<WorkerTaskRunner::Observer> stop_observers_;
-};
-
-WorkerTaskRunner::WorkerTaskRunner() {
- // Start worker ids at 1, 0 is reserved for the main thread.
- int id = id_sequence_.GetNext();
- DCHECK(!id);
-}
-
-void WorkerTaskRunner::PostTask(
- int id, const base::Closure& closure) {
- DCHECK(id > 0);
- base::AutoLock locker(loop_map_lock_);
- IDToLoopMap::iterator found = loop_map_.find(id);
- if (found != loop_map_.end())
- found->second.postTask(new RunClosureTask(closure));
-}
-
-int WorkerTaskRunner::CurrentWorkerId() {
- if (!current_tls_.Get())
- return 0;
- return current_tls_.Get()->id_;
-}
-
-WorkerTaskRunner* WorkerTaskRunner::Instance() {
- static base::LazyInstance<WorkerTaskRunner,
- base::LeakyLazyInstanceTraits<WorkerTaskRunner> >
- worker_task_runner = LAZY_INSTANCE_INITIALIZER;
- return worker_task_runner.Pointer();
-}
-
-void WorkerTaskRunner::AddStopObserver(Observer* obs) {
- DCHECK(CurrentWorkerId() > 0);
- current_tls_.Get()->stop_observers_.AddObserver(obs);
-}
-
-void WorkerTaskRunner::RemoveStopObserver(Observer* obs) {
- DCHECK(CurrentWorkerId() > 0);
- current_tls_.Get()->stop_observers_.RemoveObserver(obs);
-}
-
-WorkerTaskRunner::~WorkerTaskRunner() {
-}
-
-void WorkerTaskRunner::OnWorkerRunLoopStarted(const WebWorkerRunLoop& loop) {
- DCHECK(!current_tls_.Get());
- int id = id_sequence_.GetNext();
- current_tls_.Set(new ThreadLocalState(id, loop));
-
- base::AutoLock locker_(loop_map_lock_);
- loop_map_[id] = loop;
-}
-
-void WorkerTaskRunner::OnWorkerRunLoopStopped(const WebWorkerRunLoop& loop) {
- DCHECK(current_tls_.Get());
- FOR_EACH_OBSERVER(Observer, current_tls_.Get()->stop_observers_,
- OnWorkerRunLoopStopped());
- {
- base::AutoLock locker(loop_map_lock_);
- DCHECK(loop_map_[CurrentWorkerId()] == loop);
- loop_map_.erase(CurrentWorkerId());
- }
- delete current_tls_.Get();
- current_tls_.Set(NULL);
-}
-
-} // namespace webkit_glue
« 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