Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: components/task_scheduler_util/initialization/browser_util.cc

Issue 2565013002: Split browser-specific and generic code in components/task_scheduler_util/. (Closed)
Patch Set: CR robliao #21 + fix build error Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/task_scheduler_util/initialization/browser_util.cc
diff --git a/components/task_scheduler_util/initialization/browser_util.cc b/components/task_scheduler_util/initialization/browser_util.cc
index ff9bbf92ce5d139169bf975b8d4833cb162f8d1e..5dccd9987ad49ab24cc3d2417c2dfd1880685161 100644
--- a/components/task_scheduler_util/initialization/browser_util.cc
+++ b/components/task_scheduler_util/initialization/browser_util.cc
@@ -2,125 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/task_scheduler_util/initialization/browser_util.h"
+// TODO(fdoray): Remove this file once TaskScheduler initialization in the
+// browser process uses the components/task_scheduler_util/browser/ API on all
+// platforms.
-#include <map>
-#include <string>
+#include "components/task_scheduler_util/initialization/browser_util.h"
-#include "base/task_scheduler/initialization_util.h"
-#include "base/task_scheduler/switches.h"
-#include "base/task_scheduler/task_traits.h"
-#include "base/threading/sequenced_worker_pool.h"
+#include "components/task_scheduler_util/browser/initialization.h"
namespace task_scheduler_util {
namespace initialization {
-namespace {
-
-using StandbyThreadPolicy =
- base::SchedulerWorkerPoolParams::StandbyThreadPolicy;
-using ThreadPriority = base::ThreadPriority;
-
-struct SchedulerWorkerPoolCustomizableConfiguration {
- SchedulerWorkerPoolCustomizableConfiguration(
- const char* name_in,
- ThreadPriority priority_hint_in,
- const SingleWorkerPoolConfiguration& single_worker_pool_config_in)
- : name(name_in),
- priority_hint(priority_hint_in),
- single_worker_pool_config(single_worker_pool_config_in) {}
-
- const char* name;
- ThreadPriority priority_hint;
- const SingleWorkerPoolConfiguration& single_worker_pool_config;
-};
-
-} // namespace
-
-std::vector<base::SchedulerWorkerPoolParams>
-BrowserWorkerPoolConfigurationToSchedulerWorkerPoolParams(
- const BrowserWorkerPoolsConfiguration& config) {
- const SchedulerWorkerPoolCustomizableConfiguration worker_pool_config[] = {
- SchedulerWorkerPoolCustomizableConfiguration("Background",
- ThreadPriority::BACKGROUND,
- config.background),
- SchedulerWorkerPoolCustomizableConfiguration("BackgroundFileIO",
- ThreadPriority::BACKGROUND,
- config.background_file_io),
- SchedulerWorkerPoolCustomizableConfiguration("Foreground",
- ThreadPriority::NORMAL,
- config.foreground),
- SchedulerWorkerPoolCustomizableConfiguration("ForegroundFileIO",
- ThreadPriority::NORMAL,
- config.foreground_file_io),
-
- };
- static_assert(arraysize(worker_pool_config) == WORKER_POOL_COUNT,
- "Mismatched Worker Pool Types and Predefined Parameters");
- constexpr size_t kNumWorkerPoolsDefined = sizeof(config) /
- sizeof(config.background);
- static_assert(arraysize(worker_pool_config) == kNumWorkerPoolsDefined,
- "Mismatch in predefined parameters and worker pools.");
- std::vector<base::SchedulerWorkerPoolParams> params_vector;
- for (const auto& config : worker_pool_config) {
- params_vector.emplace_back(
- config.name, config.priority_hint,
- config.single_worker_pool_config.standby_thread_policy,
- config.single_worker_pool_config.threads,
- config.single_worker_pool_config.detach_period);
- }
- DCHECK_EQ(WORKER_POOL_COUNT, params_vector.size());
- return params_vector;
-}
-
// Returns the worker pool index for |traits| defaulting to FOREGROUND or
// FOREGROUND_FILE_IO on any priorities other than background.
size_t BrowserWorkerPoolIndexForTraits(const base::TaskTraits& traits) {
- const bool is_background =
- traits.priority() == base::TaskPriority::BACKGROUND;
- if (traits.with_file_io())
- return is_background ? BACKGROUND_FILE_IO : FOREGROUND_FILE_IO;
-
- return is_background ? BACKGROUND : FOREGROUND;
-}
-
-#if defined(OS_IOS)
-std::vector<base::SchedulerWorkerPoolParams>
-GetDefaultBrowserSchedulerWorkerPoolParams() {
- constexpr size_t kNumWorkerPoolsDefined =
- sizeof(BrowserWorkerPoolsConfiguration) /
- sizeof(SingleWorkerPoolConfiguration);
- static_assert(kNumWorkerPoolsDefined == 4,
- "Expected 4 worker pools in BrowserWorkerPoolsConfiguration");
- BrowserWorkerPoolsConfiguration config;
- constexpr size_t kSizeAssignedFields =
- sizeof(config.background.threads) +
- sizeof(config.background.detach_period) +
- sizeof(config.background.standby_thread_policy);
- static_assert(kSizeAssignedFields == sizeof(config.background),
- "Not all fields were assigned");
- config.background.standby_thread_policy = StandbyThreadPolicy::ONE;
- config.background.threads =
- base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0);
- config.background.detach_period = base::TimeDelta::FromSeconds(30);
-
- config.background_file_io.standby_thread_policy = StandbyThreadPolicy::ONE;
- config.background_file_io.threads =
- base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0);
- config.background_file_io.detach_period = base::TimeDelta::FromSeconds(30);
-
- config.foreground.standby_thread_policy = StandbyThreadPolicy::ONE;
- config.foreground.threads =
- base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.3, 0);
- config.foreground.detach_period = base::TimeDelta::FromSeconds(30);
-
- config.foreground_file_io.standby_thread_policy = StandbyThreadPolicy::ONE;
- config.foreground_file_io.threads =
- base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.3, 0);
- config.foreground_file_io.detach_period = base::TimeDelta::FromSeconds(30);
- return BrowserWorkerPoolConfigurationToSchedulerWorkerPoolParams(config);
+ return ::task_scheduler_util::BrowserWorkerPoolIndexForTraits(traits);
}
-#endif // defined(OS_IOS)
} // namespace initialization
} // namespace task_scheduler_util

Powered by Google App Engine
This is Rietveld 408576698