diff options
author | scottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-14 03:35:03 +0000 |
---|---|---|
committer | scottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-14 03:35:03 +0000 |
commit | 556fcc7dc476a0292e3b3dee21ab11faa6389bb1 (patch) | |
tree | 7a7171bdf8d5a8a2c8a0d695a4d96ae5c24b1c8d /webkit/glue | |
parent | fcea4ec67846e2326a8004c1c3b352ff987933cb (diff) | |
download | chromium_src-556fcc7dc476a0292e3b3dee21ab11faa6389bb1.zip chromium_src-556fcc7dc476a0292e3b3dee21ab11faa6389bb1.tar.gz chromium_src-556fcc7dc476a0292e3b3dee21ab11faa6389bb1.tar.bz2 |
move webkit/glue/worker_task_* to webkit/child/
(pipelined on https://codereview.chromium.org/16816003/)
TBR=jam@chromium.org, jamesr@chromium.org, michaeln@chromium.org
BUG=237249
Review URL: https://codereview.chromium.org/16834004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@206283 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue')
-rw-r--r-- | webkit/glue/webkit_glue.gypi | 5 | ||||
-rw-r--r-- | webkit/glue/webkitplatformsupport_impl.cc | 13 | ||||
-rw-r--r-- | webkit/glue/webkitplatformsupport_impl.h | 5 | ||||
-rw-r--r-- | webkit/glue/worker_task_runner.cc | 103 | ||||
-rw-r--r-- | webkit/glue/worker_task_runner.h | 58 | ||||
-rw-r--r-- | webkit/glue/worker_task_runner_unittest.cc | 56 |
6 files changed, 3 insertions, 237 deletions
diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi index 1893ba5..562beb1 100644 --- a/webkit/glue/webkit_glue.gypi +++ b/webkit/glue/webkit_glue.gypi @@ -64,6 +64,7 @@ ], 'dependencies': [ '<(DEPTH)/base/base.gyp:base', + '<(DEPTH)/base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', '<(DEPTH)/third_party/WebKit/Source/WebKit/chromium/WebKit.gyp:webkit', '<(DEPTH)/ui/ui.gyp:ui', @@ -86,6 +87,8 @@ '../child/webkit_child_export.h', '../child/webkitplatformsupport_child_impl.cc', '../child/webkitplatformsupport_child_impl.h', + '../child/worker_task_runner.cc', + '../child/worker_task_runner.h', ], 'conditions': [ @@ -290,8 +293,6 @@ 'weburlloader_impl.h', 'web_io_operators.cc', 'web_io_operators.h', - 'worker_task_runner.cc', - 'worker_task_runner.h', ], # When glue is a dependency, it needs to be a hard dependency. # Dependents may rely on files generated by this target or one of its diff --git a/webkit/glue/webkitplatformsupport_impl.cc b/webkit/glue/webkitplatformsupport_impl.cc index 704dfc7..91109de 100644 --- a/webkit/glue/webkitplatformsupport_impl.cc +++ b/webkit/glue/webkitplatformsupport_impl.cc @@ -50,7 +50,6 @@ #include "webkit/glue/websocketstreamhandle_impl.h" #include "webkit/glue/webthread_impl.h" #include "webkit/glue/weburlloader_impl.h" -#include "webkit/glue/worker_task_runner.h" #include "webkit/plugins/npapi/plugin_instance.h" #include "webkit/plugins/webplugininfo.h" #include "webkit/renderer/media/audio_decoder.h" @@ -961,18 +960,6 @@ void WebKitPlatformSupportImpl::DestroyCurrentThread(void* thread) { delete impl; } -void WebKitPlatformSupportImpl::didStartWorkerRunLoop( - const WebKit::WebWorkerRunLoop& runLoop) { - WorkerTaskRunner* worker_task_runner = WorkerTaskRunner::Instance(); - worker_task_runner->OnWorkerRunLoopStarted(runLoop); -} - -void WebKitPlatformSupportImpl::didStopWorkerRunLoop( - const WebKit::WebWorkerRunLoop& runLoop) { - WorkerTaskRunner* worker_task_runner = WorkerTaskRunner::Instance(); - worker_task_runner->OnWorkerRunLoopStopped(runLoop); -} - WebKit::WebDiscardableMemory* WebKitPlatformSupportImpl::allocateAndLockDiscardableMemory(size_t bytes) { if (!base::DiscardableMemory::Supported()) diff --git a/webkit/glue/webkitplatformsupport_impl.h b/webkit/glue/webkitplatformsupport_impl.h index b187c82..d7a64bc 100644 --- a/webkit/glue/webkitplatformsupport_impl.h +++ b/webkit/glue/webkitplatformsupport_impl.h @@ -159,11 +159,6 @@ class WEBKIT_GLUE_EXPORT WebKitPlatformSupportImpl : void ResumeSharedTimer(); virtual void OnStartSharedTimer(base::TimeDelta delay) {} - virtual void didStartWorkerRunLoop( - const WebKit::WebWorkerRunLoop& runLoop) OVERRIDE; - virtual void didStopWorkerRunLoop( - const WebKit::WebWorkerRunLoop& runLoop) OVERRIDE; - #if defined(OS_ANDROID) virtual webkit_media::WebAudioMediaCodecRunner GetWebAudioMediaCodecRunner(); diff --git a/webkit/glue/worker_task_runner.cc b/webkit/glue/worker_task_runner.cc deleted file mode 100644 index 476a7fe..0000000 --- a/webkit/glue/worker_task_runner.cc +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright (c) 2012 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); -} - -bool 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)); - return found != loop_map_.end(); -} - -int WorkerTaskRunner::CurrentWorkerId() { - if (!current_tls_.Get()) - return 0; - return current_tls_.Get()->id_; -} - -WorkerTaskRunner* WorkerTaskRunner::Instance() { - static base::LazyInstance<WorkerTaskRunner>::Leaky - 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 diff --git a/webkit/glue/worker_task_runner.h b/webkit/glue/worker_task_runner.h deleted file mode 100644 index 8e84b88..0000000 --- a/webkit/glue/worker_task_runner.h +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2012 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. - -#ifndef WEBKIT_GLUE_WORKER_TASK_RUNNER_H_ -#define WEBKIT_GLUE_WORKER_TASK_RUNNER_H_ - -#include <map> - -#include "base/atomic_sequence_num.h" -#include "base/callback_forward.h" -#include "base/synchronization/lock.h" -#include "base/threading/thread_local.h" -#include "third_party/WebKit/public/platform/WebWorkerRunLoop.h" -#include "webkit/glue/webkit_glue_export.h" - -namespace webkit_glue { - -class WEBKIT_GLUE_EXPORT WorkerTaskRunner { - public: - WorkerTaskRunner(); - - bool PostTask(int id, const base::Closure& task); - int CurrentWorkerId(); - static WorkerTaskRunner* Instance(); - - class WEBKIT_GLUE_EXPORT Observer { - public: - virtual ~Observer() {} - virtual void OnWorkerRunLoopStopped() = 0; - }; - // Add/Remove an observer that will get notified when the current worker run - // loop is stopping. This observer will not get notified when other threads - // are stopping. It's only valid to call these on a worker thread. - void AddStopObserver(Observer* observer); - void RemoveStopObserver(Observer* observer); - - private: - friend class WebKitPlatformSupportImpl; - friend class WorkerTaskRunnerTest; - - typedef std::map<int, WebKit::WebWorkerRunLoop> IDToLoopMap; - - ~WorkerTaskRunner(); - void OnWorkerRunLoopStarted(const WebKit::WebWorkerRunLoop& loop); - void OnWorkerRunLoopStopped(const WebKit::WebWorkerRunLoop& loop); - - struct ThreadLocalState; - base::ThreadLocalPointer<ThreadLocalState> current_tls_; - - base::AtomicSequenceNumber id_sequence_; - IDToLoopMap loop_map_; - base::Lock loop_map_lock_; -}; - -} // namespace webkit_glue - -#endif // WEBKIT_GLUE_WORKER_TASK_RUNNER_H_ diff --git a/webkit/glue/worker_task_runner_unittest.cc b/webkit/glue/worker_task_runner_unittest.cc deleted file mode 100644 index 0ac4f2e..0000000 --- a/webkit/glue/worker_task_runner_unittest.cc +++ /dev/null @@ -1,56 +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/logging.h" -#include "testing/gmock/include/gmock/gmock.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "webkit/glue/worker_task_runner.h" - -namespace webkit_glue { - -class WorkerTaskRunnerTest : public testing::Test { - public: - void FakeStart() { - task_runner_.OnWorkerRunLoopStarted(WebKit::WebWorkerRunLoop()); - } - void FakeStop() { - task_runner_.OnWorkerRunLoopStopped(WebKit::WebWorkerRunLoop()); - } - WorkerTaskRunner task_runner_; -}; - -class MockObserver : public WorkerTaskRunner::Observer { - public: - MOCK_METHOD0(OnWorkerRunLoopStopped, void()); - void RemoveSelfOnNotify() { - ON_CALL(*this, OnWorkerRunLoopStopped()).WillByDefault( - testing::Invoke(this, &MockObserver::RemoveSelf)); - } - void RemoveSelf() { - runner_->RemoveStopObserver(this); - } - WorkerTaskRunner* runner_; -}; - -TEST_F(WorkerTaskRunnerTest, BasicObservingAndWorkerId) { - ASSERT_EQ(0, task_runner_.CurrentWorkerId()); - MockObserver o; - EXPECT_CALL(o, OnWorkerRunLoopStopped()).Times(1); - FakeStart(); - task_runner_.AddStopObserver(&o); - ASSERT_LT(0, task_runner_.CurrentWorkerId()); - FakeStop(); -} - -TEST_F(WorkerTaskRunnerTest, CanRemoveSelfDuringNotification) { - MockObserver o; - o.RemoveSelfOnNotify(); - o.runner_ = &task_runner_; - EXPECT_CALL(o, OnWorkerRunLoopStopped()).Times(1); - FakeStart(); - task_runner_.AddStopObserver(&o); - FakeStop(); -} - -} |