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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/run_loop.h" |
16 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
17 #include "ppapi/proxy/interface_proxy.h" | 18 #include "ppapi/proxy/interface_proxy.h" |
18 #include "ppapi/proxy/ppapi_proxy_export.h" | 19 #include "ppapi/proxy/ppapi_proxy_export.h" |
19 #include "ppapi/shared_impl/ppb_message_loop_shared.h" | 20 #include "ppapi/shared_impl/ppb_message_loop_shared.h" |
20 #include "ppapi/thunk/ppb_message_loop_api.h" | 21 #include "ppapi/thunk/ppb_message_loop_api.h" |
21 | 22 |
22 struct PPB_MessageLoop_1_0; | 23 struct PPB_MessageLoop_1_0; |
23 | 24 |
24 namespace ppapi { | 25 namespace ppapi { |
25 namespace proxy { | 26 namespace proxy { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 // if there isn't. | 72 // if there isn't. |
72 // NOTE: The given closure will be run *WITHOUT* acquiring the Proxy lock. | 73 // NOTE: The given closure will be run *WITHOUT* acquiring the Proxy lock. |
73 // This only makes sense for user code and completely thread-safe | 74 // This only makes sense for user code and completely thread-safe |
74 // proxy operations (e.g., MessageLoop::QuitClosure). | 75 // proxy operations (e.g., MessageLoop::QuitClosure). |
75 void PostClosure(const tracked_objects::Location& from_here, | 76 void PostClosure(const tracked_objects::Location& from_here, |
76 const base::Closure& closure, | 77 const base::Closure& closure, |
77 int64_t delay_ms) override; | 78 int64_t delay_ms) override; |
78 base::SingleThreadTaskRunner* GetTaskRunner() override; | 79 base::SingleThreadTaskRunner* GetTaskRunner() override; |
79 bool CurrentlyHandlingBlockingMessage() override; | 80 bool CurrentlyHandlingBlockingMessage() override; |
80 | 81 |
| 82 // Quits |run_loop_|. Must be called from the thread that runs the RunLoop. |
| 83 void QuitRunLoopWhenIdle(); |
| 84 |
81 // TLS destructor function. | 85 // TLS destructor function. |
82 static void ReleaseMessageLoop(void* value); | 86 static void ReleaseMessageLoop(void* value); |
83 | 87 |
84 // Created when we attach to the current thread, since MessageLoop assumes | 88 // Created when we attach to the current thread, since MessageLoop assumes |
85 // that it's created on the thread it will run on. NULL for the main thread | 89 // that it's created on the thread it will run on. NULL for the main thread |
86 // loop, since that's owned by somebody else. This is needed for Run and Quit. | 90 // loop, since that's owned by somebody else. This is needed for Run and Quit. |
87 // Any time we post tasks, we should post them using task_runner_. | 91 // Any time we post tasks, we should post them using task_runner_. |
88 std::unique_ptr<base::MessageLoop> loop_; | 92 std::unique_ptr<base::MessageLoop> loop_; |
89 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 93 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
90 | 94 |
| 95 // RunLoop currently on the stack. |
| 96 base::RunLoop* run_loop_ = nullptr; |
| 97 |
91 // Number of invocations of Run currently on the stack. | 98 // Number of invocations of Run currently on the stack. |
92 int nested_invocations_; | 99 int nested_invocations_; |
93 | 100 |
94 // Set to true when the message loop is destroyed to prevent forther | 101 // Set to true when the message loop is destroyed to prevent forther |
95 // posting of work. | 102 // posting of work. |
96 bool destroyed_; | 103 bool destroyed_; |
97 | 104 |
98 // Set to true if all message loop invocations should exit and that the | 105 // Set to true if all message loop invocations should exit and that the |
99 // loop should be destroyed once it reaches the outermost Run invocation. | 106 // loop should be destroyed once it reaches the outermost Run invocation. |
100 bool should_destroy_; | 107 bool should_destroy_; |
(...skipping 18 matching lines...) Expand all Loading... |
119 static const PPB_MessageLoop_1_0* GetInterface(); | 126 static const PPB_MessageLoop_1_0* GetInterface(); |
120 | 127 |
121 private: | 128 private: |
122 DISALLOW_COPY_AND_ASSIGN(PPB_MessageLoop_Proxy); | 129 DISALLOW_COPY_AND_ASSIGN(PPB_MessageLoop_Proxy); |
123 }; | 130 }; |
124 | 131 |
125 } // namespace proxy | 132 } // namespace proxy |
126 } // namespace ppapi | 133 } // namespace ppapi |
127 | 134 |
128 #endif // PPAPI_PROXY_PPB_MESSAGE_LOOP_PROXY_H_ | 135 #endif // PPAPI_PROXY_PPB_MESSAGE_LOOP_PROXY_H_ |
OLD | NEW |