• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 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.
4 
5 #include "base/task_scheduler/task_traits.h"
6 
7 #include <stddef.h>
8 
9 #include <ostream>
10 
11 namespace base {
12 
13 // Do not rely on defaults hard-coded below beyond the guarantees described in
14 // the header; anything else is subject to change. Tasks should explicitly
15 // request defaults if the behavior is critical to the task.
TaskTraits()16 TaskTraits::TaskTraits()
17     : with_file_io_(false),
18       priority_(TaskPriority::BACKGROUND),
19       shutdown_behavior_(TaskShutdownBehavior::SKIP_ON_SHUTDOWN) {}
20 
21 TaskTraits::~TaskTraits() = default;
22 
WithFileIO()23 TaskTraits& TaskTraits::WithFileIO() {
24   with_file_io_ = true;
25   return *this;
26 }
27 
WithPriority(TaskPriority priority)28 TaskTraits& TaskTraits::WithPriority(TaskPriority priority) {
29   priority_ = priority;
30   return *this;
31 }
32 
WithShutdownBehavior(TaskShutdownBehavior shutdown_behavior)33 TaskTraits& TaskTraits::WithShutdownBehavior(
34     TaskShutdownBehavior shutdown_behavior) {
35   shutdown_behavior_ = shutdown_behavior;
36   return *this;
37 }
38 
operator <<(std::ostream & os,const TaskPriority & task_priority)39 std::ostream& operator<<(std::ostream& os, const TaskPriority& task_priority) {
40   switch (task_priority) {
41     case TaskPriority::BACKGROUND:
42       os << "BACKGROUND";
43       break;
44     case TaskPriority::USER_VISIBLE:
45       os << "USER_VISIBLE";
46       break;
47     case TaskPriority::USER_BLOCKING:
48       os << "USER_BLOCKING";
49       break;
50   }
51   return os;
52 }
53 
operator <<(std::ostream & os,const TaskShutdownBehavior & shutdown_behavior)54 std::ostream& operator<<(std::ostream& os,
55                          const TaskShutdownBehavior& shutdown_behavior) {
56   switch (shutdown_behavior) {
57     case TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN:
58       os << "CONTINUE_ON_SHUTDOWN";
59       break;
60     case TaskShutdownBehavior::SKIP_ON_SHUTDOWN:
61       os << "SKIP_ON_SHUTDOWN";
62       break;
63     case TaskShutdownBehavior::BLOCK_SHUTDOWN:
64       os << "BLOCK_SHUTDOWN";
65       break;
66   }
67   return os;
68 }
69 
70 }  // namespace base
71