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