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 PPAPI_PROXY_RESOURCE_REPLY_THREAD_REGISTRAR_H_ | 5 #ifndef PPAPI_PROXY_RESOURCE_REPLY_THREAD_REGISTRAR_H_ |
6 #define PPAPI_PROXY_RESOURCE_REPLY_THREAD_REGISTRAR_H_ | 6 #define PPAPI_PROXY_RESOURCE_REPLY_THREAD_REGISTRAR_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
14 #include "ppapi/c/pp_resource.h" | 14 #include "ppapi/c/pp_resource.h" |
15 #include "ppapi/proxy/ppapi_proxy_export.h" | 15 #include "ppapi/proxy/ppapi_proxy_export.h" |
16 | 16 |
17 | 17 |
18 namespace base { | 18 namespace base { |
19 class MessageLoopProxy; | 19 class SingleThreadTaskRunner; |
20 } | 20 } |
21 | 21 |
22 namespace IPC { | 22 namespace IPC { |
23 class Message; | 23 class Message; |
24 } | 24 } |
25 | 25 |
26 namespace ppapi { | 26 namespace ppapi { |
27 | 27 |
28 class TrackedCallback; | 28 class TrackedCallback; |
29 | 29 |
30 namespace proxy { | 30 namespace proxy { |
31 | 31 |
32 class ResourceMessageReplyParams; | 32 class ResourceMessageReplyParams; |
33 | 33 |
34 // ResourceReplyThreadRegistrar records the handling thread for | 34 // ResourceReplyThreadRegistrar records the handling thread for |
35 // PpapiPluginMsg_ResourceReply messages. | 35 // PpapiPluginMsg_ResourceReply messages. |
36 // This class is thread safe. | 36 // This class is thread safe. |
37 class PPAPI_PROXY_EXPORT ResourceReplyThreadRegistrar | 37 class PPAPI_PROXY_EXPORT ResourceReplyThreadRegistrar |
38 : public base::RefCountedThreadSafe<ResourceReplyThreadRegistrar> { | 38 : public base::RefCountedThreadSafe<ResourceReplyThreadRegistrar> { |
39 public: | 39 public: |
40 explicit ResourceReplyThreadRegistrar( | 40 explicit ResourceReplyThreadRegistrar( |
41 scoped_refptr<base::MessageLoopProxy> main_thread); | 41 scoped_refptr<base::SingleThreadTaskRunner> main_thread); |
42 | 42 |
43 // This method can only be called while holding the Pepper proxy lock; the | 43 // This method can only be called while holding the Pepper proxy lock; the |
44 // other methods can be called with/without the Pepper proxy lock. | 44 // other methods can be called with/without the Pepper proxy lock. |
45 void Register(PP_Resource resource, | 45 void Register(PP_Resource resource, |
46 int32_t sequence_number, | 46 int32_t sequence_number, |
47 scoped_refptr<TrackedCallback> reply_thread_hint); | 47 scoped_refptr<TrackedCallback> reply_thread_hint); |
48 void Unregister(PP_Resource resource); | 48 void Unregister(PP_Resource resource); |
49 | 49 |
50 scoped_refptr<base::MessageLoopProxy> GetTargetThread( | 50 scoped_refptr<base::SingleThreadTaskRunner> GetTargetThread( |
51 const ResourceMessageReplyParams& reply_params, | 51 const ResourceMessageReplyParams& reply_params, |
52 const IPC::Message& nested_msg); | 52 const IPC::Message& nested_msg); |
53 | 53 |
54 private: | 54 private: |
55 friend class base::RefCountedThreadSafe<ResourceReplyThreadRegistrar>; | 55 friend class base::RefCountedThreadSafe<ResourceReplyThreadRegistrar>; |
56 | 56 |
57 typedef std::map<int32_t, scoped_refptr<base::MessageLoopProxy> > | 57 typedef std::map<int32_t, scoped_refptr<base::SingleThreadTaskRunner>> |
58 SequenceThreadMap; | 58 SequenceThreadMap; |
59 typedef std::map<PP_Resource, SequenceThreadMap> ResourceMap; | 59 typedef std::map<PP_Resource, SequenceThreadMap> ResourceMap; |
60 | 60 |
61 ~ResourceReplyThreadRegistrar(); | 61 ~ResourceReplyThreadRegistrar(); |
62 | 62 |
63 // The lock that protects the data members below. | 63 // The lock that protects the data members below. |
64 // Please note that we should never try to acquire the Pepper proxy lock while | 64 // Please note that we should never try to acquire the Pepper proxy lock while |
65 // holding |lock_|, otherwise we will cause deadlock. | 65 // holding |lock_|, otherwise we will cause deadlock. |
66 base::Lock lock_; | 66 base::Lock lock_; |
67 ResourceMap map_; | 67 ResourceMap map_; |
68 scoped_refptr<base::MessageLoopProxy> main_thread_; | 68 scoped_refptr<base::SingleThreadTaskRunner> main_thread_; |
69 | 69 |
70 DISALLOW_COPY_AND_ASSIGN(ResourceReplyThreadRegistrar); | 70 DISALLOW_COPY_AND_ASSIGN(ResourceReplyThreadRegistrar); |
71 }; | 71 }; |
72 | 72 |
73 } // namespace proxy | 73 } // namespace proxy |
74 } // namespace ppapi | 74 } // namespace ppapi |
75 | 75 |
76 #endif // PPAPI_PROXY_RESOURCE_REPLY_THREAD_REGISTRAR_H_ | 76 #endif // PPAPI_PROXY_RESOURCE_REPLY_THREAD_REGISTRAR_H_ |
OLD | NEW |