Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_DELAYED_SWITCH_H_ | |
| 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_DELAYED_SWITCH_H_ | |
| 7 | |
| 8 #include "public/platform/WebCommon.h" | |
| 9 #include "base/callback.h" | |
| 10 #include "base/memory/weak_ptr.h" | |
| 11 #include "base/time/time.h" | |
| 12 #include "platform/scheduler/base/cancelable_closure_holder.h" | |
| 13 | |
| 14 namespace base { | |
| 15 class TaskRunner; | |
| 16 } | |
| 17 | |
| 18 namespace blink { | |
| 19 namespace scheduler { | |
| 20 | |
| 21 // This class is designed to proxy calls to |Enable| and |Disable| and | |
| 22 // delay call to |Disable| for |disable_delay| time. | |
| 23 // It forwards calls to |enable_callback| and |disable_callback| accouting | |
| 24 // for required delay. | |
| 25 // NOTE: This class is main-thread only. | |
| 26 class BLINK_PLATFORM_EXPORT DelayedSwitch { | |
|
Sami
2016/09/29 13:36:07
bikeshed: DebouncedSwitch might be a more accurate
altimin
2016/09/29 16:29:42
Acknowledged.
| |
| 27 public: | |
| 28 DelayedSwitch( | |
| 29 base::TaskRunner* task_runner, | |
|
alex clarke (OOO till 29th)
2016/09/29 11:16:53
Any particular reason for using base::TaskRunner i
altimin
2016/09/29 16:29:43
Acknowledged.
| |
| 30 base::TimeDelta disable_delay, | |
| 31 base::Closure enable_callback, | |
| 32 base::Closure disable_callback); | |
| 33 ~DelayedSwitch(); | |
| 34 | |
| 35 void Enable(); | |
|
alex clarke (OOO till 29th)
2016/09/29 11:16:53
In some ways I like Enable/Disable but the the con
altimin
2016/09/29 16:29:43
Done.
| |
| 36 | |
| 37 void Disable(); | |
| 38 | |
| 39 // Switch is disabled by default. | |
| 40 bool IsEnabled() const; | |
| 41 | |
| 42 private: | |
| 43 enum class State { | |
| 44 ENABLED, DISABLED | |
| 45 }; | |
| 46 | |
| 47 void DoDisable(); | |
| 48 | |
| 49 State state_; | |
| 50 | |
| 51 base::TaskRunner* task_runner_; // NOT OWNED | |
|
alex clarke (OOO till 29th)
2016/09/29 11:16:53
This should be a scoped_refptr<>
Sami
2016/09/29 13:36:07
+1, also pass it in as one in the constructor to m
altimin
2016/09/29 16:29:42
Acknowledged.
| |
| 52 | |
| 53 base::TimeDelta disable_delay_; | |
| 54 | |
| 55 base::Closure enable_callback_; | |
| 56 base::Closure disable_callback_; | |
| 57 | |
| 58 CancelableClosureHolder delayed_disable_task_; | |
| 59 bool has_disable_task_queued_; | |
| 60 | |
| 61 base::WeakPtrFactory<DelayedSwitch> weak_ptr_factory_; | |
| 62 }; | |
|
alex clarke (OOO till 29th)
2016/09/29 11:16:53
DISALLOW_COPY_AND_ASSIGN(DelayedSwitch);
altimin
2016/09/29 16:29:42
Acknowledged.
| |
| 63 | |
| 64 } // namespace scheduler | |
| 65 } // namespace blink | |
| 66 | |
| 67 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_DELAYED_SWITCH_H_ | |
| 68 | |
| OLD | NEW |