Revert of Re-enabled contenteditable and text-changed tests after content editable...
[chromium-blink-merge.git] / base / threading / worker_pool_win.cc
blob563702be15bf7931f771a3fe6870690a5fb58d99
1 // Copyright (c) 2012 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.
5 #include "base/threading/worker_pool.h"
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "base/logging.h"
10 #include "base/pending_task.h"
11 #include "base/threading/thread_local.h"
12 #include "base/trace_event/trace_event.h"
13 #include "base/tracked_objects.h"
15 namespace base {
17 namespace {
19 base::LazyInstance<ThreadLocalBoolean>::Leaky
20 g_worker_pool_running_on_this_thread = LAZY_INSTANCE_INITIALIZER;
22 DWORD CALLBACK WorkItemCallback(void* param) {
23 PendingTask* pending_task = static_cast<PendingTask*>(param);
24 TRACE_EVENT2("toplevel", "WorkItemCallback::Run",
25 "src_file", pending_task->posted_from.file_name(),
26 "src_func", pending_task->posted_from.function_name());
28 g_worker_pool_running_on_this_thread.Get().Set(true);
30 tracked_objects::TaskStopwatch stopwatch;
31 stopwatch.Start();
32 pending_task->task.Run();
33 stopwatch.Stop();
35 g_worker_pool_running_on_this_thread.Get().Set(false);
37 tracked_objects::ThreadData::TallyRunOnWorkerThreadIfTracking(
38 pending_task->birth_tally, pending_task->time_posted, stopwatch);
40 delete pending_task;
41 return 0;
44 // Takes ownership of |pending_task|
45 bool PostTaskInternal(PendingTask* pending_task, bool task_is_slow) {
46 ULONG flags = 0;
47 if (task_is_slow)
48 flags |= WT_EXECUTELONGFUNCTION;
50 if (!QueueUserWorkItem(WorkItemCallback, pending_task, flags)) {
51 DPLOG(ERROR) << "QueueUserWorkItem failed";
52 delete pending_task;
53 return false;
56 return true;
59 } // namespace
61 // static
62 bool WorkerPool::PostTask(const tracked_objects::Location& from_here,
63 const base::Closure& task, bool task_is_slow) {
64 PendingTask* pending_task = new PendingTask(from_here, task);
65 return PostTaskInternal(pending_task, task_is_slow);
68 // static
69 bool WorkerPool::RunsTasksOnCurrentThread() {
70 return g_worker_pool_running_on_this_thread.Get().Get();
73 // static
74 void WorkerPool::ShutDownCleanly() {
75 // TODO(yzshen): implement it.
76 NOTIMPLEMENTED();
79 } // namespace base