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

Unified Diff: content/common/worker_task_runner.cc

Issue 8747002: Dispatch IndexedDB IPC messages to worker threads (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: repurpose obsolete indexed-db switch to control idb on workers 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
Index: content/common/worker_task_runner.cc
diff --git a/content/common/worker_task_runner.cc b/content/common/worker_task_runner.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0e3014103a9e92f8a905f059fd1670778b635948
--- /dev/null
+++ b/content/common/worker_task_runner.cc
@@ -0,0 +1,66 @@
+// 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 "content/common/worker_task_runner.h"
+
+WorkerTaskRunner::WorkerTaskRunner() : id_sequence_(0) {
+
+}
+
+WorkerTaskRunner::~WorkerTaskRunner() {
+}
+
+void WorkerTaskRunner::PostTask(
+ int id, WebKit::WebWorkerRunLoop::Task* closure) {
+ DCHECK(id > 0);
+ base::AutoLock locker_(lock_);
+ IDToLoopMap::iterator found = loop_map_.find(id);
+ if (found != loop_map_.end())
+ found->second.postTask(closure);
+ else
+ delete closure;
+}
+
+int WorkerTaskRunner::CurrentWorkerId() {
+ if (!current_tls_.Get())
+ return 0;
+ return current_tls_.Get()->first;
+}
+
+void WorkerTaskRunner::AddObserver(Observer* obs) {
+ base::AutoLock locker(observer_lock_);
+ observer_list_.AddObserver(obs);
+}
+
+void WorkerTaskRunner::RemoveObserver(Observer* obs) {
+ base::AutoLock locker(observer_lock_);
+ observer_list_.RemoveObserver(obs);
+}
+
+void WorkerTaskRunner::RegisterCurrentWorkerLoop(const WebWorkerRunLoop& loop) {
+ DCHECK(!current_tls_.Get());
+ {
+ base::AutoLock locker_(lock_);
+ int id = ++id_sequence_;
+ current_tls_.Set(new std::pair<int, WebWorkerRunLoop>(id, loop));
+ loop_map_[id] = loop;
+ }
+ base::AutoLock locker(observer_lock_);
+ FOR_EACH_OBSERVER(Observer, observer_list_, onLoopRegistered());
+}
+
+void WorkerTaskRunner::UnRegisterCurrentWorkerLoop(
+ const WebWorkerRunLoop& loop) {
+ DCHECK(CurrentWorkerId() > 0);
+ DCHECK(current_tls_.Get());
+ {
+ base::AutoLock lock(observer_lock_);
+ FOR_EACH_OBSERVER(Observer, observer_list_, onLoopUnregistered());
+ }
+ base::AutoLock locker_(lock_);
+ DCHECK(loop_map_[CurrentWorkerId()] == loop);
+ loop_map_.erase(CurrentWorkerId());
+ delete current_tls_.Get();
+ current_tls_.Set(NULL);
+}

Powered by Google App Engine
This is Rietveld 408576698