Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: webkit/plugins/ppapi/ppb_flash_message_loop_impl.cc

Issue 9188045: Introduce PPB_Flash_MessageLoop interface for Pepper Flash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "webkit/plugins/ppapi/ppb_flash_message_loop_impl.h"
6
7 #include "base/message_loop.h"
8 #include "ppapi/c/pp_errors.h"
9
10 using ppapi::thunk::PPB_Flash_MessageLoop_API;
11
12 namespace webkit {
13 namespace ppapi {
14
15 class PPB_Flash_MessageLoop_Impl::State
16 : public RefCounted<PPB_Flash_MessageLoop_Impl::State> {
17 public:
18 State() : result_(PP_ERROR_ABORTED),
19 run_called_(false),
20 quit_called_(false),
21 run_callback_(PP_BlockUntilComplete()) {
22 }
23
24 int32_t result() const { return result_; }
25 void set_result(int32_t result) { result_ = result; }
26
27 bool run_called() const { return run_called_; }
28 void set_run_called() { run_called_ = true; }
29
30 bool quit_called() const { return quit_called_; }
31 void set_quit_called() { quit_called_ = true; }
32
33 const PP_CompletionCallback& run_callback() const { return run_callback_; }
34 void set_run_callback(const PP_CompletionCallback& run_callback) {
35 run_callback_ = run_callback;
36 }
37
38 private:
39 int32_t result_;
40 bool run_called_;
41 bool quit_called_;
42 PP_CompletionCallback run_callback_;
43 };
44
45 PPB_Flash_MessageLoop_Impl::PPB_Flash_MessageLoop_Impl(PP_Instance instance)
46 : Resource(instance),
47 state_(new State()) {
48 }
49
50 PPB_Flash_MessageLoop_Impl::~PPB_Flash_MessageLoop_Impl() {
51 // It is a no-op if either Run() hasn't been called or Quit() has been called
52 // to balance the call to Run().
53 InternalQuit(PP_ERROR_ABORTED);
54 }
55
56 // static
57 PP_Resource PPB_Flash_MessageLoop_Impl::Create(PP_Instance instance) {
58 return (new PPB_Flash_MessageLoop_Impl(instance))->GetReference();
59 }
60
61 PPB_Flash_MessageLoop_API*
62 PPB_Flash_MessageLoop_Impl::AsPPB_Flash_MessageLoop_API() {
63 return this;
64 }
65
66 int32_t PPB_Flash_MessageLoop_Impl::Run() {
67 return InternalRun(PP_BlockUntilComplete());
viettrungluu 2012/01/17 21:26:06 Using PP_BlockUntilComplete seems kind of hacky (a
yzshen1 2012/01/18 07:43:35 Thanks. I changed to PP_MakeCompletionCallback. An
68 }
69
70 void PPB_Flash_MessageLoop_Impl::RunFromHostProxy(
71 PP_CompletionCallback callback) {
72 if (!callback.func)
viettrungluu 2012/01/17 21:26:06 Should this even happen?
yzshen1 2012/01/18 07:43:35 Removed. It shouldn't happen. And it is the caller
73 return;
74 InternalRun(callback);
75 }
76
77 void PPB_Flash_MessageLoop_Impl::Quit() {
78 InternalQuit(PP_OK);
79 }
80
81 int32_t PPB_Flash_MessageLoop_Impl::InternalRun(
82 PP_CompletionCallback callback) {
83 if (state_->run_called()) {
84 if (callback.func)
85 PP_RunCompletionCallback(&callback, PP_ERROR_FAILED);
86 return PP_ERROR_FAILED;
87 }
88 state_->set_run_called();
89 state_->set_run_callback(callback);
90
91 // It is possible that the PPB_Flash_MessageLoop_Impl object has been
92 // destroyed when the nested message loop exits.
93 scoped_refptr<State> state_protector(state_);
94
95 bool old_value = MessageLoop::current()->NestableTasksAllowed();
96 MessageLoop::current()->SetNestableTasksAllowed(true);
97 MessageLoop::current()->Run();
98
99 // Don't access data members of the class below.
100
101 MessageLoop::current()->SetNestableTasksAllowed(old_value);
102 return state_protector->result();
103 }
104
105 void PPB_Flash_MessageLoop_Impl::InternalQuit(int32_t result) {
106 if (!state_->run_called() || state_->quit_called())
107 return;
108 state_->set_quit_called();
109 state_->set_result(result);
110
111 MessageLoop::current()->QuitNow();
112
113 PP_CompletionCallback callback = state_->run_callback();
114 if (callback.func)
115 PP_RunCompletionCallback(&callback, result);
116 }
117
118 } // namespace ppapi
119 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698