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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « media/base/simple_state_machine.h ('k') | media/base/state.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 MEDIA_BASE_STATE_H_
6 #define MEDIA_BASE_STATE_H_
7
8 #include <unordered_set>
9
10 #include "base/memory/ref_counted.h"
11 #include "media/base/media_export.h"
12
13 namespace media {
14
15 // Subclass this to include actual state + getters and setters. Setters will
16 // call StateChanged() as needed.
17 // TODO(liberato): StatePartition? StateGroup?
18 class MEDIA_EXPORT State : public base::RefCountedThreadSafe<State> {
19 public:
20 // Client (state machine, probably) that's notified about state
21 // changes so that it can schedule state machine runs.
22 class Client {
23 public:
24 virtual ~Client() {}
25
26 // Notify the client that some property has changed.
27 virtual void OnStateChanged() = 0;
28 };
29
30 public:
31 // Add a client to us. Must be valid until we're destroyed, or until
32 // it's unregistered.
33 void RegisterClient(Client* client);
34
35 // Unregister a previously-registered client.
36 void UnregisterClient(Client* client);
37
38 protected:
39 State();
40 virtual ~State();
41
42 friend class base::RefCountedThreadSafe<State>;
43
44 // Called by subclass to notify that a state has changed. This can
45 // happen in response to a setter, or if the state changes by itself
46 // (such as state subclasses that provide access to external state).
47 void StateChanged();
48
49 private:
50 std::unordered_set<Client*> clients_;
51
52 DISALLOW_COPY_AND_ASSIGN(State);
53 };
54
55 } // namespace media
56
57 #endif // MEDIA_BASE_STATE_H_
OLDNEW
« 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