OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_PPB_MESSAGE_LOOP_PROXY_H_ | 5 #ifndef PPAPI_PROXY_PPB_MESSAGE_LOOP_PROXY_H_ |
6 #define PPAPI_PROXY_PPB_MESSAGE_LOOP_PROXY_H_ | 6 #define PPAPI_PROXY_PPB_MESSAGE_LOOP_PROXY_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "ppapi/proxy/interface_proxy.h" | 13 #include "ppapi/proxy/interface_proxy.h" |
14 #include "ppapi/shared_impl/resource.h" | 14 #include "ppapi/shared_impl/ppb_message_loop_shared.h" |
15 #include "ppapi/thunk/ppb_message_loop_api.h" | 15 #include "ppapi/thunk/ppb_message_loop_api.h" |
16 | 16 |
17 struct PPB_MessageLoop_Dev_0_1; | 17 struct PPB_MessageLoop_Dev_0_1; |
18 | 18 |
19 namespace ppapi { | 19 namespace ppapi { |
20 namespace proxy { | 20 namespace proxy { |
21 | 21 |
22 class MessageLoopResource : public Resource, public thunk::PPB_MessageLoop_API { | 22 class MessageLoopResource : public MessageLoopShared { |
23 public: | 23 public: |
24 explicit MessageLoopResource(PP_Instance instance); | 24 explicit MessageLoopResource(PP_Instance instance); |
25 // Construct the one MessageLoopResource for the main thread. This must be | 25 // Construct the one MessageLoopResource for the main thread. This must be |
26 // invoked on the main thread. | 26 // invoked on the main thread. |
27 struct ForMainThread {}; | 27 explicit MessageLoopResource(ForMainThread); |
28 MessageLoopResource(ForMainThread); | |
29 virtual ~MessageLoopResource(); | 28 virtual ~MessageLoopResource(); |
30 | 29 |
31 // Resource overrides. | 30 // Resource overrides. |
32 virtual thunk::PPB_MessageLoop_API* AsPPB_MessageLoop_API() OVERRIDE; | 31 virtual thunk::PPB_MessageLoop_API* AsPPB_MessageLoop_API() OVERRIDE; |
33 | 32 |
34 // PPB_MessageLoop_API implementation. | 33 // PPB_MessageLoop_API implementation. |
35 virtual int32_t AttachToCurrentThread() OVERRIDE; | 34 virtual int32_t AttachToCurrentThread() OVERRIDE; |
36 virtual int32_t Run() OVERRIDE; | 35 virtual int32_t Run() OVERRIDE; |
37 virtual int32_t PostWork(PP_CompletionCallback callback, | 36 virtual int32_t PostWork(PP_CompletionCallback callback, |
38 int64_t delay_ms) OVERRIDE; | 37 int64_t delay_ms) OVERRIDE; |
39 virtual int32_t PostQuit(PP_Bool should_destroy) OVERRIDE; | 38 virtual int32_t PostQuit(PP_Bool should_destroy) OVERRIDE; |
40 | 39 |
| 40 static MessageLoopResource* GetCurrent(); |
41 void DetachFromThread(); | 41 void DetachFromThread(); |
42 bool is_main_thread_loop() const { | 42 bool is_main_thread_loop() const { |
43 return is_main_thread_loop_; | 43 return is_main_thread_loop_; |
44 } | 44 } |
45 | 45 |
46 private: | 46 private: |
47 struct TaskInfo { | 47 struct TaskInfo { |
48 tracked_objects::Location from_here; | 48 tracked_objects::Location from_here; |
49 base::Closure closure; | 49 base::Closure closure; |
50 int64 delay_ms; | 50 int64 delay_ms; |
51 }; | 51 }; |
52 | 52 |
53 // Returns true if the object is associated with the current thread. | 53 // Returns true if the object is associated with the current thread. |
54 bool IsCurrent() const; | 54 bool IsCurrent() const; |
55 | 55 |
56 // Handles posting to the message loop if there is one, or the pending queue | 56 // Handles posting to the message loop if there is one, or the pending queue |
57 // if there isn't. | 57 // if there isn't. |
58 // NOTE: The given closure will be run *WITHOUT* acquiring the Proxy lock. | 58 // NOTE: The given closure will be run *WITHOUT* acquiring the Proxy lock. |
59 // This only makes sense for user code and completely thread-safe | 59 // This only makes sense for user code and completely thread-safe |
60 // proxy operations (e.g., MessageLoop::QuitClosure). | 60 // proxy operations (e.g., MessageLoop::QuitClosure). |
61 void PostClosure(const tracked_objects::Location& from_here, | 61 virtual void PostClosure(const tracked_objects::Location& from_here, |
62 const base::Closure& closure, | 62 const base::Closure& closure, |
63 int64 delay_ms); | 63 int64 delay_ms) OVERRIDE; |
64 | 64 |
65 // TLS destructor function. | 65 // TLS destructor function. |
66 static void ReleaseMessageLoop(void* value); | 66 static void ReleaseMessageLoop(void* value); |
67 | 67 |
68 // Created when we attach to the current thread, since MessageLoop assumes | 68 // Created when we attach to the current thread, since MessageLoop assumes |
69 // that it's created on the thread it will run on. NULL for the main thread | 69 // that it's created on the thread it will run on. NULL for the main thread |
70 // loop, since that's owned by somebody else. This is needed for Run and Quit. | 70 // loop, since that's owned by somebody else. This is needed for Run and Quit. |
71 // Any time we post tasks, we should post them using loop_proxy_. | 71 // Any time we post tasks, we should post them using loop_proxy_. |
72 scoped_ptr<MessageLoop> loop_; | 72 scoped_ptr<MessageLoop> loop_; |
73 scoped_refptr<base::MessageLoopProxy> loop_proxy_; | 73 scoped_refptr<base::MessageLoopProxy> loop_proxy_; |
(...skipping 27 matching lines...) Expand all Loading... |
101 static const PPB_MessageLoop_Dev_0_1* GetInterface(); | 101 static const PPB_MessageLoop_Dev_0_1* GetInterface(); |
102 | 102 |
103 private: | 103 private: |
104 DISALLOW_COPY_AND_ASSIGN(PPB_MessageLoop_Proxy); | 104 DISALLOW_COPY_AND_ASSIGN(PPB_MessageLoop_Proxy); |
105 }; | 105 }; |
106 | 106 |
107 } // namespace proxy | 107 } // namespace proxy |
108 } // namespace ppapi | 108 } // namespace ppapi |
109 | 109 |
110 #endif // PPAPI_PROXY_PPB_MESSAGE_LOOP_PROXY_H_ | 110 #endif // PPAPI_PROXY_PPB_MESSAGE_LOOP_PROXY_H_ |
OLD | NEW |