Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(420)

Side by Side Diff: content/child/quota_message_filter.h

Issue 63843002: Add ChildMessageFilter, a base class for renderer/worker cross-thread MessageFilter (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/cross_thread_message_filter.h"
12
13 namespace base {
14 class MessageLoopProxy;
15 }
16 12
17 namespace content { 13 namespace content {
18 14
19 class ThreadSafeSender; 15 class ThreadSafeSender;
20 16
21 class QuotaMessageFilter : public IPC::ChannelProxy::MessageFilter { 17 class QuotaMessageFilter : public CrossThreadMessageFilter {
22 public: 18 public:
23 explicit QuotaMessageFilter(ThreadSafeSender* thread_safe_sender); 19 explicit QuotaMessageFilter(ThreadSafeSender* thread_safe_sender);
24 20
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 21 // Generates a new request_id, registers { request_id, thread_id } map to
29 // the message filter and returns the request_id. 22 // the message filter and returns the request_id.
30 // This method can be called on any thread. 23 // This method can be called on any thread.
31 int GenerateRequestID(int thread_id); 24 int GenerateRequestID(int thread_id);
32 25
33 // Clears all requests from the thread_id. 26 // Clears all requests from the thread_id.
34 void ClearThreadRequests(int thread_id); 27 void ClearThreadRequests(int thread_id);
35 28
36 protected: 29 protected:
37 virtual ~QuotaMessageFilter(); 30 virtual ~QuotaMessageFilter();
38 31
39 private: 32 private:
33 // CrossThreadMessageFilter implementation:
34 virtual bool OverrideThreadIDForMessage(const IPC::Message& msg,
35 int* thread_id) OVERRIDE;
36 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
37
40 typedef std::map<int, int> RequestIdToThreadId; 38 typedef std::map<int, int> RequestIdToThreadId;
41 39
42 void DispatchMessage(const IPC::Message& msg);
43
44 scoped_refptr<base::MessageLoopProxy> main_thread_loop_proxy_;
45 scoped_refptr<ThreadSafeSender> thread_safe_sender_; 40 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
46 41
47 base::Lock request_id_map_lock_; 42 base::Lock request_id_map_lock_;
48 RequestIdToThreadId request_id_map_; 43 RequestIdToThreadId request_id_map_;
49 int next_request_id_; 44 int next_request_id_;
50 45
51 DISALLOW_COPY_AND_ASSIGN(QuotaMessageFilter); 46 DISALLOW_COPY_AND_ASSIGN(QuotaMessageFilter);
52 }; 47 };
53 48
54 } // namespace content 49 } // namespace content
55 50
56 #endif // CONTENT_CHILD_QUOTA_MESSAGE_FILTER_H_ 51 #endif // CONTENT_CHILD_QUOTA_MESSAGE_FILTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698