Plugin Power Saver: Force SW rendering for peripheral plugins.
[chromium-blink-merge.git] / ppapi / proxy / resource_reply_thread_registrar.h
blobded54e9de3d90850122c9404fbef7e61d528e1bd
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 PPAPI_PROXY_RESOURCE_REPLY_THREAD_REGISTRAR_H_
6 #define PPAPI_PROXY_RESOURCE_REPLY_THREAD_REGISTRAR_H_
8 #include <map>
9 #include <set>
11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/synchronization/lock.h"
14 #include "ppapi/c/pp_resource.h"
15 #include "ppapi/proxy/ppapi_proxy_export.h"
18 namespace base {
19 class MessageLoopProxy;
22 namespace IPC {
23 class Message;
26 namespace ppapi {
28 class TrackedCallback;
30 namespace proxy {
32 class ResourceMessageReplyParams;
34 // ResourceReplyThreadRegistrar records the handling thread for
35 // PpapiPluginMsg_ResourceReply messages.
36 // This class is thread safe.
37 class PPAPI_PROXY_EXPORT ResourceReplyThreadRegistrar
38 : public base::RefCountedThreadSafe<ResourceReplyThreadRegistrar> {
39 public:
40 explicit ResourceReplyThreadRegistrar(
41 scoped_refptr<base::MessageLoopProxy> main_thread);
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.
45 void Register(PP_Resource resource,
46 int32_t sequence_number,
47 scoped_refptr<TrackedCallback> reply_thread_hint);
48 void Unregister(PP_Resource resource);
50 // This results in Resource::OnReplyReceived() for the specified message type
51 // to be called on the IO thread directly, while holding the Pepper proxy
52 // lock.
53 void HandleOnIOThread(uint32 nested_msg_type);
55 // This method returns NULL if the target thread is the IO thread (because
56 // that is the thread on which this method is supposed to be called).
57 scoped_refptr<base::MessageLoopProxy> GetTargetThread(
58 const ResourceMessageReplyParams& reply_params,
59 const IPC::Message& nested_msg);
61 private:
62 friend class base::RefCountedThreadSafe<ResourceReplyThreadRegistrar>;
64 typedef std::map<int32_t, scoped_refptr<base::MessageLoopProxy> >
65 SequenceThreadMap;
66 typedef std::map<PP_Resource, SequenceThreadMap> ResourceMap;
68 ~ResourceReplyThreadRegistrar();
70 // The lock that protects the data members below.
71 // Please note that we should never try to acquire the Pepper proxy lock while
72 // holding |lock_|, otherwise we will cause deadlock.
73 base::Lock lock_;
74 ResourceMap map_;
75 std::set<uint32> io_thread_message_types_;
76 scoped_refptr<base::MessageLoopProxy> main_thread_;
78 DISALLOW_COPY_AND_ASSIGN(ResourceReplyThreadRegistrar);
81 } // namespace proxy
82 } // namespace ppapi
84 #endif // PPAPI_PROXY_RESOURCE_REPLY_THREAD_REGISTRAR_H_