| OLD | NEW | 
|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "components/task_scheduler_util/renderer/initialization.h" | 5 #include "components/task_scheduler_util/renderer/initialization.h" | 
| 6 | 6 | 
| 7 #include <map> |  | 
| 8 #include <string> |  | 
| 9 |  | 
| 10 #include "base/command_line.h" | 7 #include "base/command_line.h" | 
| 11 #include "base/logging.h" | 8 #include "base/memory/ptr_util.h" | 
| 12 #include "base/task_scheduler/task_traits.h" |  | 
| 13 #include "base/threading/platform_thread.h" |  | 
| 14 #include "components/task_scheduler_util/common/variations_util.h" | 9 #include "components/task_scheduler_util/common/variations_util.h" | 
| 15 | 10 | 
| 16 namespace task_scheduler_util { | 11 namespace task_scheduler_util { | 
| 17 | 12 | 
| 18 namespace { | 13 std::unique_ptr<base::TaskSchedulerInitParams> | 
|  | 14 GetRendererTaskSchedulerInitParamsFromCommandLine() { | 
|  | 15   auto variation_params = GetVariationParamsFromCommandLine( | 
|  | 16       *base::CommandLine::ForCurrentProcess()); | 
| 19 | 17 | 
| 20 enum WorkerPoolType : size_t { | 18   auto init_params = base::MakeUnique<base::TaskSchedulerInitParams>( | 
| 21   BACKGROUND = 0, | 19       StringToVariableWorkerPoolParams(variation_params["RendererBackground"]), | 
| 22   BACKGROUND_BLOCKING, | 20       StringToVariableWorkerPoolParams( | 
| 23   FOREGROUND, | 21           variation_params["RendererBackgroundBlocking"]), | 
| 24   FOREGROUND_BLOCKING, | 22       StringToVariableWorkerPoolParams(variation_params["RendererForeground"]), | 
| 25   WORKER_POOL_COUNT  // Always last. | 23       StringToVariableWorkerPoolParams( | 
| 26 }; | 24           variation_params["RendererForegroundBlocking"])); | 
| 27 | 25 | 
| 28 }  // namespace | 26   if (init_params->IsValid()) | 
|  | 27     return init_params; | 
| 29 | 28 | 
| 30 std::vector<base::SchedulerWorkerPoolParams> GetRendererWorkerPoolParams() { | 29   return nullptr; | 
| 31   using ThreadPriority = base::ThreadPriority; |  | 
| 32   std::vector<SchedulerImmutableWorkerPoolParams> immutable_worker_pool_params; |  | 
| 33   DCHECK_EQ(BACKGROUND, immutable_worker_pool_params.size()); |  | 
| 34   immutable_worker_pool_params.emplace_back("RendererBackground", |  | 
| 35                                             ThreadPriority::BACKGROUND); |  | 
| 36   DCHECK_EQ(BACKGROUND_BLOCKING, immutable_worker_pool_params.size()); |  | 
| 37   immutable_worker_pool_params.emplace_back("RendererBackgroundBlocking", |  | 
| 38                                             ThreadPriority::BACKGROUND); |  | 
| 39   DCHECK_EQ(FOREGROUND, immutable_worker_pool_params.size()); |  | 
| 40   immutable_worker_pool_params.emplace_back("RendererForeground", |  | 
| 41                                             ThreadPriority::NORMAL); |  | 
| 42   DCHECK_EQ(FOREGROUND_BLOCKING, immutable_worker_pool_params.size()); |  | 
| 43   immutable_worker_pool_params.emplace_back("RendererForegroundBlocking", |  | 
| 44                                             ThreadPriority::NORMAL); |  | 
| 45   return GetWorkerPoolParams(immutable_worker_pool_params, |  | 
| 46                              GetVariationParamsFromCommandLine( |  | 
| 47                                  *base::CommandLine::ForCurrentProcess())); |  | 
| 48 } |  | 
| 49 |  | 
| 50 size_t RendererWorkerPoolIndexForTraits(const base::TaskTraits& traits) { |  | 
| 51   const bool is_background = |  | 
| 52       traits.priority() == base::TaskPriority::BACKGROUND; |  | 
| 53   if (traits.may_block() || traits.with_base_sync_primitives()) |  | 
| 54     return is_background ? BACKGROUND_BLOCKING : FOREGROUND_BLOCKING; |  | 
| 55   return is_background ? BACKGROUND : FOREGROUND; |  | 
| 56 } | 30 } | 
| 57 | 31 | 
| 58 }  // namespace task_scheduler_util | 32 }  // namespace task_scheduler_util | 
| OLD | NEW | 
|---|