| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 TONIC_DART_MESSAGE_HANDLER_H_ | 5 #ifndef TONIC_DART_MESSAGE_HANDLER_H_ |
| 6 #define TONIC_DART_MESSAGE_HANDLER_H_ | 6 #define TONIC_DART_MESSAGE_HANDLER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "dart/runtime/include/dart_api.h" | 10 #include "dart/runtime/include/dart_api.h" |
| 11 | 11 |
| 12 namespace tonic { | 12 namespace tonic { |
| 13 class DartState; | 13 class DartState; |
| 14 | 14 |
| 15 class DartMessageHandler { | 15 class DartMessageHandler { |
| 16 public: | 16 public: |
| 17 DartMessageHandler(); | 17 DartMessageHandler(); |
| 18 ~DartMessageHandler(); | 18 ~DartMessageHandler(); |
| 19 | 19 |
| 20 // Messages for the current isolate will be scheduled on |runner|. | 20 // Messages for the current isolate will be scheduled on |runner|. |
| 21 void Initialize(const scoped_refptr<base::SingleThreadTaskRunner>& runner); | 21 void Initialize(const scoped_refptr<base::SingleThreadTaskRunner>& runner); |
| 22 | 22 |
| 23 // Request the message loop to quit when isolate exits? Default is true. |
| 24 void set_quit_message_loop_when_isolate_exits( |
| 25 bool quit_message_loop_when_isolate_exits) { |
| 26 quit_message_loop_when_isolate_exits_ = |
| 27 quit_message_loop_when_isolate_exits; |
| 28 } |
| 29 |
| 30 bool quit_message_loop_when_isolate_exits() const { |
| 31 return quit_message_loop_when_isolate_exits_; |
| 32 } |
| 33 |
| 34 // Did the isolate exit? |
| 35 bool isolate_exited() const { |
| 36 return isolate_exited_; |
| 37 } |
| 38 |
| 39 // Did the isolate have an uncaught exception error? |
| 40 bool isolate_had_uncaught_exception_error() const { |
| 41 return isolate_had_uncaught_exception_error_; |
| 42 } |
| 43 |
| 23 protected: | 44 protected: |
| 24 // Called from an unknown thread for each message. | 45 // Called from an unknown thread for each message. |
| 25 void OnMessage(DartState* dart_state); | 46 void OnMessage(DartState* dart_state); |
| 26 // By default, called on the task runner's thread for each message. | 47 // By default, called on the task runner's thread for each message. |
| 27 void OnHandleMessage(DartState* dart_state); | 48 void OnHandleMessage(DartState* dart_state); |
| 28 | 49 |
| 29 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const { | 50 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const { |
| 30 return task_runner_; | 51 return task_runner_; |
| 31 } | 52 } |
| 32 | 53 |
| 33 bool handled_first_message() const { | 54 bool handled_first_message() const { |
| 34 return handled_first_message_; | 55 return handled_first_message_; |
| 35 } | 56 } |
| 36 | 57 |
| 37 void set_handled_first_message(bool handled_first_message) { | 58 void set_handled_first_message(bool handled_first_message) { |
| 38 handled_first_message_ = handled_first_message; | 59 handled_first_message_ = handled_first_message; |
| 39 } | 60 } |
| 40 | 61 |
| 41 bool handled_first_message_; | 62 bool handled_first_message_; |
| 63 bool quit_message_loop_when_isolate_exits_; |
| 64 bool isolate_exited_; |
| 65 bool isolate_had_uncaught_exception_error_; |
| 42 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 66 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 43 | 67 |
| 44 private: | 68 private: |
| 45 static void HandleMessage(base::WeakPtr<DartState> dart_state); | 69 static void HandleMessage(base::WeakPtr<DartState> dart_state); |
| 46 static void MessageNotifyCallback(Dart_Isolate dest_isolate); | 70 static void MessageNotifyCallback(Dart_Isolate dest_isolate); |
| 47 }; | 71 }; |
| 48 | 72 |
| 49 } // namespace tonic | 73 } // namespace tonic |
| 50 | 74 |
| 51 #endif // TONIC_DART_MESSAGE_HANDLER_H_ | 75 #endif // TONIC_DART_MESSAGE_HANDLER_H_ |
| OLD | NEW |