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

Unified Diff: media/base/state.h

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/simple_state_machine.h ('k') | media/base/state.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/state.h
diff --git a/media/base/state.h b/media/base/state.h
new file mode 100644
index 0000000000000000000000000000000000000000..bacdb929bcf95a79a34591e752640278d0d99321
--- /dev/null
+++ b/media/base/state.h
@@ -0,0 +1,57 @@
+// 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 MEDIA_BASE_STATE_H_
+#define MEDIA_BASE_STATE_H_
+
+#include <unordered_set>
+
+#include "base/memory/ref_counted.h"
+#include "media/base/media_export.h"
+
+namespace media {
+
+// Subclass this to include actual state + getters and setters. Setters will
+// call StateChanged() as needed.
+// TODO(liberato): StatePartition? StateGroup?
+class MEDIA_EXPORT State : public base::RefCountedThreadSafe<State> {
+ public:
+ // Client (state machine, probably) that's notified about state
+ // changes so that it can schedule state machine runs.
+ class Client {
+ public:
+ virtual ~Client() {}
+
+ // Notify the client that some property has changed.
+ virtual void OnStateChanged() = 0;
+ };
+
+ public:
+ // Add a client to us. Must be valid until we're destroyed, or until
+ // it's unregistered.
+ void RegisterClient(Client* client);
+
+ // Unregister a previously-registered client.
+ void UnregisterClient(Client* client);
+
+ protected:
+ State();
+ virtual ~State();
+
+ friend class base::RefCountedThreadSafe<State>;
+
+ // Called by subclass to notify that a state has changed. This can
+ // happen in response to a setter, or if the state changes by itself
+ // (such as state subclasses that provide access to external state).
+ void StateChanged();
+
+ private:
+ std::unordered_set<Client*> clients_;
+
+ DISALLOW_COPY_AND_ASSIGN(State);
+};
+
+} // namespace media
+
+#endif // MEDIA_BASE_STATE_H_
« no previous file with comments | « media/base/simple_state_machine.h ('k') | media/base/state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698