| 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_
|
|
|