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" |
| 11 #include "base/containers/scoped_ptr_map.h" |
9 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
10 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
11 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
12 #include "ipc/message_filter.h" | 15 #include "ipc/message_filter.h" |
13 | 16 |
| 17 namespace blink { |
| 18 class WebTaskRunner; |
| 19 } |
| 20 |
14 namespace content { | 21 namespace content { |
15 class ResourceDispatcher; | 22 class ResourceDispatcher; |
16 | 23 |
17 // This filter is used to dispatch resource messages on a specific | 24 // This filter is used to dispatch resource messages on a specific |
18 // SingleThreadTaskRunner to facilitate task scheduling. | 25 // SingleThreadTaskRunner to facilitate task scheduling. |
19 class CONTENT_EXPORT ResourceSchedulingFilter : public IPC::MessageFilter { | 26 class CONTENT_EXPORT ResourceSchedulingFilter : public IPC::MessageFilter { |
20 public: | 27 public: |
21 ResourceSchedulingFilter(const scoped_refptr<base::SingleThreadTaskRunner>& | 28 ResourceSchedulingFilter(const scoped_refptr<base::SingleThreadTaskRunner>& |
22 main_thread_task_runner, | 29 main_thread_task_runner, |
23 ResourceDispatcher* resource_dispatcher); | 30 ResourceDispatcher* resource_dispatcher); |
24 | 31 |
25 // IPC::MessageFilter overrides: | 32 // IPC::MessageFilter overrides: |
26 bool OnMessageReceived(const IPC::Message& message) override; | 33 bool OnMessageReceived(const IPC::Message& message) override; |
27 | 34 |
28 bool GetSupportedMessageClasses( | 35 bool GetSupportedMessageClasses( |
29 std::vector<uint32>* supported_message_classes) const override; | 36 std::vector<uint32>* supported_message_classes) const override; |
30 | 37 |
31 protected: | 38 // Sets the task runner associated with request messages with |id|. |
| 39 void SetRequestIdTaskRunner( |
| 40 int id, scoped_ptr<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 base::ScopedPtrMap<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 |