- add sources.
[platform/framework/web/crosswalk.git] / src / content / child / quota_message_filter.h
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.
4
5 #ifndef CONTENT_CHILD_QUOTA_MESSAGE_FILTER_H_
6 #define CONTENT_CHILD_QUOTA_MESSAGE_FILTER_H_
7
8 #include <map>
9
10 #include "base/synchronization/lock.h"
11 #include "ipc/ipc_channel_proxy.h"
12
13 namespace base {
14 class MessageLoopProxy;
15 }
16
17 namespace content {
18
19 class ThreadSafeSender;
20
21 class QuotaMessageFilter : public IPC::ChannelProxy::MessageFilter {
22  public:
23   explicit QuotaMessageFilter(ThreadSafeSender* thread_safe_sender);
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
29   // the message filter and returns the request_id.
30   // This method can be called on any thread.
31   int GenerateRequestID(int thread_id);
32
33   // Clears all requests from the thread_id.
34   void ClearThreadRequests(int thread_id);
35
36  protected:
37   virtual ~QuotaMessageFilter();
38
39  private:
40   typedef std::map<int, int> RequestIdToThreadId;
41
42   void DispatchMessage(const IPC::Message& msg);
43
44   scoped_refptr<base::MessageLoopProxy> main_thread_loop_proxy_;
45   scoped_refptr<ThreadSafeSender> thread_safe_sender_;
46
47   base::Lock request_id_map_lock_;
48   RequestIdToThreadId request_id_map_;
49   int next_request_id_;
50
51   DISALLOW_COPY_AND_ASSIGN(QuotaMessageFilter);
52 };
53
54 }  // namespace content
55
56 #endif  // CONTENT_CHILD_QUOTA_MESSAGE_FILTER_H_