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

Unified Diff: third_party/WebKit/Source/platform/scheduler/base/delayed_switch.h

Issue 2383473002: [scheduler] Teach scheduler about audio state (Closed)
Patch Set: Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/scheduler/base/delayed_switch.h
diff --git a/third_party/WebKit/Source/platform/scheduler/base/delayed_switch.h b/third_party/WebKit/Source/platform/scheduler/base/delayed_switch.h
new file mode 100644
index 0000000000000000000000000000000000000000..479e782b25414940490e0058b0acaeed79c76995
--- /dev/null
+++ b/third_party/WebKit/Source/platform/scheduler/base/delayed_switch.h
@@ -0,0 +1,68 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_DELAYED_SWITCH_H_
+#define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_DELAYED_SWITCH_H_
+
+#include "public/platform/WebCommon.h"
+#include "base/callback.h"
+#include "base/memory/weak_ptr.h"
+#include "base/time/time.h"
+#include "platform/scheduler/base/cancelable_closure_holder.h"
+
+namespace base {
+class TaskRunner;
+}
+
+namespace blink {
+namespace scheduler {
+
+// This class is designed to proxy calls to |Enable| and |Disable| and
+// delay call to |Disable| for |disable_delay| time.
+// It forwards calls to |enable_callback| and |disable_callback| accouting
+// for required delay.
+// NOTE: This class is main-thread only.
+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.
+ public:
+ DelayedSwitch(
+ 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.
+ base::TimeDelta disable_delay,
+ base::Closure enable_callback,
+ base::Closure disable_callback);
+ ~DelayedSwitch();
+
+ 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.
+
+ void Disable();
+
+ // Switch is disabled by default.
+ bool IsEnabled() const;
+
+ private:
+ enum class State {
+ ENABLED, DISABLED
+ };
+
+ void DoDisable();
+
+ State state_;
+
+ 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.
+
+ base::TimeDelta disable_delay_;
+
+ base::Closure enable_callback_;
+ base::Closure disable_callback_;
+
+ CancelableClosureHolder delayed_disable_task_;
+ bool has_disable_task_queued_;
+
+ base::WeakPtrFactory<DelayedSwitch> weak_ptr_factory_;
+};
alex clarke (OOO till 29th) 2016/09/29 11:16:53 DISALLOW_COPY_AND_ASSIGN(DelayedSwitch);
altimin 2016/09/29 16:29:42 Acknowledged.
+
+} // namespace scheduler
+} // namespace blink
+
+#endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_DELAYED_SWITCH_H_
+

Powered by Google App Engine
This is Rietveld 408576698