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