Use common code to set HttpNetworkSession::Param pointers.
[chromium-blink-merge.git] / content / renderer / raster_worker_pool.h
blobb8b4f358f2f2497dd9d5a6ad4f3a9efdab696386
1 // Copyright 2015 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 #ifndef CONTENT_RENDERER_RASTER_WORKER_POOL_H_
6 #define CONTENT_RENDERER_RASTER_WORKER_POOL_H_
8 #include "base/callback.h"
9 #include "base/containers/hash_tables.h"
10 #include "base/memory/scoped_vector.h"
11 #include "base/sequenced_task_runner.h"
12 #include "base/task_runner.h"
13 #include "base/threading/simple_thread.h"
14 #include "cc/raster/task_graph_runner.h"
15 #include "content/common/content_export.h"
17 namespace content {
19 // A pool of threads used to run raster work.
20 // Work can be scheduled on the threads using different interfaces.
21 // The pool itself implements TaskRunner interface and tasks posted via that
22 // interface might run in parallel.
23 // CreateSequencedTaskRunner creates a sequenced task runner that might run in
24 // parallel with other instances of sequenced task runners.
25 // It's also possible to get the underlying TaskGraphRunner to schedule a graph
26 // of tasks with their dependencies.
27 // TODO(reveman): make TaskGraphRunner an abstract interface and have this
28 // WorkerPool class implement it.
29 class CONTENT_EXPORT RasterWorkerPool
30 : public base::TaskRunner,
31 public base::DelegateSimpleThread::Delegate {
32 public:
33 RasterWorkerPool();
35 // Overridden from base::TaskRunner:
36 bool PostDelayedTask(const tracked_objects::Location& from_here,
37 const base::Closure& task,
38 base::TimeDelta delay) override;
39 bool RunsTasksOnCurrentThread() const override;
41 // Overridden from base::DelegateSimpleThread::Delegate:
42 void Run() override;
44 // Spawn |num_threads| number of threads and start running work on the
45 // worker threads.
46 void Start(int num_threads,
47 const base::SimpleThread::Options& thread_options);
49 // Finish running all the posted tasks (and nested task posted by those tasks)
50 // of all the associated task runners.
51 // Once all the tasks are executed the method blocks until the threads are
52 // terminated.
53 void Shutdown();
55 cc::TaskGraphRunner* GetTaskGraphRunner() { return &task_graph_runner_; }
57 // Create a new sequenced task graph runner.
58 scoped_refptr<base::SequencedTaskRunner> CreateSequencedTaskRunner();
60 protected:
61 ~RasterWorkerPool() override;
63 private:
64 class RasterWorkerPoolSequencedTaskRunner;
65 friend class RasterWorkerPoolSequencedTaskRunner;
67 // Simple Task for the TaskGraphRunner that wraps a closure.
68 // This class is used to schedule TaskRunner tasks on the
69 // |task_graph_runner_|.
70 class ClosureTask : public cc::Task {
71 public:
72 explicit ClosureTask(const base::Closure& closure);
74 // Overridden from cc::Task:
75 void RunOnWorkerThread() override;
77 protected:
78 ~ClosureTask() override;
80 private:
81 base::Closure closure_;
83 DISALLOW_COPY_AND_ASSIGN(ClosureTask);
86 // The actual threads where work is done.
87 ScopedVector<base::DelegateSimpleThread> threads_;
88 cc::TaskGraphRunner task_graph_runner_;
90 // Lock to exclusively access all the following members that are used to
91 // implement the TaskRunner interfaces.
92 base::Lock lock_;
93 // Namespace used to schedule tasks in the task graph runner.
94 cc::NamespaceToken namespace_token_;
95 // List of tasks currently queued up for execution.
96 cc::Task::Vector tasks_;
97 // Graph object used for scheduling tasks.
98 cc::TaskGraph graph_;
99 // Cached vector to avoid allocation when getting the list of complete
100 // tasks.
101 cc::Task::Vector completed_tasks_;
104 } // namespace content
106 #endif // CONTENT_RENDERER_RASTER_WORKER_POOL_H_