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