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 | 10 |
10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
12 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
13 #include "ppapi/c/pp_resource.h" | 14 #include "ppapi/c/pp_resource.h" |
14 #include "ppapi/proxy/ppapi_proxy_export.h" | 15 #include "ppapi/proxy/ppapi_proxy_export.h" |
15 | 16 |
16 | 17 |
17 namespace base { | 18 namespace base { |
18 class MessageLoopProxy; | 19 class MessageLoopProxy; |
19 } | 20 } |
20 | 21 |
22 namespace IPC { | |
23 class Message; | |
24 } | |
25 | |
21 namespace ppapi { | 26 namespace ppapi { |
22 | 27 |
23 class TrackedCallback; | 28 class TrackedCallback; |
24 | 29 |
25 namespace proxy { | 30 namespace proxy { |
26 | 31 |
32 class ResourceMessageReplyParams; | |
33 | |
27 // ResourceReplyThreadRegistrar records the handling thread for | 34 // ResourceReplyThreadRegistrar records the handling thread for |
28 // PpapiPluginMsg_ResourceReply messages. | 35 // PpapiPluginMsg_ResourceReply messages. |
29 // This class is thread safe. | 36 // This class is thread safe. |
30 class PPAPI_PROXY_EXPORT ResourceReplyThreadRegistrar | 37 class PPAPI_PROXY_EXPORT ResourceReplyThreadRegistrar |
31 : public base::RefCountedThreadSafe<ResourceReplyThreadRegistrar> { | 38 : public base::RefCountedThreadSafe<ResourceReplyThreadRegistrar> { |
32 public: | 39 public: |
33 explicit ResourceReplyThreadRegistrar( | 40 explicit ResourceReplyThreadRegistrar( |
34 scoped_refptr<base::MessageLoopProxy> default_thread); | 41 scoped_refptr<base::MessageLoopProxy> main_thread); |
35 | 42 |
36 // 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 |
37 // other methods can be called with/without the Pepper proxy lock. | 44 // other methods can be called with/without the Pepper proxy lock. |
38 void Register(PP_Resource resource, | 45 void Register(PP_Resource resource, |
39 int32_t sequence_number, | 46 int32_t sequence_number, |
40 scoped_refptr<TrackedCallback> reply_thread_hint); | 47 scoped_refptr<TrackedCallback> reply_thread_hint); |
41 | 48 |
49 // This results in Resource::OnReplyReceived() for the specified resource and | |
50 // message type to be called on the IO thread directly, while holding the | |
51 // Pepper proxy lock. | |
52 void HandleOnIOThread(PP_Resource resource, uint32 nested_msg_type); | |
53 | |
42 void Unregister(PP_Resource resource); | 54 void Unregister(PP_Resource resource); |
43 | 55 |
44 scoped_refptr<base::MessageLoopProxy> GetTargetThreadAndUnregister( | 56 // This method returns NULL if the target thread is the IO thread (because |
45 PP_Resource resource, | 57 // that is the thread on which this method is supposed to be called). |
46 int32_t sequence_number); | 58 scoped_refptr<base::MessageLoopProxy> GetTargetThread( |
59 const ResourceMessageReplyParams& reply_params, | |
60 const IPC::Message& nested_msg); | |
47 | 61 |
48 private: | 62 private: |
49 friend class base::RefCountedThreadSafe<ResourceReplyThreadRegistrar>; | 63 friend class base::RefCountedThreadSafe<ResourceReplyThreadRegistrar>; |
50 | 64 |
51 typedef std::map<int32_t, scoped_refptr<base::MessageLoopProxy> > | 65 typedef std::map<int32_t, scoped_refptr<base::MessageLoopProxy> > |
52 SequenceNumberMap; | 66 SequenceThreadMap; |
53 typedef std::map<PP_Resource, SequenceNumberMap> ResourceMap; | 67 |
68 struct ResourceInfo { | |
69 SequenceThreadMap thread_map; | |
70 std::set<uint32> io_thread_message_types; | |
dmichael (off chromium)
2014/09/12 19:49:07
I think it's likely that messages intended for the
yzshen1
2014/09/15 20:59:39
I agree. I have a question related to this in udp_
| |
71 }; | |
72 | |
73 typedef std::map<PP_Resource, ResourceInfo> ResourceMap; | |
54 | 74 |
55 ~ResourceReplyThreadRegistrar(); | 75 ~ResourceReplyThreadRegistrar(); |
56 | 76 |
57 // The lock that protects the data members below. | 77 // The lock that protects the data members below. |
58 // Please note that we should never try to acquire the Pepper proxy lock while | 78 // Please note that we should never try to acquire the Pepper proxy lock while |
59 // holding |lock_|, otherwise we will cause deadlock. | 79 // holding |lock_|, otherwise we will cause deadlock. |
60 base::Lock lock_; | 80 base::Lock lock_; |
61 ResourceMap map_; | 81 ResourceMap map_; |
62 scoped_refptr<base::MessageLoopProxy> default_thread_; | 82 scoped_refptr<base::MessageLoopProxy> main_thread_; |
63 | 83 |
64 DISALLOW_COPY_AND_ASSIGN(ResourceReplyThreadRegistrar); | 84 DISALLOW_COPY_AND_ASSIGN(ResourceReplyThreadRegistrar); |
65 }; | 85 }; |
66 | 86 |
67 } // namespace proxy | 87 } // namespace proxy |
68 } // namespace ppapi | 88 } // namespace ppapi |
69 | 89 |
70 #endif // PPAPI_PROXY_RESOURCE_REPLY_THREAD_REGISTRAR_H_ | 90 #endif // PPAPI_PROXY_RESOURCE_REPLY_THREAD_REGISTRAR_H_ |
OLD | NEW |