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

Unified Diff: media/base/state_machine.cc

Issue 2568663002: [WIP] - trying out some state machine ideas.
Patch Set: added SimpleStateMachine, updated example Created 4 years 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
« no previous file with comments | « media/base/state_machine.h ('k') | media/base/state_machine_driver.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/state_machine.cc
diff --git a/media/base/state_machine.cc b/media/base/state_machine.cc
new file mode 100644
index 0000000000000000000000000000000000000000..70fbb2e8e9f3c9991fa4baab8d53be535593d0e7
--- /dev/null
+++ b/media/base/state_machine.cc
@@ -0,0 +1,34 @@
+// 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.
+
+#include "media/base/state_machine.h"
+
+namespace media {
+
+StateMachine::StateMachine() : owner_(nullptr) {}
+
+StateMachine::~StateMachine() {
+ for (scoped_refptr<State> state : states_)
+ state->UnregisterClient(this);
+}
+
+void StateMachine::SetOwner(Owner* owner) {
+ owner_ = owner;
+}
+
+void StateMachine::OnStateChanged() {
+ DCHECK(owner_);
+ owner_->RequestRun(this);
+}
+
+void StateMachine::UsingState(scoped_refptr<State> state) {
+ // TODO(liberato): check for duplicates. Not sure why set doesn't work,
+ // since it seems like there should be a default hash defined for refptr.
+ // maybe define one if not, but probably i just forgot to tell the set
+ // about it.
+ state->RegisterClient(this);
+ states_.push_back(state);
+}
+
+} // namespace media
« no previous file with comments | « media/base/state_machine.h ('k') | media/base/state_machine_driver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698