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
3 // found in the LICENSE file.
5 #ifndef CONTENT_CHILD_QUOTA_MESSAGE_FILTER_H_
6 #define CONTENT_CHILD_QUOTA_MESSAGE_FILTER_H_
10 #include "base/synchronization/lock.h"
11 #include "ipc/ipc_channel_proxy.h"
14 class MessageLoopProxy;
19 class ThreadSafeSender;
21 class QuotaMessageFilter : public IPC::ChannelProxy::MessageFilter {
23 explicit QuotaMessageFilter(ThreadSafeSender* thread_safe_sender);
25 // IPC::Listener implementation.
26 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
28 // Generates a new request_id, registers { request_id, thread_id } map to
29 // the message filter and returns the request_id.
30 // This method can be called on any thread.
31 int GenerateRequestID(int thread_id);
33 // Clears all requests from the thread_id.
34 void ClearThreadRequests(int thread_id);
37 virtual ~QuotaMessageFilter();
40 typedef std::map<int, int> RequestIdToThreadId;
42 void DispatchMessage(const IPC::Message& msg);
44 scoped_refptr<base::MessageLoopProxy> main_thread_loop_proxy_;
45 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
47 base::Lock request_id_map_lock_;
48 RequestIdToThreadId request_id_map_;
51 DISALLOW_COPY_AND_ASSIGN(QuotaMessageFilter);
54 } // namespace content
56 #endif // CONTENT_CHILD_QUOTA_MESSAGE_FILTER_H_