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 |