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 #include "ppapi/proxy/ppb_message_loop_proxy.h" | 5 #include "ppapi/proxy/ppb_message_loop_proxy.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 return PP_ERROR_INPROGRESS; | 79 return PP_ERROR_INPROGRESS; |
80 } | 80 } |
81 // TODO(dmichael) check that the current thread can support a message loop. | 81 // TODO(dmichael) check that the current thread can support a message loop. |
82 | 82 |
83 // Take a ref to the MessageLoop on behalf of the TLS. Note that this is an | 83 // Take a ref to the MessageLoop on behalf of the TLS. Note that this is an |
84 // internal ref and not a plugin ref so the plugin can't accidentally | 84 // internal ref and not a plugin ref so the plugin can't accidentally |
85 // release it. This is released by ReleaseMessageLoop(). | 85 // release it. This is released by ReleaseMessageLoop(). |
86 AddRef(); | 86 AddRef(); |
87 slot->Set(this); | 87 slot->Set(this); |
88 | 88 |
89 loop_.reset(new MessageLoop(MessageLoop::TYPE_DEFAULT)); | 89 loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_DEFAULT)); |
90 loop_proxy_ = base::MessageLoopProxy::current(); | 90 loop_proxy_ = base::MessageLoopProxy::current(); |
91 | 91 |
92 // Post all pending work to the message loop. | 92 // Post all pending work to the message loop. |
93 for (size_t i = 0; i < pending_tasks_.size(); i++) { | 93 for (size_t i = 0; i < pending_tasks_.size(); i++) { |
94 const TaskInfo& info = pending_tasks_[i]; | 94 const TaskInfo& info = pending_tasks_[i]; |
95 PostClosure(info.from_here, info.closure, info.delay_ms); | 95 PostClosure(info.from_here, info.closure, info.delay_ms); |
96 } | 96 } |
97 pending_tasks_.clear(); | 97 pending_tasks_.clear(); |
98 | 98 |
99 return PP_OK; | 99 return PP_OK; |
100 } | 100 } |
101 | 101 |
102 int32_t MessageLoopResource::Run() { | 102 int32_t MessageLoopResource::Run() { |
103 if (!IsCurrent()) | 103 if (!IsCurrent()) |
104 return PP_ERROR_WRONG_THREAD; | 104 return PP_ERROR_WRONG_THREAD; |
105 if (is_main_thread_loop_) | 105 if (is_main_thread_loop_) |
106 return PP_ERROR_INPROGRESS; | 106 return PP_ERROR_INPROGRESS; |
107 | 107 |
108 nested_invocations_++; | 108 nested_invocations_++; |
109 CallWhileUnlocked(base::Bind(&MessageLoop::Run, | 109 CallWhileUnlocked( |
110 base::Unretained(loop_.get()))); | 110 base::Bind(&base::MessageLoop::Run, base::Unretained(loop_.get()))); |
111 nested_invocations_--; | 111 nested_invocations_--; |
112 | 112 |
113 if (should_destroy_ && nested_invocations_ == 0) { | 113 if (should_destroy_ && nested_invocations_ == 0) { |
114 loop_proxy_ = NULL; | 114 loop_proxy_ = NULL; |
115 loop_.reset(); | 115 loop_.reset(); |
116 destroyed_ = true; | 116 destroyed_ = true; |
117 } | 117 } |
118 return PP_OK; | 118 return PP_OK; |
119 } | 119 } |
120 | 120 |
(...skipping 13 matching lines...) Expand all Loading... |
134 int32_t MessageLoopResource::PostQuit(PP_Bool should_destroy) { | 134 int32_t MessageLoopResource::PostQuit(PP_Bool should_destroy) { |
135 if (is_main_thread_loop_) | 135 if (is_main_thread_loop_) |
136 return PP_ERROR_WRONG_THREAD; | 136 return PP_ERROR_WRONG_THREAD; |
137 | 137 |
138 if (PP_ToBool(should_destroy)) | 138 if (PP_ToBool(should_destroy)) |
139 should_destroy_ = true; | 139 should_destroy_ = true; |
140 | 140 |
141 if (IsCurrent() && nested_invocations_ > 0) | 141 if (IsCurrent() && nested_invocations_ > 0) |
142 loop_->Quit(); | 142 loop_->Quit(); |
143 else | 143 else |
144 PostClosure(FROM_HERE, MessageLoop::QuitClosure(), 0); | 144 PostClosure(FROM_HERE, base::MessageLoop::QuitClosure(), 0); |
145 return PP_OK; | 145 return PP_OK; |
146 } | 146 } |
147 | 147 |
148 // static | 148 // static |
149 MessageLoopResource* MessageLoopResource::GetCurrent() { | 149 MessageLoopResource* MessageLoopResource::GetCurrent() { |
150 PluginGlobals* globals = PluginGlobals::Get(); | 150 PluginGlobals* globals = PluginGlobals::Get(); |
151 if (!globals->msg_loop_slot()) | 151 if (!globals->msg_loop_slot()) |
152 return NULL; | 152 return NULL; |
153 return reinterpret_cast<MessageLoopResource*>( | 153 return reinterpret_cast<MessageLoopResource*>( |
154 globals->msg_loop_slot()->Get()); | 154 globals->msg_loop_slot()->Get()); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 PPB_MessageLoop_Proxy::~PPB_MessageLoop_Proxy() { | 266 PPB_MessageLoop_Proxy::~PPB_MessageLoop_Proxy() { |
267 } | 267 } |
268 | 268 |
269 // static | 269 // static |
270 const PPB_MessageLoop_1_0* PPB_MessageLoop_Proxy::GetInterface() { | 270 const PPB_MessageLoop_1_0* PPB_MessageLoop_Proxy::GetInterface() { |
271 return &ppb_message_loop_interface; | 271 return &ppb_message_loop_interface; |
272 } | 272 } |
273 | 273 |
274 } // namespace proxy | 274 } // namespace proxy |
275 } // namespace ppapi | 275 } // namespace ppapi |
OLD | NEW |