| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 return new AsyncMethodRunner(object, method); | 49 return new AsyncMethodRunner(object, method); |
| 50 } | 50 } |
| 51 | 51 |
| 52 ~AsyncMethodRunner() {} | 52 ~AsyncMethodRunner() {} |
| 53 | 53 |
| 54 // Schedules to run the method asynchronously. Do nothing if it's already | 54 // Schedules to run the method asynchronously. Do nothing if it's already |
| 55 // scheduled. If it's suspended, remember to schedule to run the method when | 55 // scheduled. If it's suspended, remember to schedule to run the method when |
| 56 // resume() is called. | 56 // resume() is called. |
| 57 void RunAsync() { | 57 void RunAsync() { |
| 58 if (suspended_) { | 58 if (suspended_) { |
| 59 ASSERT(!timer_.IsActive()); | 59 DCHECK(!timer_.IsActive()); |
| 60 run_when_resumed_ = true; | 60 run_when_resumed_ = true; |
| 61 return; | 61 return; |
| 62 } | 62 } |
| 63 | 63 |
| 64 // FIXME: runAsync should take a TraceLocation and pass it to timer here. | 64 // FIXME: runAsync should take a TraceLocation and pass it to timer here. |
| 65 if (!timer_.IsActive()) | 65 if (!timer_.IsActive()) |
| 66 timer_.StartOneShot(0, BLINK_FROM_HERE); | 66 timer_.StartOneShot(0, BLINK_FROM_HERE); |
| 67 } | 67 } |
| 68 | 68 |
| 69 // If it's scheduled to run the method, cancel it and remember to schedule | 69 // If it's scheduled to run the method, cancel it and remember to schedule |
| (...skipping 20 matching lines...) Expand all Loading... |
| 90 if (!run_when_resumed_) | 90 if (!run_when_resumed_) |
| 91 return; | 91 return; |
| 92 | 92 |
| 93 run_when_resumed_ = false; | 93 run_when_resumed_ = false; |
| 94 // FIXME: resume should take a TraceLocation and pass it to timer here. | 94 // FIXME: resume should take a TraceLocation and pass it to timer here. |
| 95 timer_.StartOneShot(0, BLINK_FROM_HERE); | 95 timer_.StartOneShot(0, BLINK_FROM_HERE); |
| 96 } | 96 } |
| 97 | 97 |
| 98 void Stop() { | 98 void Stop() { |
| 99 if (suspended_) { | 99 if (suspended_) { |
| 100 ASSERT(!timer_.IsActive()); | 100 DCHECK(!timer_.IsActive()); |
| 101 run_when_resumed_ = false; | 101 run_when_resumed_ = false; |
| 102 suspended_ = false; | 102 suspended_ = false; |
| 103 return; | 103 return; |
| 104 } | 104 } |
| 105 | 105 |
| 106 ASSERT(!run_when_resumed_); | 106 DCHECK(!run_when_resumed_); |
| 107 timer_.Stop(); | 107 timer_.Stop(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 bool IsActive() const { return timer_.IsActive(); } | 110 bool IsActive() const { return timer_.IsActive(); } |
| 111 | 111 |
| 112 DEFINE_INLINE_TRACE() { visitor->Trace(object_); } | 112 DEFINE_INLINE_TRACE() { visitor->Trace(object_); } |
| 113 | 113 |
| 114 private: | 114 private: |
| 115 AsyncMethodRunner(TargetClass* object, TargetMethod method) | 115 AsyncMethodRunner(TargetClass* object, TargetMethod method) |
| 116 : timer_(this, &AsyncMethodRunner<TargetClass>::Fired), | 116 : timer_(this, &AsyncMethodRunner<TargetClass>::Fired), |
| 117 object_(object), | 117 object_(object), |
| 118 method_(method), | 118 method_(method), |
| 119 suspended_(false), | 119 suspended_(false), |
| 120 run_when_resumed_(false) {} | 120 run_when_resumed_(false) {} |
| 121 | 121 |
| 122 void Fired(TimerBase*) { (object_->*method_)(); } | 122 void Fired(TimerBase*) { (object_->*method_)(); } |
| 123 | 123 |
| 124 Timer<AsyncMethodRunner<TargetClass>> timer_; | 124 Timer<AsyncMethodRunner<TargetClass>> timer_; |
| 125 | 125 |
| 126 Member<TargetClass> object_; | 126 Member<TargetClass> object_; |
| 127 TargetMethod method_; | 127 TargetMethod method_; |
| 128 | 128 |
| 129 bool suspended_; | 129 bool suspended_; |
| 130 bool run_when_resumed_; | 130 bool run_when_resumed_; |
| 131 }; | 131 }; |
| 132 | 132 |
| 133 } // namespace blink | 133 } // namespace blink |
| 134 | 134 |
| 135 #endif | 135 #endif |
| OLD | NEW |