OLD | NEW |
1 // Copyright 2015 PDFium Authors. All rights reserved. | 1 // Copyright 2015 PDFium 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 TESTING_EMBEDDER_TEST_TIMER_HANDLING_DELEGATE_H_ | 5 #ifndef TESTING_EMBEDDER_TEST_TIMER_HANDLING_DELEGATE_H_ |
6 #define TESTING_EMBEDDER_TEST_TIMER_HANDLING_DELEGATE_H_ | 6 #define TESTING_EMBEDDER_TEST_TIMER_HANDLING_DELEGATE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "embedder_test.h" | 11 #include "embedder_test.h" |
12 | 12 |
13 class EmbedderTestTimerHandlingDelegate : public EmbedderTest::Delegate { | 13 class EmbedderTestTimerHandlingDelegate : public EmbedderTest::Delegate { |
14 public: | 14 public: |
15 int SetTimer(int msecs, TimerCallback fn) override { | 15 int SetTimer(int msecs, TimerCallback fn) override { |
16 expiry_to_timer_map_.insert(std::pair<int, Timer>( | 16 expiry_to_timer_map_.insert(std::pair<int, Timer>( |
17 msecs + imaginary_elapsed_msecs_, Timer(++next_timer_id_, fn))); | 17 msecs + imaginary_elapsed_msecs_, Timer(++next_timer_id_, fn))); |
18 return next_timer_id_; | 18 return next_timer_id_; |
19 } | 19 } |
20 | 20 |
21 void KillTimer(int id) override { | 21 void KillTimer(int id) override { |
22 for (auto iter = expiry_to_timer_map_.begin(); | 22 for (auto iter = expiry_to_timer_map_.begin(); |
23 iter != expiry_to_timer_map_.end(); ++iter) { | 23 iter != expiry_to_timer_map_.end(); ++iter) { |
24 if (iter->second.first == id) { | 24 if (iter->second.first == id) { |
(...skipping 12 matching lines...) Expand all Loading... |
37 } | 37 } |
38 Timer t = iter->second; | 38 Timer t = iter->second; |
39 if (t.first > imaginary_elapsed_msecs_) { | 39 if (t.first > imaginary_elapsed_msecs_) { |
40 break; | 40 break; |
41 } | 41 } |
42 expiry_to_timer_map_.erase(iter); | 42 expiry_to_timer_map_.erase(iter); |
43 t.second(t.first); // Fire timer. | 43 t.second(t.first); // Fire timer. |
44 } | 44 } |
45 } | 45 } |
46 | 46 |
47 protected: | 47 protected: |
48 using Timer = std::pair<int, TimerCallback>; // ID, callback pair. | 48 using Timer = std::pair<int, TimerCallback>; // ID, callback pair. |
49 std::multimap<int, Timer> expiry_to_timer_map_; // Keyed by timeout. | 49 std::multimap<int, Timer> expiry_to_timer_map_; // Keyed by timeout. |
50 int next_timer_id_ = 0; | 50 int next_timer_id_ = 0; |
51 int imaginary_elapsed_msecs_ = 0; | 51 int imaginary_elapsed_msecs_ = 0; |
52 }; | 52 }; |
53 | 53 |
54 #endif // TESTING_EMBEDDER_TEST_TIMER_HANDLING_DELEGATE_H_ | 54 #endif // TESTING_EMBEDDER_TEST_TIMER_HANDLING_DELEGATE_H_ |
OLD | NEW |