OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_QUOTA_MESSAGE_FILTER_H_ | 5 #ifndef CONTENT_CHILD_QUOTA_MESSAGE_FILTER_H_ |
6 #define CONTENT_CHILD_QUOTA_MESSAGE_FILTER_H_ | 6 #define CONTENT_CHILD_QUOTA_MESSAGE_FILTER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
11 #include "ipc/ipc_channel_proxy.h" | 11 #include "content/child/child_message_filter.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 class MessageLoopProxy; | 14 class MessageLoopProxy; |
15 } | 15 } |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 | 18 |
19 class ThreadSafeSender; | 19 class ThreadSafeSender; |
20 | 20 |
21 class QuotaMessageFilter : public IPC::ChannelProxy::MessageFilter { | 21 class QuotaMessageFilter : public ChildMessageFilter { |
22 public: | 22 public: |
23 explicit QuotaMessageFilter(ThreadSafeSender* thread_safe_sender); | 23 explicit QuotaMessageFilter(ThreadSafeSender* thread_safe_sender); |
24 | 24 |
25 // IPC::Listener implementation. | |
26 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | |
27 | |
28 // Generates a new request_id, registers { request_id, thread_id } map to | 25 // Generates a new request_id, registers { request_id, thread_id } map to |
29 // the message filter and returns the request_id. | 26 // the message filter and returns the request_id. |
30 // This method can be called on any thread. | 27 // This method can be called on any thread. |
31 int GenerateRequestID(int thread_id); | 28 int GenerateRequestID(int thread_id); |
32 | 29 |
33 // Clears all requests from the thread_id. | 30 // Clears all requests from the thread_id. |
34 void ClearThreadRequests(int thread_id); | 31 void ClearThreadRequests(int thread_id); |
35 | 32 |
36 protected: | 33 protected: |
37 virtual ~QuotaMessageFilter(); | 34 virtual ~QuotaMessageFilter(); |
38 | 35 |
39 private: | 36 private: |
| 37 // ChildMessageFilter implementation: |
| 38 virtual base::TaskRunner* OverrideTaskRunnerForMessage( |
| 39 const IPC::Message& msg) OVERRIDE; |
| 40 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
| 41 |
40 typedef std::map<int, int> RequestIdToThreadId; | 42 typedef std::map<int, int> RequestIdToThreadId; |
41 | 43 |
42 void DispatchMessage(const IPC::Message& msg); | |
43 | |
44 scoped_refptr<base::MessageLoopProxy> main_thread_loop_proxy_; | 44 scoped_refptr<base::MessageLoopProxy> main_thread_loop_proxy_; |
45 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 45 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
46 | 46 |
47 base::Lock request_id_map_lock_; | 47 base::Lock request_id_map_lock_; |
48 RequestIdToThreadId request_id_map_; | 48 RequestIdToThreadId request_id_map_; |
49 int next_request_id_; | 49 int next_request_id_; |
50 | 50 |
51 DISALLOW_COPY_AND_ASSIGN(QuotaMessageFilter); | 51 DISALLOW_COPY_AND_ASSIGN(QuotaMessageFilter); |
52 }; | 52 }; |
53 | 53 |
54 } // namespace content | 54 } // namespace content |
55 | 55 |
56 #endif // CONTENT_CHILD_QUOTA_MESSAGE_FILTER_H_ | 56 #endif // CONTENT_CHILD_QUOTA_MESSAGE_FILTER_H_ |
OLD | NEW |