Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / child / quota_message_filter.h
blob7ae0c0cc5e66e0fdfd379e3b12889e1110ec19a3
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_
8 #include <map>
10 #include "base/memory/ref_counted.h"
11 #include "base/synchronization/lock.h"
12 #include "content/child/child_message_filter.h"
14 namespace base {
15 class MessageLoopProxy;
18 namespace content {
20 class ThreadSafeSender;
22 class QuotaMessageFilter : public ChildMessageFilter {
23 public:
24 explicit QuotaMessageFilter(ThreadSafeSender* thread_safe_sender);
26 // Generates a new request_id, registers { request_id, thread_id } map to
27 // the message filter and returns the request_id.
28 // This method can be called on any thread.
29 int GenerateRequestID(int thread_id);
31 // Clears all requests from the thread_id.
32 void ClearThreadRequests(int thread_id);
34 protected:
35 virtual ~QuotaMessageFilter();
37 private:
38 // ChildMessageFilter implementation:
39 virtual base::TaskRunner* OverrideTaskRunnerForMessage(
40 const IPC::Message& msg) OVERRIDE;
41 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
43 typedef std::map<int, int> RequestIdToThreadId;
45 scoped_refptr<base::MessageLoopProxy> main_thread_loop_proxy_;
46 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
48 base::Lock request_id_map_lock_;
49 RequestIdToThreadId request_id_map_;
50 int next_request_id_;
52 DISALLOW_COPY_AND_ASSIGN(QuotaMessageFilter);
55 } // namespace content
57 #endif // CONTENT_CHILD_QUOTA_MESSAGE_FILTER_H_