| 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 "content/renderer/pepper/ppb_flash_message_loop_impl.h" | 5 #include "content/renderer/pepper/ppb_flash_message_loop_impl.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
| 10 | 10 |
| 11 using ppapi::thunk::PPB_Flash_MessageLoop_API; | 11 using ppapi::thunk::PPB_Flash_MessageLoop_API; |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 class PPB_Flash_MessageLoop_Impl::State | 15 class PPB_Flash_MessageLoop_Impl::State |
| 16 : public base::RefCounted<PPB_Flash_MessageLoop_Impl::State> { | 16 : public base::RefCounted<PPB_Flash_MessageLoop_Impl::State> { |
| 17 public: | 17 public: |
| 18 State() : result_(PP_OK), run_called_(false), quit_called_(false) { | 18 State() : result_(PP_OK), run_called_(false), quit_called_(false) {} |
| 19 } | |
| 20 | 19 |
| 21 int32_t result() const { return result_; } | 20 int32_t result() const { return result_; } |
| 22 void set_result(int32_t result) { result_ = result; } | 21 void set_result(int32_t result) { result_ = result; } |
| 23 | 22 |
| 24 bool run_called() const { return run_called_; } | 23 bool run_called() const { return run_called_; } |
| 25 void set_run_called() { run_called_ = true; } | 24 void set_run_called() { run_called_ = true; } |
| 26 | 25 |
| 27 bool quit_called() const { return quit_called_; } | 26 bool quit_called() const { return quit_called_; } |
| 28 void set_quit_called() { quit_called_ = true; } | 27 void set_quit_called() { quit_called_ = true; } |
| 29 | 28 |
| 30 const RunFromHostProxyCallback& run_callback() const { return run_callback_; } | 29 const RunFromHostProxyCallback& run_callback() const { return run_callback_; } |
| 31 void set_run_callback(const RunFromHostProxyCallback& run_callback) { | 30 void set_run_callback(const RunFromHostProxyCallback& run_callback) { |
| 32 run_callback_ = run_callback; | 31 run_callback_ = run_callback; |
| 33 } | 32 } |
| 34 | 33 |
| 35 private: | 34 private: |
| 36 friend class base::RefCounted<State>; | 35 friend class base::RefCounted<State>; |
| 37 virtual ~State() {} | 36 virtual ~State() {} |
| 38 | 37 |
| 39 int32_t result_; | 38 int32_t result_; |
| 40 bool run_called_; | 39 bool run_called_; |
| 41 bool quit_called_; | 40 bool quit_called_; |
| 42 RunFromHostProxyCallback run_callback_; | 41 RunFromHostProxyCallback run_callback_; |
| 43 }; | 42 }; |
| 44 | 43 |
| 45 PPB_Flash_MessageLoop_Impl::PPB_Flash_MessageLoop_Impl(PP_Instance instance) | 44 PPB_Flash_MessageLoop_Impl::PPB_Flash_MessageLoop_Impl(PP_Instance instance) |
| 46 : Resource(ppapi::OBJECT_IS_IMPL, instance), | 45 : Resource(ppapi::OBJECT_IS_IMPL, instance), state_(new State()) {} |
| 47 state_(new State()) { | |
| 48 } | |
| 49 | 46 |
| 50 PPB_Flash_MessageLoop_Impl::~PPB_Flash_MessageLoop_Impl() { | 47 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 | 48 // It is a no-op if either Run() hasn't been called or Quit() has been called |
| 52 // to balance the call to Run(). | 49 // to balance the call to Run(). |
| 53 InternalQuit(PP_ERROR_ABORTED); | 50 InternalQuit(PP_ERROR_ABORTED); |
| 54 } | 51 } |
| 55 | 52 |
| 56 // static | 53 // static |
| 57 PP_Resource PPB_Flash_MessageLoop_Impl::Create(PP_Instance instance) { | 54 PP_Resource PPB_Flash_MessageLoop_Impl::Create(PP_Instance instance) { |
| 58 return (new PPB_Flash_MessageLoop_Impl(instance))->GetReference(); | 55 return (new PPB_Flash_MessageLoop_Impl(instance))->GetReference(); |
| 59 } | 56 } |
| 60 | 57 |
| 61 PPB_Flash_MessageLoop_API* | 58 PPB_Flash_MessageLoop_API* |
| 62 PPB_Flash_MessageLoop_Impl::AsPPB_Flash_MessageLoop_API() { | 59 PPB_Flash_MessageLoop_Impl::AsPPB_Flash_MessageLoop_API() { |
| 63 return this; | 60 return this; |
| 64 } | 61 } |
| 65 | 62 |
| 66 int32_t PPB_Flash_MessageLoop_Impl::Run() { | 63 int32_t PPB_Flash_MessageLoop_Impl::Run() { |
| 67 return InternalRun(RunFromHostProxyCallback()); | 64 return InternalRun(RunFromHostProxyCallback()); |
| 68 } | 65 } |
| 69 | 66 |
| 70 void PPB_Flash_MessageLoop_Impl::RunFromHostProxy( | 67 void PPB_Flash_MessageLoop_Impl::RunFromHostProxy( |
| 71 const RunFromHostProxyCallback& callback) { | 68 const RunFromHostProxyCallback& callback) { |
| 72 InternalRun(callback); | 69 InternalRun(callback); |
| 73 } | 70 } |
| 74 | 71 |
| 75 void PPB_Flash_MessageLoop_Impl::Quit() { | 72 void PPB_Flash_MessageLoop_Impl::Quit() { InternalQuit(PP_OK); } |
| 76 InternalQuit(PP_OK); | |
| 77 } | |
| 78 | 73 |
| 79 int32_t PPB_Flash_MessageLoop_Impl::InternalRun( | 74 int32_t PPB_Flash_MessageLoop_Impl::InternalRun( |
| 80 const RunFromHostProxyCallback& callback) { | 75 const RunFromHostProxyCallback& callback) { |
| 81 if (state_->run_called()) { | 76 if (state_->run_called()) { |
| 82 if (!callback.is_null()) | 77 if (!callback.is_null()) |
| 83 callback.Run(PP_ERROR_FAILED); | 78 callback.Run(PP_ERROR_FAILED); |
| 84 return PP_ERROR_FAILED; | 79 return PP_ERROR_FAILED; |
| 85 } | 80 } |
| 86 state_->set_run_called(); | 81 state_->set_run_called(); |
| 87 state_->set_run_callback(callback); | 82 state_->set_run_callback(callback); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 105 state_->set_quit_called(); | 100 state_->set_quit_called(); |
| 106 state_->set_result(result); | 101 state_->set_result(result); |
| 107 | 102 |
| 108 base::MessageLoop::current()->QuitNow(); | 103 base::MessageLoop::current()->QuitNow(); |
| 109 | 104 |
| 110 if (!state_->run_callback().is_null()) | 105 if (!state_->run_callback().is_null()) |
| 111 state_->run_callback().Run(result); | 106 state_->run_callback().Run(result); |
| 112 } | 107 } |
| 113 | 108 |
| 114 } // namespace content | 109 } // namespace content |
| OLD | NEW |