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" |
(...skipping 30 matching lines...) Expand all Loading... |
41 static MessageLoopResource* GetCurrent(); | 41 static MessageLoopResource* GetCurrent(); |
42 void DetachFromThread(); | 42 void DetachFromThread(); |
43 bool is_main_thread_loop() const { | 43 bool is_main_thread_loop() const { |
44 return is_main_thread_loop_; | 44 return is_main_thread_loop_; |
45 } | 45 } |
46 | 46 |
47 const scoped_refptr<base::MessageLoopProxy>& message_loop_proxy() { | 47 const scoped_refptr<base::MessageLoopProxy>& message_loop_proxy() { |
48 return loop_proxy_; | 48 return loop_proxy_; |
49 } | 49 } |
50 | 50 |
| 51 void set_currently_handling_blocking_message(bool handling_blocking_message) { |
| 52 currently_handling_blocking_message_ = handling_blocking_message; |
| 53 } |
| 54 |
51 private: | 55 private: |
52 struct TaskInfo { | 56 struct TaskInfo { |
53 tracked_objects::Location from_here; | 57 tracked_objects::Location from_here; |
54 base::Closure closure; | 58 base::Closure closure; |
55 int64 delay_ms; | 59 int64 delay_ms; |
56 }; | 60 }; |
57 | 61 |
58 // Returns true if the object is associated with the current thread. | 62 // Returns true if the object is associated with the current thread. |
59 bool IsCurrent() const; | 63 bool IsCurrent() const; |
60 | 64 |
| 65 // MessageLoopShared implementation. |
| 66 // |
61 // Handles posting to the message loop if there is one, or the pending queue | 67 // Handles posting to the message loop if there is one, or the pending queue |
62 // if there isn't. | 68 // if there isn't. |
63 // NOTE: The given closure will be run *WITHOUT* acquiring the Proxy lock. | 69 // NOTE: The given closure will be run *WITHOUT* acquiring the Proxy lock. |
64 // This only makes sense for user code and completely thread-safe | 70 // This only makes sense for user code and completely thread-safe |
65 // proxy operations (e.g., MessageLoop::QuitClosure). | 71 // proxy operations (e.g., MessageLoop::QuitClosure). |
66 virtual void PostClosure(const tracked_objects::Location& from_here, | 72 virtual void PostClosure(const tracked_objects::Location& from_here, |
67 const base::Closure& closure, | 73 const base::Closure& closure, |
68 int64 delay_ms) OVERRIDE; | 74 int64 delay_ms) OVERRIDE; |
69 | |
70 virtual base::MessageLoopProxy* GetMessageLoopProxy() OVERRIDE; | 75 virtual base::MessageLoopProxy* GetMessageLoopProxy() OVERRIDE; |
| 76 virtual bool CurrentlyHandlingBlockingMessage() OVERRIDE; |
71 | 77 |
72 // TLS destructor function. | 78 // TLS destructor function. |
73 static void ReleaseMessageLoop(void* value); | 79 static void ReleaseMessageLoop(void* value); |
74 | 80 |
75 // Created when we attach to the current thread, since MessageLoop assumes | 81 // Created when we attach to the current thread, since MessageLoop assumes |
76 // that it's created on the thread it will run on. NULL for the main thread | 82 // that it's created on the thread it will run on. NULL for the main thread |
77 // loop, since that's owned by somebody else. This is needed for Run and Quit. | 83 // loop, since that's owned by somebody else. This is needed for Run and Quit. |
78 // Any time we post tasks, we should post them using loop_proxy_. | 84 // Any time we post tasks, we should post them using loop_proxy_. |
79 scoped_ptr<base::MessageLoop> loop_; | 85 scoped_ptr<base::MessageLoop> loop_; |
80 scoped_refptr<base::MessageLoopProxy> loop_proxy_; | 86 scoped_refptr<base::MessageLoopProxy> loop_proxy_; |
81 | 87 |
82 // Number of invocations of Run currently on the stack. | 88 // Number of invocations of Run currently on the stack. |
83 int nested_invocations_; | 89 int nested_invocations_; |
84 | 90 |
85 // Set to true when the message loop is destroyed to prevent forther | 91 // Set to true when the message loop is destroyed to prevent forther |
86 // posting of work. | 92 // posting of work. |
87 bool destroyed_; | 93 bool destroyed_; |
88 | 94 |
89 // Set to true if all message loop invocations should exit and that the | 95 // Set to true if all message loop invocations should exit and that the |
90 // loop should be destroyed once it reaches the outermost Run invocation. | 96 // loop should be destroyed once it reaches the outermost Run invocation. |
91 bool should_destroy_; | 97 bool should_destroy_; |
92 | 98 |
93 bool is_main_thread_loop_; | 99 bool is_main_thread_loop_; |
94 | 100 |
| 101 bool currently_handling_blocking_message_; |
| 102 |
95 // Since we allow tasks to be posted before the message loop is actually | 103 // Since we allow tasks to be posted before the message loop is actually |
96 // created (when it's associated with a thread), we keep tasks posted here | 104 // created (when it's associated with a thread), we keep tasks posted here |
97 // until that happens. Once the loop_ is created, this is unused. | 105 // until that happens. Once the loop_ is created, this is unused. |
98 std::vector<TaskInfo> pending_tasks_; | 106 std::vector<TaskInfo> pending_tasks_; |
99 | 107 |
100 DISALLOW_COPY_AND_ASSIGN(MessageLoopResource); | 108 DISALLOW_COPY_AND_ASSIGN(MessageLoopResource); |
101 }; | 109 }; |
102 | 110 |
103 class PPB_MessageLoop_Proxy : public InterfaceProxy { | 111 class PPB_MessageLoop_Proxy : public InterfaceProxy { |
104 public: | 112 public: |
105 explicit PPB_MessageLoop_Proxy(Dispatcher* dispatcher); | 113 explicit PPB_MessageLoop_Proxy(Dispatcher* dispatcher); |
106 virtual ~PPB_MessageLoop_Proxy(); | 114 virtual ~PPB_MessageLoop_Proxy(); |
107 | 115 |
108 static const PPB_MessageLoop_1_0* GetInterface(); | 116 static const PPB_MessageLoop_1_0* GetInterface(); |
109 | 117 |
110 private: | 118 private: |
111 DISALLOW_COPY_AND_ASSIGN(PPB_MessageLoop_Proxy); | 119 DISALLOW_COPY_AND_ASSIGN(PPB_MessageLoop_Proxy); |
112 }; | 120 }; |
113 | 121 |
114 } // namespace proxy | 122 } // namespace proxy |
115 } // namespace ppapi | 123 } // namespace ppapi |
116 | 124 |
117 #endif // PPAPI_PROXY_PPB_MESSAGE_LOOP_PROXY_H_ | 125 #endif // PPAPI_PROXY_PPB_MESSAGE_LOOP_PROXY_H_ |
OLD | NEW |