OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 #ifndef CONTENT_CHILD_RESOURCE_SCHEDULING_FILTER_H_ | 5 #ifndef CONTENT_CHILD_RESOURCE_SCHEDULING_FILTER_H_ |
6 #define CONTENT_CHILD_RESOURCE_SCHEDULING_FILTER_H_ | 6 #define CONTENT_CHILD_RESOURCE_SCHEDULING_FILTER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <memory> | 11 #include <memory> |
12 | 12 |
13 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
17 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
18 #include "ipc/message_filter.h" | 18 #include "ipc/message_filter.h" |
19 | 19 |
20 namespace blink { | |
21 class WebTaskRunner; | |
22 } | |
23 | |
24 namespace content { | 20 namespace content { |
25 class ResourceDispatcher; | 21 class ResourceDispatcher; |
26 | 22 |
27 // This filter is used to dispatch resource messages on a specific | 23 // This filter is used to dispatch resource messages on a specific |
28 // SingleThreadTaskRunner to facilitate task scheduling. | 24 // SingleThreadTaskRunner to facilitate task scheduling. |
29 class CONTENT_EXPORT ResourceSchedulingFilter : public IPC::MessageFilter { | 25 class CONTENT_EXPORT ResourceSchedulingFilter : public IPC::MessageFilter { |
30 public: | 26 public: |
31 ResourceSchedulingFilter(const scoped_refptr<base::SingleThreadTaskRunner>& | 27 ResourceSchedulingFilter(const scoped_refptr<base::SingleThreadTaskRunner>& |
32 main_thread_task_runner, | 28 main_thread_task_runner, |
33 ResourceDispatcher* resource_dispatcher); | 29 ResourceDispatcher* resource_dispatcher); |
34 | 30 |
35 // IPC::MessageFilter overrides: | 31 // IPC::MessageFilter overrides: |
36 bool OnMessageReceived(const IPC::Message& message) override; | 32 bool OnMessageReceived(const IPC::Message& message) override; |
37 | 33 |
38 bool GetSupportedMessageClasses( | 34 bool GetSupportedMessageClasses( |
39 std::vector<uint32_t>* supported_message_classes) const override; | 35 std::vector<uint32_t>* supported_message_classes) const override; |
40 | 36 |
41 // Sets the task runner associated with request messages with |id|. | 37 // Sets the task runner associated with request messages with |id|. |
42 void SetRequestIdTaskRunner( | 38 void SetRequestIdTaskRunner( |
43 int id, | 39 int id, |
44 std::unique_ptr<blink::WebTaskRunner> web_task_runner); | 40 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); |
45 | 41 |
46 // Removes the task runner associated with |id|. | 42 // Removes the task runner associated with |id|. |
47 void ClearRequestIdTaskRunner(int id); | 43 void ClearRequestIdTaskRunner(int id); |
48 | 44 |
49 void DispatchMessage(const IPC::Message& message); | 45 void DispatchMessage(const IPC::Message& message); |
50 | 46 |
51 private: | 47 private: |
52 ~ResourceSchedulingFilter() override; | 48 ~ResourceSchedulingFilter() override; |
53 | 49 |
54 using RequestIdToTaskRunnerMap = | 50 using RequestIdToTaskRunnerMap = |
55 std::map<int, std::unique_ptr<blink::WebTaskRunner>>; | 51 std::map<int, scoped_refptr<base::SingleThreadTaskRunner>>; |
56 | 52 |
57 // This lock guards |request_id_to_task_runner_map_| | 53 // This lock guards |request_id_to_task_runner_map_| |
58 base::Lock request_id_to_task_runner_map_lock_; | 54 base::Lock request_id_to_task_runner_map_lock_; |
59 RequestIdToTaskRunnerMap request_id_to_task_runner_map_; | 55 RequestIdToTaskRunnerMap request_id_to_task_runner_map_; |
60 | 56 |
61 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | 57 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
62 ResourceDispatcher* resource_dispatcher_; // NOT OWNED | 58 ResourceDispatcher* resource_dispatcher_; // NOT OWNED |
63 base::WeakPtrFactory<ResourceSchedulingFilter> weak_ptr_factory_; | 59 base::WeakPtrFactory<ResourceSchedulingFilter> weak_ptr_factory_; |
64 | 60 |
65 private: | 61 private: |
66 DISALLOW_COPY_AND_ASSIGN(ResourceSchedulingFilter); | 62 DISALLOW_COPY_AND_ASSIGN(ResourceSchedulingFilter); |
67 }; | 63 }; |
68 | 64 |
69 } // namespace content | 65 } // namespace content |
70 | 66 |
71 #endif // CONTENT_CHILD_RESOURCE_SCHEDULING_FILTER_H_ | 67 #endif // CONTENT_CHILD_RESOURCE_SCHEDULING_FILTER_H_ |
OLD | NEW |