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

Side by Side Diff: components/scheduler/base/time_domain.h

Issue 2155143002: Fix a bug that could occasionaly cause setInterval to stop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed ThrottledTimeDomain to be based on RealTimeDomain Created 4 years, 5 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 COMPONENTS_SCHEDULER_BASE_TIME_DOMAIN_H_ 5 #ifndef COMPONENTS_SCHEDULER_BASE_TIME_DOMAIN_H_
6 #define COMPONENTS_SCHEDULER_BASE_TIME_DOMAIN_H_ 6 #define COMPONENTS_SCHEDULER_BASE_TIME_DOMAIN_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 virtual ~TimeDomain(); 43 virtual ~TimeDomain();
44 44
45 // Returns a LazyNow that evaluate this TimeDomain's Now. Can be called from 45 // Returns a LazyNow that evaluate this TimeDomain's Now. Can be called from
46 // any thread. 46 // any thread.
47 // TODO(alexclarke): Make this main thread only. 47 // TODO(alexclarke): Make this main thread only.
48 virtual LazyNow CreateLazyNow() const = 0; 48 virtual LazyNow CreateLazyNow() const = 0;
49 49
50 // Evaluate this TimeDomain's Now. Can be called from any thread. 50 // Evaluate this TimeDomain's Now. Can be called from any thread.
51 virtual base::TimeTicks Now() const = 0; 51 virtual base::TimeTicks Now() const = 0;
52 52
53 // Computes a runtime which is >= |time_domain_now| + |delay|. This is used to
54 // allow the TimeDomain to decide if the real or virtual time should be used
55 // when computing the task run time. This can be called from any thread.
56 virtual base::TimeTicks ComputeDelayedRunTime(
57 base::TimeTicks time_domain_now,
58 base::TimeDelta delay) const = 0;
59
60 // Some TimeDomains support virtual time, this method tells us to advance time 53 // Some TimeDomains support virtual time, this method tells us to advance time
61 // if possible and return true if time was advanced. 54 // if possible and return true if time was advanced.
62 virtual bool MaybeAdvanceTime() = 0; 55 virtual bool MaybeAdvanceTime() = 0;
63 56
64 // Returns the name of this time domain for tracing. 57 // Returns the name of this time domain for tracing.
65 virtual const char* GetName() const = 0; 58 virtual const char* GetName() const = 0;
66 59
67 // If there is a scheduled delayed task, |out_time| is set to the scheduled 60 // If there is a scheduled delayed task, |out_time| is set to the scheduled
68 // runtime for the next one and it returns true. Returns false otherwise. 61 // runtime for the next one and it returns true. Returns false otherwise.
69 bool NextScheduledRunTime(base::TimeTicks* out_time) const; 62 bool NextScheduledRunTime(base::TimeTicks* out_time) const;
70 63
64 // Clears expired entries from |delayed_wakeup_multimap_|. Caution needs to be
65 // taken to ensure TaskQueueImpl::UpdateDelayedWorkQueue or
66 // TaskQueueImpl::Pump is called on the affected queues.
67 void ClearExpiredWakeups();
rmcilroy 2016/07/18 15:22:57 Did this need to be moved? I don't see it being us
alex clarke (OOO till 29th) 2016/07/18 15:35:52 I made it public.
rmcilroy 2016/07/18 16:01:42 Right, my point was why did you need to make it Pu
alex clarke (OOO till 29th) 2016/07/18 16:06:38 It's used by ThrottlingHelper::PumpThrottledTasks.
rmcilroy 2016/07/18 16:10:44 Ahh I see. I think it's better now that it's expli
68
71 protected: 69 protected:
72 friend class internal::TaskQueueImpl; 70 friend class internal::TaskQueueImpl;
73 friend class TaskQueueManager; 71 friend class TaskQueueManager;
74 72
75 void AsValueInto(base::trace_event::TracedValue* state) const; 73 void AsValueInto(base::trace_event::TracedValue* state) const;
76 74
77 // Migrates |queue| from this time domain to |destination_time_domain|. 75 // Migrates |queue| from this time domain to |destination_time_domain|.
78 void MigrateQueue(internal::TaskQueueImpl* queue, 76 void MigrateQueue(internal::TaskQueueImpl* queue,
79 TimeDomain* destination_time_domain); 77 TimeDomain* destination_time_domain);
80 78
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 virtual void AsValueIntoInternal( 120 virtual void AsValueIntoInternal(
123 base::trace_event::TracedValue* state) const = 0; 121 base::trace_event::TracedValue* state) const = 0;
124 122
125 // Call TaskQueueImpl::UpdateDelayedWorkQueue for each queue where the delay 123 // Call TaskQueueImpl::UpdateDelayedWorkQueue for each queue where the delay
126 // has elapsed. 124 // has elapsed.
127 void WakeupReadyDelayedQueues( 125 void WakeupReadyDelayedQueues(
128 LazyNow* lazy_now, 126 LazyNow* lazy_now,
129 bool should_trigger_wakeup, 127 bool should_trigger_wakeup,
130 const internal::TaskQueueImpl::Task* previous_task); 128 const internal::TaskQueueImpl::Task* previous_task);
131 129
132 protected:
133 // Clears expired entries from |delayed_wakeup_multimap_|. Caution needs to be
134 // taken to ensure TaskQueueImpl::UpdateDelayedWorkQueue or
135 // TaskQueueImpl::Pump is called on the affected queues.
136 void ClearExpiredWakeups();
137
138 private: 130 private:
139 void MoveNewlyUpdatableQueuesIntoUpdatableQueueSet(); 131 void MoveNewlyUpdatableQueuesIntoUpdatableQueueSet();
140 132
141 typedef std::multimap<base::TimeTicks, internal::TaskQueueImpl*> 133 typedef std::multimap<base::TimeTicks, internal::TaskQueueImpl*>
142 DelayedWakeupMultimap; 134 DelayedWakeupMultimap;
143 135
144 DelayedWakeupMultimap delayed_wakeup_multimap_; 136 DelayedWakeupMultimap delayed_wakeup_multimap_;
145 137
146 // This lock guards only |newly_updatable_|. It's not expected to be heavily 138 // This lock guards only |newly_updatable_|. It's not expected to be heavily
147 // contended. 139 // contended.
148 base::Lock newly_updatable_lock_; 140 base::Lock newly_updatable_lock_;
149 std::vector<internal::TaskQueueImpl*> newly_updatable_; 141 std::vector<internal::TaskQueueImpl*> newly_updatable_;
150 142
151 // Set of task queues with avaliable work on the incoming queue. This should 143 // Set of task queues with avaliable work on the incoming queue. This should
152 // only be accessed from the main thread. 144 // only be accessed from the main thread.
153 std::set<internal::TaskQueueImpl*> updatable_queue_set_; 145 std::set<internal::TaskQueueImpl*> updatable_queue_set_;
154 146
155 Observer* observer_; // NOT OWNED. 147 Observer* observer_; // NOT OWNED.
156 148
157 base::ThreadChecker main_thread_checker_; 149 base::ThreadChecker main_thread_checker_;
158 150
159 DISALLOW_COPY_AND_ASSIGN(TimeDomain); 151 DISALLOW_COPY_AND_ASSIGN(TimeDomain);
160 }; 152 };
161 153
162 } // namespace scheduler 154 } // namespace scheduler
163 155
164 #endif // COMPONENTS_SCHEDULER_BASE_TIME_DOMAIN_H_ 156 #endif // COMPONENTS_SCHEDULER_BASE_TIME_DOMAIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698