| Index: base/task_scheduler/utils.cc | 
| diff --git a/base/task_scheduler/utils.cc b/base/task_scheduler/utils.cc | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..d43028fe7773dcf82199470d98bb971d58393220 | 
| --- /dev/null | 
| +++ b/base/task_scheduler/utils.cc | 
| @@ -0,0 +1,47 @@ | 
| +// Copyright 2016 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/task_scheduler/utils.h" | 
| + | 
| +#include <utility> | 
| + | 
| +#include "base/logging.h" | 
| +#include "base/memory/ptr_util.h" | 
| +#include "base/task_scheduler/priority_queue.h" | 
| +#include "base/task_scheduler/sequence_sort_key.h" | 
| +#include "base/task_scheduler/task_tracker.h" | 
| + | 
| +namespace base { | 
| +namespace internal { | 
| + | 
| +bool PostTaskHelper(std::unique_ptr<Task> task, | 
| +                    scoped_refptr<Sequence> sequence, | 
| +                    PriorityQueue* priority_queue, | 
| +                    TaskTracker* task_tracker) { | 
| +  DCHECK(task); | 
| +  DCHECK(sequence); | 
| +  DCHECK(priority_queue); | 
| +  DCHECK(task_tracker); | 
| + | 
| +  if (!task_tracker->WillPostTask(task.get())) | 
| +    return false; | 
| + | 
| +  const bool sequence_was_empty = sequence->PushTask(std::move(task)); | 
| +  if (sequence_was_empty) { | 
| +    // Insert |sequence| in |priority_queue| if it was empty before |task| was | 
| +    // inserted into it. When that's not the case, one of these must be true: | 
| +    // - |sequence| is already in a PriorityQueue, or, | 
| +    // - A worker thread is running a Task from |sequence|. It will insert | 
| +    //   |sequence| in a PriorityQueue once it's done running the Task. | 
| +    const auto sequence_sort_key = sequence->GetSortKey(); | 
| +    priority_queue->BeginTransaction()->Push( | 
| +        WrapUnique(new PriorityQueue::SequenceAndSortKey(std::move(sequence), | 
| +                                                         sequence_sort_key))); | 
| +  } | 
| + | 
| +  return true; | 
| +} | 
| + | 
| +}  // namespace internal | 
| +}  // namespace base | 
|  |